コード例 #1
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
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
コード例 #2
0
ファイル: security_groups.py プロジェクト: vogxn/ec2stack
def _parse_security_group_request(args=None):
    if args is None:
        args = {}

    helpers.require_atleast_one_parameter(["GroupName", "GroupId"])

    if helpers.contains_parameter("GroupName"):
        args["securityGroupName"] = helpers.get("GroupName")
        args["name"] = helpers.get("GroupName")
    elif helpers.contains_parameter("GroupId"):
        args["securityGroupId"] = helpers.get("GroupId")
        args["id"] = helpers.get("GroupId")

    helpers.require_parameters(["IpProtocol"])

    args["protocol"] = helpers.get("IpProtocol")

    helpers.require_parameters(["FromPort", "ToPort"])

    if args["protocol"] in ["icmp"]:
        args["icmptype"] = helpers.get("FromPort")
        args["icmpcode"] = helpers.get("ToPort")
    else:
        args["startport"] = helpers.get("FromPort")
        args["endport"] = helpers.get("ToPort")

    if helpers.get("CidrIp") is None:
        args["cidrlist"] = "0.0.0.0/0"
    else:
        args["cidrlist"] = helpers.get("CidrIp")

    return args
コード例 #3
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.uuid1()

    response = requester.make_request_async(args)

    return response
コード例 #4
0
ファイル: default.py プロジェクト: ninetian/ec2stack
def register_secret_key():
    """
    Register a user's API key and secret key.

    @return: Response.
    @raise Ec2stackError: API key already registered.
    """
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    found_user = USERS.get(get('AWSAccessKeyId'))
    if found_user is None:
        USERS.create(
            apikey=get('AWSAccessKeyId'),
            secretkey=get('AWSSecretKey')
        )
        return {
            'template_name_or_list': 'secretkey.xml',
            'response_type': 'RegisterSecretKeyResponse',
            'AWSAccessKeyId': get('AWSAccessKeyId'),
            'AWSSecretKey': get('AWSSecretKey'),
            'Message': 'Successfully Registered!'
        }
    else:
        raise Ec2stackError(
            '400',
            'DuplicateUser',
            'The given AWSAccessKeyId is already registered'
        )
コード例 #5
0
def remove_secret_key():
    """
    Remove a user's API key and secret key

    @return: Response.
    @raise Ec2stackError: API key doesn't exist.
    """
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    accesskey = get('AWSAccessKeyId')
    secretkey = get('AWSSecretKey')

    found_user = USERS.get(accesskey)
    if found_user is not None and found_user.secretkey == secretkey:
        USERS.delete(found_user)
        return {
            'template_name_or_list': 'secretkey.xml',
            'response_type': 'RemoveSecretKeyResponse',
            'AWSAccessKeyId': get('AWSAccessKeyId'),
            'AWSSecretKey': get('AWSSecretKey'),
            'Message': 'Successfully removed!'
        }
    else:
        raise Ec2stackError(
            '400', 'NoSuchUser',
            'The no matching AWSAccessKeyId and AWSSecretKey was not found')
コード例 #6
0
ファイル: default.py プロジェクト: ninetian/ec2stack
def remove_secret_key():
    """
    Remove a user's API key and secret key

    @return: Response.
    @raise Ec2stackError: API key doesn't exist.
    """
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    accesskey = get('AWSAccessKeyId')
    secretkey = get('AWSSecretKey')

    found_user = USERS.get(accesskey)
    if found_user is not None and found_user.secretkey == secretkey:
        USERS.delete(found_user)
        return {
            'template_name_or_list': 'secretkey.xml',
            'response_type': 'RemoveSecretKeyResponse',
            'AWSAccessKeyId': get('AWSAccessKeyId'),
            'AWSSecretKey': get('AWSSecretKey'),
            'Message': 'Successfully removed!'
        }
    else:
        raise Ec2stackError(
            '400',
            'NoSuchUser',
            'The no matching AWSAccessKeyId and AWSSecretKey was not found'
        )
