Example #1
0
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)
Example #2
0
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)
Example #3
0
def describe_items_aggregated(authorization, args, type, gce_type, to_cloudstack, **kwargs):
    from gstack.controllers import zones
    items = {}

    zone_list = zones.get_zone_names(authorization=authorization)

    for zone in zone_list:
        kwargs['zone'] = zone
        zone_items = _get_requested_items(authorization, args, type, to_cloudstack, **kwargs)
        items['zone/' + zone] = {}
        if zone_items:
            items['zone/' + zone][gce_type] = zone_items
        else:
            items['zone/' + zone] = errors.no_results_found(zone)

    return items
Example #4
0
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)
Example #5
0
def describe_items_aggregated(authorization, args, type, gce_type,
                              to_cloudstack, **kwargs):
    from gstack.controllers import zones
    items = {}

    zone_list = zones.get_zone_names(authorization=authorization)

    for zone in zone_list:
        kwargs['zone'] = zone
        zone_items = _get_requested_items(authorization, args, type,
                                          to_cloudstack, **kwargs)
        items['zone/' + zone] = {}
        if zone_items:
            items['zone/' + zone][gce_type] = zone_items
        else:
            items['zone/' + zone] = errors.no_results_found(zone)

    return items