diff --git a/saltcloud/clouds/EC2.py b/saltcloud/clouds/EC2.py index c1e83bdac3..5c45518cc2 100644 --- a/saltcloud/clouds/EC2.py +++ b/saltcloud/clouds/EC2.py @@ -15,6 +15,7 @@ from libcloud.compute.deployment import MultiStepDeployment, ScriptDeployment, S # Import salt libs import saltcloud.utils +from saltcloud.libcloudfuncs import * # Import paramiko import paramiko @@ -33,107 +34,6 @@ def get_conn(): ) -def ssh_pub(vm_): - ''' - Deploy the primary ssh authentication key - ''' - ssh = '' - if 'ssh_auth' in vm_: - if not os.path.isfile(vm_['ssh_auth']): - return None - ssh = vm_['ssh_auth'] - if not ssh: - if not os.path.isfile(__opts__['ssh_auth']): - return None - ssh = __opts__['ssh_auth'] - - return SSHKeyDeployment(open(os.path.expanduser(ssh)).read()) - - -def script(vm_): - ''' - Return the script deployment object - ''' - minion = saltcloud.utils.minion_conf_string(__opts__, vm_) - return ScriptDeployment( - saltcloud.utils.os_script( - saltcloud.utils.get_option( - 'os', - __opts__, - vm_ - ), - vm_, - __opts__, - minion, - ), - name='/home/ec2-user/deployment.sh' - ) - - -def avail_images(): - ''' - Return a dict of all available vm images on the cloud provider with - relevant data - ''' - conn = get_conn() - images = conn.list_images() - ret = {} - for img in images: - ret[img.name] = {} - for attr in dir(img): - if attr.startswith('_'): - continue - ret[img.name][attr] = getattr(img, attr) - return ret - - -def avail_sizes(): - ''' - Return a dict of all available vm images on the cloud provider with - relevant data - ''' - conn = get_conn() - sizes = conn.list_sizes() - ret = {} - for size in sizes: - ret[size.name] = {} - for attr in dir(size): - if attr.startswith('_'): - continue - ret[size.name][attr] = getattr(size, attr) - return ret - - -def get_image(conn, vm_): - ''' - Return the image object to use - ''' - images = conn.list_images() - if not 'image' in vm_: - return images[0] - if isinstance(vm_['image'], int): - return images[vm_['image']] - for img in images: - if img.id == vm_['image']: - return img - - -def get_size(conn, vm_): - ''' - Return the vm's size object - ''' - sizes = conn.list_sizes() - if not 'size' in vm_: - return sizes[0] - if isinstance(vm_['size'], int): - return sizes[vm_['size']] - for size in sizes: - if size.id == vm_['size']: - return size - if size.name == vm_['size']: - return size - - def keyname(vm_): ''' Return the keyname @@ -151,24 +51,6 @@ def securitygroup(vm_): ) -def list_nodes(): - ''' - Return a list of the vms that are on the provider - ''' - conn = get_conn() - nodes = conn.list_nodes() - ret = {} - for node in nodes: - ret[node.name] = { - 'id': node.id, - 'image': node.image, - 'private_ips': node.private_ips, - 'public_ips': node.public_ips, - 'size': node.size, - 'state': node.state} - return ret - - def create(vm_): ''' Create a single vm from a data dict