コード例 #7
0
ファイル: security_groups.py プロジェクト: maduhu/ec2stack
def _parse_security_group_request(args=None):
    if args is None:
        args = {}

    helpers.require_atleast_one_parameter(['GroupName', 'GroupId'])

    if helpers.contains_parameter('GroupName'):
        args['securityGroupName'] = helpers.get('GroupName')
        args['name'] = helpers.get('GroupName')
    elif helpers.contains_parameter('GroupId'):
        args['securityGroupId'] = helpers.get('GroupId')
        args['id'] = helpers.get('GroupId')

    helpers.require_parameters(['IpProtocol'])

    args['protocol'] = helpers.get('IpProtocol')

    helpers.require_parameters(['FromPort', 'ToPort'])

    if args['protocol'] in ['icmp']:
        args['icmptype'] = helpers.get('FromPort')
        args['icmpcode'] = helpers.get('ToPort')
    else:
        args['startport'] = helpers.get('FromPort')
        args['endport'] = helpers.get('ToPort')

    if helpers.get('CidrIp') is None:
        args['cidrlist'] = '0.0.0.0/0'
    else:
        args['cidrlist'] = helpers.get('CidrIp')

    return args
コード例 #8
0
def detach_volume():
    """
    Detach a specified volume.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId'])
    response = _detach_volume_request()
    return _detach_volume_response(response)
コード例 #9
0
def attach_volume():
    """
    Attach a volume to the specified instance.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId', 'InstanceId', 'Device'])
    response = _attach_volume_request()
    return _attach_volume_response(response)
コード例 #10
0
def delete_vpc():
    """
    Delete a vpc.

    @return: Response.
    """
    helpers.require_parameters(['VpcId'])
    _delete_vpc_request()
    return _delete_vpc_response()
コード例 #11
0
def get_password_data():
    """
    Gets the password for a specified instance.

    @return: Response.
    """
    helpers.require_parameters(["InstanceId"])
    response = _get_password_data_request()
    return _get_password_data_format_response(response)
コード例 #12
0
def delete_vpc():
    """
    Delete a vpc.

    @return: Response.
    """
    helpers.require_parameters(['VpcId'])
    _delete_vpc_request()
    return _delete_vpc_response()
コード例 #13
0
def delete_keypair():
    """
    Delete a keypair.

    @return: Response.
    """
    helpers.require_parameters(['KeyName'])
    _delete_keypair_request()
    return _delete_keypair_response()
コード例 #14
0
def create_security_group():
    """
    Create a security group.

    @return: Response.
    """
    helpers.require_parameters(['GroupName', 'GroupDescription'])
    response = _create_security_group_request()
    return _create_security_group_response(response)
コード例 #15
0
def import_keypair():
    """
    Imports a keypair.

    @return: Response.
    """
    helpers.require_parameters(['KeyName', 'PublicKeyMaterial'])
    response = _import_keypair_request()
    return _import_keypair_response(response)
コード例 #16
0
ファイル: keypairs.py プロジェクト: ninetian/ec2stack
def import_keypair():
    """
    Imports a keypair.

    @return: Response.
    """
    helpers.require_parameters(["KeyName", "PublicKeyMaterial"])
    response = _import_keypair_request()
    return _import_keypair_response(response)
コード例 #17
0
def get_password_data():
    """
    Gets the password for a specified instance.

    @return: Response.
    """
    helpers.require_parameters(['InstanceId'])
    response = _get_password_data_request()
    return _get_password_data_format_response(response)
コード例 #18
0
def delete_snapshot():
    """
    Delete a snapshot.

    @return: Response.
    """
    helpers.require_parameters(['SnapshotId'])
    response = _delete_snapshot_request()
    return _delete_snapshot_response(response)
コード例 #19
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
def attach_volume():
    """
    Attach a volume to the specified instance.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId', 'InstanceId', 'Device'])
    response = _attach_volume_request()
    return _attach_volume_response(response)
コード例 #20
0
def create_snapshot():
    """
    Create a snapshot.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId'])
    response = _create_snapshot_request()
    return _create_snapshot_response(response)
