Commits

Peter Sanchez committed c29ca8c

Added find_by_hostname to NSZone and NSHost objects

Comments (0)

Files changed (1)

         data = self.parse(xml)
         zone.load(data['zone'])
         return zone
+    
+    def find_by_hostname(self, hostname):
+        host = NSHost(
+            self.user,
+            self.key,
+            is_secure=self.is_secure,
+            is_debug=self.is_debug,
+        )
+        fqdn = '%s.%s' % (hostname, self.domain)
+        return host.find_by_hostname(fqdn, self)
 
 
 class NSHost(ZerigoDNS):
         self.xml_skip = ('id', 'created-at', 'updated-at',)
         self.element = 'hosts'
     
+    def _get_zone_id(self, zone_id):
+        return zone_id.id if isinstance(zone_id, NSZone) else zone_id
+    
     def to_xml(self):
         return self._to_xml({'host': self.get_xml_data()})
     
         if data.has_key('host'):
             data = data.get('host')
         if zone_id is not None:
-            data['zone_id'] = \
-                zone_id.id if isinstance(zone_id, NSZone) else zone_id
+            data['zone_id'] = self._get_zone_id(zone_id)
         host = NSHost(
             self.user,
             self.key,
         return host
     
     def find_all(self, zone_id, opts={}):
-        opts['zone_id'] = \
-            zone_id.id if isinstance(zone_id, NSZone) else zone_id
+        opts['zone_id'] = self._get_zone_id(zone_id)
         return self.hosts(opts=opts)
 
     def hosts(self, opts={}):
         if not opts.has_key('zone_id'):
             opts['zone_id'] = self.zone_id
+        else:
+            opts['zone_id'] = self._get_zone_id(opts['zone_id'])
         xml = self.send_request(method='GET', opts=opts)
         data = self.parse(xml)
         return [
         ]
     
     def find(self, id, zone_id):
-        zone_id = zone_id.id if isinstance(zone_id, NSZone) else zone_id
+        zone_id = self._get_zone_id(zone_id)
         host = NSHost(
             self.user,
             self.key,
         data = self.parse(xml)
         self.load(data['host'])
         return self
+    
+    def find_by_hostname(self, hostname, zone_id):
+        zone_id = self._get_zone_id(zone_id)
+        host = NSHost(
+            self.user,
+            self.key,
+            data={'zone_id': zone_id,},
+            is_secure=self.is_secure,
+            is_debug=self.is_debug
+        )
+        xml = host.send_request(method='GET', opts={'fqdn': hostname})
+        data = self.parse(xml)
+        return [
+            NSHost(
+                self.user,
+                self.key,
+                data=zdata['host'],
+                is_secure=self.is_secure,
+                is_debug=self.is_debug,
+            ) for zdata in data.get('hosts', [])
+        ]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.