diff options
Diffstat (limited to 'snaps/openstack/create_keypairs.py')
-rw-r--r-- | snaps/openstack/create_keypairs.py | 48 |
1 files changed, 7 insertions, 41 deletions
diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py index 6c66134..a181a7b 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) @@ -141,47 +141,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) |