コード例 #21
0
ファイル: volumes.py プロジェクト: ninetian/ec2stack
def detach_volume():
    """
    Detach a specified volume.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId'])
    response = _detach_volume_request()
    return _detach_volume_response(response)
コード例 #22
0
def create_snapshot():
    """
    Create a snapshot.

    @return: Response.
    """
    helpers.require_parameters(['VolumeId'])
    response = _create_snapshot_request()
    return _create_snapshot_response(response)
コード例 #23
0
def create_security_group():
    """
    Create a security group.

    @return: Response.
    """
    helpers.require_parameters(['GroupName', 'GroupDescription'])
    response = _create_security_group_request()
    return _create_security_group_response(response)
コード例 #24
0
ファイル: keypairs.py プロジェクト: ninetian/ec2stack
def create_keypair():
    """
    Create a keypair.

    @return: Response.
    """
    helpers.require_parameters(["KeyName"])
    response = _create_keypair_request()
    return _create_keypair_response(response)
コード例 #25
0
ファイル: instances.py プロジェクト: maduhu/ec2stack
def stop_instance():
    helpers.require_parameters(['InstanceId.1'])
    instance_id = helpers.get('InstanceId.1')
    previous_instance_state_description = describe_instance_by_id(instance_id)
    new_instance_state_description = _stop_instance_request(instance_id)
    return _stop_instance_response(
        previous_instance_state_description,
        new_instance_state_description
    )
コード例 #26
0
def run_instance():
    """
    Run a instance.

    @return: Response.
    """
    helpers.require_parameters(['ImageId', 'MinCount', 'MaxCount'])
    response = _run_instance_request()
    return _run_instance_response(response)
コード例 #27
0
def delete_snapshot():
    """
    Delete a snapshot.

    @return: Response.
    """
    helpers.require_parameters(['SnapshotId'])
    response = _delete_snapshot_request()
    return _delete_snapshot_response(response)
コード例 #28
0
ファイル: keypairs.py プロジェクト: ninetian/ec2stack
def delete_keypair():
    """
    Delete a keypair.

    @return: Response.
    """
    helpers.require_parameters(["KeyName"])
    _delete_keypair_request()
    return _delete_keypair_response()
コード例 #29
0
def create_keypair():
    """
    Create a keypair.

    @return: Response.
    """
    helpers.require_parameters(['KeyName'])
    response = _create_keypair_request()
    return _create_keypair_response(response)
コード例 #30
0
def delete_volume():
    """
    Delete a volume.

    @return: Response
    """
    helpers.require_parameters(['VolumeId'])
    response = _delete_volume_request()

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

    @return: Response
    """
    helpers.require_parameters(['VolumeId'])
    response = _delete_volume_request()

    return _delete_volume_response(response)
コード例 #32
0
ファイル: instances.py プロジェクト: ninetian/ec2stack
def run_instance():
    """
    Run a instance.

    @return: Response.
    """
    helpers.require_parameters(
        ['ImageId', 'MinCount', 'MaxCount'])
    response = _run_instance_request()
    return _run_instance_response(response)
コード例 #33
0
def reboot_instance():
    """
    Reboot an instance.

    @return: Response.
    """
    helpers.require_parameters(['InstanceId.1'])
    instance_id = helpers.get('InstanceId.1')
    _reboot_instance_request(instance_id)
    return _reboot_instance_response()
コード例 #34
0
ファイル: instances.py プロジェクト: ninetian/ec2stack
def reboot_instance():
    """
    Reboot an instance.

    @return: Response.
    """
    helpers.require_parameters(['InstanceId.1'])
    instance_id = helpers.get('InstanceId.1')
    _reboot_instance_request(instance_id)
    return _reboot_instance_response()
コード例 #35
0
def terminate_instance():
    """
    Terminate an instance.

    @return: Response.
    """
    helpers.require_parameters(['InstanceId.1'])
    instance_id = helpers.get('InstanceId.1')
    previous_state = describe_instance_by_id(instance_id)
    new_state = _terminate_instance_request(instance_id)
    return _modify_instance_state_response('TerminateInstancesResponse',
                                           previous_state, new_state)
