Peter Sanchez avatar Peter Sanchez committed e9c13da

Began adding support for ZoneTemplates

Comments (0)

Files changed (2)

zerigodns/__init__.py

 ''' Copyright 2009 Peter Sanchez <petersanchez@gmail.com>.  
     See BSD-LICENSE for license information.
 '''
-from api import ZerigoError, ZerigoNotFound, NSZone, NSHost
+from api import ZerigoError, ZerigoNotFound, NSZone, NSHost, \
+                NSZoneTemplate
                 is_debug=self.is_debug,
             ) for zdata in data.get('hosts', [])
         ]
+
+
+class NSZoneTemplate(ZerigoDNS):
+    ''' Class to manage zone templates 
+    '''
+    def __init__(self, *args, **kwargs):
+        super(NSZoneTemplate, self).__init__(*args, **kwargs)
+        self.xml_skip = ('id', 'created-at', 'updated-at',)
+        self.element = 'zone_templates'
+    
+    def to_xml(self):
+        return self._to_xml({'zone-template': self.get_xml_data()})
+
+    def build_blank_template(self):
+        self.load(self.get_blank()['zone-template'])
+    
+    def create(self, data, load_blank=False):
+        if data.has_key('zone-template'):
+            data = data.get('zone-template')
+        template = NSZoneTemplate(
+            self.user,
+            self.key,
+            data=data,
+            is_secure=self.is_secure,
+            is_debug=self.is_debug,
+        )
+        if load_blank:
+            template.build_blank_template()
+            template.load(data, reset=False)
+        template.save()
+        return template
+    
+    def find_all(self, opts={}):
+        return self.templates(opts=opts)
+
+    def templates(self, opts={}):
+        xml = self.send_request(opts=opts)
+        data = self.parse(xml)
+        return [
+            NSZoneTemplate(
+                self.user,
+                self.key,
+                data=zdata['zone-template'],
+                is_secure=self.is_secure,
+                is_debug=self.is_debug,
+            ) for zdata in data.get('zone-templates', [])
+        ]
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.