X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=snaps%2Fopenstack%2Fcreate_keypairs.py;h=b037c3f59d90114cfc779465b969d758787785f9;hb=refs%2Fchanges%2F35%2F53435%2F4;hp=3869afcaea27d8666d8b6fd113e9151aeab73991;hpb=8810b59c9a3a61013398bac256b84bbb365b4d87;p=snaps.git 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)