コード例 #36
0
ファイル: instances.py プロジェクト: ninetian/ec2stack
def terminate_instance():
    """
    Terminate an instance.

    @return: Response.
    """
    helpers.require_parameters(['InstanceId.1'])
    instance_id = helpers.get('InstanceId.1')
    previous_state = describe_instance_by_id(instance_id)
    new_state = _terminate_instance_request(instance_id)
    return _modify_instance_state_response(
        'TerminateInstancesResponse',
        previous_state,
        new_state
    )
コード例 #37
0
def register_secret_key():
    require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
    found_user = USERS.get(get('AWSAccessKeyId'))
    if found_user is None:
        USERS.create(apikey=get('AWSAccessKeyId'),
                     secretkey=get('AWSSecretKey'))
        return {
            'template_name_or_list': 'secretkey.xml',
            'response_type': 'RegisterSecretKeyResponse',
            'AWSAccessKeyId': get('AWSAccessKeyId'),
            'AWSSecretKey': get('AWSSecretKey'),
            'Message': 'Successfully Registered!'
        }
    else:
        raise Ec2stackError('400', 'DuplicateUser',
                            'The given AWSAccessKeyId is already registered')
コード例 #38
0
def register_secret_key():
    """
    Register a user's API key and secret key.

    @return: Response.
    @raise Ec2stackError: API key already registered.
    """
    require_parameters({"AWSAccessKeyId", "AWSSecretKey"})
    found_user = USERS.get(get("AWSAccessKeyId"))
    if found_user is None:
        USERS.create(apikey=get("AWSAccessKeyId"), secretkey=get("AWSSecretKey"))
        return {
            "template_name_or_list": "secretkey.xml",
            "response_type": "RegisterSecretKeyResponse",
            "AWSAccessKeyId": get("AWSAccessKeyId"),
            "AWSSecretKey": get("AWSSecretKey"),
            "Message": "Successfully Registered!",
        }
    else:
        raise Ec2stackError("400", "DuplicateUser", "The given AWSAccessKeyId is already registered")
コード例 #39
0
def _parse_security_group_request(args=None):
    """
    Parse the request parameters into a Cloudstack request payload.

    @param args: Arguments to include in the request.
    @return: Request payload.
    """
    if args is None:
        args = {}

    helpers.require_atleast_one_parameter(['GroupName', 'GroupId'])

    if helpers.contains_parameter('GroupName'):
        args['securityGroupName'] = helpers.get('GroupName')
        args['name'] = helpers.get('GroupName')
    elif helpers.contains_parameter('GroupId'):
        args['securityGroupId'] = helpers.get('GroupId')
        args['id'] = helpers.get('GroupId')

    helpers.require_parameters(['IpProtocol'])

    args['protocol'] = helpers.get('IpProtocol')

    helpers.require_parameters(['FromPort', 'ToPort'])

    if args['protocol'] in ['icmp']:
        args['icmptype'] = helpers.get('FromPort')
        args['icmpcode'] = helpers.get('ToPort')
    else:
        args['startport'] = helpers.get('FromPort')
        args['endport'] = helpers.get('ToPort')

    if helpers.get('CidrIp') is None:
        args['cidrlist'] = '0.0.0.0/0'
    else:
        args['cidrlist'] = helpers.get('CidrIp')

    return args
コード例 #40
0
def _parse_security_group_request(args=None):
    """
    Parse the request parameters into a Cloudstack request payload.

    @param args: Arguments to include in the request.
    @return: Request payload.
    """
    if args is None:
        args = {}

    helpers.require_atleast_one_parameter(['GroupName', 'GroupId'])

    if helpers.contains_parameter('GroupName'):
        args['securityGroupName'] = helpers.get('GroupName')
        args['name'] = helpers.get('GroupName')
    elif helpers.contains_parameter('GroupId'):
        args['securityGroupId'] = helpers.get('GroupId')
        args['id'] = helpers.get('GroupId')

    helpers.require_parameters(['IpProtocol'])

    args['protocol'] = helpers.get('IpProtocol')

    helpers.require_parameters(['FromPort', 'ToPort'])

    if args['protocol'] in ['icmp']:
        args['icmptype'] = helpers.get('FromPort')
        args['icmpcode'] = helpers.get('ToPort')
    else:
        args['startport'] = helpers.get('FromPort')
        args['endport'] = helpers.get('ToPort')

    if helpers.get('CidrIp') is None:
        args['cidrlist'] = '0.0.0.0/0'
    else:
        args['cidrlist'] = helpers.get('CidrIp')

    return args
