Skip to content
Permalink
Browse files
Add comments to controllers
  • Loading branch information
brogand93 committed Mar 9, 2014
1 parent c97e358 commit 0a4e766a0a29e0dd99dd1e76e1eaab61d35f809b
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 141 deletions.
@@ -7,9 +7,10 @@

def get_disk_offering(disk_name):
"""
Get the disk offering with the specified name.
@param disk_name:
@return:
@param disk_name: The name of the disk offering to get.
@return: Response.
"""
args = {'name': disk_name, 'command': 'listDiskOfferings'}
response = cloudstack.describe_item_request(
@@ -8,9 +8,9 @@
@helpers.authentication_required
def describe_image_attribute():
"""
Describes an image attribute.
@return:
@return: Response.
"""
image_id = helpers.get('ImageId')
attribute = helpers.get('Attribute')
@@ -32,11 +32,12 @@ def describe_image_attribute():

def _describe_image_attribute_response(response, attribute, attr_map):
"""
Generates a response for a describe image attribute request.
@param response:
@param attribute:
@param attr_map:
@return:
@param response: Response from Cloudstack.
@param attribute: Attribute to Describe.
@param attr_map: Map of attributes from EC2 to Cloudstack.
@return: Response.
"""
return {
'template_name_or_list': 'image_attribute.xml',
@@ -50,9 +51,9 @@ def _describe_image_attribute_response(response, attribute, attr_map):
@helpers.authentication_required
def describe_images():
"""
Describe a specific image or all images.
@return:
@return: Response.
"""
args = {'templatefilter': 'executable', 'command': 'listTemplates'}
response = cloudstack.describe_item(
@@ -64,24 +65,12 @@ def describe_images():
)


def _describe_images_response(response):
"""
@param response:
@return:
"""
return {
'template_name_or_list': 'images.xml',
'response_type': 'DescribeImagesResponse',
'response': response
}


def describe_image_by_id(image_id):
"""
Describe an image by Id.
@param image_id:
@return:
@param image_id: Id of the image.
@return: Response.
"""
args = {
'id': image_id,
@@ -91,3 +80,17 @@ def describe_image_by_id(image_id):
args, 'template', errors.invalid_image_id
)
return response


def _describe_images_response(response):
"""
Generates a response for a describe images request.
@param response: Response from Cloudstack.
@return: Response.
"""
return {
'template_name_or_list': 'images.xml',
'response_type': 'DescribeImagesResponse',
'response': response
}
@@ -114,7 +114,7 @@ def run_instance():

def _run_instance_request():
"""
Request to bring up an instance
Request to bring up an instance.
@return: Response.
"""
@@ -280,13 +280,13 @@ def _start_instance_request(instance_id):


def _modify_instance_state_response(response_type, previous_state, new_state):
# TODO @BroganD1993 commenting.
"""
Generates a response for a Start, Stop, Terminate requests.
@param response_type:
@param previous_state:
@param new_state:
@return:
@param response_type: Cloudstack response.
@param previous_state: The previous state of the instance
@param new_state: The new state of the instance
@return: Response
"""
response = {
'template_name_or_list': 'change_instance_state.xml',
@@ -350,7 +350,7 @@ def terminate_instance():

def _terminate_instance_request(instance_id):
"""
Request ot terminate an instance.
Request to terminate an instance.
@param instance_id: Id of instance to terminate.
@return: Response.
@@ -12,9 +12,9 @@
@helpers.authentication_required
def create_keypair():
"""
Create a keypair.
@return:
@return: Response.
"""
helpers.require_parameters(['KeyName'])
response = _create_keypair_request()
@@ -23,9 +23,10 @@ def create_keypair():

def _create_keypair_request():
"""
Request to create a keypair.
@return:
@param: response
@return: Response.
"""
args = {'command': 'createSSHKeyPair', 'name': helpers.get('KeyName')}

@@ -38,9 +39,10 @@ def _create_keypair_request():

def _create_keypair_response(response):
"""
Generates a response for create keypair request.
@param response:
@return:
@param response: Response from cloudstack.
@return: Response.
"""
if 'errortext' in response:
errors.duplicate_keypair_name()
@@ -56,9 +58,9 @@ def _create_keypair_response(response):
@helpers.authentication_required
def delete_keypair():
"""
Delete a keypair.
@return:
@return: Response
"""
helpers.require_parameters(['KeyName'])
_delete_keypair_request()
@@ -67,9 +69,9 @@ def delete_keypair():

def _delete_keypair_request():
"""
Request to delete a keypair.
@return:
@return: Response.
"""
args = {'command': 'deleteSSHKeyPair', 'name': helpers.get('KeyName')}

@@ -80,9 +82,9 @@ def _delete_keypair_request():

def _delete_keypair_response():
"""
Generates a response for delete keypair request.
@return:
@return: Response.
"""
return {
'template_name_or_list': 'status.xml',
@@ -94,9 +96,9 @@ def _delete_keypair_response():
@helpers.authentication_required
def describe_keypairs():
"""
Describes a specific keypair or all keypairs.
@return:
@return: Response.
"""
args = {'command': 'listSSHKeyPairs'}
response = cloudstack.describe_item(
@@ -110,9 +112,10 @@ def describe_keypairs():

def _describe_keypair_response(response):
"""
Generates a response for describe keypair request.
@param response:
@return:
@param response: Response from cloudstack.
@return: Response.
"""
return {
'template_name_or_list': 'keypairs.xml',
@@ -124,9 +127,9 @@ def _describe_keypair_response(response):
@helpers.authentication_required
def import_keypair():
"""
Imports a keypair.
@return:
@return: Response
"""
helpers.require_parameters(['KeyName', 'PublicKeyMaterial'])
response = _import_keypair_request()
@@ -135,9 +138,9 @@ def import_keypair():

def _import_keypair_request():
"""
Request to import a keypair.
@return:
@return: Response.
"""
args = {'command': 'registerSSHKeyPair', 'name': helpers.get('KeyName'),
'publickey': b64decode(helpers.get('PublicKeyMaterial'))}
@@ -150,9 +153,10 @@ def _import_keypair_request():

def _import_keypair_response(response):
"""
Generates a response for import keypair request.
@param response:
@return:
@param response: Response from cloudstack.
@return: Response.
"""
if 'errortext' in response:
errors.duplicate_keypair_name()
@@ -1,17 +1,16 @@
#!/usr/bin/env python
# encoding: utf-8

from ec2stack import helpers
from ec2stack.core import Ec2stackError
from ec2stack import helpers, errors
from ec2stack.providers.cloudstack import requester


@helpers.authentication_required
def get_password_data():
"""
Gets the password for a specified instance.
@return:
@return: Response.
"""
helpers.require_parameters(['InstanceId'])
response = _get_password_data_request()
@@ -20,9 +19,9 @@ def get_password_data():

def _get_password_data_request():
"""
Request to get password.
@return:
@return: Response.
"""
args = {'command': 'getVMPassword', 'id': helpers.get('InstanceId')}

@@ -35,17 +34,13 @@ def _get_password_data_request():

def _get_password_data_format_response(response):
"""
Generate a response for get password request.
@param response:
@return: @raise Ec2stackError:
@param response: Cloudstack response.
@return: Response
"""
instanceid = helpers.get('InstanceId')
if 'errortext' in response:
raise Ec2stackError(
'400',
'InvalidInstanceID.NotFound',
'The instance ID \'%s\' does not exist.' % instanceid
)
errors.invalid_instance_id()
else:
response = response['password']
return {

0 comments on commit 0a4e766

Please sign in to comment.