The watcher.common.nova_helper Module

class watcher.common.nova_helper.NovaHelper(osc=None)[source]

Bases: object

create_image_from_instance(instance_id, image_name, metadata={'reason': 'instance_migrate'})[source]

This method creates a new image from a given instance.

It waits for this image to be in ‘active’ state before returning. It returns the unique UUID of the created image if successful, None otherwise.

Parameters:
  • instance_id – the uniqueid of the instance to backup as an image.
  • image_name – the name of the image to create.
  • metadata – a dictionary containing the list of key-value pairs to associate to the image as metadata.
create_instance(node_id, inst_name='test', image_id=None, flavor_name='m1.tiny', sec_group_list=['default'], network_names_list=['demo-net'], keypair_name='mykeys', create_new_floating_ip=True, block_device_mapping_v2=None)[source]

This method creates a new instance

It also creates, if requested, a new floating IP and associates it with the new instance It returns the unique id of the created instance.

delete_instance(instance_id)[source]

This method deletes a given instance.

Parameters:instance_id – the unique id of the instance to delete.
disable_service_nova_compute(hostname)[source]
enable_service_nova_compute(hostname)[source]
find_instance(instance_id)[source]
get_aggregate_detail(aggregate_id)[source]
get_aggregate_list()[source]
get_availability_zone_list()[source]
get_compute_node_by_hostname(node_hostname)[source]

Get compute node by ID (not UUID)

get_compute_node_by_id(node_id)[source]

Get compute node by ID (not UUID)

get_compute_node_list()[source]
get_flavor_instance(instance, cache)[source]
get_hostname(instance)[source]
get_instances_by_node(host)[source]
get_network_id_from_name(net_name='private')[source]

This method returns the unique id of the provided network name

live_migrate_instance(instance_id, dest_hostname, block_migration=False, retry=120)[source]

This method does a live migration of a given instance

This method uses the Nova built-in live_migrate() action to do a live migration of a given instance.

It returns True if the migration was successful, False otherwise.

Parameters:
  • instance_id – the unique id of the instance to migrate.
  • dest_hostname – the name of the destination compute node.
  • block_migration – No shared storage is required.
set_host_offline(hostname)[source]
stop_instance(instance_id)[source]

This method stops a given instance.

Parameters:instance_id – the unique id of the instance to stop.
wait_for_instance_state(server, state, retry, sleep)[source]

Waits for server to be in a specific state

The state can be one of the following : active, stopped

Parameters:
  • server – server object.
  • state – for which state we are waiting for
  • retry – how many times to retry
  • sleep – seconds to sleep between the retries
wait_for_instance_status(instance, status_list, retry, sleep)[source]

Waits for instance to be in a specific status

The status can be one of the following : BUILD, ACTIVE, ERROR, VERIFY_RESIZE, SHUTOFF

Parameters:
  • instance – instance object.
  • status_list – tuple containing the list of status we are waiting for
  • retry – how many times to retry
  • sleep – seconds to sleep between the retries
wait_for_volume_status(volume, status, timeout=60, poll_interval=1)[source]

Wait until volume reaches given status.

Parameters:
  • volume – volume resource
  • status – expected status of volume
  • timeout – timeout in seconds
  • poll_interval – poll interval in seconds
watcher_non_live_migrate_instance(instance_id, node_id, keep_original_image_name=True)[source]

This method migrates a given instance

using an image of this instance and creating a new instance from this image. It saves some configuration information about the original instance : security group, list of networks, list of attached volumes, floating IP, ... in order to apply the same settings to the new instance. At the end of the process the original instance is deleted. It returns True if the migration was successful, False otherwise.

Parameters:
  • instance_id – the unique id of the instance to migrate.
  • keep_original_image_name – flag indicating whether the image name from which the original instance was built must be used as the name of the intermediate image used for migration. If this flag is False, a temporary image name is built