def wait_for_stop(self): """Wait for instance stop.""" wait_till_ready( func=self.compute_client.get_instance, current_data=self.instance_data, desired_state='STOPPED', )
def wait_for_delete(self): """Wait for instance to be deleted.""" wait_till_ready( func=self.compute_client.get_instance, current_data=self.instance_data, desired_state='TERMINATED', )
def _wait_for_instance_start(self): """Wait for instance to be up.""" wait_till_ready( func=self.compute_client.get_instance, current_data=self.instance_data, desired_state='RUNNING', )
def wait(self): """Wait for instance to be up and cloud-init to be complete.""" wait_till_ready( func=self.compute_client.get_instance, current_data=self.instance_data, desired_state='RUNNING', )
def wait(self): """Wait for instance to be up and cloud-init to be complete.""" wait_till_ready( func=self.compute_client.get_instance, current_data=self.instance_data, desired_state='RUNNING', ) self.execute('/usr/bin/cloud-init status --wait --long')
def launch(self, image_id, instance_type='VM.Standard2.1', user_data=None, wait=True, **kwargs): """Launch an instance. Args: image_id: string, image ID to use for the instance instance_type: string, type of instance to create. https://docs.cloud.oracle.com/en-us/iaas/Content/Compute/References/computeshapes.htm user_data: used by Cloud-Init to run custom scripts or provide custom Cloud-Init configuration wait: wait for instance to be live **kwargs: dictionary of other arguments to pass as LaunchInstanceDetails Returns: An instance object to use to manipulate the instance further. """ vcn_id = self.network_client.list_vcns(self.compartment_id).data[0].id subnet = self.network_client.list_subnets(self.compartment_id, vcn_id=vcn_id).data[0] subnet_id = subnet.id availability_domain = subnet.availability_domain metadata = { 'ssh_authorized_keys': self.key_pair.public_key_content, } if user_data: metadata['user_data'] = base64.b64encode( user_data.encode('utf8')).decode('ascii') instance_details = oci.core.models.LaunchInstanceDetails( display_name=self.tag, availability_domain=availability_domain, compartment_id=self.compartment_id, shape=instance_type, subnet_id=subnet_id, image_id=image_id, metadata=metadata, **kwargs) instance_data = self.compute_client.launch_instance( instance_details).data instance = self.get_instance(instance_data.id) if wait: wait_till_ready( func=self.compute_client.get_instance, current_data=instance_data, desired_state='RUNNING', ) instance.wait() return instance
def snapshot(self, instance, clean=True, wait=True, name=None): """Snapshot an instance and generate an image from it. Args: instance: Instance to snapshot clean: run instance clean method before taking snapshot wait: wait for instance to get created name: (Optional) Name of created image Returns: An image object """ if clean: instance.clean() image_details = { 'compartment_id': self.compartment_id, 'instance_id': instance.instance_id, } if name: image_details['display_name'] = name image_data = self.compute_client.create_image( oci.core.models.CreateImageDetails(**image_details)).data if wait: image_data = wait_till_ready(func=self.compute_client.get_image, current_data=image_data, desired_state='AVAILABLE') return image_data.id