def addinstance(authorization, projectid, zone): data = json.loads(request.data) args = {} args['name'] = data['name'] args['serviceoffering'] = data['machineType'].rsplit('/', 1)[1] args['template'] = data['disks'][0][ 'initializeParams']['sourceImage'].rsplit('/', 1)[1] args['zone'] = zone network = data['networkInterfaces'][0]['network'].rsplit('/', 1)[1] if network is not 'default': args['network'] = network deployment_result = _deploy_virtual_machine(authorization, args, projectid) if 'errortext' in deployment_result['deployvirtualmachineresponse']: func_route = url_for('addinstance', projectid=projectid, zone=zone) return errors.resource_not_found(func_route) else: return helpers.create_response(operations.create_async_response( projectid=projectid, operationid=deployment_result[ 'deployvirtualmachineresponse']['jobid'], authorization=authorization ))
def addinstance(authorization, projectid, zone): data = json.loads(request.data) args = {} args['name'] = data['name'] args['serviceoffering'] = data['machineType'].rsplit('/', 1)[1] args['template'] = data['disks'][0]['initializeParams'][ 'sourceImage'].rsplit('/', 1)[1] args['zone'] = zone network = data['networkInterfaces'][0]['network'].rsplit('/', 1)[1] if network is not 'default': args['network'] = network deployment_result = _deploy_virtual_machine(authorization, args, projectid) if 'errortext' in deployment_result['deployvirtualmachineresponse']: func_route = url_for('addinstance', projectid=projectid, zone=zone) return errors.resource_not_found(func_route) else: return helpers.create_response( operations.create_async_response( projectid=projectid, operationid=deployment_result['deployvirtualmachineresponse'] ['jobid'], authorization=authorization))
def getsecuritygroup(projectid, authorization, firewall): command = 'listSecurityGroups' args = { 'securitygroupname': firewall } cloudstack_response = requester.make_request( command, args, authorization.client_id, authorization.client_secret ) cloudstack_response = cloudstack_response if cloudstack_response['listsecuritygroupsresponse']['securitygroup']: response_item = cloudstack_response[ 'listsecuritygroupsresponse']['securitygroup'][0] firewall = _cloudstack_securitygroup_to_gce(response_item) res = jsonify(firewall) res.status_code = 200 else: func_route = url_for('getsecuritygroup', projectid=projectid, firewall=firewall) res = errors.resource_not_found(func_route) return res
def get_item_with_name_or_error(authorization, name, args, type, func_route, to_cloudstack, **kwargs): cloudstack_item = get_item_with_name(authorization, name, args, type) if cloudstack_item: return helpers.create_response(to_cloudstack( cloudstack_response=cloudstack_item, **kwargs )) else: return errors.resource_not_found(func_route)
def get_item_with_name_or_error(authorization, name, args, type, func_route, to_cloudstack, **kwargs): cloudstack_item = get_item_with_name(authorization, name, args, type) if cloudstack_item: return helpers.create_response( to_cloudstack(cloudstack_response=cloudstack_item, **kwargs)) else: return errors.resource_not_found(func_route)
def getimage(projectid, authorization, image): response = get_template_by_name( authorization=authorization, image=image ) if response: return helper.create_response( data=_cloudstack_template_to_gce(response) ) else: func_route = url_for('getimage', projectid=projectid, image=image) return errors.resource_not_found(func_route)
def getproject(authorization, projectid): project = _get_account_by_name(authorization, projectid) if project: metadata = {} metadata['sshKeys'] = _list_ssh_keys(authorization) publickey_storage[projectid] = metadata['sshKeys'] res = jsonify(_cloudstack_project_to_gce(project, metadata)) res.status_code = 200 else: func_route = urllib.unquote_plus( url_for('getproject', projectid=projectid)) res = errors.resource_not_found(func_route) return res
def getnetwork(projectid, authorization, network): response = get_network_by_name( authorization=authorization, securitygroup=network ) if response: return helper.create_response( data=_cloudstack_network_to_gce(response) ) else: func_route = url_for( 'getnetwork', projectid=projectid, network=network) return errors.resource_not_found(func_route)
def getproject(authorization, projectid): project = _get_account_by_name(authorization, projectid) if project: metadata = {} metadata['sshKeys'] = _list_ssh_keys(authorization) publickey_storage[projectid] = metadata['sshKeys'] res = jsonify(_cloudstack_project_to_gce(project, metadata)) res.status_code = 200 else: func_route = urllib.unquote_plus( url_for( 'getproject', projectid=projectid)) res = errors.resource_not_found(func_route) return res
def _destroy_virtual_machine(authorization, instance): virtual_machine_id = _get_virtual_machine_by_name( authorization, instance)['id'] if virtual_machine_id is None: func_route = url_for('_destroy_virtual_machine', instance=instance) return errors.resource_not_found(func_route) args = { 'id': virtual_machine_id } return requester.make_request( 'destroyVirtualMachine', args, authorization.client_id, authorization.client_secret )
def deletenetwork(projectid, authorization, network): response = _delete_network(authorization, projectid, network) if not response: func_route = url_for( 'getnetwork', projectid=projectid, network=network ) return errors.resource_not_found(func_route) populated_response = { 'kind': 'compute#operation', 'operationType': 'delete', 'targetLink': '', 'status': 'DONE', 'progress': 100 } return helpers.create_response(data=populated_response)
def getinstance(projectid, authorization, zone, instance): response = _get_virtual_machine_by_name( authorization=authorization, instance=instance ) if response: return helper.create_response( data=_cloudstack_virtual_machine_to_gce( cloudstack_response=response, projectid=projectid, zone=zone ) ) else: function_route = url_for( 'getinstance', projectid=projectid, instance=instance) return errors.resource_not_found(function_route)
def getdisk(projectid, authorization, zone, disk): response = get_disk_by_name( authorization=authorization, disk=disk ) if response: return helper.create_response( data=_cloudstack_volume_to_gce( cloudstack_response=response, projectid=projectid, zone=zone ) ) else: func_route = url_for( 'getdisk', projectid=projectid, disk=disk ) return errors.resource_not_found(func_route)
def getmachinetype(projectid, authorization, zone, machinetype): response = get_machinetype_by_name( authorization=authorization, machinetype=machinetype ) if response: return helper.create_response( data=_cloudstack_machinetype_to_gce( cloudstack_response=response, projectid=projectid, zone=zone ) ) else: func_route = url_for( 'getmachinetype', projectid=projectid, machinetype=machinetype, zone=zone) return errors.resource_not_found(func_route)
def _delete_network(authorization, projectid, network): securitygroup_id = get_network_by_name(authorization, network)['id'] if securitygroup_id is None: func_route = url_for( 'getnetwork', projectid=projectid, network=network ) return errors.resource_not_found(func_route) args = { 'id': securitygroup_id } return requester.make_request( 'deleteSecurityGroup', args, authorization.client_id, authorization.client_secret )