def run_backup(project_id, backup_storage_id): cluster = Cluster.objects.get(id=project_id) steps = cluster.get_steps('cluster-backup') cluster.configs = cluster.load_config_file() hostname = Setting.objects.get(key='local_hostname') domain_suffix = Setting.objects.get(key="domain_suffix") project = Project.objects.get(id=project_id) print(project) backup_storage = BackupStorage.objects.get(id=backup_storage_id) extra_vars = { "cluster_name": cluster.name, "local_hostname": hostname.value, "domain_suffix": domain_suffix.value, "APP_DOMAIN": "apps.{}.{}".format(cluster.name, domain_suffix.value), } extra_vars.update(cluster.configs) run_playbooks(steps, extra_vars, project) now = datetime.datetime.now().strftime('%Y-%m-%d') client = StorageClient(backup_storage) client.check_valid() file_name = cluster.name + '-' + str(now) + '.zip' file_remote_path = cluster.name + '/' + file_name result, message = client.upload_file( "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip", file_remote_path) if result: clusterBackup = ClusterBackup(name=file_name, size=10, folder=file_remote_path, backup_storage_id=backup_storage_id, project_id=project_id) clusterBackup.save() return True
def post(self, request, **kwargs): client = StorageClient(request.data) valid = client.check_valid() response = HttpResponse() result = {"message": '验证成功!', "success": True} if valid: response.write(json.dumps(result)) else: result['message'] = '验证失败!' result['success'] = False response.write(json.dumps(result)) return response
def upload_backup_file(project_id, backup_storage_id): cluster = Cluster.objects.get(id=project_id) backup_storage = BackupStorage.objects.get(id=backup_storage_id) now = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S') client = StorageClient(backup_storage) client.check_valid() file_name = cluster.name + '-' + str(now) + '.zip' file_remote_path = cluster.name + '/' + file_name result, message = client.upload_file( "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip", file_remote_path) if result: clusterBackup = ClusterBackup(name=file_name, size=10, folder=file_remote_path, backup_storage_id=backup_storage_id, project_id=project_id) clusterBackup.save() return True else: return False
def run_backup(project_id, backup_storage_id): cluster = Cluster.objects.get(id=project_id) steps = cluster.get_steps('cluster-backup') backup_storage = BackupStorage.objects.get(id=backup_storage_id) project = Project.objects.get(id=project_id) extra_vars = {"cluster_name": cluster.name} extra_vars.update(cluster.configs) run_playbooks(steps, extra_vars, project) now = datetime.now().strftime('%Y-%m-%d-%H-%M-%S') client = StorageClient(backup_storage) client.check_valid() file_name = cluster.name + '-' + str(now) + '.zip' file_remote_path = cluster.name + '/' + file_name result, message = client.upload_file( "/etc/ansible/roles/cluster-backup/files/cluster-backup.zip", file_remote_path) if result: clusterBackup = ClusterBackup(name=file_name, size=10, folder=file_remote_path, backup_storage_id=backup_storage_id, project_id=project_id) clusterBackup.save() return True