Example #1
0
def get_machinetype_by_name(authorization, machinetype):
    machinetype_list = _get_machinetypes(
        authorization=authorization
    )

    if machinetype_list['listserviceofferingsresponse']:
        response = helper.filter_by_name(
            data=machinetype_list['listserviceofferingsresponse'][
                'serviceoffering'],
            name=machinetype
        )
        return response
    else:
        return None
Example #2
0
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)
Example #3
0
def _get_account_by_name(authorization, projectid):
    account_list = _get_accounts(
        authorization=authorization,
        args={
            'keyword': projectid
        }
    )

    if account_list['listaccountsresponse']:
        response = helper.filter_by_name(
            data=account_list['listaccountsresponse']['account'],
            name=projectid
        )
        return response
    else:
        return None
Example #4
0
def get_disk_by_name(authorization, disk):
    disk_list = _get_disks(
        authorization=authorization,
        args={
            'keyword': disk
        }
    )

    if disk_list['listvolumesresponse']:
        response = helper.filter_by_name(
            data=disk_list['listvolumesresponse']['volume'],
            name=disk
        )
        return response
    else:
        return None
Example #5
0
def get_template_by_name(authorization, image):
    image_list = _get_templates(
        authorization=authorization,
        args={
            'keyword': image
        }
    )

    if image_list['listtemplatesresponse']:
        response = helper.filter_by_name(
            data=image_list['listtemplatesresponse']['template'],
            name=image
        )
        return response
    else:
        return None
Example #6
0
def get_zone_by_name(authorization, zone):
    zone_list = _get_zones(
        authorization=authorization,
        args={
            'keyword': zone
        }
    )

    if zone_list['listzonesresponse']:
        response = helper.filter_by_name(
            data=zone_list['listzonesresponse']['zone'],
            name=zone
        )
        return response
    else:
        return None
Example #7
0
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)
Example #8
0
def _get_virtual_machine_by_name(authorization, instance):
    virtual_machine_list = _get_virtual_machines(
        authorization=authorization,
        args={
            'keyword': instance
        }
    )

    if virtual_machine_list['listvirtualmachinesresponse']:
        response = helper.filter_by_name(
            data=virtual_machine_list[
                'listvirtualmachinesresponse']['virtualmachine'],
            name=instance
        )
        return response
    else:
        return None
Example #9
0
def get_network_by_name(authorization, securitygroup):
    securitygroup_list = _get_networks(
        authorization=authorization,
        args={
            'keyword': securitygroup
        }
    )

    if securitygroup_list['listsecuritygroupsresponse']:
        response = helper.filter_by_name(
            data=securitygroup_list[
                'listsecuritygroupsresponse']['securitygroup'],
            name=securitygroup
        )
        return response
    else:
        return None