コード例 #1
0
def _run_instance_response(response):
    """
    Generates a response for a run instance request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'Object vm_template' in response['errortext']:
            errors.invalid_image_id()
        elif 'Object security_group' in response['errortext']:
            errors.invalid_security_group()
        elif 'A key pair with name' in response['errortext']:
            errors.invalid_keypair_name()
        else:
            errors.invalid_request(response['errortext'])
    else:
        response = response['virtualmachine']
        response = {
            'template_name_or_list': 'run_instance.xml',
            'response_type': 'RunInstancesResponse',
            'response': response
        }

    return response
コード例 #2
0
ファイル: tags.py プロジェクト: terbolous/cloudstack-ec2stack
def _delete_tag_request():
    """
    Request to delete a tag.

    @return: Response.
    """
    key = helpers.get('Tag.1.Key')
    resource_id = helpers.get('ResourceId.1')

    if resource_id in current_app.config['RESOURCE_TYPE_MAP']:
        resource_type = current_app.config['RESOURCE_TYPE_MAP'][resource_id]
    else:
        errors.invalid_request(
            str(resource_id) + " not found in configuration")

    args = {
        'command': 'deleteTags',
        'resourceids': resource_id,
        'resourcetype': resource_type,
        'tags[0].key': key
    }

    response = requester.make_request_async(args)

    return response
コード例 #3
0
def _authenticate_security_group_response(response, rule_type):
    """
    Generate a response for authenticate security group request.

    @param response: Cloudstack response.
    @param rule_type: The type of rule to add.
    @raise Ec2stackError: If authorize security group fails.
    @return: Response
    """
    if 'errortext' in response:
        if 'Failed to authorize security group' in response['errortext']:
            cidrlist = str(helpers.get('CidrIp'))
            protocol = str(helpers.get('IpProtocol'))
            from_port = str(helpers.get('FromPort'))
            to_port = str(helpers.get('toPort'))
            raise Ec2stackError(
                '400', 'InvalidPermission.Duplicate',
                'the specified rule "peer: ' + cidrlist + ', ' + protocol +
                ', from port: ' + from_port + ', to port: ' + to_port +
                ', ALLOW" already exists')
        elif 'Unable to find security group' in response['errortext']:
            errors.invalid_security_group()
        else:
            errors.invalid_request(response['errortext'])
    else:
        if rule_type == 'ingress':
            rule_type = 'AuthorizeSecurityGroupIngressResponse'
        elif rule_type == 'egress':
            rule_type = 'AuthorizeSecurityGroupEgressResponse'

        return {
            'template_name_or_list': 'status.xml',
            'response_type': rule_type,
            'return': 'true'
        }
コード例 #4
0
ファイル: instances.py プロジェクト: ninetian/ec2stack
def _run_instance_response(response):
    """
    Generates a response for a run instance request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'Object vm_template' in response['errortext']:
            errors.invalid_image_id()
        elif 'Object security_group' in response['errortext']:
            errors.invalid_security_group()
        elif 'A key pair with name' in response['errortext']:
            errors.invalid_keypair_name()
        else:
            errors.invalid_request(response['errortext'])
    else:
        response = response['virtualmachine']
        response = {
            'template_name_or_list': 'run_instance.xml',
            'response_type': 'RunInstancesResponse',
            'response': response
        }

    return response
