cfme.common.vm module

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

class cfme.common.vm.BaseVM(parent, name, provider)[source]

Bases: cfme.modeling.base.BaseEntity, cfme.utils.pretty.Pretty, cfme.utils.update.Updateable, cfme.common.PolicyProfileAssignable, cfme.common.Taggable, cfme.common.vm_console.ConsoleMixin

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
PROVISION_CANCEL = 'Add of new VM Provision Request was cancelled by the user'
PROVISION_START = 'VM Provision Request was Submitted, you will be notified when your VMs are ready'
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
__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

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
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.

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

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 (User) – user object for ownership
  • group (Group) – group object 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

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.BaseVMCollection(parent, filters=NOTHING)[source]

Bases: cfme.modeling.base.BaseCollection

ENTITY

alias of BaseVM

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

create(vm_name, provider, form_values=None, cancel=False, check_existing=False, find_in_cfme=False, wait=True, request_description=None, auto_approve=False, override=False)[source]

Provisions an vm/instance with the given properties through CFME

Parameters:
  • vm_name – the vm/instance’s name
  • provider – provider object
  • form_values – dictionary of form values for provisioning, structured into tabs
  • cancel – boolean, whether or not to cancel form filling
  • check_existing – verify if such vm_name exists
  • find_in_cfme – verify that vm was created and appeared in CFME
  • wait – wait for vm provision request end
  • request_description – request description that test needs to search in request table.
  • auto_approve – if true the request is approved before waiting for completion.
  • override – To override any failure related exception

Note

Calling create on a sub-class of instance will generate the properly formatted dictionary when the correct fields are supplied.

create_rest(vm_name, provider, form_values=None, check_existing=False)[source]

Provisions a VM/Instance with the default self.vm_default_args_rest.

self.vm_default_args_rest may be overridden by form_values. For more details about rest attributes please check: https://access.redhat.com/documentation/en-us/red_hat_cloudforms/4.6/html-single/ red_hat_cloudforms_rest_api/index#provision-request-supported-attributes or http://manageiq.org/docs/reference/fine/api/appendices/provision_attributes NOTE: placement_auto defaults to True for requests made from the API or CloudForms Automate. :param vm_name: vm name :param provider: provider object :param form_values: overrides default provision arguments or extends it. :param check_existing: cancel creation if VM exists

Return: Instance object

instantiate(name, provider, template_name=None)[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:
  • 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.
class cfme.common.vm.Template(parent, name, provider)[source]

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

A base class for all templates.

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

exists_on_provider
mgmt

Holds wrapanapi template entity object for this template.

class cfme.common.vm.TemplateCollection(parent, filters=NOTHING)[source]

Bases: cfme.common.vm.BaseVMCollection

ENTITY

alias of Template

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

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

Bases: cfme.common.vm.BaseVM

STATE_OFF = 'off'
STATE_ON = 'on'
STATE_PAUSED = 'paused'
STATE_SUSPENDED = 'suspended'
TO_RETIRE = None
__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

capture_historical_data(interval='hourly', back='6.days')[source]

Capture historical utilization data for this VM/Instance

Parameters:
  • interval – Data interval (hourly/ daily)
  • back – back time interval from which you want data
cleanup_on_provider()[source]

Clean up entity on the provider if it has been created on the provider

Helper method to avoid NotFoundError’s during test case tear down.

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
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 1 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
exists_on_provider
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
mgmt

Returns the wrapanapi VM entity object to manipulate this VM directly via the provider API

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

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 in the UI.

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

class cfme.common.vm.VMCollection(parent, filters=NOTHING)[source]

Bases: cfme.common.vm.BaseVMCollection

ENTITY

alias of VM

__ge__(other)

Automatically created by attrs.

__gt__(other)

Automatically created by attrs.

__le__(other)

Automatically created by attrs.

__lt__(other)

Automatically created by attrs.

__ne__(other)

Check equality and either forward a NotImplemented or return the result negated.

__repr__()

Automatically created by attrs.

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]