@@ 353,6 353,16 @@ class NSZone(ZerigoDNS):
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):
@@ 363,6 373,9 @@ 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()})
@@ 373,8 386,7 @@ class NSHost(ZerigoDNS):
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,
@@ 389,13 401,14 @@ class NSHost(ZerigoDNS):
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 [
@@ 409,7 422,7 @@ class NSHost(ZerigoDNS):
]
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,
@@ 427,3 440,24 @@ class NSHost(ZerigoDNS):
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', [])
+ ]