def get_public_key(request): with get_user(request, readonly=True) as user: keypairs = user.get('keypairs', {}) key_id = request.matchdict['key'] if not key_id: return Response('Key id not provided', 400) if key_id in keypairs: return keypairs[key_id].get('public', '') else: return Response('Keypair not found %s' % key_id, 404)
def connect(request, backend_id=False): """Establishes backend connection using the credentials specified. It has been tested with: * EC2, and the alternative providers like EC2_EU, * Rackspace, old style and the new Nova powered one, * Openstack Diablo through Trystack, should also try Essex, * Linode """ with get_user(request, readonly=True) as user: backends = user['backends'] #~ log.error(backends.keys()) if not backend_id: backend_id = request.matchdict['backend'] backend = backends.get(backend_id) if backend['provider'] != 'bare_metal': driver = get_driver(backend['provider']) if backend['provider'] == Provider.OPENSTACK: conn = driver(backend['apikey'], backend['apisecret'], ex_force_auth_version=backend.get('auth_version', '2.0_password'), ex_force_auth_url=backend.get('apiurl', None), ex_tenant_name=backend.get('tenant_name', None)) elif backend['provider'] == Provider.LINODE: conn = driver(backend['apisecret']) elif backend['provider'] == Provider.RACKSPACE_FIRST_GEN: conn = driver(backend['apikey'], backend['apisecret'], region=backend['region']) elif backend['provider'] == Provider.RACKSPACE: conn = driver(backend['apikey'], backend['apisecret'], region=backend['region']) elif backend['provider'] in [Provider.NEPHOSCALE, Provider.DIGITAL_OCEAN]: conn = driver(backend['apikey'], backend['apisecret']) elif backend['provider'] == Provider.SOFTLAYER: conn = driver(backend['apikey'], backend['apisecret']) elif backend['provider'] == 'bare_metal': conn = BareMetalDriver(backend['list_of_machines']) else: # ec2 conn = driver(backend['apikey'], backend['apisecret']) # Account for sub-provider regions (EC2_US_WEST, EC2_US_EAST etc.) conn.type = backend['provider'] return conn
def connect(request, backend_id=False): """Establishes backend connection using the credentials specified. It has been tested with: * EC2, and the alternative providers like EC2_EU, * Rackspace, old style and the new Nova powered one, * Openstack Diablo through Trystack, should also try Essex, * Linode """ with get_user(request, readonly=True) as user: backends = user['backends'] #~ log.error(backends.keys()) if not backend_id: backend_id = request.matchdict['backend'] backend = backends.get(backend_id) driver = get_driver(backend['provider']) if backend['provider'] == Provider.OPENSTACK: conn = driver(backend['apikey'], backend['apisecret'], ex_force_auth_version=backend.get( 'auth_version', '2.0_password'), ex_force_auth_url=backend.get('apiurl', None), ex_tenant_name=backend.get('tenant_name', None)) elif backend['provider'] == Provider.LINODE: conn = driver(backend['apisecret']) elif backend['provider'] == Provider.RACKSPACE_FIRST_GEN: conn = driver(backend['apikey'], backend['apisecret'], region=backend['region']) elif backend['provider'] == Provider.RACKSPACE: conn = driver(backend['apikey'], backend['apisecret'], region=backend['region']) elif backend['provider'] in [Provider.NEPHOSCALE, Provider.DIGITAL_OCEAN]: conn = driver(backend['apikey'], backend['apisecret']) elif backend['provider'] == Provider.SOFTLAYER: conn = driver(backend['apikey'], backend['apisecret']) else: # ec2 conn = driver(backend['apikey'], backend['apisecret']) # Account for sub-provider regions (EC2_US_WEST, EC2_US_EAST etc.) conn.type = backend['provider'] return conn
def get_private_key(request): """Gets private key from keypair name. It is used in single key view when the user clicks the display private key button. """ with get_user(request, readonly=True) as user: keypairs = user.get('keypairs', {}) key_id = request.matchdict['key'] if not key_id: return Response('Key id not provided', 400) if key_id in keypairs: return keypairs[key_id].get('private', '') else: return Response('Keypair not found %s' % key_id, 404)
def set_default_key(request): """Sets a key as default. After all changes take place, it updates the configuration and saves the updated yaml. """ key_id = request.matchdict['key'] if not key_id: return Response('Key name not provided', 400) with get_user(request) as user: keypairs = user.get('keypairs', {}) if not key_id in keypairs: return Response('Keypair not found', 404) for key in keypairs: keypairs[key]['default'] = False keypairs[key_id]['default'] = True return Response('OK', 200)
def get_auth_key(request): with get_user(request, readonly=True) as user: from base64 import urlsafe_b64encode auth_key = "%s:%s" % (user['email'], user['password']) auth_key = urlsafe_b64encode(auth_key) return auth_key