コード例 #5
0
def _create_vpc_request():
    """
    Request to create a vpc.

    @return: Response.
    """
    args = {'command': 'createVPC'}
    name = uuid.uuid1()
    args['name'] = name
    args['displaytext'] = name
    args['zoneid'] = zones.get_zone(
        current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id']

    if 'VPC_OFFERING_ID' in current_app.config:
        args['vpcofferingid'] = current_app.config['VPC_OFFERING_ID']
    else:
        errors.invalid_request(
            str('VPC_OFFERING_ID') + " not found in configuration, " +
            "please run ec2stack-configure -a True")

    args['cidr'] = helpers.get('CidrBlock')

    response = requester.make_request_async(args)

    return response
コード例 #6
0
def _create_vpc_request():
    """
    Request to create a vpc.

    @return: Response.
    """
    args = {'command': 'createVPC'}
    name = uuid.uuid1()
    args['name'] = name
    args['displaytext'] = name
    args['zoneid'] = zones.get_zone(
        current_app.config['CLOUDSTACK_DEFAULT_ZONE'])['id']

    if 'VPC_OFFERING_ID' in current_app.config:
        args['vpcofferingid'] = current_app.config['VPC_OFFERING_ID']
    else:
        errors.invalid_request(
            str('VPC_OFFERING_ID') + " not found in configuration, " +
            "please run ec2stack-configure -a True")

    args['cidr'] = helpers.get('CidrBlock')

    response = requester.make_request_async(args)

    return response
コード例 #7
0
ファイル: tags.py プロジェクト: BillTheBest/ec2stack
def _delete_tag_request():
    """
    Request to delete a tag.

    @return: Response.
    """
    key = helpers.get('Tag.1.Key')
    resource_id = helpers.get('ResourceId.1')

    if resource_id in current_app.config['RESOURCE_TYPE_MAP']:
        resource_type = current_app.config['RESOURCE_TYPE_MAP'][resource_id]
    else:
        errors.invalid_request(
            str(resource_id) + " not found in configuration")

    args = {
        'command': 'deleteTags',
        'resourceids': resource_id,
        'resourcetype': resource_type,
        'tags[0].key': key
    }

    response = requester.make_request_async(args)

    return response
コード例 #8
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
def _delete_volume_response(response):
    """
    Generates a response for delete volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'Unable to aquire volume' in response['errortext']:
            errors.invalid_volume_id()
        else:
            errors.invalid_request(response['errortext'])

    return {
        'template_name_or_list': 'status.xml',
        'response_type': 'DeleteVolumeResponse',
        'return': 'true'
    }
コード例 #9
0
def _delete_volume_response(response):
    """
    Generates a response for delete volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'Unable to aquire volume' in response['errortext']:
            errors.invalid_volume_id()
        else:
            errors.invalid_request(response['errortext'])

    return {
        'template_name_or_list': 'status.xml',
        'response_type': 'DeleteVolumeResponse',
        'return': 'true'
    }
コード例 #10
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
def _create_volume_response(response):
    """
    Generates a response for create volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'unable to find a snapshot with id' in response['errortext']:
            errors.invalid_snapshot_id()
        else:
            errors.invalid_request(response['errortext'])

    response = response['volume']
    return {
        'template_name_or_list': 'create_volume.xml',
        'response_type': 'CreateVolumeResponse',
        'response': response
    }
コード例 #11
0
def _create_volume_response(response):
    """
    Generates a response for create volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'unable to find a snapshot with id' in response['errortext']:
            errors.invalid_snapshot_id()
        else:
            errors.invalid_request(response['errortext'])

    response = response['volume']
    return {
        'template_name_or_list': 'create_volume.xml',
        'response_type': 'CreateVolumeResponse',
        'response': response
    }
コード例 #12
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
def _attach_volume_response(response):
    """
    Generates a response for attach volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'specify a volume that is not attached' in response['errortext']:
            errors.invalid_volume_attached()
        elif 'Invalid parameter virtualmachineid' in response['errortext']:
            errors.invalid_instance_id()
        elif 'Invalid parameter id' in response['errortext']:
            errors.invalid_volume_id()
        else:
            errors.invalid_request(response['errortext'])

    response = response['volume']
    return {
        'template_name_or_list': 'volume_attachment.xml',
        'response_type': 'AttachVolumeResponse',
        'response': response
    }
コード例 #13
0
def _attach_volume_response(response):
    """
    Generates a response for attach volume request.

    @param response: Response from Cloudstack.
    @return: Response.
    """
    if 'errortext' in response:
        if 'specify a volume that is not attached' in response['errortext']:
            errors.invalid_volume_attached()
        elif 'Invalid parameter virtualmachineid' in response['errortext']:
            errors.invalid_instance_id()
        elif 'Invalid parameter id' in response['errortext']:
            errors.invalid_volume_id()
        else:
            errors.invalid_request(response['errortext'])

    response = response['volume']
    return {
        'template_name_or_list': 'volume_attachment.xml',
        'response_type': 'AttachVolumeResponse',
        'response': response
    }
コード例 #14
0
def _authenticate_security_group_response(response, rule_type):
    """
    Generate a response for authenticate security group request.

    @param response: Cloudstack response.
    @param rule_type: The type of rule to add.
    @raise Ec2stackError: If authorize security group fails.
    @return: Response
    """
    if 'errortext' in response:
        if 'Failed to authorize security group' in response['errortext']:
            cidrlist = str(helpers.get('CidrIp'))
            protocol = str(helpers.get('IpProtocol'))
            from_port = str(helpers.get('FromPort'))
            to_port = str(helpers.get('toPort'))
            raise Ec2stackError(
                '400',
                'InvalidPermission.Duplicate',
                'the specified rule "peer: ' + cidrlist + ', ' + protocol +
                ', from port: ' + from_port + ', to port: ' + to_port +
                ', ALLOW" already exists'
            )
        elif 'Unable to find security group' in response['errortext']:
            errors.invalid_security_group()
        else:
            errors.invalid_request(response['errortext'])
    else:
        if rule_type == 'ingress':
            rule_type = 'AuthorizeSecurityGroupIngressResponse'
        elif rule_type == 'egress':
            rule_type = 'AuthorizeSecurityGroupEgressResponse'

        return {
            'template_name_or_list': 'status.xml',
            'response_type': rule_type,
            'return': 'true'
        }
コード例 #15
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)

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

    args['command'] = 'deployVirtualMachine'

    response = requester.make_request_async(args)

    return response
コード例 #16
0
ファイル: instances.py プロジェクト: BillTheBest/ec2stack
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