Ejemplo n.º 1
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)
    def get_backups(self):
        """Retrieves all backups associated with this virtual_machine.

        Returns:
            list: List of backup objects
        """
        method_url = "{}/{}/backups".format(URL, self.data["id"])
        backup_data = self._client.do_get(method_url).get("backups", [])

        backup_objs = []
        for backup in backup_data:
            obj = backups.Backups(self._connection).get_by_id(backup["id"])
            backup_objs.append(obj)

        return backup_objs
    def create_backup(self,
                      backup_name,
                      cluster=None,
                      app_consistent=False,
                      consistency_type=None,
                      retention=0,
                      timeout=-1):
        """Backs up a virtual machine.

        Args:
            backup_name: The name of the new backup created from this action.
            cluster: Destination OmnistackCluster object/name.
            app_consistent: An indicator to show if the backup represents
              a snapshot of a virtual machine with data that was first flushed to disk.
            consistency_type: The consistency type of the backup.
            retention: The number of minutes to keep backups.
            timeout: Time out for the request in seconds.

        Returns:
            Backup object: object of the newly created backup.
        """
        method_url = "{}/{}/backup".format(URL, self.data["id"])

        if cluster and not isinstance(cluster,
                                      omnistack_clusters.OmnistackCluster):
            # if passed name of the omnistack cluster
            clusters_obj = omnistack_clusters.OmnistackClusters(
                self._connection)
            cluster = clusters_obj.get_by_name(cluster)

        data = {
            "backup_name": backup_name,
            "app_consistent": app_consistent,
            "consistency_type": consistency_type,
            "retention": retention
        }

        if cluster:
            data["destination_id"] = cluster.data["id"]

        backup = self._client.do_post(method_url, data, timeout, None)[0]
        return backups.Backups(self._connection).get_by_id(backup["object_id"])
Ejemplo n.º 4
0
 def setUp(self):
     self.connection = Connection('127.0.0.1')
     self.connection._access_token = "123456789"
     self.backups = backups.Backups(self.connection)