コード例 #1
0
ファイル: machine_type.py プロジェクト: ninetian/gstack
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)
コード例 #2
0
ファイル: instances.py プロジェクト: ninetian/gstack
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)
コード例 #3
0
ファイル: index.py プロジェクト: ninetian/gstack
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)
コード例 #4
0
ファイル: networks.py プロジェクト: ninetian/gstack
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)
コード例 #5
0
ファイル: images.py プロジェクト: ninetian/gstack
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)
コード例 #6
0
ファイル: images.py プロジェクト: ninetian/gstack
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)
コード例 #7
0
ファイル: disks.py プロジェクト: ninetian/gstack
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)
コード例 #8
0
ファイル: machine_type.py プロジェクト: ninetian/gstack
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)
コード例 #9
0
ファイル: networks.py プロジェクト: ninetian/gstack
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)
コード例 #10
0
ファイル: zones.py プロジェクト: ninetian/gstack
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)
コード例 #11
0
ファイル: disks.py プロジェクト: ninetian/gstack
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)
コード例 #12
0
ファイル: instances.py プロジェクト: ninetian/gstack
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)
コード例 #13
0
ファイル: networks.py プロジェクト: ninetian/gstack
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)
コード例 #14
0
ファイル: instances.py プロジェクト: ninetian/gstack
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)
コード例 #15
0
ファイル: disks.py プロジェクト: ninetian/gstack
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)
コード例 #16
0
ファイル: machine_type.py プロジェクト: ninetian/gstack
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)
コード例 #17
0
ファイル: instances.py プロジェクト: ninetian/gstack
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)
コード例 #18
0
ファイル: networks.py プロジェクト: ninetian/gstack
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)
コード例 #19
0
ファイル: operations.py プロジェクト: ninetian/gstack
def getoperations(authorization, operationid, projectid):
    return helper.create_response(create_response(
        authorization=authorization,
        operationid=operationid,
        projectid=projectid
    ))
コード例 #20
0
ファイル: images.py プロジェクト: ninetian/gstack
def listnocentoscloudimages(authorization):
    populated_response = _create_populated_image_response('centos-cloud')
    return helper.create_response(data=populated_response)
コード例 #21
0
ファイル: images.py プロジェクト: ninetian/gstack
def listnodebiancloudimages(authorization):
    populated_response = _create_populated_image_response('debian-cloud')
    return helper.create_response(data=populated_response)