Beispiel #1
0
def _create_volume_request():
    """
    Request to create a volume.

    @return: Response.
    """
    args = {}

    if helpers.contains_parameter('SnapshotId'):
        args['snapshotid'] = helpers.get('SnapshotId')

    else:
        helpers.require_parameters(['Size'])
        args['size'] = helpers.get('Size')
        args['diskofferingid'] = disk_offerings.get_disk_offering(
            current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
        )['id']

    zone_name = helpers.get('AvailabilityZone')
    zone_id = zones.get_zone(zone_name)['id']

    args['zoneid'] = zone_id
    args['command'] = 'createVolume'
    args['name'] = uuid.uuid4()

    response = requester.make_request_async(args)

    return response
def _create_volume_request():
    """
    Request to create a volume.

    @return: Response.
    """
    args = {}

    if helpers.contains_parameter('SnapshotId'):
        args['snapshotid'] = helpers.get('SnapshotId')

    else:
        helpers.require_parameters(['Size'])
        args['size'] = helpers.get('Size')
        args['diskofferingid'] = disk_offerings.get_disk_offering(
            current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
        )['id']

    zone_name = helpers.get('AvailabilityZone')
    zone_id = zones.get_zone(zone_name)['id']

    args['zoneid'] = zone_id
    args['command'] = 'createVolume'
    args['name'] = uuid.uuid1()

    response = requester.make_request_async(args)

    return response
Beispiel #3
0
def _create_volume_request():
    args = {}

    if helpers.contains_parameter("SnapshotId"):
        args["snapshotid"] = helpers.get("SnapshotId")

    else:
        args["size"] = helpers.get("Size")
        args["diskofferingid"] = disk_offerings.get_disk_offering(
            current_app.config["CLOUDSTACK_CUSTOM_DISK_OFFERING"]
        )["id"]

    zone_name = helpers.get("AvailabilityZone")
    zone_id = zones.get_zone(zone_name)["id"]

    args["zoneid"] = zone_id
    args["command"] = "createVolume"
    args["name"] = uuid.uuid4()

    response = requester.make_request_async(args)

    return response
def _run_instance_request():
    """
    Request to bring up an instance.

    @return: Response.
    """
    args = {}
    if helpers.contains_parameter('Placement.AvailabilityZone'):
        args['zoneid'] = zones.get_zone(
            helpers.get('Placement.AvailabilityZone'))
    else:
        args['zoneid'] = zones.get_zone(
            current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id']

    if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None:
        disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType')
        if disk_type == 'gp2':
            args['diskofferingid'] = disk_offerings.get_disk_offering(
                current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING'])['id']

        if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None:
            errors.invalid_request(
                "VolumeSize not found in BlockDeviceMapping")
        else:
            args['size'] = helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize')

    if helpers.get('InstanceType') is None:
        instance_type = 'm1.small'
    else:
        instance_type = helpers.get('InstanceType')

    if instance_type in current_app.config['INSTANCE_TYPE_MAP']:
        instance_type = current_app.config['INSTANCE_TYPE_MAP'][instance_type]
    else:
        instance_type = instance_type

    args['serviceofferingid'] = \
        service_offerings.get_service_offering(instance_type)['id']
    args['templateid'] = helpers.get('ImageId')

    if helpers.contains_parameter('KeyName'):
        args['keypair'] = helpers.get('KeyName')

    if helpers.contains_parameter('UserData'):
        args['userdata'] = helpers.get('UserData')

    if helpers.contains_parameter_with_keyword('SecurityGroupId.'):
        keys = helpers.get_request_parameter_keys('SecurityGroupId.')
        securitygroupids = []

        for key in keys:
            securitygroupids.append(helpers.get(key))

        args['securitygroupids'] = ",".join(securitygroupids)

    if helpers.contains_parameter_with_keyword('SecurityGroup.'):
        keys = helpers.get_request_parameter_keys('SecurityGroup.')
        securitygroupnames = []

        for key in keys:
            securitygroupnames.append(helpers.get(key))

        args['securitygroupnames'] = ",".join(securitygroupnames)

    if helpers.get('SubnetId') is not None:
        args['networkids'] = helpers.get('SubnetId')

    args['command'] = 'deployVirtualMachine'

    response = requester.make_request_async(args)

    return response
Beispiel #5
0
def _run_instance_request():
    """
    Request to bring up an instance.

    @return: Response.
    """
    args = {}
    if helpers.contains_parameter('Placement.AvailabilityZone'):
        args['zoneid'] = zones.get_zone(
            helpers.get('Placement.AvailabilityZone')
        )
    else:
        args['zoneid'] = zones.get_zone(
            current_app.config['CLOUDSTACK_DEFAULT_ZONE']
        )['id']

    if helpers.get('BlockDeviceMapping.1.Ebs.VolumeType') is not None:
        disk_type = helpers.get('BlockDeviceMapping.1.Ebs.VolumeType')
        if disk_type == 'gp2':
            args['diskofferingid'] = disk_offerings.get_disk_offering(
                current_app.config['CLOUDSTACK_CUSTOM_DISK_OFFERING']
            )['id']

        if helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize') is None:
            errors.invalid_request("VolumeSize not found in BlockDeviceMapping")
        else:
            args['size'] = helpers.get('BlockDeviceMapping.1.Ebs.VolumeSize')

    if helpers.get('InstanceType') is None:
        instance_type = 'm1.small'
    else:
        instance_type = helpers.get('InstanceType')

    if instance_type in current_app.config['INSTANCE_TYPE_MAP']:
        instance_type = current_app.config[
            'INSTANCE_TYPE_MAP'][instance_type]
    else:
        instance_type = instance_type

    args['serviceofferingid'] = \
        service_offerings.get_service_offering(instance_type)['id']
    args['templateid'] = helpers.get('ImageId')

    if helpers.contains_parameter('KeyName'):
        args['keypair'] = helpers.get('KeyName')

    if helpers.contains_parameter('UserData'):
        args['userdata'] = helpers.get('UserData')

    if helpers.contains_parameter_with_keyword('SecurityGroupId.'):
        keys = helpers.get_request_parameter_keys('SecurityGroupId.')
        securitygroupids = []

        for key in keys:
            securitygroupids.append(helpers.get(key))

        args['securitygroupids'] = ",".join(securitygroupids)

    if helpers.contains_parameter_with_keyword('SecurityGroup.'):
        keys = helpers.get_request_parameter_keys('SecurityGroup.')
        securitygroupnames = []

        for key in keys:
            securitygroupnames.append(helpers.get(key))

        args['securitygroupnames'] = ",".join(securitygroupnames)

    args['command'] = 'deployVirtualMachine'

    response = requester.make_request_async(args)

    return response