Commits

Shinya Okano committed 5d0b737

get instant templates

  • Participants
  • Parent commits a20b020

Comments (0)

Files changed (2)

File xswizard/api.py

         """
         return self._api.host.get_record(ref)
 
+    def _vm_get_all_records(self):
+        """
+        xenapi.VM.get_all_records
+        """
+        return self._api.VM.get_all_records()
+
     def _vm_get_record(self, ref):
         """
         xenapi.VM.get_record
         """
         data = self._vm_get_snapshots(vm.ref)
         return [VM(record, self) for record in data]
+
+    def get_all_vms(self):
+        """
+        all vm records
+        """
+        data = self._vm_get_all_records()
+        return [VM(record, self) for record in data]
+
+    def get_all_vm_templates(self):
+        """
+        all vm templates
+        """
+        vms = self.get_all_vms()
+        return filter(lambda vm: vm.is_a_template, vms)
+
+    def get_instant_vm_templates(self):
+        """
+        vm templates not default
+        """
+        vms = self.get_all_vm_templates()
+        return filter(lambda vm: vm.is_instant, vms)

File xswizard/models.py

         return self.record['is_control_domain']
     is_control_domain = property(get_is_control_domain)
 
+    def get_is_a_template(self):
+        return self.record['is_a_template']
+    is_a_template = property(get_is_a_template)
+
+    def get_is_default_template(self):
+        value = self.record['other_config'].get('default_template')
+        return value == 'true'
+    is_default_template = property(get_is_default_template)
+
+    def get_is_instant(self):
+        value = self.record['other_config'].get('instant')
+        return value == 'true'
+    is_instant = property(get_is_instant)
+
     def snapshot(self, name):
         return self.api.snapshot_vm(self, name)