Skip to content
Permalink
Browse files
auto cleanup
  • Loading branch information
imduffy15 committed Feb 27, 2014
1 parent 48961dd commit ed1cbfcc3a38436e98060e88b422a1db40271487
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 147 deletions.
@@ -1,3 +1,3 @@
==================
=======
History
==================
=======
@@ -21,7 +21,7 @@ Usage
-----

Configuration
''''''''''''''
'''''''''''''

When you install ec2stack a default global configuration file is placed into /etc/ec2stack.conf or the site-package directory for ec2stack if you are running it within a virtualenv.

@@ -47,12 +47,12 @@ def _create_config_file(config_folder):
cloudstack_path = '/client/api'

config_file = open(config_folder + '/ec2stack.conf', 'w+')
config_file.write('EC2STACK_BIND_ADDRESS = \'%s\'\n' % (ec2stack_address))
config_file.write('EC2STACK_PORT = \'%s\'\n' % (ec2stack_port))
config_file.write('CLOUDSTACK_HOST = \'%s\'\n' % (cloudstack_host))
config_file.write('CLOUDSTACK_PORT = \'%s\'\n' % (cloudstack_port))
config_file.write('CLOUDSTACK_PROTOCOL = \'%s\'\n' % (cloudstack_protocol))
config_file.write('CLOUDSTACK_PATH = \'%s\'\n' % (cloudstack_path))
config_file.write('EC2STACK_BIND_ADDRESS = \'%s\'\n' % ec2stack_address)
config_file.write('EC2STACK_PORT = \'%s\'\n' % ec2stack_port)
config_file.write('CLOUDSTACK_HOST = \'%s\'\n' % cloudstack_host)
config_file.write('CLOUDSTACK_PORT = \'%s\'\n' % cloudstack_port)
config_file.write('CLOUDSTACK_PROTOCOL = \'%s\'\n' % cloudstack_protocol)
config_file.write('CLOUDSTACK_PATH = \'%s\'\n' % cloudstack_path)
config_file.close()


@@ -45,8 +45,8 @@ def _get_action(action):
'DescribeVolumes': volumes.describe_volumes,
'GetPasswordData': passwords.get_password_data,
'ImportKeyPair': keypairs.import_keypair,
'RegisterSecretKey': registerSecretKey,
'RemoveSecretKey': removeSecretKey,
'RegisterSecretKey': register_secret_key,
'RemoveSecretKey': remove_secret_key,
'RevokeSecurityGroupEgress':
security_groups.revoke_security_group_egress,
'RevokeSecurityGroupIngress':
@@ -59,11 +59,11 @@ def _get_action(action):
raise Ec2stackError(
'400',
'InvalidAction',
'The action %s is not valid for this web service' % (action)
'The action %s is not valid for this web service' % action
)


def registerSecretKey():
def register_secret_key():
require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
found_user = USERS.get(get('AWSAccessKeyId'))
if found_user is None:
@@ -85,7 +85,7 @@ def registerSecretKey():
)


def removeSecretKey():
def remove_secret_key():
require_parameters({'AWSAccessKeyId', 'AWSSecretKey'})
accesskey = get('AWSAccessKeyId')
secretkey = get('AWSSecretKey')
@@ -17,8 +17,7 @@ def describe_item(args, keyname, not_found, prefix):
def _describe_specific_item(args, keyname, not_found, prefix):
keys = helpers.get_request_parameter_keys(prefix)

response = {}
response[keyname] = []
response = {keyname: []}

for key in keys:
name = helpers.get(key)
@@ -5,8 +5,7 @@


def get_disk_offerings_id_by_name(name):
args = {}
args['name'] = name
args = {'name': name}
response = _describe_disk_offerings_request(args)
response = response['diskoffering'][0]
return response['id']
@@ -7,9 +7,7 @@

@helpers.authentication_required
def describe_images():
args = {}
args['templatefilter'] = 'executable'
args['command'] = 'listTemplates'
args = {'templatefilter': 'executable', 'command': 'listTemplates'}
response = cloudstack.describe_item(
args, 'template', errors.invalid_image_id, 'ImageId'
)
@@ -47,10 +45,10 @@ def _describe_image_attribute_response(response):


