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 _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
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
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' )
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')
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' )
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
def detach_volume(): """ Detach a specified volume. @return: Response. """ helpers.require_parameters(['VolumeId']) response = _detach_volume_request() return _detach_volume_response(response)
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)
def delete_vpc(): """ Delete a vpc. @return: Response. """ helpers.require_parameters(['VpcId']) _delete_vpc_request() return _delete_vpc_response()
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)
def delete_keypair(): """ Delete a keypair. @return: Response. """ helpers.require_parameters(['KeyName']) _delete_keypair_request() return _delete_keypair_response()
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)
def import_keypair(): """ Imports a keypair. @return: Response. """ helpers.require_parameters(['KeyName', 'PublicKeyMaterial']) response = _import_keypair_request() return _import_keypair_response(response)
def import_keypair(): """ Imports a keypair. @return: Response. """ helpers.require_parameters(["KeyName", "PublicKeyMaterial"]) response = _import_keypair_request() return _import_keypair_response(response)
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)
def delete_snapshot(): """ Delete a snapshot. @return: Response. """ helpers.require_parameters(['SnapshotId']) response = _delete_snapshot_request() return _delete_snapshot_response(response)
def create_snapshot(): """ Create a snapshot. @return: Response. """ helpers.require_parameters(['VolumeId']) response = _create_snapshot_request() return _create_snapshot_response(response)
def create_keypair(): """ Create a keypair. @return: Response. """ helpers.require_parameters(["KeyName"]) response = _create_keypair_request() return _create_keypair_response(response)
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 )
def run_instance(): """ Run a instance. @return: Response. """ helpers.require_parameters(['ImageId', 'MinCount', 'MaxCount']) response = _run_instance_request() return _run_instance_response(response)
def delete_keypair(): """ Delete a keypair. @return: Response. """ helpers.require_parameters(["KeyName"]) _delete_keypair_request() return _delete_keypair_response()
def create_keypair(): """ Create a keypair. @return: Response. """ helpers.require_parameters(['KeyName']) response = _create_keypair_request() return _create_keypair_response(response)
def delete_volume(): """ Delete a volume. @return: Response """ helpers.require_parameters(['VolumeId']) response = _delete_volume_request() return _delete_volume_response(response)
def run_instance(): """ Run a instance. @return: Response. """ helpers.require_parameters( ['ImageId', 'MinCount', 'MaxCount']) response = _run_instance_request() return _run_instance_response(response)
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()
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)
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 )
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')
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")
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
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")
def create_keypair(): helpers.require_parameters(['KeyName']) response = _create_keypair_request() return _create_keypair_response(response)
def delete_keypair(): helpers.require_parameters(['KeyName']) _delete_keypair_request() return _delete_keypair_response()
def import_keypair(): helpers.require_parameters(['KeyName', 'PublicKeyMaterial']) response = _import_keypair_request() return _import_keypair_response(response)
def delete_volume(): helpers.require_parameters(['VolumeId']) response = _delete_volume_request() return _delete_volume_response(response)
def get_password_data(): helpers.require_parameters(['InstanceId']) response = _get_password_data_request() return _get_password_data_format_response(response)
def attach_volume(): helpers.require_parameters(['VolumeId', 'InstanceId', 'Device']) response = _attach_volume_request() return _attach_volume_response(response)
def attach_volume(): helpers.require_parameters(["VolumeId", "InstanceId", "Device"]) response = _attach_volume_request() return _attach_volume_response(response)
def delete_volume(): helpers.require_parameters(["VolumeId"]) response = _delete_volume_request() return _delete_volume_response(response)
def create_security_group(): helpers.require_parameters(["GroupName", "GroupDescription"]) response = _create_security_group_request() return _create_security_group_response(response)