Resource handler model

A resource handler holds the connection to a cloud or hypervisor and pairs it with the Python class that makes the API calls

Every resource handler is an instance of resourcehandlers.models.ResourceHandler. Each supported technology subclasses it: a vCenter connection is a VsphereResourceHandler and an AWS connection is an AWSHandler. The base model uses HasSubModelsMixin, meaning that a query against ResourceHandler returns base instances. Call cast() on one to get the subclass, with the fields and methods specific to that technology.

Diagram of resource handler subclasses, each paired with a TechnologyWrapper. (opens full-size image in a new tab)

How a handler reaches the provider API

Each resource handler is paired with a wrapper class, and get_api_wrapper() returns that wrapper, already connected, so a plugin never has to read credentials. Wrappers share a common set of operations, including validate_connection(), create_vm(), power_vm(), and get_all_templates(). Check the wrapper for the technology you are working with.

Capability flags

Handler classes declare what their technology can do as class attributes. Read the flag rather than testing for a specific technology, so your code keeps working when another handler gains the same capability. For example:

Flag What it reports
can_support_console The technology can open a remote console session to one of its servers.
can_sync_vms Existing VMs can be discovered and synced into CMP.
can_add_disks_at_prov, can_add_disks_after_prov, can_add_nics_after_prov Whether disks can be added during provisioning, and whether disks or network cards can be added to a server afterward.
can_resources_be_changed CPU and memory can be changed on an existing server.
can_import_networks, can_import_templates Networks and images or templates can be pulled from the provider. Setting can_import_networks to False also hides the Import Networks button on the handler’s Networks tab.

Tech-specific parameters

Each technology contributes its own parameters to an environment, such as an AWS instance type or a vCenter resource pool. These are exposed to users as tech-specific parameters: return available parameters with tech_parameter_fields(). These parameters belong to the handler rather than to the environment, so changing an environment’s resource handler clears them.

  • Resource handlers: Add and configure a connection to a cloud or hypervisor.
  • Environment model: The model for the provisioning targets a handler serves.
  • Shell Plus: Query models interactively, including the mixins that make subtyping work.