INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Applies the values of cluster_dict dictionary to a cluster spec (vim.ClusterConfigSpecEx). All vsan values (cluster_dict['vsan']) will be applied to vsan_spec (vim.vsan.cluster.ConfigInfoEx). Can be not omitted if not required. VSAN 6.1 config needs to be applied differently than the post VSAN 6.1...
def _apply_cluster_dict(cluster_spec, cluster_dict, vsan_spec=None, vsan_61=True): ''' Applies the values of cluster_dict dictionary to a cluster spec (vim.ClusterConfigSpecEx). All vsan values (cluster_dict['vsan']) will be applied to vsan_spec (vim.vsan.cluster.ConfigInfoE...
Creates a cluster. Note: cluster_dict['name'] will be overridden by the cluster param value config_dict Dictionary with the config values of the new cluster. datacenter Name of datacenter containing the cluster. Ignored if already contained by proxy details. Default value ...
def create_cluster(cluster_dict, datacenter=None, cluster=None, service_instance=None): ''' Creates a cluster. Note: cluster_dict['name'] will be overridden by the cluster param value config_dict Dictionary with the config values of the new cluster. datacenter N...
Updates a cluster. config_dict Dictionary with the config values of the new cluster. datacenter Name of datacenter containing the cluster. Ignored if already contained by proxy details. Default value is None. cluster Name of cluster. Ignored if already cont...
def update_cluster(cluster_dict, datacenter=None, cluster=None, service_instance=None): ''' Updates a cluster. config_dict Dictionary with the config values of the new cluster. datacenter Name of datacenter containing the cluster. Ignored if already contained...
Returns a list of dict representations of the datastores visible to the proxy object. The list of datastores can be filtered by datastore names, backing disk ids (canonical names) or backing disk scsi addresses. Supported proxy types: esxi, esxcluster, esxdatacenter datastore_names List of the...
def list_datastores_via_proxy(datastore_names=None, backing_disk_ids=None, backing_disk_scsi_addresses=None, service_instance=None): ''' Returns a list of dict representations of the datastores visible to the proxy object. The list of datastores ca...
Creates a ESXi host disk group with the specified cache and capacity disks. datastore_name The name of the datastore to be created. disk_id The disk id (canonical name) on which the datastore is created. vmfs_major_version The VMFS major version. safety_checks Specify...
def create_vmfs_datastore(datastore_name, disk_id, vmfs_major_version, safety_checks=True, service_instance=None): ''' Creates a ESXi host disk group with the specified cache and capacity disks. datastore_name The name of the datastore to be created. disk_id T...
Renames a datastore. The datastore needs to be visible to the proxy. datastore_name Current datastore name. new_datastore_name New datastore name. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash ...
def rename_datastore(datastore_name, new_datastore_name, service_instance=None): ''' Renames a datastore. The datastore needs to be visible to the proxy. datastore_name Current datastore name. new_datastore_name New datastore name. service_instance Ser...
Removes a datastore. If multiple datastores an error is raised. datastore Datastore name service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash salt '*' vsphere.remove_datastore ds_name
def remove_datastore(datastore, service_instance=None): ''' Removes a datastore. If multiple datastores an error is raised. datastore Datastore name service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash ...
Lists all licenses on a vCenter. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash salt '*' vsphere.list_licenses
def list_licenses(service_instance=None): ''' Lists all licenses on a vCenter. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash salt '*' vsphere.list_licenses ''' log.trace('Retrieving all licenses'...
Adds a license to the vCenter or ESXi host key License key. description License description added in as a label. safety_checks Specify whether to perform safety check or to skip the checks and try performing the required task service_instance Service instance ...
def add_license(key, description, safety_checks=True, service_instance=None): ''' Adds a license to the vCenter or ESXi host key License key. description License description added in as a label. safety_checks Specify whether to perform safety check or to sk...
Returns the entity associated with the entity dict representation Supported entities: cluster, vcenter Expected entity format: .. code-block:: python cluster: {'type': 'cluster', 'datacenter': <datacenter_name>, 'cluster': <cluster_name>} vcenter: ...
def _get_entity(service_instance, entity): ''' Returns the entity associated with the entity dict representation Supported entities: cluster, vcenter Expected entity format: .. code-block:: python cluster: {'type': 'cluster', 'datacenter': <datacenter_name>, ...
Validates the entity dict representation entity Dictionary representation of an entity. See ``_get_entity`` docstrings for format.
def _validate_entity(entity): ''' Validates the entity dict representation entity Dictionary representation of an entity. See ``_get_entity`` docstrings for format. ''' #Validate entity: if entity['type'] == 'cluster': schema = ESXClusterEntitySchema.serialize() eli...
Lists the licenses assigned to an entity entity Dictionary representation of an entity. See ``_get_entity`` docstrings for format. entity_display_name Entity name used in logging license_keys: List of license keys to be retrieved. Default is None. service_instance ...
def list_assigned_licenses(entity, entity_display_name, license_keys=None, service_instance=None): ''' Lists the licenses assigned to an entity entity Dictionary representation of an entity. See ``_get_entity`` docstrings for format. entity_display_name ...
Assigns a license to an entity license_key Key of the license to assign See ``_get_entity`` docstrings for format. license_name Display name of license entity Dictionary representation of an entity entity_display_name Entity name used in logging safety_ch...
def assign_license(license_key, license_name, entity, entity_display_name, safety_checks=True, service_instance=None): ''' Assigns a license to an entity license_key Key of the license to assign See ``_get_entity`` docstrings for format. license_name Display ...
Returns a list of hosts for the the specified VMware environment. The list of hosts can be filtered by datacenter name and/or cluster name hostnames Hostnames to filter on. datacenter_name Name of datacenter. Only hosts in this datacenter will be retrieved. Default is None. cl...
def list_hosts_via_proxy(hostnames=None, datacenter=None, cluster=None, service_instance=None): ''' Returns a list of hosts for the the specified VMware environment. The list of hosts can be filtered by datacenter name and/or cluster name hostnames Hostnames to filter o...
Returns a list of dict representations of the disks in an ESXi host. The list of disks can be filtered by disk canonical names or scsi addresses. disk_ids: List of disk canonical names to be retrieved. Default is None. scsi_addresses List of scsi addresses of disks to be retrieved. Def...
def list_disks(disk_ids=None, scsi_addresses=None, service_instance=None): ''' Returns a list of dict representations of the disks in an ESXi host. The list of disks can be filtered by disk canonical names or scsi addresses. disk_ids: List of disk canonical names to be retrieved. Default is...
Erases the partitions on a disk. The disk can be specified either by the canonical name, or by the scsi_address. disk_id Canonical name of the disk. Either ``disk_id`` or ``scsi_address`` needs to be specified (``disk_id`` supersedes ``scsi_address``. scsi_address Scsi ...
def erase_disk_partitions(disk_id=None, scsi_address=None, service_instance=None): ''' Erases the partitions on a disk. The disk can be specified either by the canonical name, or by the scsi_address. disk_id Canonical name of the disk. Either ``disk_id`` or...
Lists the partitions on a disk. The disk can be specified either by the canonical name, or by the scsi_address. disk_id Canonical name of the disk. Either ``disk_id`` or ``scsi_address`` needs to be specified (``disk_id`` supersedes ``scsi_address``. scsi_address` Scsi ...
def list_disk_partitions(disk_id=None, scsi_address=None, service_instance=None): ''' Lists the partitions on a disk. The disk can be specified either by the canonical name, or by the scsi_address. disk_id Canonical name of the disk. Either ``disk_id`` or `...
Returns a list of disk group dict representation on an ESXi host. The list of disk groups can be filtered by the cache disks canonical names. If no filtering is applied, all disk groups are returned. cache_disk_ids: List of cache disk canonical names of the disk groups to be retrieved. Defa...
def list_diskgroups(cache_disk_ids=None, service_instance=None): ''' Returns a list of disk group dict representation on an ESXi host. The list of disk groups can be filtered by the cache disks canonical names. If no filtering is applied, all disk groups are returned. cache_disk_ids: List o...
Creates disk group on an ESXi host with the specified cache and capacity disks. cache_disk_id The canonical name of the disk to be used as a cache. The disk must be ssd. capacity_disk_ids A list containing canonical names of the capacity disks. Must contain at least one id....
def create_diskgroup(cache_disk_id, capacity_disk_ids, safety_checks=True, service_instance=None): ''' Creates disk group on an ESXi host with the specified cache and capacity disks. cache_disk_id The canonical name of the disk to be used as a cache. The disk must be ...
Remove the diskgroup with the specified cache disk. cache_disk_id The canonical name of the cache disk. data_accessibility Specifies whether to ensure data accessibility. Default value is True. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. ...
def remove_diskgroup(cache_disk_id, data_accessibility=True, service_instance=None): ''' Remove the diskgroup with the specified cache disk. cache_disk_id The canonical name of the cache disk. data_accessibility Specifies whether to ensure data accessibility. Defau...
Returns the host cache configuration on the proxy host. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash salt '*' vsphere.get_host_cache
def get_host_cache(service_instance=None): ''' Returns the host cache configuration on the proxy host. service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. Default is None. .. code-block:: bash salt '*' vsphere.get_host_cache ''' # Default ...
Configures the host cache on the selected host. enabled Boolean flag specifying whether the host cache is enabled. datastore Name of the datastore that contains the host cache. Must be set if enabled is ``true``. swap_size_MiB Swap size in Mibibytes. Needs to be set if ena...
def configure_host_cache(enabled, datastore=None, swap_size_MiB=None, service_instance=None): ''' Configures the host cache on the selected host. enabled Boolean flag specifying whether the host cache is enabled. datastore Name of the datastore that contains th...
Helper function that checks to see if the host provided is a vCenter Server or an ESXi host. If it's an ESXi host, returns a list of a single host_name. If a host reference isn't found, we're trying to find a host object for a vCenter server. Raises a CommandExecutionError in this case, as we need host ref...
def _check_hosts(service_instance, host, host_names): ''' Helper function that checks to see if the host provided is a vCenter Server or an ESXi host. If it's an ESXi host, returns a list of a single host_name. If a host reference isn't found, we're trying to find a host object for a vCenter server...
Helper function to format the stdout from the get_coredump_network_config function. cmd_ret The return dictionary that comes from a cmd.run_all call.
def _format_coredump_stdout(cmd_ret): ''' Helper function to format the stdout from the get_coredump_network_config function. cmd_ret The return dictionary that comes from a cmd.run_all call. ''' ret_dict = {} for line in cmd_ret['stdout'].splitlines(): line = line.strip().lower...
Helper function to format the stdout from the get_firewall_status function. cmd_ret The return dictionary that comes from a cmd.run_all call.
def _format_firewall_stdout(cmd_ret): ''' Helper function to format the stdout from the get_firewall_status function. cmd_ret The return dictionary that comes from a cmd.run_all call. ''' ret_dict = {'success': True, 'rulesets': {}} for line in cmd_ret['stdout'].splitlin...
Helper function to format the stdout from the get_syslog_config function. cmd_ret The return dictionary that comes from a cmd.run_all call.
def _format_syslog_config(cmd_ret): ''' Helper function to format the stdout from the get_syslog_config function. cmd_ret The return dictionary that comes from a cmd.run_all call. ''' ret_dict = {'success': cmd_ret['retcode'] == 0} if cmd_ret['retcode'] != 0: ret_dict['message'...
Helper function that returns a host object either from the host location or the host_name. If host_name is provided, that is the host_object that will be returned. The function will first search for hosts by DNS Name. If no hosts are found, it will try searching by IP Address.
def _get_host_ref(service_instance, host, host_name=None): ''' Helper function that returns a host object either from the host location or the host_name. If host_name is provided, that is the host_object that will be returned. The function will first search for hosts by DNS Name. If no hosts are found,...
Helper function that returns a dictionary containing a list of SSD and Non-SSD disks.
def _get_host_disks(host_reference): ''' Helper function that returns a dictionary containing a list of SSD and Non-SSD disks. ''' storage_system = host_reference.configManager.storageSystem disks = storage_system.storageDeviceInfo.scsiLun ssds = [] non_ssds = [] for disk in disks: ...
Helper function that returns a dictionary of host_name keys with either a list of eligible disks that can be added to VSAN or either an 'Error' message or a message saying no eligible disks were found. Possible keys/values look like: return = {'host_1': {'Error': 'VSAN System Config Manager is unset ...'},...
def _get_vsan_eligible_disks(service_instance, host, host_names): ''' Helper function that returns a dictionary of host_name keys with either a list of eligible disks that can be added to VSAN or either an 'Error' message or a message saying no eligible disks were found. Possible keys/values look like: ...
Helper function for reset_syslog_config that resets the config and populates the return dictionary.
def _reset_syslog_config_params(host, username, password, cmd, resets, valid_resets, protocol=None, port=None, esxi_host=None, credstore=None): ''' Helper function for reset_syslog_config that resets the config and populates the return dictionary. ''' ret_dict = {} al...
Helper function for set_syslog_config that sets the config and populates the return dictionary.
def _set_syslog_config_helper(host, username, password, syslog_config, config_value, protocol=None, port=None, reset_service=None, esxi_host=None, credstore=None): ''' Helper function for set_syslog_config that sets the config and populates the return dictionary. ''' cmd = ...
Adds an ESXi host to a vSphere Distributed Virtual Switch and migrates the desired adapters to the DVS from the standard switch. host The location of the vCenter server. username The username used to login to the vCenter server. password The password used to login to the vCent...
def add_host_to_dvs(host, username, password, vmknic_name, vmnic_name, dvs_name, target_portgroup_name, uplink_portgroup_name, protocol=None, port=None, host_names=None): ''' Adds an ESXi host to a vSphere Distributed Virtual Switch and migrates the desired adapters t...
Returns the target object of a proxy. If the object doesn't exist a VMwareObjectRetrievalError is raised service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host.
def _get_proxy_target(service_instance): ''' Returns the target object of a proxy. If the object doesn't exist a VMwareObjectRetrievalError is raised service_instance Service instance (vim.ServiceInstance) of the vCenter/ESXi host. ''' proxy_type = get_proxy_type() if not salt.util...
Returns the running esxdatacenter's proxy details
def _get_esxdatacenter_proxy_details(): ''' Returns the running esxdatacenter's proxy details ''' det = __salt__['esxdatacenter.get_details']() return det.get('vcenter'), det.get('username'), det.get('password'), \ det.get('protocol'), det.get('port'), det.get('mechanism'), \ ...
Returns the running esxi's proxy details
def _get_esxi_proxy_details(): ''' Returns the running esxi's proxy details ''' det = __proxy__['esxi.get_details']() host = det.get('host') if det.get('vcenter'): host = det['vcenter'] esxi_hosts = None if det.get('esxi_host'): esxi_hosts = [det['esxi_host']] return ...
Returns the running esxcluster's proxy details
def _get_esxcluster_proxy_details(): ''' Returns the running esxcluster's proxy details ''' det = __salt__['esxcluster.get_details']() return det.get('vcenter'), det.get('username'), det.get('password'), \ det.get('protocol'), det.get('port'), det.get('mechanism'), \ det.get(...
Returns vm object properties. name Name of the virtual machine. datacenter Datacenter name vm_properties List of vm properties. traversal_spec Traversal Spec object(s) for searching. parent_ref Container Reference object for searching under a given object...
def get_vm(name, datacenter=None, vm_properties=None, traversal_spec=None, parent_ref=None, service_instance=None): ''' Returns vm object properties. name Name of the virtual machine. datacenter Datacenter name vm_properties List of vm properties. traversal...
Queries the virtual machine config file and returns vim.host.DatastoreBrowser.SearchResults object on success None on failure name Name of the virtual machine datacenter Datacenter name datastore Datastore where the virtual machine files are stored service_instance ...
def get_vm_config_file(name, datacenter, placement, datastore, service_instance=None): ''' Queries the virtual machine config file and returns vim.host.DatastoreBrowser.SearchResults object on success None on failure name Name of the virtual machine datacenter ...
Specifies vm container version or schedules upgrade, returns True on change and False if nothing have been changed. hardware_version Hardware version string eg. vmx-08 config_spec Configuration spec object operation Defines the operation which should be used, the possi...
def _apply_hardware_version(hardware_version, config_spec, operation='add'): ''' Specifies vm container version or schedules upgrade, returns True on change and False if nothing have been changed. hardware_version Hardware version string eg. vmx-08 config_spec Configuration spec ob...
Sets CPU core count to the given value config_spec vm.ConfigSpec object cpu_props CPU properties dict
def _apply_cpu_config(config_spec, cpu_props): ''' Sets CPU core count to the given value config_spec vm.ConfigSpec object cpu_props CPU properties dict ''' log.trace('Configuring virtual machine CPU ' 'settings cpu_props=%s', cpu_props) if 'count' in cpu_prop...
Sets memory size to the given value config_spec vm.ConfigSpec object memory Memory size and unit
def _apply_memory_config(config_spec, memory): ''' Sets memory size to the given value config_spec vm.ConfigSpec object memory Memory size and unit ''' log.trace('Configuring virtual machine memory ' 'settings memory=%s', memory) if 'size' in memory and 'unit'...
Returns extra config parameters from a virtual machine advanced config list vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available service_instance vCenter service instance for connection and configuration
def get_advanced_configs(vm_name, datacenter, service_instance=None): ''' Returns extra config parameters from a virtual machine advanced config list vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available service_instance vCenter ser...
Sets configuration parameters for the vm config_spec vm.ConfigSpec object advanced_config config key value pairs vm_extra_config Virtual machine vm_ref.config.extraConfig object
def _apply_advanced_config(config_spec, advanced_config, vm_extra_config=None): ''' Sets configuration parameters for the vm config_spec vm.ConfigSpec object advanced_config config key value pairs vm_extra_config Virtual machine vm_ref.config.extraConfig object ''' ...
Appends extra config parameters to a virtual machine advanced config list vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available advanced_configs Dictionary with advanced parameter key value pairs service_instance vCenter servic...
def set_advanced_configs(vm_name, datacenter, advanced_configs, service_instance=None): ''' Appends extra config parameters to a virtual machine advanced config list vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available ...
Removes configuration parameters for the vm config_spec vm.ConfigSpec object advanced_config List of advanced config keys to be deleted vm_extra_config Virtual machine vm_ref.config.extraConfig object
def _delete_advanced_config(config_spec, advanced_config, vm_extra_config): ''' Removes configuration parameters for the vm config_spec vm.ConfigSpec object advanced_config List of advanced config keys to be deleted vm_extra_config Virtual machine vm_ref.config.extraConfig...
Removes extra config parameters from a virtual machine vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available advanced_configs List of advanced config values to be removed service_instance vCenter service instance for connection...
def delete_advanced_configs(vm_name, datacenter, advanced_configs, service_instance=None): ''' Removes extra config parameters from a virtual machine vm_name Virtual machine name datacenter Datacenter name where the virtual machine is available advanced...
Returns key number of the SCSI controller keys bus_number Controller bus number from the adapter scsi_ctrls List of SCSI Controller objects (old+newly created)
def _get_scsi_controller_key(bus_number, scsi_ctrls): ''' Returns key number of the SCSI controller keys bus_number Controller bus number from the adapter scsi_ctrls List of SCSI Controller objects (old+newly created) ''' # list of new/old VirtualSCSIController objects, both ne...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a virtual disk device unit_number Add network adapter to this address key Device key number operation Action which should be done on the device add or edit disk_label Label of the new disk, ca...
def _apply_hard_disk(unit_number, key, operation, disk_label=None, size=None, unit='GB', controller_key=None, thin_provision=None, eagerly_scrub=None, datastore=None, filename=None): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a virtu...
Returns a vim.vm.device.VirtualEthernetCard object specifying a virtual ethernet card information network_adapter None or VirtualEthernet object adapter_type String, type of adapter network_adapter_label string, network adapter name
def _create_adapter_type(network_adapter, adapter_type, network_adapter_label=''): ''' Returns a vim.vm.device.VirtualEthernetCard object specifying a virtual ethernet card information network_adapter None or VirtualEthernet object adapter_type String, type...
Returns a vim.vm.device.VirtualDevice.BackingInfo object specifying a virtual ethernet card backing information network_name string, network name switch_type string, type of switch parent_ref Parent reference to search for network
def _create_network_backing(network_name, switch_type, parent_ref): ''' Returns a vim.vm.device.VirtualDevice.BackingInfo object specifying a virtual ethernet card backing information network_name string, network name switch_type string, type of switch parent_ref Paren...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a network device network_adapter_label Network adapter label key Unique key for device creation network_name Network or port group name adapter_type Type of the adapter eg. vmxnet3 switch...
def _apply_network_adapter_config(key, network_name, adapter_type, switch_type, network_adapter_label=None, operation='add', connectable=None, mac=None, parent=None): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a SCSI controller adapter SCSI controller adapter name adapter_type SCSI controller adapter type eg. paravirtual bus_sharing SCSI controller bus sharing eg. virtual_sharing key SCSI controlle...
def _apply_scsi_controller(adapter, adapter_type, bus_sharing, key, bus_number, operation): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a SCSI controller adapter SCSI controller adapter name adapter_type SCSI controller ada...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing IDE controllers ide_controllers IDE properties
def _create_ide_controllers(ide_controllers): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing IDE controllers ide_controllers IDE properties ''' ide_ctrls = [] keys = range(-200, -250, -1) if ide_controllers: devs = [ide['adapter'] for ide in i...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit an IDE controller ide_controller_label Controller label of the IDE adapter operation Type of operation: add or edit key Unique key of the device bus_number Device bus number property
def _apply_ide_controller_config(ide_controller_label, operation, key, bus_number=0): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit an IDE controller ide_controller_label Controller label of the IDE adapter operation Ty...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing SATA controllers sata_controllers SATA properties
def _create_sata_controllers(sata_controllers): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing SATA controllers sata_controllers SATA properties ''' sata_ctrls = [] keys = range(-15000, -15050, -1) if sata_controllers: devs = [sata['adapter'] ...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a SATA controller sata_controller_label Controller label of the SATA adapter operation Type of operation: add or edit key Unique key of the device bus_number Device bus number property
def _apply_sata_controller_config(sata_controller_label, operation, key, bus_number=0): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a SATA controller sata_controller_label Controller label of the SATA adapter operation ...
Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a CD/DVD drive drive_label Leble of the CD/DVD drive key Unique key of the device device_type Type of the device: client or iso operation Type of operation: add or edit client_device ...
def _apply_cd_drive(drive_label, key, device_type, operation, client_device=None, datastore_iso_file=None, connectable=None, controller_key=200, parent_ref=None): ''' Returns a vim.vm.device.VirtualDeviceSpec object specifying to add/edit a CD/DVD drive drive_lab...
Returns a vim.vm.customization.AdapterMapping object containing the IP properties of a network adapter card domain Domain of the host gateway Gateway address ip_addr IP address subnet_mask Subnet mask mac MAC address of the guest
def _set_network_adapter_mapping(domain, gateway, ip_addr, subnet_mask, mac): ''' Returns a vim.vm.customization.AdapterMapping object containing the IP properties of a network adapter card domain Domain of the host gateway Gateway address ip_addr IP address subne...
Returns a vim.vm.device.VirtualSerialPort representing a serial port component serial_device_spec Serial device properties key Unique key of the device operation Add or edit the given device .. code-block:: bash serial_ports: adapter: 'Serial port 1' ...
def _apply_serial_port(serial_device_spec, key, operation='add'): ''' Returns a vim.vm.device.VirtualSerialPort representing a serial port component serial_device_spec Serial device properties key Unique key of the device operation Add or edit the given device .. ...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing SCSI controllers scsi_devices: List of SCSI device properties
def _create_scsi_devices(scsi_devices): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing SCSI controllers scsi_devices: List of SCSI device properties ''' keys = range(-1000, -1050, -1) scsi_specs = [] if scsi_devices: devs = [scsi['adapter'] fo...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the interfaces to be created for a virtual machine network_interfaces List of network interfaces and properties parent Parent object reference .. code-block: bash interfaces: adapter: 'Network ad...
def _create_network_adapters(network_interfaces, parent=None): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the interfaces to be created for a virtual machine network_interfaces List of network interfaces and properties parent Parent object reference ...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the serial ports to be created for a virtual machine serial_ports Serial port properties
def _create_serial_ports(serial_ports): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the serial ports to be created for a virtual machine serial_ports Serial port properties ''' ports = [] keys = range(-9000, -9050, -1) if serial_ports: devs...
Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the CD/DVD drives to be created for a virtual machine cd_drives CD/DVD drive properties controllers CD/DVD drive controllers (IDE, SATA) parent_ref Parent object reference
def _create_cd_drives(cd_drives, controllers=None, parent_ref=None): ''' Returns a list of vim.vm.device.VirtualDeviceSpec objects representing the CD/DVD drives to be created for a virtual machine cd_drives CD/DVD drive properties controllers CD/DVD drive controllers (IDE, SATA) ...
Returns the device with the given key, raises error if the device is not found. devices list of vim.vm.device.VirtualDevice objects key Unique key of device
def _get_device_by_key(devices, key): ''' Returns the device with the given key, raises error if the device is not found. devices list of vim.vm.device.VirtualDevice objects key Unique key of device ''' device_keys = [d for d in devices if d.key == key] if device_keys: ...
Returns the device with the given label, raises error if the device is not found. devices list of vim.vm.device.VirtualDevice objects key Unique key of device
def _get_device_by_label(devices, label): ''' Returns the device with the given label, raises error if the device is not found. devices list of vim.vm.device.VirtualDevice objects key Unique key of device ''' device_labels = [d for d in devices if d.deviceInfo.label == labe...
Updates the size and unit dictionary values with the new unit values devices List of device data objects
def _convert_units(devices): ''' Updates the size and unit dictionary values with the new unit values devices List of device data objects ''' if devices: for device in devices: if 'unit' in device and 'size' in device: device.update( s...
Compares virtual machine current and new configuration, the current is the one which is deployed now, and the new is the target config. Returns the differences between the objects in a dictionary, the keys are the configuration parameter keys and the values are differences objects: either list or recurs...
def compare_vm_configs(new_config, current_config): ''' Compares virtual machine current and new configuration, the current is the one which is deployed now, and the new is the target config. Returns the differences between the objects in a dictionary, the keys are the configuration parameter keys a...
Queries and converts the virtual machine properties to the available format from the schema. If the objects attribute is True the config objects will have extra properties, like 'object' which will include the vim.vm.device.VirtualDevice, this is necessary for deletion and update actions. name ...
def get_vm_config(name, datacenter=None, objects=True, service_instance=None): ''' Queries and converts the virtual machine properties to the available format from the schema. If the objects attribute is True the config objects will have extra properties, like 'object' which will include the vim.vm....
Changes the disk size and returns the config spec objects in a list. The controller property cannot be updated, because controller address identifies the disk by the unit and bus number properties. disks_diffs List of old and new disk properties, the properties are dictionary objects
def _update_disks(disks_old_new): ''' Changes the disk size and returns the config spec objects in a list. The controller property cannot be updated, because controller address identifies the disk by the unit and bus number properties. disks_diffs List of old and new disk properties, the pr...
Returns a list of vim.vm.device.VirtualDeviceSpec specifying the scsi properties as input the old and new configs are defined in a dictionary. scsi_diffs List of old and new scsi properties
def _update_scsi_devices(scsis_old_new, current_disks): ''' Returns a list of vim.vm.device.VirtualDeviceSpec specifying the scsi properties as input the old and new configs are defined in a dictionary. scsi_diffs List of old and new scsi properties ''' device_config_specs = [] if ...
Returns a list of vim.vm.device.VirtualDeviceSpec specifying configuration(s) for changed network adapters, the adapter type cannot be changed, as input the old and new configs are defined in a dictionary. interface_old_new Dictionary with old and new keys which contains the current and the ...
def _update_network_adapters(interface_old_new, parent): ''' Returns a list of vim.vm.device.VirtualDeviceSpec specifying configuration(s) for changed network adapters, the adapter type cannot be changed, as input the old and new configs are defined in a dictionary. interface_old_new Dictio...
Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a deployed serial port configuration to the new given config serial_old_new Dictionary with old and new keys which contains the current and the next config for a serial port device
def _update_serial_ports(serial_old_new): ''' Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a deployed serial port configuration to the new given config serial_old_new Dictionary with old and new keys which contains the current and the next config for a serial ...
Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a deployed cd drive configuration to the new given config drives_old_new Dictionary with old and new keys which contains the current and the next config for a cd drive controllers Controller device list paren...
def _update_cd_drives(drives_old_new, controllers=None, parent=None): ''' Returns a list of vim.vm.device.VirtualDeviceSpec specifying to edit a deployed cd drive configuration to the new given config drives_old_new Dictionary with old and new keys which contains the current and the nex...
Returns a vim.vm.device.VirtualDeviceSpec specifying to remove a virtual machine device device Device data type object
def _delete_device(device): ''' Returns a vim.vm.device.VirtualDeviceSpec specifying to remove a virtual machine device device Device data type object ''' log.trace('Deleting device with type %s', type(device)) device_spec = vim.vm.device.VirtualDeviceSpec() device_spec.operatio...
Creates a virtual machine container. CLI Example: .. code-block:: bash salt vm_minion vsphere.create_vm vm_name=vmname cpu='{count: 2, nested: True}' ... vm_name Name of the virtual machine cpu Properties of CPUs for freshly created machines memory Memory size f...
def create_vm(vm_name, cpu, memory, image, version, datacenter, datastore, placement, interfaces, disks, scsi_devices, serial_ports=None, ide_controllers=None, sata_controllers=None, cd_drives=None, advanced_configs=None, service_instance=None): ''' Creates a virtual ma...
Updates the configuration of the virtual machine if the config differs vm_name Virtual Machine name to be updated cpu CPU configuration options memory Memory configuration options version Virtual machine container hardware version image Virtual machine gu...
def update_vm(vm_name, cpu=None, memory=None, image=None, version=None, interfaces=None, disks=None, scsi_devices=None, serial_ports=None, datacenter=None, datastore=None, cd_dvd_drives=None, sata_controllers=None, advanced_configs=None, service_instance=None): ...
Registers a virtual machine to the inventory with the given vmx file. Returns comments and change list name Name of the virtual machine datacenter Datacenter of the virtual machine placement Placement dictionary of the virtual machine, host or cluster vmx_path: Fu...
def register_vm(name, datacenter, placement, vmx_path, service_instance=None): ''' Registers a virtual machine to the inventory with the given vmx file. Returns comments and change list name Name of the virtual machine datacenter Datacenter of the virtual machine placement ...
Powers on a virtual machine specified by it's name. name Name of the virtual machine datacenter Datacenter of the virtual machine service_instance Service instance (vim.ServiceInstance) of the vCenter. Default is None. .. code-block:: bash salt '*' vsphere.po...
def power_on_vm(name, datacenter=None, service_instance=None): ''' Powers on a virtual machine specified by it's name. name Name of the virtual machine datacenter Datacenter of the virtual machine service_instance Service instance (vim.ServiceInstance) of the vCenter. ...
Helper function to remove a virtual machine name Name of the virtual machine service_instance vCenter service instance for connection and configuration datacenter Datacenter of the virtual machine placement Placement information of the virtual machine
def _remove_vm(name, datacenter, service_instance, placement=None, power_off=None): ''' Helper function to remove a virtual machine name Name of the virtual machine service_instance vCenter service instance for connection and configuration datacenter Datacen...
Deletes a virtual machine defined by name and placement name Name of the virtual machine datacenter Datacenter of the virtual machine placement Placement information of the virtual machine service_instance vCenter service instance for connection and configuration ...
def delete_vm(name, datacenter, placement=None, power_off=False, service_instance=None): ''' Deletes a virtual machine defined by name and placement name Name of the virtual machine datacenter Datacenter of the virtual machine placement Placement information ...
Acquire Azure ARM Credentials
def _determine_auth(**kwargs): ''' Acquire Azure ARM Credentials ''' if 'profile' in kwargs: azure_credentials = __salt__['config.option'](kwargs['profile']) kwargs.update(azure_credentials) service_principal_creds_kwargs = ['client_id', 'secret', 'tenant'] user_pass_creds_kwarg...
Dynamically load the selected client and return a management client object
def get_client(client_type, **kwargs): ''' Dynamically load the selected client and return a management client object ''' client_map = {'compute': 'ComputeManagement', 'authorization': 'AuthorizationManagement', 'dns': 'DnsManagement', 'storage': 'St...
Log an azurearm cloud error exception
def log_cloud_error(client, message, **kwargs): ''' Log an azurearm cloud error exception ''' try: cloud_logger = getattr(log, kwargs.get('azurearm_log_level')) except (AttributeError, TypeError): cloud_logger = getattr(log, 'error') cloud_logger( 'An AzureARM %s CloudE...
Extract all pages within a paged object as a list of dictionaries
def paged_object_to_list(paged_object): ''' Extract all pages within a paged object as a list of dictionaries ''' paged_return = [] while True: try: page = next(paged_object) paged_return.append(page.as_dict()) except CloudError: raise exce...
Assemble an object from incoming parameters.
def create_object_model(module_name, object_name, **kwargs): ''' Assemble an object from incoming parameters. ''' object_kwargs = {} try: model_module = importlib.import_module('azure.mgmt.{0}.models'.format(module_name)) # pylint: disable=invalid-name Model = getattr(model_...
Compare lists of dictionaries representing Azure objects. Only keys found in the "new" dictionaries are compared to the "old" dictionaries, since getting Azure objects from the API returns some read-only data which should not be used in the comparison. A list of parameter names can be passed in order to compare...
def compare_list_of_dicts(old, new, convert_id_to_name=None): ''' Compare lists of dictionaries representing Azure objects. Only keys found in the "new" dictionaries are compared to the "old" dictionaries, since getting Azure objects from the API returns some read-only data which should not be used in t...
Warn if dependencies aren't met.
def get_dependencies(): ''' Warn if dependencies aren't met. ''' if LIBCLOUD_IMPORT_ERROR: log.error("Failure when importing LibCloud: ", exc_info=LIBCLOUD_IMPORT_ERROR) log.error("Note: The libcloud dependency is called 'apache-libcloud' on PyPi/pip.") return config.check_driver_dep...
Return a conn object for the passed VM data
def get_conn(): ''' Return a conn object for the passed VM data ''' driver = get_driver(Provider.GCE) provider = get_configured_provider() project = config.get_cloud_config_value('project', provider, __opts__) email = config.get_cloud_config_value( 'service_account_email_address', ...
Convert the libcloud Node object into something more serializable.
def _expand_node(node): ''' Convert the libcloud Node object into something more serializable. ''' ret = {} ret.update(node.__dict__) try: del ret['extra']['boot_disk'] except Exception: # pylint: disable=W0703 pass zone = ret['extra']['zone'] ret['extra']['zone'] = ...
Convert the libcloud Volume object into something more serializable.
def _expand_disk(disk): ''' Convert the libcloud Volume object into something more serializable. ''' ret = {} ret.update(disk.__dict__) zone = ret['extra']['zone'] ret['extra']['zone'] = {} ret['extra']['zone'].update(zone.__dict__) return ret
Convert the libcloud GCEAddress object into something more serializable.
def _expand_address(addy): ''' Convert the libcloud GCEAddress object into something more serializable. ''' ret = {} ret.update(addy.__dict__) ret['extra']['zone'] = addy.region.name return ret
Convert the libcloud load-balancer object into something more serializable.
def _expand_balancer(lb): ''' Convert the libcloud load-balancer object into something more serializable. ''' ret = {} ret.update(lb.__dict__) hc = ret['extra']['healthchecks'] ret['extra']['healthchecks'] = [] for item in hc: ret['extra']['healthchecks'].append(_expand_item(item...
Show the details of the existing instance.
def show_instance(vm_name, call=None): ''' Show the details of the existing instance. ''' if call != 'action': raise SaltCloudSystemExit( 'The show_instance action must be called with -a or --action.' ) conn = get_conn() node = _expand_node(conn.ex_get_node(vm_name)) ...
Return a dict of available instances sizes (a.k.a machine types) and convert them to something more serializable.
def avail_sizes(conn=None): ''' Return a dict of available instances sizes (a.k.a machine types) and convert them to something more serializable. ''' if not conn: conn = get_conn() raw_sizes = conn.list_sizes('all') # get *all* the machine types! sizes = [] for size in raw_sizes...
Return a dict of all available VM images on the cloud provider with relevant data. Note that for GCE, there are custom images within the project, but the generic images are in other projects. This returns a dict of images in the project plus images in well-known public projects that provide supported ...
def avail_images(conn=None): ''' Return a dict of all available VM images on the cloud provider with relevant data. Note that for GCE, there are custom images within the project, but the generic images are in other projects. This returns a dict of images in the project plus images in well-know...
The get_image for GCE allows partial name matching and returns a libcloud object.
def __get_image(conn, vm_): ''' The get_image for GCE allows partial name matching and returns a libcloud object. ''' img = config.get_cloud_config_value( 'image', vm_, __opts__, default='debian-7', search_global=False) return conn.ex_get_image(img)
Need to override libcloud to find the zone.
def __get_location(conn, vm_): ''' Need to override libcloud to find the zone. ''' location = config.get_cloud_config_value( 'location', vm_, __opts__) return conn.ex_get_zone(location)
Need to override libcloud to find the machine type in the proper zone.
def __get_size(conn, vm_): ''' Need to override libcloud to find the machine type in the proper zone. ''' size = config.get_cloud_config_value( 'size', vm_, __opts__, default='n1-standard-1', search_global=False) return conn.ex_get_size(size, __get_location(conn, vm_))
Get configured tags.
def __get_tags(vm_): ''' Get configured tags. ''' t = config.get_cloud_config_value( 'tags', vm_, __opts__, default='[]', search_global=False) # Consider warning the user that the tags in the cloud profile # could not be interpreted, bad formatting? try: tags = litera...
Get configured metadata and add 'salt-cloud-profile'.
def __get_metadata(vm_): ''' Get configured metadata and add 'salt-cloud-profile'. ''' md = config.get_cloud_config_value( 'metadata', vm_, __opts__, default='{}', search_global=False) # Consider warning the user that the metadata in the cloud profile # could not be interpreted, ...