From 85eb362579efbbc57e2851b2da2fd9599461f1ae Mon Sep 17 00:00:00 2001 From: spisarski Date: Mon, 30 Oct 2017 12:08:58 -0600 Subject: Added method to OpenStackHeatStack to return OpenStackKeypair objects. Continuation of the story SNAPS-153 for adding creator/state machine instances for OpenStack objects deployed via Heat. JIRA: SNAPS-175 Change-Id: I7196279086b1935b4ec4a01483d46921cc567b15 Signed-off-by: spisarski --- snaps/openstack/utils/settings_utils.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'snaps/openstack/utils/settings_utils.py') diff --git a/snaps/openstack/utils/settings_utils.py b/snaps/openstack/utils/settings_utils.py index 7169319..68dbf71 100644 --- a/snaps/openstack/utils/settings_utils.py +++ b/snaps/openstack/utils/settings_utils.py @@ -109,6 +109,32 @@ def create_volume_type_settings(volume_type): qos_spec_name=qos_spec_name, public=volume_type.public) +def create_keypair_settings(heat_cli, stack, keypair, pk_output_key): + """ + Instantiates a KeypairSettings object from a Keypair domain objects + :param heat_cli: the heat client + :param stack: the Stack domain object + :param keypair: the Keypair SNAPS domain object + :param pk_output_key: the key to the heat template's outputs for retrieval + of the private key file + :return: a KeypairSettings object + """ + if pk_output_key: + outputs = heat_utils.get_outputs(heat_cli, stack) + for output in outputs: + if output.key == pk_output_key: + # Save to file + guid = uuid.uuid4() + key_file = file_utils.save_string_to_file( + output.value, str(guid), 0o400) + + # Use outputs, file and resources for the KeypairSettings + return KeypairSettings( + name=keypair.name, private_filepath=key_file.name) + + return KeypairSettings(name=keypair.name) + + def create_vm_inst_settings(nova, neutron, server): """ Returns a NetworkSettings object -- cgit 1.2.3-korg