1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 from neutronclient.common.utils import str2bool
18 class KeypairConfig(object):
20 Class representing a keypair configuration
23 def __init__(self, **kwargs):
25 Constructor - all parameters are optional
26 :param name: The keypair name.
27 :param public_filepath: The path to/from the filesystem where the
28 public key file is or will be stored
29 :param private_filepath: The path where the generated private key file
31 :param key_size: The number of bytes for the key size when it needs to
32 be generated (Must be >=512 default 1024)
33 :param delete_on_clean: when True, the key files will be deleted when
34 OpenStackKeypair#clean() is called
38 self.name = kwargs.get('name')
39 self.public_filepath = kwargs.get('public_filepath')
40 self.private_filepath = kwargs.get('private_filepath')
41 self.key_size = int(kwargs.get('key_size', 1024))
43 if kwargs.get('delete_on_clean') is not None:
44 if isinstance(kwargs.get('delete_on_clean'), bool):
45 self.delete_on_clean = kwargs.get('delete_on_clean')
47 self.delete_on_clean = str2bool(kwargs.get('delete_on_clean'))
49 self.delete_on_clean = None
52 raise KeypairConfigError('Name is a required attribute')
54 if self.key_size < 512:
55 raise KeypairConfigError('key_size must be >=512')
58 class KeypairConfigError(Exception):
60 Exception to be thrown when keypair settings are incorrect