def aggregatedlistmachinetypes(projectid, authorization): machine_types = _get_machinetypes(authorization) zonelist = zones.get_zone_names(authorization) items = {} for zone in zonelist: zone_machine_types = [] if machine_types['listserviceofferingsresponse']: for machineType in machine_types['listserviceofferingsresponse']['serviceoffering']: zone_machine_types.append( _cloudstack_machinetype_to_gce( cloudstack_response=machineType, projectid=projectid, zone=zone ) ) else: zone_machine_types.append(errors.no_results_found(zone)) items['zone/' + zone] = {} items['zone/' + zone]['zone'] = zone items['zone/' + zone]['machineTypes'] = zone_machine_types populated_response = { 'kind': 'compute#machineTypeAggregatedList', 'id': 'projects/' + projectid + '/aggregated/machineTypes', 'selfLink': urllib.unquote_plus(request.base_url), 'items': items } return helper.create_response(data=populated_response)
def deleteinstance(projectid, authorization, zone, instance): deletion_result = _destroy_virtual_machine(authorization, instance) populated_response = operations.create_response( projectid=projectid, operationid=deletion_result['destroyvirtualmachineresponse']['jobid'], authorization=authorization ) return helper.create_response(data=populated_response)
def discovery(): with open(app.config['DATA'] + '/v1.json') as template: discovery_template = json.loads(template.read()) discovery_template[ 'baseUrl'] = helper.get_root_url() + '/' + app.config['PATH'] discovery_template['basePath'] = '/' + app.config['PATH'] discovery_template['rootUrl'] = helper.get_root_url() + '/' discovery_template['servicePath'] = app.config['PATH'] return helper.create_response(data=discovery_template)
def deletenetwork(projectid, authorization, network): _delete_network(authorization, projectid, network) populated_response = { 'kind': 'compute#operation', 'operationType': 'delete', 'targetLink': '', 'status': 'DONE', 'progress': 100 } return helper.create_response(data=populated_response)
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 listimages(projectid, authorization): image_list = _get_templates( authorization=authorization ) images = [] if image_list['listtemplatesresponse']: for image in image_list['listtemplatesresponse']['template']: images.append(_cloudstack_template_to_gce( cloudstack_response=image, selfLink=request.base_url + '/' + image['name'])) populated_response = _create_populated_image_response(projectid, images) return helper.create_response(data=populated_response)
def aggregatedlistdisks(projectid, authorization): disk_list = _get_disks(authorization=authorization) zone_list = zones.get_zone_names(authorization=authorization) disk = None filter = helper.get_filter(request.args) if 'name' in filter: disk = filter['name'] items = {} for zone in zone_list: zone_disks = [] if disk: disk = get_disk_by_name( authorization=authorization, disk=disk ) if disk: zone_disks.append( _cloudstack_volume_to_gce( cloudstack_response=disk, projectid=projectid, zone=zone, ) ) elif disk_list['listvolumesresponse']: for disk in disk_list['listvolumesresponse']['volume']: zone_disks.append( _cloudstack_volume_to_gce( cloudstack_response=disk, projectid=projectid, zone=zone, ) ) items['zone/' + zone] = {} items['zone/' + zone]['disks'] = zone_disks populated_response = { 'kind': 'compute#diskAggregatedList', 'selfLink': urllib.unquote_plus(request.base_url), 'id': 'projects/' + projectid + '/global/images', 'items': items } return helper.create_response(data=populated_response)
def listmachinetype(projectid, authorization, zone): machinetype = None filter = helper.get_filter(request.args) if 'name' in filter: machinetype = filter['name'] items = [] if machinetype: machinetype_list = _get_machinetypes( authorization=authorization, args={'keyword': machinetype} ) if machinetype_list['listvolumesresponse']: machinetype = helper.filter_by_name( data=machinetype_list['listserviceofferingsresponse'][ 'serviceoffering'], name=machinetype ) if machinetype: items.append( _cloudstack_machinetype_to_gce( cloudstack_response=machinetype, projectid=projectid, zone=zone ) ) else: machinetype_list = _get_machinetypes(authorization=authorization) if machinetype_list['listserviceofferingsresponse']: for machinetype in machinetype_list['listserviceofferingsresponse']['serviceoffering']: items.append( _cloudstack_machinetype_to_gce( cloudstack_response=machinetype, projectid=projectid, zone=zone ) ) populated_response = { 'kind': 'compute#imageList', 'selfLink': urllib.unquote_plus(request.base_url), 'id': 'projects/' + projectid + '/global/images', 'items': items } return helper.create_response(data=populated_response)
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 listzones(projectid, authorization): zone_list = _get_zones(authorization) items = [] if zone_list['listzonesresponse']: for zone in zone_list['listzonesresponse']['zone']: items.append(_cloudstack_zone_to_gce(zone)) populated_response = { 'kind': 'compute#zoneList', 'id': 'projects/' + projectid + '/zones', 'selfLink': request.base_url, 'items': items } return helper.create_response(data=populated_response)
def listdisks(projectid, authorization, zone): disk = None filter = helper.get_filter(request.args) if 'name' in filter: disk = filter['name'] items = [] if disk: disk_list = _get_disks( authorization=authorization, args={'keyword': disk} ) if disk_list['listvolumesresponse']: disk = helper.filter_by_name( data=disk_list['listvolumesresponse']['volume'], name=disk ) if disk: items.append( _cloudstack_volume_to_gce( cloudstack_response=disk, projectid=projectid, zone=zone ) ) else: disk_list = _get_disks(authorization=authorization) if disk_list['listvolumesresponse']: for disk in disk_list['listvolumesresponse']['volume']: items.append( _cloudstack_volume_to_gce( cloudstack_response=disk, projectid=projectid, zone=zone ) ) populated_response = { 'kind': 'compute#imageList', 'selfLink': urllib.unquote_plus(request.base_url), 'id': 'projects/' + projectid + '/global/images', 'items': items } return helper.create_response(data=populated_response)
def aggregatedlistinstances(authorization, projectid): zone_list = zones.get_zone_names(authorization=authorization) virtual_machine_list = _get_virtual_machines(authorization=authorization) instance = None filter = helper.get_filter(request.args) if 'name' in filter: instance = filter['name'] items = {} for zone in zone_list: zone_instances = [] if instance: virtual_machine = _get_virtual_machine_by_name( authorization=authorization, instance=instance ) if virtual_machine: zone_instances.append( _cloudstack_virtual_machine_to_gce( cloudstack_response=virtual_machine, projectid=projectid, zone=zone ) ) elif virtual_machine_list['listvirtualmachinesresponse']: for instance in virtual_machine_list['listvirtualmachinesresponse']['virtualmachine']: zone_instances.append( _cloudstack_virtual_machine_to_gce( cloudstack_response=instance, projectid=projectid, zone=zone ) ) items['zone/' + zone] = {} items['zone/' + zone]['instances'] = zone_instances populated_response = { 'kind': 'compute#instanceAggregatedList', 'id': 'projects/' + projectid + '/instances', 'selfLink': request.base_url, 'items': items } return helper.create_response(data=populated_response)
def listnetworks(projectid, authorization): securitygroup_list = _get_networks( authorization=authorization ) networks = [] if securitygroup_list['listsecuritygroupsresponse']: for network in securitygroup_list['listsecuritygroupsresponse']['securitygroup']: networks.append(_cloudstack_network_to_gce( cloudstack_response=network, selfLink=request.base_url + '/' + network['name'])) populated_response = _create_populated_network_response( projectid, networks ) return helper.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 addinstance(authorization, projectid, zone): data = json.loads(request.data) print 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']: populated_response = { 'kind': 'compute#operation', 'operationType': 'insert', 'targetLink': '', 'status': 'DONE', 'progress': 100, 'error': { 'errors': [{ 'code': 'RESOURCE_ALREADY_EXISTS', 'message': 'the resource \'projects/\'' + projectid + '/zones/' + zone + '/instances/' + args['name'] }] } } else: populated_response = operations.create_response( projectid=projectid, operationid=deployment_result[ 'deployvirtualmachineresponse']['jobid'], authorization=authorization ) return helper.create_response(data=populated_response)
def addnetwork(authorization, projectid): data = json.loads(request.data) args = {} args['name'] = data['name'] args['description'] = data['description'] network_result = _get_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( helper.get_root_url() + url_for( 'getnetwork', projectid=projectid, network=data['name'] ) ), 'status': 'DONE', 'progress': 100 } return helper.create_response(data=populated_response)
def getoperations(authorization, operationid, projectid): return helper.create_response(create_response( authorization=authorization, operationid=operationid, projectid=projectid ))
def listnocentoscloudimages(authorization): populated_response = _create_populated_image_response('centos-cloud') return helper.create_response(data=populated_response)
def listnodebiancloudimages(authorization): populated_response = _create_populated_image_response('debian-cloud') return helper.create_response(data=populated_response)