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:
Daryl Walleck 2013-06-10 21:06:31 -05:00
parent c482861408
commit 941945632a
8 changed files with 40 additions and 10 deletions

View File

@ -127,3 +127,7 @@ class ComputeHypervisors(object):
KVM = 'kvm'
QEMU = 'qemu'
HYPER_V = 'hyper_v'
class InstanceAuthStrategies(object):
PASSWORD = 'password'
KEY = 'key'

View File

@ -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

View File

@ -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):
"""

View File

@ -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"""

View File

@ -40,6 +40,7 @@ compute_endpoint_name=nova
username=demo
password=password
tenant_name=demo
user_id=
[compute_admin_user]
username=admin
@ -64,6 +65,7 @@ snapshot_timeout=900
can_get_deleted_image=false
[servers]
instance_auth_strategy=key
server_status_interval=15
server_build_timeout=600
server_resize_timeout=1800

View File

@ -40,6 +40,7 @@ compute_endpoint_name=nova
username=demo
password=password
tenant_name=demo
user_id=
[compute_admin_user]
username=admin
@ -64,6 +65,7 @@ snapshot_timeout=900
can_get_deleted_image=false
[servers]
instance_auth_strategy=key
server_status_interval=15
server_build_timeout=600
server_resize_timeout=1800

View File

@ -40,6 +40,7 @@ compute_endpoint_name=<compute_name>
username=<username>
password=<password>
tenant_name=<tenant_name>
user_id=<user_id>
[compute_admin_user]
username=<username>
@ -64,6 +65,7 @@ snapshot_timeout=900
can_get_deleted_image=<true/false>
[servers]
instance_auth_strategy=<password/key>
server_status_interval=15
server_build_timeout=600
server_resize_timeout=1800

View File

@ -64,6 +64,7 @@ snapshot_timeout=900
can_get_deleted_image=<true/false>
[servers]
instance_auth_strategy=<password/key>
server_status_interval=15
server_build_timeout=600
server_resize_timeout=1800