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))
Exemple #2
0
def listimages(projectid, authorization):
    args = {'templatefilter': 'executable', 'command': 'listTemplates'}
    items = controllers.describe_items(authorization, args, 'template',
                                       _cloudstack_template_to_gce, **{})

    populated_response = _create_populated_image_response(projectid, items)
    return helpers.create_response(data=populated_response)
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
        ))
Exemple #4
0
def listimages(projectid, authorization):
    args = {'templatefilter': 'executable', 'command': 'listTemplates'}
    items = controllers.describe_items(
        authorization, args, 'template',
        _cloudstack_template_to_gce, **{})

    populated_response = _create_populated_image_response(projectid, items)
    return helpers.create_response(data=populated_response)
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)
Exemple #7
0
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)
Exemple #8
0
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 listnetworks(projectid, authorization):
    args = {'command': 'listSecurityGroups'}
    kwargs = {}
    items = controllers.describe_items(
        authorization, args, 'securitygroup',
        _cloudstack_network_to_gce, **kwargs)

    populated_response = _create_populated_network_response(
        projectid,
        items
    )
    return helpers.create_response(data=populated_response)
Exemple #10
0
def listregions(projectid, authorization):
    args = {'command': 'listRegions'}
    kwargs = {}
    items = controllers.describe_items(authorization, args, 'region',
                                       _cloudstack_account_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#regionList',
        'id': 'projects/' + projectid + '/regions',
        'selfLink': request.base_url,
        'items': items
    }
    return helpers.create_response(data=populated_response)
Exemple #11
0
def aggregatedlistinstances(authorization, projectid):
    args = {'command': 'listVirtualMachines'}
    kwargs = {'projectid': projectid}
    items = controllers.describe_items_aggregated(
        authorization, args, 'virtualmachine', 'instances',
        _cloudstack_virtual_machine_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#instanceAggregatedList',
        'id': 'projects/' + projectid + '/instances',
        'selfLink': request.base_url,
        'items': items
    }
    return helpers.create_response(data=populated_response)
Exemple #12
0
def aggregatedlistmachinetypes(projectid, authorization):
    args = {'command': 'listServiceOfferings'}
    kwargs = {'projectid': projectid}
    items = controllers.describe_items_aggregated(
        authorization, args, 'serviceoffering', 'machineTypes',
        _cloudstack_service_offering_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#machineTypeAggregatedList',
        'id': 'projects/' + projectid + '/aggregated/machineTypes',
        'selfLink': urllib.unquote_plus(request.base_url),
        'items': items
    }
    return helpers.create_response(data=populated_response)
Exemple #13
0
def listregions(projectid, authorization):
    args = {'command': 'listRegions'}
    kwargs = {}
    items = controllers.describe_items(
        authorization, args, 'region',
        _cloudstack_account_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#regionList',
        'id': 'projects/' + projectid + '/regions',
        'selfLink': request.base_url,
        'items': items
    }
    return helpers.create_response(data=populated_response)
def aggregatedlistmachinetypes(projectid, authorization):
    args = {'command': 'listServiceOfferings'}
    kwargs = {'projectid': projectid}
    items = controllers.describe_items_aggregated(
        authorization, args, 'serviceoffering', 'machineTypes',
        _cloudstack_service_offering_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#machineTypeAggregatedList',
        'id': 'projects/' + projectid + '/aggregated/machineTypes',
        'selfLink': urllib.unquote_plus(request.base_url),
        'items': items
    }
    return helpers.create_response(data=populated_response)
def aggregatedlistinstances(authorization, projectid):
    args = {'command': 'listVirtualMachines'}
    kwargs = {'projectid': projectid}
    items = controllers.describe_items_aggregated(
        authorization, args, 'virtualmachine', 'instances',
        _cloudstack_virtual_machine_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#instanceAggregatedList',
        'id': 'projects/' + projectid + '/instances',
        'selfLink': request.base_url,
        'items': items
    }
    return helpers.create_response(data=populated_response)
