Modifications to allow for instance auth via ssh keys
* Adds private key field to keypair model * Adds config for instance auth strategy * Added logic into server behaviors to decide on instance auth strategy Change-Id: Ia60bc1285bf5d5ba6a86c2a572724ad9d2df7e39
This commit is contained in:
@@ -127,3 +127,7 @@ class ComputeHypervisors(object):
|
||||
KVM = 'kvm'
|
||||
QEMU = 'qemu'
|
||||
HYPER_V = 'hyper_v'
|
||||
|
||||
class InstanceAuthStrategies(object):
|
||||
PASSWORD = 'password'
|
||||
KEY = 'key'
|
||||
|
||||
@@ -23,10 +23,11 @@ from cloudcafe.compute.common.equality_tools import EqualityTools
|
||||
|
||||
class Keypair(AutoMarshallingModel):
|
||||
|
||||
def __init__(self, public_key, name, fingerprint):
|
||||
def __init__(self, public_key, name, fingerprint, private_key=None):
|
||||
self.public_key = public_key
|
||||
self.name = name
|
||||
self.fingerprint = fingerprint
|
||||
self.private_key = private_key
|
||||
|
||||
def __repr__(self):
|
||||
values = []
|
||||
@@ -43,7 +44,8 @@ class Keypair(AutoMarshallingModel):
|
||||
def _dict_to_obj(cls, json_dict):
|
||||
return Keypair(json_dict.get('public_key'),
|
||||
json_dict.get('name'),
|
||||
json_dict.get('fingerprint'))
|
||||
json_dict.get('fingerprint'),
|
||||
json_dict.get('private_key'))
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
@@ -78,5 +80,6 @@ class Keypairs(Keypair):
|
||||
key = key.get('keypair')
|
||||
ret.append(Keypair(key.get('public_key'),
|
||||
key.get('name'),
|
||||
key.get('fingerprint')))
|
||||
key.get('fingerprint'),
|
||||
key.get('private_key')))
|
||||
return ret
|
||||
|
||||
@@ -19,6 +19,7 @@ import time
|
||||
from cafe.engine.behaviors import BaseBehavior
|
||||
from cafe.engine.clients.remote_instance.instance_client import \
|
||||
InstanceClientFactory
|
||||
from cloudcafe.compute.common.types import InstanceAuthStrategies
|
||||
from cloudcafe.compute.common.types import NovaServerStatusTypes \
|
||||
as ServerStates
|
||||
from cloudcafe.compute.common.datagen import rand_name
|
||||
@@ -174,7 +175,8 @@ class ServerBehaviors(BaseBehavior):
|
||||
return server.addresses.public.ipv6
|
||||
|
||||
def get_remote_instance_client(self, server, config=None, ip_address=None,
|
||||
username=None, password=None):
|
||||
username=None, password=None, key=None,
|
||||
auth_strategy=None):
|
||||
"""
|
||||
@summary: Gets an client of the server
|
||||
@param server: Instance uuid id of the server
|
||||
@@ -189,15 +191,24 @@ class ServerBehaviors(BaseBehavior):
|
||||
@rtype: String
|
||||
"""
|
||||
|
||||
if password is None:
|
||||
password = server.admin_pass
|
||||
if ip_address is None:
|
||||
ip_address = self.get_public_ip_address(server)
|
||||
|
||||
# (TODO) dwalleck: Remove hard coding of distro
|
||||
return InstanceClientFactory.get_instance_client(
|
||||
ip_address=ip_address, username=username, password=password,
|
||||
os_distro='linux', config=config)
|
||||
strategy = auth_strategy or self.config.instance_auth_strategy.lower()
|
||||
|
||||
if InstanceAuthStrategies.PASSWORD in strategy:
|
||||
|
||||
if password is None:
|
||||
password = server.admin_pass
|
||||
|
||||
# (TODO) dwalleck: Remove hard coding of distro
|
||||
return InstanceClientFactory.get_instance_client(
|
||||
ip_address=ip_address, username=username, password=password,
|
||||
os_distro='linux', config=config)
|
||||
else:
|
||||
return InstanceClientFactory.get_instance_client(
|
||||
ip_address=ip_address, username=username, os_distro='linux',
|
||||
config=config, key=key)
|
||||
|
||||
def resize_and_await(self, server_id, new_flavor):
|
||||
"""
|
||||
|
||||
@@ -21,6 +21,11 @@ class ServersConfig(ConfigSectionInterface):
|
||||
|
||||
SECTION_NAME = 'servers'
|
||||
|
||||
@property
|
||||
def instance_auth_strategy(self):
|
||||
"""Strategy to use for authenticating to an instance (password|key)"""
|
||||
return self.get("instance_auth_strategy")
|
||||
|
||||
@property
|
||||
def server_status_interval(self):
|
||||
"""Amount of time to wait between polling the status of a server"""
|
||||
|
||||
Reference in New Issue
Block a user