Ejemplo n.º 1
0
def run_restore(cluster_backup_id):
    cluster_backup = ClusterBackup.objects.get(id=cluster_backup_id)
    backup_storage = BackupStorage.objects.get(
        id=cluster_backup.backup_storage_id)
    project = Project.objects.get(id=cluster_backup.project_id)
    cluster = Cluster.objects.get(id=cluster_backup.project_id)
    steps = cluster.get_steps('cluster-restore')
    cluster.configs = cluster.load_config_file()
    client = StorageClient(backup_storage)
    backup_file_path = cluster.name + '/' + cluster_backup.name
    if client.exists(backup_file_path):
        success = client.download_file(
            backup_file_path,
            "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip")
        if success:
            extra_vars = {
                "cluster_name": cluster.name,
            }
            extra_vars.update(cluster.configs)
            run_playbooks(steps, extra_vars, project)
            return True
        else:
            raise Exception('download file failed!')
    else:
        raise Exception('File is not exist!')
def run_restore(cluster_backup_id):
    playbook_name = 'cluster-restore'
    cluster_backup = ClusterBackup.objects.get(id=cluster_backup_id)
    backup_storage = BackupStorage.objects.get(
        id=cluster_backup.backup_storage_id)
    project = Project.objects.get(id=cluster_backup.project_id)
    playbook = project.playbook_set.get(name=playbook_name)
    cluster = Cluster.objects.get(id=cluster_backup.project_id)
    client = StorageClient(backup_storage)
    backup_file_path = cluster.name + '/' + cluster_backup.name
    if client.exists(backup_file_path):
        success = client.download_file(
            backup_file_path,
            "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip")
        if success:
            extra_vars = {
                "cluster_name": cluster.name,
                "NODE_NAME": cluster.name
            }
            _result = playbook.execute(extra_vars=extra_vars)
            if _result:
                return True
            else:
                return False
        else:
            raise Exception('download file failed!')

    else:
        raise Exception('File is not exist!')
Ejemplo n.º 3
0
 def on_restore(self, extra_vars, cluster_backup_id):
     cluster_backup = ClusterBackup.objects.get(id=cluster_backup_id)
     backup_storage = BackupStorage.objects.get(id=cluster_backup.backup_storage_id)
     cluster = self.get_cluster()
     self.steps = cluster.get_steps('cluster-restore')
     client = StorageClient(backup_storage)
     backup_file_path = cluster.name + '/' + cluster_backup.name
     if client.exists(backup_file_path):
         success = client.download_file(backup_file_path,
                                        "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip")
         if success:
             return self.run_playbooks(extra_vars)
         else:
             raise Exception('download file failed!')
     else:
         raise Exception('File is not exist!')