def deploy_on_rds(data): """Deploy the Postgres instance on RDS.""" _cmd = 'python' _cmd_script = '{0}/pgacloud/pgacloud.py'.format(root) _label = None from subprocess import Popen, PIPE _label = data['instance_details']['name'] args = [ _cmd_script, data['cloud'], '--region', str(data['secret']['region']), 'create-instance', '--name', data['instance_details']['name'], '--db-name', data['db_details']['db_name'], '--db-username', data['db_details']['db_username'], '--db-port', str(data['db_details']['db_port']), '--db-version', str(data['instance_details']['db_version']), '--instance-type', data['instance_details']['instance_type'], '--storage-type', data['instance_details']['storage_type'], '--storage-size', str(data['instance_details']['storage_size']), '--public-ip', str(data['instance_details']['public_ip']), ] if data['instance_details']['storage_type'] == 'io1': args.append('--storage-iops') args.append(str(data['instance_details']['storage_IOPS'])) _cmd_msg = '{0} {1} {2}'.format(_cmd, _cmd_script, ' '.join(args)) try: sid = _create_server({ 'gid': data['db_details']['gid'], 'name': data['instance_details']['name'], 'db': data['db_details']['db_name'], 'username': data['db_details']['db_username'], 'port': data['db_details']['db_port'], 'cloud_status': -1 }) p = BatchProcess(desc=CloudProcessDesc( sid, _cmd_msg, data['cloud'], data['instance_details']['name']), cmd=_cmd, args=args) env = dict() env['AWS_ACCESS_KEY_ID'] = data['secret']['access_key'] env['AWS_SECRET_ACCESS_KEY'] = data['secret']['secret_access_key'] if 'session_token' in data['secret'] and\ data['secret']['session_token'] is not None: env['AWS_SESSION_TOKEN'] = data['secret']['session_token'] if 'db_password' in data['db_details']: env['AWS_DATABASE_PASSWORD'] = data['db_details']['db_password'] p.set_env_variables(None, env=env) p.update_server_id(p.id, sid) p.start() return True, p, {'label': _label, 'sid': sid} except Exception as e: current_app.logger.exception(e) return False, None, str(e)
def deploy_on_cloud(): """Deploy on Cloud""" data = json.loads(request.data, encoding='utf-8') from subprocess import Popen, PIPE _cmd = 'python' _cmd_script = '{0}/pgacloud/pgacloud.py'.format(root) args = [ _cmd_script, '--debug', data['cloud'], '--region', str(data['secret']['aws_region']), 'create-instance', '--name', data['instance_details']['aws_name'], '--db-name', data['db_details']['aws_db_name'], '--db-username', data['db_details']['aws_db_username'], '--db-port', str(data['db_details']['aws_db_port']), '--db-version', str(data['instance_details']['aws_db_version']), '--instance-type', data['instance_details']['aws_instance_type'], '--storage-type', data['instance_details']['aws_storage_type'], '--storage-size', str(data['instance_details']['aws_storage_size']), '--public-ip', str(data['instance_details']['aws_public_ip']), ] if data['instance_details']['aws_storage_type'] == 'io1': args.append('--storage-iops') args.append(str(data['instance_details']['aws_storage_IOPS'])) _cmd_msg = '{0} {1} {2}'.format(_cmd, _cmd_script, ' '.join(args)) try: sid = _create_server({ 'gid': data['db_details']['gid'], 'name': data['instance_details']['aws_name'], 'db': data['db_details']['aws_db_name'], 'username': data['db_details']['aws_db_username'], 'port': data['db_details']['aws_db_port'], 'cloud_status': -1 }) p = BatchProcess(desc=CloudProcessDesc( sid, _cmd_msg, data['cloud'], data['instance_details']['aws_name']), cmd=_cmd, args=args) env = dict() env['AWS_ACCESS_KEY_ID'] = data['secret']['aws_access_key'] env['AWS_SECRET_ACCESS_KEY'] = data['secret']['aws_secret_access_key'] if 'aws_session_token' in data['secret'] and\ data['secret']['aws_session_token'] is not None: env['AWS_SESSION_TOKEN'] = data['secret']['aws_session_token'] if 'aws_db_password' in data['db_details']: env['AWS_DATABASE_PASSWORD'] = data['db_details'][ 'aws_db_password'] p.set_env_variables(None, env=env) p.update_server_id(p.id, sid) p.start() except Exception as e: current_app.logger.exception(e) return make_json_response(status=410, success=0, errormsg=str(e)) # Return response return make_json_response(success=1, data={ 'job_id': 1, 'node': { '_id': sid, '_pid': data['db_details']['gid'], 'connected': False, '_type': 'server', 'icon': 'icon-server-cloud-deploy', 'id': 'server_{}'.format(sid), 'inode': True, 'label': data['instance_details']['aws_name'], 'server_type': 'pg', 'module': 'pgadmin.node.server', 'cloud_status': -1 } })
def deploy_on_biganimal(data): """Deploy Postgres instance on BigAnimal""" _cmd = 'python' _cmd_script = '{0}/pgacloud/pgacloud.py'.format(root) _label = data['instance_details']['name'] _private_network = '1' if str( data['instance_details']['cloud_type']) == 'private' else '0' _instance_size = data['instance_details']['instance_size'].split('||')[1] cluster_arch = SINGLE_CLUSTER_ARCH nodes = 1 if data['db_details']['high_availability']: cluster_arch = HA_CLUSTER_ARCH nodes = int(data['db_details']['replicas']) + nodes args = [ _cmd_script, data['cloud'], 'create-instance', '--name', data['instance_details']['name'], '--region', str(data['instance_details']['region']), '--db-type', str(data['db_details']['database_type']), '--db-version', str(data['db_details']['postgres_version']), '--volume-type', str(data['instance_details']['volume_type']), '--volume-properties', str(data['instance_details']['volume_properties']), '--instance-type', str(_instance_size), '--private-network', _private_network, '--cluster-arch', cluster_arch, '--nodes', str(nodes) ] if 'biganimal_public_ip' in data['instance_details']: args.append('--public-ip') args.append(str(data['instance_details']['biganimal_public_ip'])) _cmd_msg = '{0} {1} {2}'.format(_cmd, _cmd_script, ' '.join(args)) try: sid = _create_server({ 'gid': data['db_details']['gid'], 'name': data['instance_details']['name'], 'db': 'edb_admin', 'username': '******', 'port': 5432, 'cloud_status': -1 }) p = BatchProcess(desc=CloudProcessDesc( sid, _cmd_msg, data['cloud'], data['instance_details']['name']), cmd=_cmd, args=args) env = dict() biganimal_obj = pickle.loads(session['biganimal']['provider_obj']) env['BIGANIMAL_ACCESS_KEY'] = biganimal_obj.access_token if 'password' in data['db_details']: env['BIGANIMAL_DATABASE_PASSWORD'] = data['db_details']['password'] p.set_env_variables(None, env=env) p.update_server_id(p.id, sid) p.start() return True, p, {'label': _label, 'sid': sid} except Exception as e: current_app.logger.exception(e) return False, None, str(e)
def deploy_on_azure(data): """Deploy the Postgres instance on Azure.""" _cmd = 'python' _cmd_script = '{0}/pgacloud/pgacloud.py'.format(root) _label = data['instance_details']['name'] if 'high_availability' in data['instance_details']: if data['instance_details']['high_availability']: data['instance_details']['high_availability'] = "ZoneRedundant" else: data['instance_details']['high_availability'] = "Disabled" args = [ _cmd_script, 'azure', '--region', str(data['instance_details']['region']), '--resource-group', data['instance_details']['resource_group'], 'create-instance', '--name', data['instance_details']['name'], '--db-username', data['db_details']['db_username'], '--db-major-version', str(data['instance_details']['db_version']), '--instance_tier_type', data['instance_details']['db_instance_class'], '--instance-type', data['instance_details']['instance_type'], '--storage-size', str(data['instance_details']['storage_size']), '--public-ips', str(data['instance_details']['public_ips']), '--availability-zone', str(data['instance_details']['availability_zone']), '--high-availability', data['instance_details']['high_availability'] ] _cmd_msg = '{0} {1} {2}'.format(_cmd, _cmd_script, ' '.join(args)) try: sid = _create_server({ 'gid': data['db_details']['gid'], 'name': data['instance_details']['name'], 'db': 'postgres', 'username': data['db_details']['db_username'], 'port': 5432, 'cloud_status': -1 }) p = BatchProcess(desc=CloudProcessDesc( sid, _cmd_msg, data['cloud'], data['instance_details']['name']), cmd=_cmd, args=args) env = dict() azure = session['azure']['azure_obj'] env['AZURE_SUBSCRIPTION_ID'] = azure.subscription_id env['AUTH_TYPE'] = data['secret']['auth_type'] env['AZURE_CRED_CACHE_NAME'] = azure.azure_cache_name env['AZURE_CRED_CACHE_LOCATION'] = azure.azure_cache_location if azure.authentication_record_json is not None: env['AUTHENTICATION_RECORD_JSON'] = \ azure.authentication_record_json env['AZURE_TENANT_ID'] = data['secret']['azure_tenant_id'] if 'db_password' in data['db_details']: env['AZURE_DATABASE_PASSWORD'] = data['db_details']['db_password'] p.set_env_variables(None, env=env) p.update_server_id(p.id, sid) p.start() # add pid: cache file dict in session['azure_cache_files_list'] if 'azure_cache_files_list' in session and \ session['azure_cache_files_list'] is not None: session['azure_cache_files_list'][p.id] = azure.azure_cache_name else: session['azure_cache_files_list'] = {p.id: azure.azure_cache_name} del session['azure']['azure_cache_file_name'] return True, p, {'label': _label, 'sid': sid} except Exception as e: current_app.logger.exception(e) return False, None, str(e) finally: del session['azure']['azure_obj']