def _create_nova_connection(): try: platform = node.__node__['platform'] kwds = dict(auth_url=platform.get_access_data('keystone_url'), region_name=platform.get_access_data('cloud_location'), service_type='compute') if not bool(platform.get_access_data('ssl_verify_peer')): kwds['insecure'] = True import novaclient # NameError: name 'novaclient' is not defined if hasattr(novaclient, '__version__') and os.environ.get('OS_AUTH_SYSTEM'): try: import novaclient.auth_plugin auth_plugin = novaclient.auth_plugin.load_plugin( os.environ['OS_AUTH_SYSTEM']) kwds['auth_plugin'] = auth_plugin except ImportError: pass conn = nova_client.Client( platform.get_access_data('username'), platform.get_access_data('api_key') or platform.get_access_data('password'), platform.get_access_data('tenant_name'), **kwds) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_connection(): pl = node.__node__['platform'] try: conn = cloudstack.Client(pl.get_access_data('api_url'), apiKey=pl.get_access_data('api_key'), secretKey=pl.get_access_data('secret_key')) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_s3_connection(): platform = __node__['platform'] region = platform.get_region() endpoint = platform._s3_endpoint(region) try: key_id, key = platform.get_access_keys() conn = boto.connect_s3(host=endpoint, aws_access_key_id=key_id, aws_secret_access_key=key) except (AttributeError, PlatformError, boto.exception.NoAuthHandlerFound): raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_ec2_connection(): platform = __node__['platform'] region = platform.get_region() try: key_id, key = platform.get_access_keys() conn = boto.ec2.connect_to_region(region, aws_access_key_id=key_id, aws_secret_access_key=key) if not conn: raise ConnectionError('Invalid region: %s' % region) except (PlatformError, boto.exception.NoAuthHandlerFound): raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_connection(self): platform_obj = node.__node__['platform'] http = httplib2.Http() try: email = platform_obj.get_access_data('service_account_name') pk = base64.b64decode(platform_obj.get_access_data('key')) except platform.PlatformError: raise NoCredentialsError(sys.exc_info()[1]) try: cred = SignedJwtAssertionCredentials(email, pk, scope=self.scope) conn = build(self.service_name, self.api_version, http=cred.authorize(http)) except: raise InvalidCredentialsError(sys.exc_info()[1]) return BadStatusLineHandler(conn)
def _create_cinder_connection(): try: platform = node.__node__['platform'] kwds = dict(auth_url=platform.get_access_data('keystone_url'), region_name=platform.get_access_data('cloud_location')) if not bool(platform.get_access_data('ssl_verify_peer')): kwds['insecure'] = True conn = cinder_client.Client( platform.get_access_data('username'), platform.get_access_data('api_key') or platform.get_access_data('password'), platform.get_access_data('tenant_name'), **kwds) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_nova_connection(): try: kwds = _get_client_kwds('compute') import novaclient # NameError: name 'novaclient' is not defined if hasattr(novaclient, '__version__') and os.environ.get('OS_AUTH_SYSTEM'): try: import novaclient.auth_plugin auth_plugin = novaclient.auth_plugin.load_plugin( os.environ['OS_AUTH_SYSTEM']) kwds['auth_plugin'] = auth_plugin except ImportError: pass conn = nova_client.Client('2', **kwds) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn
def new_ec2_conn(self): """ @rtype: boto.ec2.connection.EC2Connection """ try: region = self.get_region() key_id, key = self.get_access_keys() proxy = __node__['access_data'].get('proxy', {}) log_msg = 'Returning EC2 connection (region: {}'.format(region) if proxy.get('host'): log_msg += ', http proxy: {}:{}'.format( proxy['host'], proxy.get('port')) log_msg += ')' self._logger.debug(log_msg) return boto.ec2.connect_to_region(region, aws_access_key_id=key_id, aws_secret_access_key=key, proxy=proxy.get('host'), proxy_port=proxy.get('port'), proxy_user=proxy.get('user'), proxy_pass=proxy.get('pass')) except (PlatformError, boto.exception.NoAuthHandlerFound): raise NoCredentialsError(sys.exc_info()[1])
def new_s3_conn(self): try: region = self.get_region() endpoint = self._s3_endpoint(region) key_id, key = self.get_access_keys() proxy = __node__['access_data'].get('proxy', {}) log_msg = 'Returning S3 connection (region: {}'.format(region) if proxy.get('host'): log_msg += ', http proxy: {}:{}'.format( proxy['host'], proxy.get('port')) log_msg += ')' self._logger.debug(log_msg) return boto.connect_s3(host=endpoint, aws_access_key_id=key_id, aws_secret_access_key=key, proxy=proxy.get('host'), proxy_port=proxy.get('port'), proxy_user=proxy.get('user'), proxy_pass=proxy.get('pass')) except (AttributeError, PlatformError, boto.exception.NoAuthHandlerFound): raise NoCredentialsError(sys.exc_info()[1])
def _create_swift_connection(): try: platform = node.__node__['platform'] api_key = platform.get_access_data("api_key") password = platform.get_access_data("password") auth_url = platform.get_access_data("keystone_url") kwds = {} if 'rackspacecloud' in auth_url: auth_url = re.sub(r'v2\.\d$', 'v1.0', auth_url) kwds['auth_version'] = '1' else: kwds['auth_version'] = '2' kwds['tenant_name'] = platform.get_access_data("tenant_name") if not bool(platform.get_access_data('ssl_verify_peer')): kwds['insecure'] = True conn = swiftclient.Connection( authurl=auth_url, user=platform.get_access_data('username'), key=password or api_key, **kwds) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn
def _create_cinder_connection(): try: conn = cinder_client.Client(**_get_client_kwds('volume')) except PlatformError: raise NoCredentialsError(sys.exc_info()[1]) return conn