Просмотр исходного кода

Added admin_email support for gcp and aws

Nuwan Goonasekera 6 лет назад
Родитель
Сommit
be51ae5e7a

+ 9 - 1
cloudbridge/providers/aws/resources.py

@@ -1160,7 +1160,15 @@ class AWSDnsZone(BaseDnsZone):
 
     @property
     def admin_email(self):
-        return self._dns_zone.get('Name')
+        comment = self._dns_zone.get('Config', {}).get('Comment')
+        if comment:
+            email_field = comment.split(",")[0].split("=")
+            if email_field[0] == "admin_email":
+                return email_field[1]
+            else:
+                return None
+        else:
+            return None
 
     @property
     def records(self):

+ 6 - 2
cloudbridge/providers/aws/services.py

@@ -1365,11 +1365,15 @@ class AWSDnsZoneService(BaseDnsZoneService):
 
     @dispatch(event="provider.dns.host_zones.create",
               priority=BaseDnsZoneService.STANDARD_EVENT_PRIORITY)
-    def create(self, name):
+    def create(self, name, admin_email):
         AWSDnsZone.assert_valid_resource_name(name)
 
         response = self.provider.dns.client.create_hosted_zone(
-            Name=name, CallerReference=uuid.uuid4().hex)
+            Name=name, CallerReference=uuid.uuid4().hex,
+            HostedZoneConfig={
+                'Comment': 'admin_email=' + admin_email
+            }
+        )
         return AWSDnsZone(self.provider, response.get('HostedZone'))
 
     @dispatch(event="provider.dns.host_zones.delete",

+ 12 - 0
cloudbridge/providers/gcp/resources.py

@@ -2044,6 +2044,18 @@ class GCPDnsZone(BaseDnsZone):
     def name(self):
         return self._dns_zone.get('dnsName')
 
+    @property
+    def admin_email(self):
+        comment = self._dns_zone.get('description')
+        if comment:
+            email_field = comment.split(",")[0].split("=")
+            if email_field[0] == "admin_email":
+                return email_field[1]
+            else:
+                return None
+        else:
+            return None
+
     @property
     def records(self):
         return self._dns_record_container

+ 2 - 2
cloudbridge/providers/gcp/services.py

@@ -1669,13 +1669,13 @@ class GCPDnsZoneService(BaseDnsZoneService):
 
     @dispatch(event="provider.dns.host_zones.create",
               priority=BaseDnsZoneService.STANDARD_EVENT_PRIORITY)
-    def create(self, name):
+    def create(self, name, admin_email):
         GCPDnsZone.assert_valid_resource_name(name)
         body = {
             'kind': 'dns#managedZone',
             'name': cb_helpers.to_resource_name(name),
             'dnsName':  self._get_fully_qualified_dns(name),
-            'description': name,
+            'description': 'admin_email=' + admin_email,
             'visibility': 'public'
         }
         try: