cfme.common.vm module

Module containing classes with common behaviour for both VMs and Instances of all types.

class cfme.common.vm.BaseVM(name, provider, template_name=None, appliance=None)[source]

Bases: cfme.utils.pretty.Pretty, cfme.utils.update.Updateable, cfme.common.PolicyProfileAssignable, cfme.common.Taggable, cfme.utils.appliance.Navigatable

Base VM and Template class that holds the largest common functionality between VMs, instances, templates and images.

In order to inherit these, you have to implement the on_details method.

ALL_LIST_LOCATION = None
DETAILS_VIEW_CLASS = None
QUADICON_TYPE = 'vm'
REMOVE_SELECTED

A class that implements the version picking functionality.

Basic usage is a descriptor in which you place instances of VersionPick in a view. Whenever is this instance accessed from an instance, it automatically picks the correct variant based on product_version defined in the widgetastic.browser.Browser.

You can also use this separately using the pick() method.

Example:

class MyView(View):
    something_version_dependent = VersionPick({
        '1.0.0': Foo('bar'),
        '2.5.0': Bar('baz'),
    })

This sample will resolve the correct (Foo or Bar) kind of item and returns it.

Parameters:version_dict – Dictionary of version_introduced: item
REMOVE_SINGLE

A class that implements the version picking functionality.

Basic usage is a descriptor in which you place instances of VersionPick in a view. Whenever is this instance accessed from an instance, it automatically picks the correct variant based on product_version defined in the widgetastic.browser.Browser.

You can also use this separately using the pick() method.

Example:

class MyView(View):
    something_version_dependent = VersionPick({
        '1.0.0': Foo('bar'),
        '2.5.0': Bar('baz'),
    })

This sample will resolve the correct (Foo or Bar) kind of item and returns it.

Parameters:version_dict – Dictionary of version_introduced: item
RETIRE_DATE_FMT

A class that implements the version picking functionality.

Basic usage is a descriptor in which you place instances of VersionPick in a view. Whenever is this instance accessed from an instance, it automatically picks the correct variant based on product_version defined in the widgetastic.browser.Browser.

You can also use this separately using the pick() method.

Example:

class MyView(View):
    something_version_dependent = VersionPick({
        '1.0.0': Foo('bar'),
        '2.5.0': Bar('baz'),
    })

This sample will resolve the correct (Foo or Bar) kind of item and returns it.

Parameters:version_dict – Dictionary of version_introduced: item
TO_OPEN_EDIT = None
check_compliance(timeout=240)[source]

Initiates compliance check and waits for it to finish.

compliance_status

Returns the title of the compliance SummaryTable. The title contains datetime so it can be compared.

Returns:NoneType if no title is present (no compliance checks before), otherwise str
compliant

Check if the VM is compliant.

Returns:bool
console_handle

The basic algorithm for getting the consoles window handle is to get the appliances window handle and then iterate through the window_handles till we find one that is not the appliances window handle. Once we find this check that it has a canvas widget with a specific ID

delete(cancel=False, from_details=False)[source]

Deletes the VM/Instance from the VMDB.

Parameters:
  • cancel – Whether to cancel the action in the alert.
  • from_details – Whether to use the details view or list view.
exists

Checks presence of the quadicon in the CFME.

classmethod factory(vm_name, provider, template_name=None, template=False)[source]

Factory class method that determines the correct subclass for given provider.

For reference how does that work, refer to the entrypoints in the setup.py

Parameters:
  • vm_name – Name of the VM/Instance as it appears in the UI
  • provider – The provider object (not the string!)
  • template_name – Source template name. Useful when the VM/Instance does not exist and you want to create it.
  • template – Whether the generated object class should be VM/Instance or a template class.
find_quadicon(from_any_provider=False, use_search=True)[source]

Find and return a quadicon belonging to a specific vm

Parameters:from_any_provider – Whether to look for it anywhere (root of the tree). Useful when looking up archived or orphaned VMs

Returns: entity of appropriate type Raises: VmOrInstanceNotFound

classmethod get_first_vm(provider)[source]

Get first VM/Instance.

ip_address

Fetches IP Address of VM

is_retired

Check retirement status of vm

is_vm
last_analysed

Returns the contents of the Last Analysed field in summary

load_details(refresh=False, from_any_provider=False)[source]

Navigates to an VM’s details page.

Parameters:
  • refresh – Refreshes the VM page if already there
  • from_any_provider – Archived/Orphaned VMs need this
open_console(console='VM Console', invokes_alert=None)[source]

Initiates the opening of one of the console types supported by the Access button. Presently we only support VM Console, which is the HTML5 Console. In case of VMware provider it could be VMRC, VNC/HTML5, WebMKS, but we only support VNC/HTML5. Possible values for ‘console’ could be ‘VM Console’ and ‘Web Console’, but Web Console is not supported as well.

Parameters:
  • console – one of the supported console types given by the Access button.
  • invokes_alert – If the particular console will invoke a CFME popup/alert setting this to true will handle this.
open_details(properties=None)[source]

Clicks on details infoblock

open_edit()[source]

Loads up the edit page of the object.

open_timelines()[source]

Navigates to an VM’s timeline page.

Returns:TimelinesView object
pretty_attrs = ['name', 'provider', 'template_name']
quadicon_type
rediscover()[source]

Deletes the VM from the provider and lets it discover again

rediscover_if_analysis_data_present()[source]

Rediscovers the object if it has some analysis data present.

Returns:Boolean if the rediscovery happened.
refresh_relationships(from_details=False, cancel=False, from_any_provider=False)[source]

Executes a refresh of relationships.

Parameters:
  • from_details – Whether or not to perform action from instance details page
  • cancel – Whether or not to cancel the refresh relationships action
retirement_date

Returns the retirement date of the selected machine, or ‘Never’

Returns:str object
set_ownership(user=None, group=None, click_cancel=False, click_reset=False)[source]

Set instance ownership

Parameters:
  • user (str) – username for ownership
  • group (str) – groupname for ownership
  • click_cancel (bool) – Whether to cancel form submission
  • click_reset (bool) – Whether to reset form after filling
smartstate_scan(cancel=False, from_details=False, wait_for_task_result=False)[source]

Initiates fleecing from the UI.

Parameters:
  • cancel – Whether or not to cancel the refresh relationships action
  • from_details – Whether or not to perform action from instance details page
unset_ownership()[source]

Remove user ownership and return group to EvmGroup-Administrator

vm_console

Get the consoles window handle, and then create a VMConsole object, and store the VMConsole object aside.

wait_for_delete(timeout=600)

Wait for a VM to disappear within CFME

Parameters:timeout – time (in seconds) to wait for it to appear
wait_to_appear(timeout=600, load_details=True)[source]

Wait for a VM to appear within CFME

Parameters:
  • timeout – time (in seconds) to wait for it to appear
  • load_details – when found, should it load the vm details
wait_to_disappear(timeout=600)[source]

Wait for a VM to disappear within CFME

Parameters:timeout – time (in seconds) to wait for it to appear
class cfme.common.vm.Template(name, provider, template_name=None)[source]

Bases: cfme.common.vm.BaseVM, cfme.common.vm._TemplateMixin

A base class for all templates. The constructor is a bit different, it scraps template_name.

does_template_exist_on_provider()[source]

Check if template exists on provider itself

class cfme.common.vm.VM(name, provider, template_name=None, appliance=None)[source]

Bases: cfme.common.vm.BaseVM

STATE_OFF = 'off'
STATE_ON = 'on'
STATE_PAUSED = 'paused'
STATE_SUSPENDED = 'suspended'
TO_RETIRE = None
cleanup_on_provider()[source]

Method to remove a VM from the provider after tests.

Checks that the VM exists on the provider, ensures it is in ‘powered off’ state, and deletes it. Any exceptions raised during delete will be logged only.

This method may be overriden at the provider-specific level to delete and then do some additional work afterwards (like deleting resources attached to this VM)

create_on_provider(timeout=900, find_in_cfme=False, delete_on_failure=True, **kwargs)[source]

Create the VM on the provider via MgmtSystem. deploy_template handles errors during VM provision on MgmtSystem sideNS deletes VM if provisioned incorrectly

Parameters:
  • timeout – Number of seconds to wait for the VM to appear in CFME Will not wait at all, if set to 0 (Defaults to 900)
  • find_in_cfme – Verifies that VM exists in CFME UI
  • delete_on_failure – Attempts to remove VM on UI navigation failure
delete_from_provider()[source]

Delete VM/instance from provider.

You cannot expect additional cleanup of attached resources by calling this method. You should use cleanup_on_provider() to guarantee that.

does_vm_exist_on_provider()[source]

Check if VM exists on provider itself

ensure_state_on_provider(state, timeout='6m', delay=15)[source]

Ensures that the VM/instance is in desired state on provider using provider API.

State can be one of:
VM.STATE_ON, VM.STATE_OFF, VM.STATE_SUSPENDED, VM.STATE_PAUSED

Each desired state requires various checks/steps to ensure we “achieve” that state.

The logic implied while waiting is: 1. Check if VM is in_desired_state, if so, we’re done 2. If not, check if it is in_state_requiring_prep

(for example, you can’t stop a suspended VM, so we need to prep the VM by starting it)
  1. Move the VM to the correct ‘prep state’ (calling method do_prep)
  2. Check if the VM is in a state that allows moving to the desired state
    (in_actionable_state should return True)
  3. Perform the action to put the VM into that state (calling method do_action)

The methods are defined differently for each desired state.

For some states, step 2 and 3 do not apply, see for example when desired state is ‘running’, in those cases just make sure that ‘in_state_requiring_prep’ always returns false.

Parameters:
  • provider – Provider class object
  • vm_name – Name of the VM/instance
  • state – str, one of: VM.STATE_ON, VM.STATE_OFF, VM.STATE_SUSPENDED, VM.STATE_PAUSED
  • timeout – timeout in sec (or string like “6m”) used in wait_for
  • delay – delay in sec to use in each loop of the wait_for
equal_drift_results(drift_section, section, *indexes)[source]

Compares drift analysis results of a row specified by it’s title text.

Parameters:
  • drift_section (str) – Title text of the row to compare
  • section (str) – Accordion section where the change happened
  • indexes – Indexes of results to compare starting with 0 for first row (latest result). Compares all available drifts, if left empty (default)

Note

There have to be at least 2 drift results available for this to work.

Returns:bool
is_pwr_option_available_in_cfme(option, from_details=False)[source]

Checks to see if a power option is available on the VM

Parameters:
  • option – corresponds to option values under the power button, see EC2Instance and OpenStackInstance
  • from_details – Whether or not to perform action from instance details page
power_control_from_cfme(option, cancel=True, from_details=False)[source]

Power controls a VM from within CFME

Parameters:
  • option – corresponds to option values under the power button
  • cancel – Whether or not to cancel the power operation on confirmation
  • from_details – Whether or not to perform action from instance details page
Raises:

OptionNotAvailable – option param is not visible or enabled

power_control_from_provider()[source]
retire()[source]
set_retirement_date(when=None, offset=None, warn=None)[source]

Overriding common method to use widgetastic views/widgets properly

Parameters:
  • whendatetime.datetime object, when to retire (date in future)
  • offsetdict with months, weeks, days, hours keys. other keys ignored
  • warn – When to warn, fills the select in the form in case the when is specified.

Note: this should be moved up to the common VM class when infra+cloud+common are all WT

If when and offset are both None, this removes retirement date

Examples

# To set a specific retirement date 2 days from today two_days_later = datetime.date.today() + datetime.timedelta(days=2) vm.set_retirement_date(when=two_days_later)

# To set a retirement offset 2 weeks from now vm.set_retirement_date(offset={weeks=2})

Offset is dict to remove ambiguity between timedelta/datetime and months/weeks/days/hours timedelta supports creation with weeks, but not months timedelta supports days attr, but not weeks or months timedelta days attr will report a total summary, not the component that was passed to it For these reasons timedelta isn’t appropriate for offset An enhancement to cfme.utils.timeutil extending timedelta would be great for making this a bit cleaner

wait_candu_data_available(timeout=600)[source]

Waits until C&U data are available for this VM/Instance

Parameters:timeout – Timeout passed to utils.wait.wait_for()
wait_for_vm_state_change(desired_state=None, timeout=300, from_details=False, with_relationship_refresh=True, from_any_provider=False)[source]

Wait for VM to come to desired state.

This function waits just the needed amount of time thanks to wait_for.

Parameters:
  • desired_state – on, off, suspended... for available states, see EC2Instance and OpenStackInstance
  • timeout – Specify amount of time (in seconds) to wait
  • from_any_provider – Archived/Orphaned vms need this
Raises:
  • TimedOutError

    When instance does not come up to desired state in specified period of time.

  • InstanceNotFound

    When unable to find the instance passed

cfme.common.vm.all_types(template=False)[source]
cfme.common.vm.base_types(template=False)[source]
cfme.common.vm.instance_types(category, template=False)[source]