Exemple #16
0
def listdisks(projectid, authorization, zone):
    args = {'command': 'listVolumes'}
    kwargs = {'projectid': projectid, 'zone': zone}
    items = controllers.describe_items(authorization, args, 'volume',
                                       _cloudstack_volume_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#imageList',
        'selfLink': urllib.unquote_plus(request.base_url),
        'id': 'projects/' + projectid + '/global/images',
        'items': items
    }

    return helpers.create_response(data=populated_response)
def listsecuritygroups(projectid, authorization):
    args = {'command': 'listSecurityGroups'}
    items = controllers.describe_items(
        authorization, args, 'securitygroup',
        _cloudstack_securitygroup_to_gce, **{})

    populated_response = {
        'kind': 'compute#firewallList',
        'id': 'projects/' + projectid + '/global/firewalls',
        'selfLink': request.base_url,
        'items': items
    }

    return helpers.create_response(data=populated_response)
def listmachinetype(projectid, authorization, zone):
    args = {'command': 'listServiceOfferings'}
    kwargs = {'projectid': projectid, 'zone': zone}
    items = controllers.describe_items(
        authorization, args, 'serviceoffering',
        _cloudstack_service_offering_to_gce, **kwargs)

    populated_response = {
        'kind': 'compute#imageList',
        'selfLink': urllib.unquote_plus(request.base_url),
        'id': 'projects/' + projectid + '/global/images',
        'items': items
    }

    return helpers.create_response(data=populated_response)
Exemple #19
0
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 helpers.create_response(data=populated_response)
Exemple #20
0
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 helpers.create_response(data=populated_response)
def deleteinstance(projectid, authorization, zone, instance):
    args = {'command': 'listVirtualMachines'}
    virtual_machine = controllers.get_item_with_name(authorization, instance,
                                                     args, 'virtualmachine')

    virtual_machine_id = virtual_machine['id']
    args = {'id': virtual_machine_id}

    deletion_result = requester.make_request('destroyVirtualMachine', args,
                                             authorization.client_id,
                                             authorization.client_secret)

    return helpers.create_response(
        operations.create_async_response(
            projectid=projectid,
            operationid=deletion_result['destroyvirtualmachineresponse']
            ['jobid'],
            authorization=authorization))
Exemple #22
0
def deleteinstance(projectid, authorization, zone, instance):
    args = {'command': 'listVirtualMachines'}
    virtual_machine = controllers.get_item_with_name(authorization, instance, args, 'virtualmachine')

    virtual_machine_id = virtual_machine['id']
    args = {'id': virtual_machine_id}

    deletion_result = requester.make_request(
        'destroyVirtualMachine',
        args,
        authorization.client_id,
        authorization.client_secret
    )

    return helpers.create_response(operations.create_async_response(
        projectid=projectid,
        operationid=deletion_result['destroyvirtualmachineresponse']['jobid'],
        authorization=authorization
    ))
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 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)
Exemple #25
0
def listnocentoscloudimages(authorization):
    populated_response = _create_populated_image_response('centos-cloud')
    return helpers.create_response(data=populated_response)
Exemple #26
0
def listnocentoscloudimages(authorization):
    populated_response = _create_populated_image_response('centos-cloud')
    return helpers.create_response(data=populated_response)
Exemple #27
0
def listnodebiancloudimages(authorization):
    populated_response = _create_populated_image_response('debian-cloud')
    return helpers.create_response(data=populated_response)
def getoperations(authorization, operationid, projectid):
    return helpers.create_response(
        create_async_response(authorization=authorization,
                              operationid=operationid,
                              projectid=projectid))
def getoperations(authorization, operationid, projectid):
    return helpers.create_response(create_async_response(
        authorization=authorization,
        operationid=operationid,
        projectid=projectid
    ))
Exemple #30
0
def listnodebiancloudimages(authorization):
    populated_response = _create_populated_image_response('debian-cloud')
    return helpers.create_response(data=populated_response)