Пример #1
0
 def setUp(self):
     self.connection = Connection('127.0.0.1')
     self.connection._access_token = "123456789"
     self.machines = machines.VirtualMachines(self.connection)
     self.policies = policies.Policies(self.connection)
     self.datastores = datastores.Datastores(self.connection)
     self.clusters = omnistack_clusters.OmnistackClusters(self.connection)
Пример #2
0
    def restore(self,
                restore_original,
                virtual_machine_name=None,
                datastore=None,
                timeout=-1):
        """Creates a new virtual machine or replaces the original virtual machine from the specified backup

        Args:
           restore_original: If True, Resets the original virtual machine to the same state it was in when the backup was created
                             If False, Creates a new virtual machine from the backup with the provided name, optionally to a different datastore
           virtual_machine_name: The name of the new virtual machine created from this action.
           datastore: Destination datastore object/name.
           timeout: Time out for the request in seconds.

        Returns:
              Virtual machine object

        """
        resource_uri = "{}/{}/restore".format(URL, self.data["id"])
        data = {}
        if not restore_original:
            data["virtual_machine_name"] = virtual_machine_name
            if datastore:
                if not isinstance(datastore, datastores.Datastore):
                    # if passed by datastore name
                    datastore_obj = datastores.Datastores(self._connection)
                    datastore = datastore_obj.get_by_name(datastore)
                data["datastore_id"] = datastore.data["id"]

        flags = {"restore_original": restore_original}
        affected_object = self._client.do_post(resource_uri, data, timeout,
                                               None, flags)[0]
        virtual_machines_obj = virtual_machines.VirtualMachines(
            self._connection)
        return virtual_machines_obj.get_by_id(affected_object["object_id"])
Пример #3
0
 def setUp(self):
     self.connection = Connection('127.0.0.1')
     self.connection._access_token = "123456789"
     self.backups = backups.Backups(self.connection)
     self.datastores = datastores.Datastores(self.connection)
     self.virtual_machines = virtual_machines.VirtualMachines(self.connection)
     self.clusters = omnistack_clusters.OmnistackClusters(self.connection)
     self.cluster_groups = cluster_groups.ClusterGroups(self.connection)
Пример #4
0
    def get_vms(self):
        """Retrieves the virtual machines using this policy.

        Returns:
          list: List of vms.
        """
        method_url = "{}/{}/virtual_machines".format(URL, self.data["id"])
        vm_data = self._client.do_get(method_url).get("virtual_machines", [])

        vms_obj = virtual_machines.VirtualMachines(self._connection)
        vms = []

        for vm in vm_data:
            vms.append(vms_obj.get_by_data(vm))

        return vms