def run(self): volumes.list_volumes(self) volumes.list_volume_type(self) volumes.create_volume(self) volumes.check_available(self) images.select_image(self) networks.select_network(self) keypairs.select_keypair(self) servers.create_volume_instance(self) servers.check_active(self) volumes.attach_volume(self) sleep(5) volumes.detach_volume(self) volumes.check_available(self) volumes.delete_volume(self) servers.delete_instance(self) images.select_image(self) volumes.create_with_image(self) volumes.check_available(self) images.select_image(self) networks.select_network(self) keypairs.select_keypair(self) servers.create_instance_with_bdm(self) servers.check_active(self) servers.delete_instance(self) volumes.delete_volume(self) if self.overall_success is True: exit(0) else: exit(1)
def detach_volume(self): """ Description - Detach volume from an instance using the values self.instance.id self.volume.id After the volume is detached wait for the status to change to available, fail or time-out """ sleep(5) try: self.nova_client.volumes.delete_server_volume( self.instance.id, self.volume.id) for x in range(1, 10): sleep(5) if self.cinder_client.volumes.get(self.volume.id).status == \ 'available': self.logger.warning("Volume Detached") self.success = True return True self.logger.warning("Volume Detach Timed Out") self.success, self.overall_success = False, False self.failure = "Volume Detach Time Out" servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) except cinder_exceptions.NotFound: self.logger.error("404 volume not found detach failed %s", self.volume.id) self.success, self.overall_success = False, False self.failure = "Not Found" servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) except Exception as e: self.logger.warning("Volume Detach Failed") self.logger.error('Got exception: {}'.format(e)) self.success, self.overall_success = False, False self.failure = e servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1)
def run(self): # Add sec_group rule floating_ip.create_delete_security_group(self) # Keypair processing keypairs.list_keypair(self) keypairs.create_keypair(self) keypairs.delete_keypair(self) # Flavor processing flavors.list_flavors(self) flavors.get_flavor(self) # Create server images.select_image(self) keypairs.select_keypair(self) networks.select_network(self) servers.create_instance(self) servers.check_active(self) # floating IP floating_ip.create_floating(self) sleep(10) floating_ip.add_floating(self) # SSH to Instance if self.ssh_to_instance == "True": floating_ip.ssh_to_instance(self) # Stop server servers.get_server(self) servers.stop_server(self) servers.check_stopped(self) # Start stopped server servers.get_server(self) servers.start_server(self) servers.check_active(self) # Reboot server Hard servers.reboot_server_hard(self) servers.check_active(self) # Set and delete server metadata servers.set_server_metadata(self) servers.delete_server_metadata(self) # Delete floating ip floating_ip.delete_floating(self) # Delete instance servers.delete_instance(self) sleep(5) if self.overall_success is True: exit(0) else: exit(1)
def attach_volume(self): """ Description - Attach volume to a instance using the values self.instance.id self.volume.id After the volume is attached wait for the status to change to in-use or fail or time-out """ sleep(5) try: device_list = [] device_path = 'cdefghijklmnopqrstuvwxyz' for volume in self.nova_client.volumes.get_server_volumes( self.instance.id): device_list.append(volume.device) device = '/dev/sd%s' % choice(device_path) self.logger.warning("Using Device %s", device) try: self.nova_client.volumes.create_server_volume( self.instance.id, self.volume.id, device) self.success = True except cinder_exceptions.ClientException as e: self.logger.warning(e) device = '/dev/sd%s' % \ choice(device_path.strip(device.split()[-1])) try: self.nova_client.volumes.create_server_volume( self.instance.id, self.volume.id, device) self.success = True except Exception as e: self.logger.error("Volume attach failed ") self.logger.error('Got exception: {}'.format(e)) self.success, self.overall_success = False, False self.failure = e servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) try: for x in range(1, 20): sleep(10) self.logger.warning('Volume Status: %s' % str(self.cinder_client.volumes.get( self.volume.id).status)) if self.cinder_client.volumes.get(self.volume.id).status == \ 'in-use': self.logger.warning("Volume Is Attached") self.success = True return True if self.cinder_client.volumes.get(self.volume.id).status == \ 'error': self.logger.warning("Volume Is In Error State") self.success, self.overall_success = False, False servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) except cinder_exceptions.NotFound: self.logger.error("404 volume not found %s", self.volume.id) self.success, self.overall_success = False, False self.failure = "Not Found" servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) self.logger.error("Volume Attach Timed out") self.success, self.overall_success = False, False self.failure = "Volume Attach Timed Out" servers.delete_instance(self) self.delete_volume() self.logger.error("Deleting volume") exit(1) except Exception as e: self.logger.warning("Volume Attachment Failed ") self.logger.error('Got exception: {}'.format(e)) self.success, self.overall_success = False, False self.failure = e servers.delete_instance(self) exit(1)