def describe_image_by_id(image_id):
args = {}
args['id'] = image_id
args['templatefilter'] = 'executable'
args['command'] = 'listTemplates'
args = {
'id': image_id,
'templatefilter': 'executable',
'command': 'listTemplates'}
response = cloudstack.describe_item_request(
args, 'template', errors.invalid_image_id
)
@@ -8,8 +8,7 @@

@helpers.authentication_required
def describe_instances():
args = {}
args['command'] = 'listVirtualMachines'
args = {'command': 'listVirtualMachines'}
response = cloudstack.describe_item(
args, 'virtualmachine', errors.invalid_instance_id, 'InstanceId'
)
@@ -20,9 +19,7 @@ def describe_instances():


def describe_instance_by_id(instance_id):
args = {}
args['id'] = instance_id
args['command'] = 'listVirtualMachines'
args = {'id': instance_id, 'command': 'listVirtualMachines'}
response = cloudstack.describe_item_request(
args, 'virtualmachine', errors.invalid_instance_id
)
@@ -17,9 +17,7 @@ def create_keypair():


def _create_keypair_request():
args = {}
args['command'] = 'createSSHKeyPair'
args['name'] = helpers.get('KeyName')
args = {'command': 'createSSHKeyPair', 'name': helpers.get('KeyName')}

response = requester.make_request(args)

@@ -42,8 +40,7 @@ def _create_keypair_response(response):

@helpers.authentication_required
def describe_keypairs():
args = {}
args['command'] = 'listSSHKeyPairs'
args = {'command': 'listSSHKeyPairs'}
response = cloudstack.describe_item(
args, 'sshkeypair', errors.invalid_keypair_name, 'KeyName'
)
@@ -69,9 +66,7 @@ def delete_keypair():


def _delete_keypair_request():
args = {}
args['command'] = 'deleteSSHKeyPair'
args['name'] = helpers.get('KeyName')
args = {'command': 'deleteSSHKeyPair', 'name': helpers.get('KeyName')}

response = requester.make_request(args)

@@ -94,10 +89,8 @@ def import_keypair():


def _import_keypair_request():
args = {}
args['command'] = 'registerSSHKeyPair'
args['name'] = helpers.get('KeyName')
args['publickey'] = b64decode(helpers.get('PublicKeyMaterial'))
args = {'command': 'registerSSHKeyPair', 'name': helpers.get('KeyName'),
'publickey': b64decode(helpers.get('PublicKeyMaterial'))}

response = requester.make_request(args)
response = response['registersshkeypairresponse']
@@ -14,9 +14,7 @@ def get_password_data():


def _get_password_data_request():
args = {}
args['command'] = 'getVMPassword'
args['id'] = helpers.get('InstanceId')
args = {'command': 'getVMPassword', 'id': helpers.get('InstanceId')}

response = requester.make_request(args)

@@ -47,9 +47,8 @@ def make_request_async(args, poll_period=2, timeout=3600):
responsekey = response.keys()[0]

if 'jobid' in response[responsekey]:
args = {}
args['command'] = 'queryAsyncJobResult'
args['jobid'] = response[responsekey]['jobid']
args = {'command': 'queryAsyncJobResult',
'jobid': response[responsekey]['jobid']}

response = make_request(args)

@@ -60,7 +59,7 @@ def make_request_async(args, poll_period=2, timeout=3600):
return response['jobresult']
elif job_status == 0:
time.sleep(poll_period)
timeout = timeout - poll_period
timeout -= poll_period
return make_request_async(args, poll_period=poll_period,
timeout=timeout)
else:
@@ -15,10 +15,8 @@ def create_security_group():


def _create_security_group_request():
args = {}
args['command'] = 'createSecurityGroup'
args['name'] = helpers.get('GroupName')
args['description'] = helpers.get('GroupDescription')
args = {'command': 'createSecurityGroup', 'name': helpers.get('GroupName'),
'description': helpers.get('GroupDescription')}

response = requester.make_request(args)

@@ -74,8 +72,7 @@ def _delete_security_group_response():

@helpers.authentication_required
def describe_security_groups():
args = {}
args['command'] = 'listSecurityGroups'
args = {'command': 'listSecurityGroups'}

