From 9a2b0d9dd748ffbc2322fc3f6a72a86355829f2f Mon Sep 17 00:00:00 2001 From: K Jonathan Harker Date: Fri, 26 Oct 2012 23:50:28 +0000 Subject: [PATCH] hpcs.py has been merged into openstack.py --- saltcloud/clouds/hpcs.py | 163 --------------------------------------- 1 file changed, 163 deletions(-) delete mode 100644 saltcloud/clouds/hpcs.py diff --git a/saltcloud/clouds/hpcs.py b/saltcloud/clouds/hpcs.py deleted file mode 100644 index f797dbc189..0000000000 --- a/saltcloud/clouds/hpcs.py +++ /dev/null @@ -1,163 +0,0 @@ -''' -HP Cloud Module -====================== - -The HP cloud module. This module uses the preferred means to set up a -libcloud based cloud module and should be used as the general template for -setting up additional libcloud based modules. - -The HP cloud module interfaces with the HP public cloud service -and requires that two configuration paramaters be set for use: - -.. code-block:: yaml - - # The login user - HPCLOUD.user: fred - # The user's password - HPCLOUD.password: mylittlesecret - # The auth endpoint url - HPCLOUD.auth_endpoint: https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/ - # The compute region - HPCLOUD.region: az-1.region-a.geo-1 - # The keypair name - HPCLOUD.keyname: cloudKey - # The tenant name (not tenant ID) - HPCLOUD.tenant_name: fred-tenant1 - -''' - -# The import section is mostly libcloud boilerplate - -# Import python libs -import os -import sys -import types -import paramiko -import tempfile -import traceback - -# Import libcloud -from libcloud.compute.types import Provider -from libcloud.compute.providers import get_driver -from libcloud.compute.deployment import MultiStepDeployment, ScriptDeployment, SSHKeyDeployment - -# Import generic libcloud functions -from saltcloud.libcloudfuncs import * - -# Some of the libcloud functions need to be in the same namespace as the -# functions defined in the module, so we create new function objects inside -# this module namespace -avail_images = types.FunctionType(avail_images.__code__, globals()) -avail_sizes = types.FunctionType(avail_sizes.__code__, globals()) -script = types.FunctionType(script.__code__, globals()) -destroy = types.FunctionType(destroy.__code__, globals()) -list_nodes = types.FunctionType(list_nodes.__code__, globals()) -list_nodes_full = types.FunctionType(list_nodes_full.__code__, globals()) - - -# Only load in this module is the HPCLOUD configurations are in place -def __virtual__(): - ''' - Set up the libcloud functions and check for HPCLOUD configs - ''' - key_values = [ 'HPCLOUD.user' - , 'HPCLOUD.password' - , 'HPCLOUD.auth_endpoint' - , 'HPCLOUD.region' - , 'HPCLOUD.keyname' - , 'HPCLOUD.tenant_name' - ] - have_values = 0 - for value in key_values: - if value in __opts__: - have_values += 1 - print have_values, len(key_values), value - if have_values == len(key_values): - return 'hpcs' - return False - - -def get_conn(): - ''' - Return a conn object for the passed vm data - ''' - driver = get_driver(Provider.OPENSTACK) - return driver( - __opts__['HPCLOUD.user'], - __opts__['HPCLOUD.password'], - ex_force_auth_url = __opts__['HPCLOUD.auth_endpoint'], - ex_force_auth_version = '2.0_password', - ex_force_service_name = 'Compute', - ex_force_service_region = __opts__['HPCLOUD.region'], - ex_tenant_name = __opts__['HPCLOUD.tenant_name'] - ) - - -def create(vm_): - ''' - Create a single vm from a data dict - ''' - print('Creating Cloud VM {0}'.format(vm_['name'])) - conn = get_conn() - deploy_script = script(vm_) - kwargs = {} - kwargs['name'] = vm_['name'] - kwargs['image'] = get_image(conn, vm_) - if not kwargs['image']: - err = ('Error creating {0} on HPCLOUD\n\n' - 'Could not find image {1}\n').format( - vm_['name'], vm_['image'] - ) - sys.stderr.write(err) - return False - kwargs['size'] = get_size(conn, vm_) - if not kwargs['size']: - err = ('Error creating {0} on HPCLOUD\n\n' - 'Could not find size {1}\n').format( - vm_['name'], vm_['size'] - ) - sys.stderr.write(err) - return False - kwargs['ex_keyname'] = __opts__['HPCLOUD.keyname'] - try: - data = conn.create_node(**kwargs) - except Exception as exc: - err = ('Error creating {0} on HPCLOUD\n\n' - 'The following exception was thrown by libcloud when trying to ' - 'run the initial deployment: \n{1}\n').format( - vm_['name'], exc - ) - sys.stderr.write(err) - print traceback.format_exc() - return False - # NOTE - # We need to insert a wait / poll into libcloud until we have - # public ips for our node. Otherwise, we cannot complete the - # next step of deploying a script to the new server :( - if data.public_ips: - host_addr = data.public_ips[0] - else: - host_addr = None - - if 'ssh_username' in vm_: - ssh_user = vm_['ssh_username'] - else: - ssh_user = 'root' - - deployed = saltcloud.utils.deploy_script( - host=host_addr, - username=ssh_user, - password=data.extra['password'], - script=deploy_script.script, - name=vm_['name'], - sock_dir=__opts__['sock_dir']) - if deployed: - print('Salt installed on {0}'.format(vm_['name'])) - else: - print('Failed to start Salt on Cloud VM {0}'.format(vm_['name'])) - - print('Created Cloud VM {0} with the following values:'.format( - vm_['name'] - )) - for key, val in data.__dict__.items(): - print(' {0}: {1}'.format(key, val))