summaryrefslogtreecommitdiffstats
path: root/snaps/openstack/create_keypairs.py
diff options
context:
space:
mode:
Diffstat (limited to 'snaps/openstack/create_keypairs.py')
-rw-r--r--snaps/openstack/create_keypairs.py52
1 files changed, 11 insertions, 41 deletions
diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py
index 3869afc..b037c3f 100644
--- a/snaps/openstack/create_keypairs.py
+++ b/snaps/openstack/create_keypairs.py
@@ -15,10 +15,10 @@
import logging
import os
-from neutronclient.common.utils import str2bool
from novaclient.exceptions import NotFound
from snaps import file_utils
+from snaps.config.keypair import KeypairConfig
from snaps.openstack.openstack_creator import OpenStackComputeObject
from snaps.openstack.utils import nova_utils
@@ -36,7 +36,7 @@ class OpenStackKeypair(OpenStackComputeObject):
"""
Constructor - all parameters are required
:param os_creds: The credentials to connect with OpenStack
- :param keypair_settings: The settings used to create a keypair
+ :param keypair_settings: a KeypairConfig object
"""
super(self.__class__, self).__init__(os_creds)
@@ -123,6 +123,7 @@ class OpenStackKeypair(OpenStackComputeObject):
self.keypair_settings.public_filepath)
os.chmod(expanded_path, 0o755)
os.remove(expanded_path)
+ logger.info('Deleted public key file [%s]', expanded_path)
if (self.keypair_settings.private_filepath and
file_utils.file_exists(
self.keypair_settings.private_filepath)):
@@ -130,6 +131,9 @@ class OpenStackKeypair(OpenStackComputeObject):
self.keypair_settings.private_filepath)
os.chmod(expanded_path, 0o755)
os.remove(expanded_path)
+ logger.info('Deleted private key file [%s]', expanded_path)
+
+ super(self.__class__, self).clean()
def get_keypair(self):
"""
@@ -139,47 +143,13 @@ class OpenStackKeypair(OpenStackComputeObject):
return self.__keypair
-class KeypairSettings:
+class KeypairSettings(KeypairConfig):
"""
Class representing a keypair configuration
"""
def __init__(self, **kwargs):
- """
- Constructor - all parameters are optional
- :param name: The keypair name.
- :param public_filepath: The path to/from the filesystem where the
- public key file is or will be stored
- :param private_filepath: The path where the generated private key file
- will be stored
- :param key_size: The number of bytes for the key size when it needs to
- be generated (Must be >=512 default 1024)
- :param delete_on_clean: when True, the key files will be deleted when
- OpenStackKeypair#clean() is called
- :return:
- """
-
- self.name = kwargs.get('name')
- self.public_filepath = kwargs.get('public_filepath')
- self.private_filepath = kwargs.get('private_filepath')
- self.key_size = int(kwargs.get('key_size', 1024))
-
- if kwargs.get('delete_on_clean') is not None:
- if isinstance(kwargs.get('delete_on_clean'), bool):
- self.delete_on_clean = kwargs.get('delete_on_clean')
- else:
- self.delete_on_clean = str2bool(kwargs.get('delete_on_clean'))
- else:
- self.delete_on_clean = None
-
- if not self.name:
- raise KeypairSettingsError('Name is a required attribute')
-
- if self.key_size < 512:
- raise KeypairSettingsError('key_size must be >=512')
-
-
-class KeypairSettingsError(Exception):
- """
- Exception to be thrown when keypair settings are incorrect
- """
+ from warnings import warn
+ warn('Use snaps.config.keypair.KeypairConfig instead',
+ DeprecationWarning)
+ super(self.__class__, self).__init__(**kwargs)