Exemple #1
0
    def retrieve_backup_data_list(self, verbose=False):
        """

        Argument:
            verbose: boolean flag of listing objects
        """
        if not client.is_container(self.token, self.storage_url,
                                   self.container_name, verify=self.verify):
            return []

        if verbose:
            backup_l = [i for i in client.list_objects(self.token,
                                                       self.storage_url,
                                                       self.container_name,
                                                       verify=self.verify)]
        else:
            backup_l = [i.get('name') for i
                        in client.list_objects(self.token,
                                               self.storage_url,
                                               self.container_name,
                                               verify=self.verify)]
        return backup_l
Exemple #2
0
    def backup_file(self, filename):
        """

        Argument:
            filename: path of backup target file
        """
        object_name = os.path.basename(filename)

        if not client.is_container(self.token, self.storage_url,
                                   self.container_name, verify=self.verify):
            # False is no container
            rc = client.create_container(self.token,
                                         self.storage_url,
                                         self.container_name,
                                         verify=self.verify)
            if not (rc == 201 or rc == 202):
                # 201; Created, 202; Accepted
                raise RuntimeError('Failed to create the container "%s"'
                                   % self.container_name, verify=self.verify)

        objects_list = [object.get('name') for object in
                        client.list_objects(self.token,
                                            self.storage_url,
                                            self.container_name,
                                            verify=self.verify)]

        if object_name in objects_list:
            self.rotate(filename, object_name, objects_list)
        else:
            rc = client.create_object(self.token,
                                      self.storage_url,
                                      self.container_name,
                                      filename,
                                      verify=self.verify)
            if not (rc == 201 or rc == 202):
                raise RuntimeError('Failed to create the object "%s"'
                                   % object_name)
        return True