コード例 #1
0
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))
コード例 #2
0
ファイル: images.py プロジェクト: maduhu/cloudstack-gcestack
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)
コード例 #3
0
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
        ))
コード例 #4
0
ファイル: images.py プロジェクト: grze/gstack
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)
コード例 #5
0
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)
コード例 #6
0
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)
コード例 #7
0
ファイル: index.py プロジェクト: grze/gstack
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)
コード例 #8
0
ファイル: index.py プロジェクト: maduhu/cloudstack-gcestack
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)
コード例 #9
0
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)
コード例 #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)
コード例 #11
0
ファイル: instances.py プロジェクト: grze/gstack
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)
コード例 #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)
コード例 #13
0
ファイル: regions.py プロジェクト: apache/cloudstack-gcestack
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)
コード例 #14
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)
コード例 #15
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)
コード例 #16
0
ファイル: disks.py プロジェクト: maduhu/cloudstack-gcestack
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)
コード例 #17
0
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)
コード例 #18
0
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)
コード例 #19
0
ファイル: zones.py プロジェクト: apache/cloudstack-gcestack
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)
コード例 #20
0
ファイル: zones.py プロジェクト: maduhu/cloudstack-gcestack
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)
コード例 #21
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))
コード例 #22
0
ファイル: instances.py プロジェクト: grze/gstack
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
    ))
コード例 #23
0
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)
コード例 #24
0
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)
コード例 #25
0
ファイル: images.py プロジェクト: grze/gstack
def listnocentoscloudimages(authorization):
    populated_response = _create_populated_image_response('centos-cloud')
    return helpers.create_response(data=populated_response)
コード例 #26
0
ファイル: images.py プロジェクト: maduhu/cloudstack-gcestack
def listnocentoscloudimages(authorization):
    populated_response = _create_populated_image_response('centos-cloud')
    return helpers.create_response(data=populated_response)
コード例 #27
0
ファイル: images.py プロジェクト: maduhu/cloudstack-gcestack
def listnodebiancloudimages(authorization):
    populated_response = _create_populated_image_response('debian-cloud')
    return helpers.create_response(data=populated_response)
コード例 #28
0
def getoperations(authorization, operationid, projectid):
    return helpers.create_response(
        create_async_response(authorization=authorization,
                              operationid=operationid,
                              projectid=projectid))
コード例 #29
0
def getoperations(authorization, operationid, projectid):
    return helpers.create_response(create_async_response(
        authorization=authorization,
        operationid=operationid,
        projectid=projectid
    ))
コード例 #30
0
ファイル: images.py プロジェクト: grze/gstack
def listnodebiancloudimages(authorization):
    populated_response = _create_populated_image_response('debian-cloud')
    return helpers.create_response(data=populated_response)