Be explicit about salt.utils.vmware function calls and avoid namespacing

This commit is contained in:
rallytime 2015-11-05 08:02:09 -07:00
parent f2ac256209
commit 718d3e39ac

View File

@ -72,7 +72,7 @@ import subprocess
import salt.utils
import salt.utils.cloud
import salt.utils.xmlutil
import salt.utils.vmware as vmware
import salt.utils.vmware
from salt.exceptions import SaltCloudSystemExit
# Import salt cloud libs
@ -198,11 +198,11 @@ def _get_si():
'port', get_configured_provider(), __opts__, search_global=False, default=443
)
return vmware.get_service_instance(url,
username,
password,
protocol=protocol,
port=port)
return salt.utils.vmware.get_service_instance(url,
username,
password,
protocol=protocol,
port=port)
def _edit_existing_hard_disk_helper(disk, size_kb):
@ -242,7 +242,7 @@ def _edit_existing_network_adapter(network_adapter, new_network_name, adapter_ty
switch_type.strip().lower()
if adapter_type in ["vmxnet", "vmxnet2", "vmxnet3", "e1000", "e1000e"]:
edited_network_adapter = vmware.get_network_adapter_type(adapter_type)
edited_network_adapter = salt.utils.vmware.get_network_adapter_type(adapter_type)
if isinstance(network_adapter, type(edited_network_adapter)):
edited_network_adapter = network_adapter
else:
@ -254,12 +254,14 @@ def _edit_existing_network_adapter(network_adapter, new_network_name, adapter_ty
edited_network_adapter = network_adapter
if switch_type == 'standard':
network_ref = vmware.get_mor_by_property(_get_si(), vim.Network, new_network_name)
network_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Network, new_network_name)
edited_network_adapter.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
edited_network_adapter.backing.deviceName = new_network_name
edited_network_adapter.backing.network = network_ref
elif switch_type == 'distributed':
network_ref = vmware.get_mor_by_property(_get_si(), vim.dvs.DistributedVirtualPortgroup, new_network_name)
network_ref = salt.utils.vmware.get_mor_by_property(_get_si(),
vim.dvs.DistributedVirtualPortgroup,
new_network_name)
dvs_port_connection = vim.dvs.PortConnection(
portgroupKey=network_ref.key,
switchUuid=network_ref.config.distributedVirtualSwitch.uuid
@ -299,7 +301,7 @@ def _add_new_network_adapter_helper(network_adapter_label, network_name, adapter
network_spec = vim.vm.device.VirtualDeviceSpec()
if adapter_type in ["vmxnet", "vmxnet2", "vmxnet3", "e1000", "e1000e"]:
network_spec.device = vmware.get_network_adapter_type(adapter_type)
network_spec.device = salt.utils.vmware.get_network_adapter_type(adapter_type)
else:
# If type not specified or does not match, create adapter of type vmxnet3
if not adapter_type:
@ -313,9 +315,13 @@ def _add_new_network_adapter_helper(network_adapter_label, network_name, adapter
if switch_type == 'standard':
network_spec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
network_spec.device.backing.deviceName = network_name
network_spec.device.backing.network = vmware.get_mor_by_property(_get_si(), vim.Network, network_name)
network_spec.device.backing.network = salt.utils.vmware.get_mor_by_property(_get_si(),
vim.Network,
network_name)
elif switch_type == 'distributed':
network_ref = vmware.get_mor_by_property(_get_si(), vim.dvs.DistributedVirtualPortgroup, network_name)
network_ref = salt.utils.vmware.get_mor_by_property(_get_si(),
vim.dvs.DistributedVirtualPortgroup,
network_name)
dvs_port_connection = vim.dvs.PortConnection(
portgroupKey=network_ref.key,
switchUuid=network_ref.config.distributedVirtualSwitch.uuid
@ -426,7 +432,7 @@ def _set_cd_or_dvd_backing_type(drive, device_type, mode, iso_path):
drive.backing.fileName = iso_path
datastore = iso_path.partition('[')[-1].rpartition(']')[0]
datastore_ref = vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
datastore_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
if datastore_ref:
drive.backing.datastore = datastore_ref
@ -1123,7 +1129,7 @@ def get_vcenter_version(kwargs=None, call=None):
)
# Get the inventory
inv = vmware.get_inventory(_get_si())
inv = salt.utils.vmware.get_inventory(_get_si())
return inv.about.fullName
@ -1147,7 +1153,7 @@ def list_datacenters(kwargs=None, call=None):
datacenters = []
datacenter_properties = ["name"]
datacenter_list = vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
datacenter_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
for datacenter in datacenter_list:
datacenters.append(datacenter["name"])
@ -1174,7 +1180,9 @@ def list_clusters(kwargs=None, call=None):
clusters = []
cluster_properties = ["name"]
cluster_list = vmware.get_mors_with_properties(_get_si(), vim.ClusterComputeResource, cluster_properties)
cluster_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.ClusterComputeResource,
cluster_properties)
for cluster in cluster_list:
clusters.append(cluster["name"])
@ -1201,7 +1209,9 @@ def list_datastore_clusters(kwargs=None, call=None):
datastore_clusters = []
datastore_cluster_properties = ["name"]
datastore_cluster_list = vmware.get_mors_with_properties(_get_si(), vim.StoragePod, datastore_cluster_properties)
datastore_cluster_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.StoragePod,
datastore_cluster_properties)
for datastore_cluster in datastore_cluster_list:
datastore_clusters.append(datastore_cluster["name"])
@ -1228,7 +1238,9 @@ def list_datastores(kwargs=None, call=None):
datastores = []
datastore_properties = ["name"]
datastore_list = vmware.get_mors_with_properties(_get_si(), vim.Datastore, datastore_properties)
datastore_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.Datastore,
datastore_properties)
for datastore in datastore_list:
datastores.append(datastore["name"])
@ -1255,7 +1267,9 @@ def list_hosts(kwargs=None, call=None):
hosts = []
host_properties = ["name"]
host_list = vmware.get_mors_with_properties(_get_si(), vim.HostSystem, host_properties)
host_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.HostSystem,
host_properties)
for host in host_list:
hosts.append(host["name"])
@ -1282,7 +1296,9 @@ def list_resourcepools(kwargs=None, call=None):
resource_pools = []
resource_pool_properties = ["name"]
resource_pool_list = vmware.get_mors_with_properties(_get_si(), vim.ResourcePool, resource_pool_properties)
resource_pool_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.ResourcePool,
resource_pool_properties)
for resource_pool in resource_pool_list:
resource_pools.append(resource_pool["name"])
@ -1309,7 +1325,7 @@ def list_networks(kwargs=None, call=None):
networks = []
network_properties = ["name"]
network_list = vmware.get_mors_with_properties(_get_si(), vim.Network, network_properties)
network_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Network, network_properties)
for network in network_list:
networks.append(network["name"])
@ -1336,7 +1352,7 @@ def list_nodes_min(kwargs=None, call=None):
ret = {}
vm_properties = ["name"]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
ret[vm["name"]] = True
@ -1379,7 +1395,7 @@ def list_nodes(kwargs=None, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
cpu = vm["config.hardware.numCPU"] if "config.hardware.numCPU" in vm else "N/A"
@ -1440,7 +1456,7 @@ def list_nodes_full(kwargs=None, call=None):
"guest.toolsStatus"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
ret[vm["name"]] = _format_instance_info(vm)
@ -1529,7 +1545,7 @@ def list_nodes_select(call=None):
elif 'name' not in vm_properties:
vm_properties.append("name")
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
ret[vm["name"]] = _format_instance_info_select(vm, selection)
@ -1569,7 +1585,7 @@ def show_instance(name, call=None):
"guest.toolsStatus"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm['name'] == name:
@ -1602,7 +1618,7 @@ def avail_images(call=None):
"config.hardware.memoryMB"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if "config.template" in vm and vm["config.template"]:
@ -1703,7 +1719,7 @@ def list_folders(kwargs=None, call=None):
folders = []
folder_properties = ["name"]
folder_list = vmware.get_mors_with_properties(_get_si(), vim.Folder, folder_properties)
folder_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Folder, folder_properties)
for folder in folder_list:
folders.append(folder["name"])
@ -1745,7 +1761,7 @@ def list_snapshots(kwargs=None, call=None):
"snapshot"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["rootSnapshot"]:
@ -1778,7 +1794,7 @@ def start(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
@ -1825,7 +1841,7 @@ def stop(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
@ -1872,7 +1888,7 @@ def suspend(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
@ -1923,7 +1939,7 @@ def reset(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
@ -1971,7 +1987,7 @@ def terminate(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
@ -2027,12 +2043,12 @@ def destroy(name, call=None):
"summary.runtime.powerState"
]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
if vm["name"] == name:
if vm["summary.runtime.powerState"] != "poweredOff":
#Power off the vm first
# Power off the vm first
try:
log.info('Powering Off VM {0}'.format(name))
task = vm["object"].PowerOff()
@ -2174,7 +2190,7 @@ def create(vm_):
if 'clonefrom' in vm_:
# Clone VM/template from specified VM/template
object_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_['clonefrom'])
object_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_['clonefrom'])
if object_ref:
clone_type = "template" if object_ref.config.template else "vm"
else:
@ -2187,13 +2203,13 @@ def create(vm_):
# Either a cluster, or a resource pool must be specified when cloning from template or creating.
if resourcepool:
resourcepool_ref = vmware.get_mor_by_property(_get_si(), vim.ResourcePool, resourcepool)
resourcepool_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ResourcePool, resourcepool)
if not resourcepool_ref:
log.error("Specified resource pool: '{0}' does not exist".format(resourcepool))
if not clone_type or clone_type == "template":
raise SaltCloudSystemExit('You must specify a resource pool that exists.')
elif cluster:
cluster_ref = vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster)
cluster_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster)
if not cluster_ref:
log.error("Specified cluster: '{0}' does not exist".format(cluster))
if not clone_type or clone_type == "template":
@ -2214,13 +2230,13 @@ def create(vm_):
# Either a datacenter or a folder can be optionally specified when cloning, required when creating.
# If not specified when cloning, the existing VM/template\'s parent folder is used.
if folder:
folder_ref = vmware.get_mor_by_property(_get_si(), vim.Folder, folder)
folder_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Folder, folder)
if not folder_ref:
log.error("Specified folder: '{0}' does not exist".format(folder))
log.debug("Using folder in which {0} {1} is present".format(clone_type, vm_['clonefrom']))
folder_ref = object_ref.parent
elif datacenter:
datacenter_ref = vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter)
datacenter_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter)
if not datacenter_ref:
log.error("Specified datacenter: '{0}' does not exist".format(datacenter))
log.debug("Using datacenter folder in which {0} {1} is present".format(clone_type, vm_['clonefrom']))
@ -2245,12 +2261,12 @@ def create(vm_):
# Either a datastore/datastore cluster can be optionally specified.
# If not specified, the current datastore is used.
if datastore:
datastore_ref = vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
datastore_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
if datastore_ref:
# specific datastore has been specified
reloc_spec.datastore = datastore_ref
else:
datastore_cluster_ref = vmware.get_mor_by_property(_get_si(), vim.StoragePod, datastore)
datastore_cluster_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.StoragePod, datastore)
if not datastore_cluster_ref:
log.error("Specified datastore/datastore cluster: '{0}' does not exist".format(datastore))
log.debug("Using datastore used by the {0} {1}".format(clone_type, vm_['clonefrom']))
@ -2259,7 +2275,7 @@ def create(vm_):
log.debug("Using datastore used by the {0} {1}".format(clone_type, vm_['clonefrom']))
if host:
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host)
if host_ref:
reloc_spec.host = host_ref
else:
@ -2270,7 +2286,7 @@ def create(vm_):
'You must specify a datastore when creating not cloning.'
)
else:
datastore_ref = vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
datastore_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datastore, datastore)
if not datastore_ref:
raise SaltCloudSystemExit("Specified datastore: '{0}' does not exist".format(datastore))
@ -2414,7 +2430,7 @@ def create(vm_):
)
return {'Error': err_msg}
new_vm_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_name)
new_vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, vm_name)
# Find how to power on in CreateVM_Task (if possible), for now this will do
if not clone_type and power:
@ -2478,7 +2494,7 @@ def create_datacenter(kwargs=None, call=None):
)
# Check if datacenter already exists
datacenter_ref = vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
datacenter_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
if datacenter_ref:
return {datacenter_name: 'datacenter already exists'}
@ -2538,14 +2554,14 @@ def create_cluster(kwargs=None, call=None):
)
if not isinstance(datacenter, vim.Datacenter):
datacenter = vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter)
datacenter = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter)
if not datacenter:
raise SaltCloudSystemExit(
'The specified datacenter does not exist.'
)
# Check if cluster already exists
cluster_ref = vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster_name)
cluster_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster_name)
if cluster_ref:
return {cluster_name: 'cluster already exists'}
@ -2598,7 +2614,7 @@ def rescan_hba(kwargs=None, call=None):
'You must specify name of the host system.'
)
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
try:
if hba:
@ -2649,7 +2665,7 @@ def upgrade_tools_all(call=None):
ret = {}
vm_properties = ["name"]
vm_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
vm_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualMachine, vm_properties)
for vm in vm_list:
ret[vm['name']] = _upg_tools_helper(vm['object'])
@ -2680,7 +2696,7 @@ def upgrade_tools(name, reboot=False, call=None):
'-a or --action.'
)
vm_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
return _upg_tools_helper(vm_ref, reboot)
@ -2716,7 +2732,9 @@ def list_hosts_by_cluster(kwargs=None, call=None):
cluster_name = kwargs.get('cluster') if kwargs and 'cluster' in kwargs else None
cluster_properties = ["name"]
cluster_list = vmware.get_mors_with_properties(_get_si(), vim.ClusterComputeResource, cluster_properties)
cluster_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.ClusterComputeResource,
cluster_properties)
for cluster in cluster_list:
ret[cluster['name']] = []
@ -2760,7 +2778,7 @@ def list_clusters_by_datacenter(kwargs=None, call=None):
datacenter_name = kwargs.get('datacenter') if kwargs and 'datacenter' in kwargs else None
datacenter_properties = ["name"]
datacenter_list = vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
datacenter_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
for datacenter in datacenter_list:
ret[datacenter['name']] = []
@ -2804,7 +2822,7 @@ def list_hosts_by_datacenter(kwargs=None, call=None):
datacenter_name = kwargs.get('datacenter') if kwargs and 'datacenter' in kwargs else None
datacenter_properties = ["name"]
datacenter_list = vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
datacenter_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
for datacenter in datacenter_list:
ret[datacenter['name']] = []
@ -2881,7 +2899,7 @@ def list_hbas(kwargs=None, call=None):
'Specified hba type {0} currently not supported.'.format(hba_type)
)
host_list = vmware.get_mors_with_properties(_get_si(), vim.HostSystem, host_properties)
host_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.HostSystem, host_properties)
for host in host_list:
ret[host['name']] = {}
@ -2927,7 +2945,7 @@ def list_dvs(kwargs=None, call=None):
distributed_vswitches = []
dvs_properties = ["name"]
dvs_list = vmware.get_mors_with_properties(_get_si(), vim.DistributedVirtualSwitch, dvs_properties)
dvs_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.DistributedVirtualSwitch, dvs_properties)
for dvs in dvs_list:
distributed_vswitches.append(dvs["name"])
@ -2954,7 +2972,7 @@ def list_vapps(kwargs=None, call=None):
vapps = []
vapp_properties = ["name"]
vapp_list = vmware.get_mors_with_properties(_get_si(), vim.VirtualApp, vapp_properties)
vapp_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualApp, vapp_properties)
for vapp in vapp_list:
vapps.append(vapp["name"])
@ -2980,7 +2998,7 @@ def enter_maintenance_mode(kwargs=None, call=None):
host_name = kwargs.get('host') if kwargs and 'host' in kwargs else None
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_name or not host_ref:
raise SaltCloudSystemExit(
@ -3025,7 +3043,7 @@ def exit_maintenance_mode(kwargs=None, call=None):
host_name = kwargs.get('host') if kwargs and 'host' in kwargs else None
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_name or not host_ref:
raise SaltCloudSystemExit(
@ -3174,7 +3192,7 @@ def create_snapshot(name, kwargs=None, call=None):
memdump = _str_to_bool(kwargs.get('memdump', True))
quiesce = _str_to_bool(kwargs.get('quiesce', False))
vm_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
if vm_ref.summary.runtime.powerState != "poweredOn":
log.debug('VM {0} is not powered on. Setting both memdump and quiesce to False'.format(name))
@ -3202,7 +3220,8 @@ def create_snapshot(name, kwargs=None, call=None):
)
return 'failed to create snapshot'
return {'Snapshot created successfully': _get_snapshots(vm_ref.snapshot.rootSnapshotList, vm_ref.snapshot.currentSnapshot)}
return {'Snapshot created successfully': _get_snapshots(vm_ref.snapshot.rootSnapshotList,
vm_ref.snapshot.currentSnapshot)}
def revert_to_snapshot(name, kwargs=None, call=None):
@ -3236,7 +3255,7 @@ def revert_to_snapshot(name, kwargs=None, call=None):
suppress_power_on = _str_to_bool(kwargs.get('power_off', False))
vm_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
if not vm_ref.rootSnapshot:
log.error('VM {0} does not contain any current snapshots'.format(name))
@ -3284,7 +3303,7 @@ def remove_all_snapshots(name, kwargs=None, call=None):
)
connection = _str_to_bool(kwargs.get('merge_snapshots')) if kwargs and 'merge_snapshots' in kwargs else True
vm_ref = vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
vm_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.VirtualMachine, name)
try:
task = vm_ref.RemoveAllSnapshots()
@ -3384,14 +3403,14 @@ def add_host(kwargs=None, call=None):
)
if cluster_name:
cluster_ref = vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster_name)
cluster_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.ClusterComputeResource, cluster_name)
if not cluster_ref:
raise SaltCloudSystemExit(
'Specified cluster does not exist.'
)
if datacenter_name:
datacenter_ref = vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
datacenter_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
if not datacenter_ref:
raise SaltCloudSystemExit(
'Specified datacenter does not exist.'
@ -3475,7 +3494,7 @@ def remove_host(kwargs=None, call=None):
'You must specify name of the host system.'
)
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_ref:
raise SaltCloudSystemExit(
'Specified host system does not exist.'
@ -3526,7 +3545,7 @@ def connect_host(kwargs=None, call=None):
'You must specify name of the host system.'
)
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_ref:
raise SaltCloudSystemExit(
'Specified host system does not exist.'
@ -3575,7 +3594,7 @@ def disconnect_host(kwargs=None, call=None):
'You must specify name of the host system.'
)
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_ref:
raise SaltCloudSystemExit(
'Specified host system does not exist.'
@ -3631,7 +3650,7 @@ def reboot_host(kwargs=None, call=None):
'You must specify name of the host system.'
)
host_ref = vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
host_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.HostSystem, host_name)
if not host_ref:
raise SaltCloudSystemExit(
'Specified host system does not exist.'
@ -3706,11 +3725,11 @@ def create_datastore_cluster(kwargs=None, call=None):
)
# Check if datastore cluster already exists
datastore_cluster_ref = vmware.get_mor_by_property(_get_si(), vim.StoragePod, datastore_cluster_name)
datastore_cluster_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.StoragePod, datastore_cluster_name)
if datastore_cluster_ref:
return {datastore_cluster_name: 'datastore cluster already exists'}
datacenter_ref = vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
datacenter_ref = salt.utils.vmware.get_mor_by_property(_get_si(), vim.Datacenter, datacenter_name)
if not datacenter_ref:
raise SaltCloudSystemExit(
'The specified datacenter does not exist.'