diff options
-rw-r--r-- | snaps/openstack/create_flavor.py | 3 | ||||
-rw-r--r-- | snaps/openstack/create_image.py | 3 | ||||
-rw-r--r-- | snaps/openstack/create_instance.py | 22 | ||||
-rw-r--r-- | snaps/openstack/create_keypairs.py | 3 | ||||
-rw-r--r-- | snaps/openstack/create_network.py | 57 | ||||
-rw-r--r-- | snaps/openstack/create_project.py | 3 | ||||
-rw-r--r-- | snaps/openstack/create_router.py | 4 | ||||
-rw-r--r-- | snaps/openstack/create_security_group.py | 7 | ||||
-rw-r--r-- | snaps/openstack/create_user.py | 3 |
9 files changed, 56 insertions, 49 deletions
diff --git a/snaps/openstack/create_flavor.py b/snaps/openstack/create_flavor.py index 30271c1..2d78be4 100644 --- a/snaps/openstack/create_flavor.py +++ b/snaps/openstack/create_flavor.py @@ -41,7 +41,7 @@ class OpenStackFlavor: self.__os_creds = os_creds self.flavor_settings = flavor_settings self.__flavor = None - self.__nova = nova_utils.nova_client(self.__os_creds) + self.__nova = None def create(self, cleanup=False): """ @@ -49,6 +49,7 @@ class OpenStackFlavor: :param cleanup: Denotes whether or not this is being called for cleanup or not :return: The OpenStack flavor object """ + self.__nova = nova_utils.nova_client(self.__os_creds) self.__flavor = nova_utils.get_flavor_by_name(self.__nova, self.flavor_settings.name) if self.__flavor: logger.info('Found flavor with name - ' + self.flavor_settings.name) diff --git a/snaps/openstack/create_image.py b/snaps/openstack/create_image.py index 1e2e4dc..e8220d3 100644 --- a/snaps/openstack/create_image.py +++ b/snaps/openstack/create_image.py @@ -45,7 +45,7 @@ class OpenStackImage: self.__image = None self.__kernel_image = None self.__ramdisk_image = None - self.__glance = glance_utils.glance_client(os_creds) + self.__glance = None def create(self, cleanup=False): """ @@ -53,6 +53,7 @@ class OpenStackImage: :param cleanup: Denotes whether or not this is being called for cleanup or not :return: The OpenStack Image object """ + self.__glance = glance_utils.glance_client(self.__os_creds) self.__image = glance_utils.get_image(self.__glance, self.image_settings.name) if self.__image: logger.info('Found image with name - ' + self.image_settings.name) diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py index 9fa3232..e1e38a1 100644 --- a/snaps/openstack/create_instance.py +++ b/snaps/openstack/create_instance.py @@ -49,8 +49,8 @@ class OpenStackVmInstance: """ self.__os_creds = os_creds - self.__nova = nova_utils.nova_client(self.__os_creds) - self.__neutron = neutron_utils.neutron_client(self.__os_creds) + self.__nova = None + self.__neutron = None self.instance_settings = instance_settings self.image_settings = image_settings @@ -74,16 +74,14 @@ class OpenStackVmInstance: Additionally, when True, floating IPs will not be applied until VM is active. :return: The VM reference object """ - try: - self.__ports = self.__setup_ports(self.instance_settings.port_settings, cleanup) - self.__lookup_existing_vm_by_name() - if not self.__vm and not cleanup: - self.__create_vm(block) - return self.__vm - except Exception as e: - logger.exception('Error occurred while setting up instance') - self.clean() - raise e + self.__nova = nova_utils.nova_client(self.__os_creds) + self.__neutron = neutron_utils.neutron_client(self.__os_creds) + + self.__ports = self.__setup_ports(self.instance_settings.port_settings, cleanup) + self.__lookup_existing_vm_by_name() + if not self.__vm and not cleanup: + self.__create_vm(block) + return self.__vm def __lookup_existing_vm_by_name(self): """ diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py index 6af40c6..250acec 100644 --- a/snaps/openstack/create_keypairs.py +++ b/snaps/openstack/create_keypairs.py @@ -35,6 +35,7 @@ class OpenStackKeypair: :param os_creds: The credentials to connect with OpenStack :param keypair_settings: The settings used to create a keypair """ + self.__nova = None self.__os_creds = os_creds self.keypair_settings = keypair_settings self.__nova = nova_utils.nova_client(os_creds) @@ -47,6 +48,8 @@ class OpenStackKeypair: Responsible for creating the keypair object. :param cleanup: Denotes whether or not this is being called for cleanup or not """ + self.__nova = nova_utils.nova_client(self.__os_creds) + logger.info('Creating keypair %s...' % self.keypair_settings.name) self.__keypair = nova_utils.get_keypair_by_name(self.__nova, self.keypair_settings.name) diff --git a/snaps/openstack/create_network.py b/snaps/openstack/create_network.py index 210c2bf..54f0b12 100644 --- a/snaps/openstack/create_network.py +++ b/snaps/openstack/create_network.py @@ -36,7 +36,7 @@ class OpenStackNetwork: """ self.__os_creds = os_creds self.network_settings = network_settings - self.__neutron = neutron_utils.neutron_client(self.__os_creds) + self.__neutron = None # Attributes instantiated on create() self.__network = None @@ -48,37 +48,34 @@ class OpenStackNetwork: :param cleanup: When true, only perform lookups for OpenStack objects. :return: the created network object or None """ - try: - logger.info('Creating neutron network %s...' % self.network_settings.name) - net_inst = neutron_utils.get_network(self.__neutron, self.network_settings.name, - self.network_settings.get_project_id(self.__os_creds)) - if net_inst: - self.__network = net_inst + self.__neutron = neutron_utils.neutron_client(self.__os_creds) + + logger.info('Creating neutron network %s...' % self.network_settings.name) + net_inst = neutron_utils.get_network(self.__neutron, self.network_settings.name, + self.network_settings.get_project_id(self.__os_creds)) + if net_inst: + self.__network = net_inst + else: + if not cleanup: + self.__network = neutron_utils.create_network(self.__neutron, self.__os_creds, + self.network_settings) + else: + logger.info('Network does not exist and will not create as in cleanup mode') + return + logger.debug("Network '%s' created successfully" % self.__network['network']['id']) + + logger.debug('Creating Subnets....') + for subnet_setting in self.network_settings.subnet_settings: + sub_inst = neutron_utils.get_subnet_by_name(self.__neutron, subnet_setting.name) + if sub_inst: + self.__subnets.append(sub_inst) + logger.debug("Subnet '%s' created successfully" % sub_inst['subnet']['id']) else: if not cleanup: - self.__network = neutron_utils.create_network(self.__neutron, self.__os_creds, - self.network_settings) - else: - logger.info('Network does not exist and will not create as in cleanup mode') - return - logger.debug("Network '%s' created successfully" % self.__network['network']['id']) - - logger.debug('Creating Subnets....') - for subnet_setting in self.network_settings.subnet_settings: - sub_inst = neutron_utils.get_subnet_by_name(self.__neutron, subnet_setting.name) - if sub_inst: - self.__subnets.append(sub_inst) - logger.debug("Subnet '%s' created successfully" % sub_inst['subnet']['id']) - else: - if not cleanup: - self.__subnets.append(neutron_utils.create_subnet(self.__neutron, subnet_setting, - self.__os_creds, self.__network)) - - return self.__network - except Exception as e: - logger.error('Unexpected exception thrown while creating network - ' + str(e)) - self.clean() - raise e + self.__subnets.append(neutron_utils.create_subnet(self.__neutron, subnet_setting, + self.__os_creds, self.__network)) + + return self.__network def clean(self): """ diff --git a/snaps/openstack/create_project.py b/snaps/openstack/create_project.py index 2658d13..b60d396 100644 --- a/snaps/openstack/create_project.py +++ b/snaps/openstack/create_project.py @@ -39,7 +39,7 @@ class OpenStackProject: self.project_settings = project_settings self.__project = None self.__role = None - self.__keystone = keystone_utils.keystone_client(self.__os_creds) + self.__keystone = None def create(self, cleanup=False): """ @@ -47,6 +47,7 @@ class OpenStackProject: :param cleanup: Denotes whether or not this is being called for cleanup or not :return: The OpenStack Image object """ + self.__keystone = keystone_utils.keystone_client(self.__os_creds) self.__project = keystone_utils.get_project(keystone=self.__keystone, project_name=self.project_settings.name) if self.__project: diff --git a/snaps/openstack/create_router.py b/snaps/openstack/create_router.py index 5c461cc..0b56424 100644 --- a/snaps/openstack/create_router.py +++ b/snaps/openstack/create_router.py @@ -42,7 +42,7 @@ class OpenStackRouter: raise Exception('router_settings is required') self.router_settings = router_settings - self.__neutron = neutron_utils.neutron_client(os_creds) + self.__neutron = None # Attributes instantiated on create() self.__router = None @@ -58,6 +58,8 @@ class OpenStackRouter: :param cleanup: When true, only perform lookups for OpenStack objects. :return: the router object """ + self.__neutron = neutron_utils.neutron_client(self.__os_creds) + logger.debug('Creating Router with name - ' + self.router_settings.name) existing = False router_inst = neutron_utils.get_router_by_name(self.__neutron, self.router_settings.name) diff --git a/snaps/openstack/create_security_group.py b/snaps/openstack/create_security_group.py index 57f7284..4e98e82 100644 --- a/snaps/openstack/create_security_group.py +++ b/snaps/openstack/create_security_group.py @@ -37,8 +37,8 @@ class OpenStackSecurityGroup: """ self.__os_creds = os_creds self.sec_grp_settings = sec_grp_settings - self.__neutron = neutron_utils.neutron_client(os_creds) - self.__keystone = keystone_utils.keystone_client(os_creds) + self.__neutron = None + self.__keystone = None # Attributes instantiated on create() self.__security_group = None @@ -52,6 +52,9 @@ class OpenStackSecurityGroup: :param cleanup: Denotes whether or not this is being called for cleanup or not :return: the OpenStack security group object """ + self.__neutron = neutron_utils.neutron_client(self.__os_creds) + self.__keystone = keystone_utils.keystone_client(self.__os_creds) + logger.info('Creating security group %s...' % self.sec_grp_settings.name) self.__security_group = neutron_utils.get_security_group(self.__neutron, self.sec_grp_settings.name) diff --git a/snaps/openstack/create_user.py b/snaps/openstack/create_user.py index a8d0fcc..fe7a64c 100644 --- a/snaps/openstack/create_user.py +++ b/snaps/openstack/create_user.py @@ -38,7 +38,7 @@ class OpenStackUser: self.__os_creds = os_creds self.user_settings = user_settings self.__user = None - self.__keystone = keystone_utils.keystone_client(self.__os_creds) + self.__keystone = None def create(self, cleanup=False): """ @@ -46,6 +46,7 @@ class OpenStackUser: :param cleanup: Denotes whether or not this is being called for cleanup or not :return: The OpenStack user object """ + self.__keystone = keystone_utils.keystone_client(self.__os_creds) self.__user = keystone_utils.get_user(self.__keystone, self.user_settings.name) if self.__user: logger.info('Found user with name - ' + self.user_settings.name) |