response = cloudstack.describe_item(
args, 'securitygroup', errors.invalid_security_group, 'Group'
@@ -21,9 +21,7 @@ def describe_volumes():


def _describe_volumes_request():
args = {}

args['command'] = 'listVolumes'
args = {'command': 'listVolumes'}

response = requester.make_request(args)
response = response['listvolumesresponse']
@@ -90,9 +88,7 @@ def delete_volume():


def _delete_volume_request():
args = {}
args['id'] = helpers.get('VolumeId')
args['command'] = 'deleteVolume'
args = {'id': helpers.get('VolumeId'), 'command': 'deleteVolume'}

response = requester.make_request(args)
response = response['deletevolumeresponse']
@@ -8,8 +8,7 @@

@helpers.authentication_required
def describe_zones():
args = {}
args['command'] = 'listZones'
args = {'command': 'listZones'}
response = cloudstack.describe_item(
args, 'zone', errors.invalid_zone, 'ZoneName'
)
@@ -20,9 +19,7 @@ def describe_zones():


def describe_zone_by_name(zone_name):
args = {}
args['name'] = zone_name
args['command'] = 'listZones'
args = {'name': zone_name, 'command': 'listZones'}
response = cloudstack.describe_item_request(
args, 'zone', errors.invalid_zone
)
@@ -29,7 +29,7 @@ def read_file(name):
LONG_DESC = read_file('README.rst')
REQUIRES = [
'Flask', 'Flask-Migrate', 'Flask-Script', 'Flask-SQLAlchemy', 'Requests',
'factory-boy==1.3.0', 'mock'
'factory-boy==1.3.0', 'mock', 'factory'
]
DATA_FILES = []
if os.getenv('VIRTUAL_ENV', False):
@@ -18,7 +18,7 @@ def test_invalid_action(self):
data={}
)

self.assertBadRequest(response)
self.assert_bad_request(response)
assert 'not valid for this web service' in response.data

def test_authentication_required_parameters(self):
@@ -34,7 +34,7 @@ def _test_authentication_required_helper(self, item, data):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)
data[item] = value

def test_invalid_signature_version(self):
@@ -46,7 +46,7 @@ def test_invalid_signature_version(self):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)
assert 'SignatureVersion is invalid' in response.data

def test_invalid_signature_method(self):
@@ -58,7 +58,7 @@ def test_invalid_signature_method(self):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)
assert 'SignatureMethod is invalid' in response.data

def test_failure_to_find_secretkey(self):
@@ -69,7 +69,7 @@ def test_failure_to_find_secretkey(self):
data=data
)

self.assertStatusCode(response, 401)
self.assert_status_code(response, 401)
assert 'Unable to find a secret key' in response.data

def test_invalid_signature(self):
@@ -80,7 +80,7 @@ def test_invalid_signature(self):
data=data
)

self.assertStatusCode(response, 401)
self.assert_status_code(response, 401)

assert 'AWS was not able to validate the provided access credentials.' \
in response.data
@@ -97,7 +97,7 @@ def test_duplicate_register_secretkey(self):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)

assert 'The given AWSAccessKeyId is already registered' \
in response.data
@@ -114,7 +114,7 @@ def test_successful_register_secretkey(self):
data=data
)

self.assertOk(response)
self.assert_ok(response)

assert 'RegisterSecretKeyResponse' in response.data

@@ -130,7 +130,7 @@ def test_successful_delete_secretkey(self):
data=data
)

self.assertOk(response)
self.assert_ok(response)
assert 'RemoveSecretKeyResponse' in response.data

def test_not_found_delete_secretkey(self):
@@ -145,15 +145,15 @@ def test_not_found_delete_secretkey(self):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)
assert 'The no matching AWSAccessKeyId' in response.data

def test_not_found(self):
response = self.post(
'/example-not-found-url',
)

self.assertNotFound(response)
self.assert_not_found(response)

def test_bad_request_on_provider_error(self):
data = self.get_example_data()
@@ -170,4 +170,4 @@ def test_bad_request_on_provider_error(self):
data=data
)

self.assertBadRequest(response)
self.assert_bad_request(response)

0 comments on commit ed1cbfc

Please sign in to comment.