コード例 #41
0
def remove_secret_key():
    """
    Remove a user's API key and secret key

    @return: Response.
    @raise Ec2stackError: API key doesn't exist.
    """
    require_parameters({"AWSAccessKeyId", "AWSSecretKey"})
    accesskey = get("AWSAccessKeyId")
    secretkey = get("AWSSecretKey")

    found_user = USERS.get(accesskey)
    if found_user is not None and found_user.secretkey == secretkey:
        USERS.delete(found_user)
        return {
            "template_name_or_list": "secretkey.xml",
            "response_type": "RemoveSecretKeyResponse",
            "AWSAccessKeyId": get("AWSAccessKeyId"),
            "AWSSecretKey": get("AWSSecretKey"),
            "Message": "Successfully removed!",
        }
    else:
        raise Ec2stackError("400", "NoSuchUser", "The no matching AWSAccessKeyId and AWSSecretKey was not found")
コード例 #42
0
ファイル: keypairs.py プロジェクト: vogxn/ec2stack
def create_keypair():
    helpers.require_parameters(['KeyName'])
    response = _create_keypair_request()
    return _create_keypair_response(response)
コード例 #43
0
ファイル: keypairs.py プロジェクト: maduhu/ec2stack
def delete_keypair():
    helpers.require_parameters(['KeyName'])
    _delete_keypair_request()
    return _delete_keypair_response()
コード例 #44
0
ファイル: keypairs.py プロジェクト: maduhu/ec2stack
def create_keypair():
    helpers.require_parameters(['KeyName'])
    response = _create_keypair_request()
    return _create_keypair_response(response)
コード例 #45
0
ファイル: keypairs.py プロジェクト: vogxn/ec2stack
def import_keypair():
    helpers.require_parameters(['KeyName', 'PublicKeyMaterial'])
    response = _import_keypair_request()
    return _import_keypair_response(response)
コード例 #46
0
def delete_volume():
    helpers.require_parameters(['VolumeId'])
    response = _delete_volume_request()

    return _delete_volume_response(response)
コード例 #47
0
ファイル: passwords.py プロジェクト: maduhu/ec2stack
def get_password_data():
    helpers.require_parameters(['InstanceId'])
    response = _get_password_data_request()
    return _get_password_data_format_response(response)
コード例 #48
0
def attach_volume():
    helpers.require_parameters(['VolumeId', 'InstanceId', 'Device'])
    response = _attach_volume_request()
    return _attach_volume_response(response)
コード例 #49
0
ファイル: volumes.py プロジェクト: vogxn/ec2stack
def attach_volume():
    helpers.require_parameters(["VolumeId", "InstanceId", "Device"])
    response = _attach_volume_request()
    return _attach_volume_response(response)
コード例 #50
0
ファイル: volumes.py プロジェクト: vogxn/ec2stack
def delete_volume():
    helpers.require_parameters(["VolumeId"])
    response = _delete_volume_request()

    return _delete_volume_response(response)
コード例 #51
0
ファイル: security_groups.py プロジェクト: vogxn/ec2stack
def create_security_group():
    helpers.require_parameters(["GroupName", "GroupDescription"])
    response = _create_security_group_request()
    return _create_security_group_response(response)
コード例 #52
0
ファイル: keypairs.py プロジェクト: vogxn/ec2stack
def delete_keypair():
    helpers.require_parameters(['KeyName'])
    _delete_keypair_request()
    return _delete_keypair_response()