def _get_instance_async_response(async_result, projectid, type): response = {} response['kind'] = 'compute#operation' response['id'] = async_result['jobid'] response['operationType'] = type response['name'] = async_result['jobid'] response['insertTime'] = async_result['created'] response['startTime'] = async_result['created'] response['selfLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for('getoperations', projectid=projectid, operationid=async_result['jobid'])) if async_result['jobstatus'] is 0: response['targetLink'] = '' response['status'] = 'PENDING' response['progress'] = 0 elif async_result['jobstatus'] is 1: response['status'] = 'DONE' response['zone'] = urllib.unquote_plus( helpers.get_root_url() + url_for( 'getzone', projectid=projectid, zone=async_result['jobresult']['virtualmachine']['zonename'], )) response['targetLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for( 'getinstance', projectid=projectid, zone=async_result['jobresult']['virtualmachine']['zonename'], instance=async_result['jobresult']['virtualmachine']['name'])) return response
def discovery(): with open(app.config['DATA'] + '/v1.json') as template: discovery_template = json.loads(template.read()) discovery_template['baseUrl'] = helpers.get_root_url() + '/' + app.config['PATH'] discovery_template['basePath'] = '/' + app.config['PATH'] discovery_template['rootUrl'] = helpers.get_root_url() + '/' discovery_template['servicePath'] = app.config['PATH'] return helpers.create_response(data=discovery_template)
def discovery(): with open(app.config['DATA'] + '/v1.json') as template: discovery_template = json.loads(template.read()) discovery_template['baseUrl'] = helpers.get_root_url( ) + '/' + app.config['PATH'] discovery_template['basePath'] = '/' + app.config['PATH'] discovery_template['rootUrl'] = helpers.get_root_url() + '/' discovery_template['servicePath'] = app.config['PATH'] return helpers.create_response(data=discovery_template)
def _get_instance_async_response(async_result, projectid, type): response = {} response['kind'] = 'compute#operation' response['id'] = async_result['jobid'] response['operationType'] = type response['name'] = async_result['jobid'] response['insertTime'] = async_result['created'] response['startTime'] = async_result['created'] response['selfLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for( 'getoperations', projectid=projectid, operationid=async_result['jobid'] )) if async_result['jobstatus'] is 0: response['targetLink'] = '' response['status'] = 'PENDING' response['progress'] = 0 elif async_result['jobstatus'] is 1: response['status'] = 'DONE' response['zone'] = urllib.unquote_plus( helpers.get_root_url() + url_for( 'getzone', projectid=projectid, zone=async_result['jobresult']['virtualmachine']['zonename'], )) response['targetLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for( 'getinstance', projectid=projectid, zone=async_result['jobresult']['virtualmachine']['zonename'], instance=async_result['jobresult']['virtualmachine']['name'])) return response
def _cloudstack_volume_to_gce(cloudstack_response, projectid, zone): response = {} response['kind'] = 'compute#disk' response['id'] = cloudstack_response['id'] response['creationTimestamp'] = cloudstack_response['created'] response['status'] = cloudstack_response['state'].upper() response['name'] = cloudstack_response['name'] response['description'] = cloudstack_response['name'] response['sizeGb'] = cloudstack_response['size'] response['selfLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for('getmachinetype', projectid=projectid, machinetype=cloudstack_response['name'], zone=zone)) response['zone'] = zone return response
def _cloudstack_service_offering_to_gce(cloudstack_response, projectid, zone): response = {} response['kind'] = 'compute#machineType' response['name'] = cloudstack_response['name'] response['id'] = cloudstack_response['id'] response['description'] = cloudstack_response['displaytext'] response['creationTimestamp'] = cloudstack_response['created'] response['guestCpus'] = cloudstack_response['cpunumber'] response['memoryMb'] = cloudstack_response['memory'] response['selfLink'] = urllib.unquote_plus(helpers.get_root_url() + url_for( 'getmachinetype', projectid=projectid, machinetype=cloudstack_response['name'], zone=zone )) response['zone'] = zone return response
def _cloudstack_service_offering_to_gce(cloudstack_response, projectid, zone): response = {} response['kind'] = 'compute#machineType' response['name'] = cloudstack_response['name'] response['id'] = cloudstack_response['id'] response['description'] = cloudstack_response['displaytext'] response['creationTimestamp'] = cloudstack_response['created'] response['guestCpus'] = cloudstack_response['cpunumber'] response['memoryMb'] = cloudstack_response['memory'] response['selfLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for('getmachinetype', projectid=projectid, machinetype=cloudstack_response['name'], zone=zone)) response['zone'] = zone return response
def setglobalmetadata(projectid, authorization): data = json.loads(request.data) publickey_storage[projectid] = data['items'][0]['value'] data = data['items'][0]['value'].split(':')[1] command = 'deleteSSHKeyPair' args = { 'name': projectid } requester.make_request( command, args, authorization.client_id, authorization.client_secret, ) command = 'registerSSHKeyPair' args = { 'name': projectid, 'publickey': data } requester.make_request( command, args, authorization.client_id, authorization.client_secret, ) res = jsonify({ "kind": "compute#operation", 'operationType': 'setMetadata', 'targetLink': urllib.unquote_plus(helpers.get_root_url() + url_for( 'getproject', projectid=projectid )), 'status': 'PENDING', 'progress': 0 }) res.status_code = 200 return res
def _cloudstack_virtual_machine_to_gce(cloudstack_response, projectid, zone, **kwargs): response = {} response['kind'] = 'compute#instance' response['id'] = cloudstack_response['id'] response['creationTimestamp'] = cloudstack_response['created'] response['status'] = cloudstack_response['state'].upper() response['name'] = cloudstack_response['name'] response['description'] = cloudstack_response['name'] response['machineType'] = cloudstack_response['serviceofferingname'] response['image'] = cloudstack_response['templatename'] response['canIpForward'] = 'true' response['networkInterfaces'] = [] response['disks'] = [] networking = {} accessconfig = [] accessconfig.append({}) if 'securitygroup' in cloudstack_response: networking['network'] = cloudstack_response['securitygroup'][0]['name'] networking['networkIP'] = cloudstack_response['nic'][0]['ipaddress'] networking['name'] = cloudstack_response['nic'][0]['id'] accessconfig[0]['natIP'] = cloudstack_response['nic'][0]['ipaddress'] networking['accessConfigs'] = [] accessconfig[0]['kind'] = 'compute#accessConfig' accessconfig[0]['type'] = 'ONE_TO_ONE_NAT' accessconfig[0]['name'] = 'External NAT' networking['accessConfigs'] = accessconfig response['networkInterfaces'].append(networking) response['selfLink'] = urllib.unquote_plus( helpers.get_root_url() + url_for('getinstance', projectid=projectid, instance=cloudstack_response['name'], zone=zone)) response['zone'] = zone return response
def _cloudstack_virtual_machine_to_gce(cloudstack_response, projectid, zone, **kwargs): response = {} response['kind'] = 'compute#instance' response['id'] = cloudstack_response['id'] response['creationTimestamp'] = cloudstack_response['created'] response['status'] = cloudstack_response['state'].upper() response['name'] = cloudstack_response['name'] response['description'] = cloudstack_response['name'] response['machineType'] = cloudstack_response['serviceofferingname'] response['image'] = cloudstack_response['templatename'] response['canIpForward'] = 'true' response['networkInterfaces'] = [] response['disks'] = [] networking = {} accessconfig = [] accessconfig.append({}) if 'securitygroup' in cloudstack_response: networking['network'] = cloudstack_response['securitygroup'][0]['name'] networking['networkIP'] = cloudstack_response['nic'][0]['ipaddress'] networking['name'] = cloudstack_response['nic'][0]['id'] accessconfig[0]['natIP'] = cloudstack_response['nic'][0]['ipaddress'] networking['accessConfigs'] = [] accessconfig[0]['kind'] = 'compute#accessConfig' accessconfig[0]['type'] = 'ONE_TO_ONE_NAT' accessconfig[0]['name'] = 'External NAT' networking['accessConfigs'] = accessconfig response['networkInterfaces'].append(networking) response['selfLink'] = urllib.unquote_plus(helpers.get_root_url() + url_for( 'getinstance', projectid=projectid, instance=cloudstack_response['name'], zone=zone )) response['zone'] = zone return response
def setglobalmetadata(projectid, authorization): data = json.loads(request.data) publickey_storage[projectid] = data['items'][0]['value'] data = data['items'][0]['value'].split(':')[1] command = 'deleteSSHKeyPair' args = {'name': projectid} requester.make_request( command, args, authorization.client_id, authorization.client_secret, ) command = 'registerSSHKeyPair' args = {'name': projectid, 'publickey': data} requester.make_request( command, args, authorization.client_id, authorization.client_secret, ) res = jsonify({ "kind": "compute#operation", 'operationType': 'setMetadata', 'targetLink': urllib.unquote_plus(helpers.get_root_url() + url_for('getproject', projectid=projectid)), 'status': 'PENDING', 'progress': 0 }) res.status_code = 200 return res
def addnetwork(authorization, projectid): data = json.loads(request.data) args = {} args['name'] = data['name'] args['description'] = data['description'] network_result = _add_network(authorization, args) if 'errortext' in network_result['createsecuritygroupresponse']: populated_response = { 'kind': 'compute#operation', 'operationType': 'insert', 'targetLink': '', 'status': 'DONE', 'progress': 100, 'error': { 'errors': [{ 'code': 'RESOURCE_ALREADY_EXISTS', 'message': 'The resource \'projects/\'' + projectid + '/global/networks/' + args['name'] }] } } else: populated_response = { 'kind': 'compute#operation', 'operationType': 'insert', 'targetLink': urllib.unquote_plus( helpers.get_root_url() + url_for( 'getnetwork', projectid=projectid, network=data['name'] ) ), 'status': 'DONE', 'progress': 100 } return helpers.create_response(data=populated_response)