Merge pull request #28755 from rallytime/vmware-utils

Move most vmware driver list_* functions to use salt.utils.vmware functions
This commit is contained in:
Mike Place 2015-11-11 10:49:15 -07:00
commit f273c46f07
2 changed files with 144 additions and 96 deletions

View file

@ -1099,15 +1099,7 @@ def list_datacenters(kwargs=None, call=None):
'-f or --function.'
)
datacenters = []
datacenter_properties = ["name"]
datacenter_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Datacenter, datacenter_properties)
for datacenter in datacenter_list:
datacenters.append(datacenter["name"])
return {'Datacenters': datacenters}
return {'Datacenters': salt.utils.vmware.list_datacenters(_get_si())}
def list_clusters(kwargs=None, call=None):
@ -1126,17 +1118,7 @@ def list_clusters(kwargs=None, call=None):
'-f or --function.'
)
clusters = []
cluster_properties = ["name"]
cluster_list = salt.utils.vmware.get_mors_with_properties(_get_si(),
vim.ClusterComputeResource,
cluster_properties)
for cluster in cluster_list:
clusters.append(cluster["name"])
return {'Clusters': clusters}
return {'Clusters': salt.utils.vmware.list_clusters(_get_si())}
def list_datastore_clusters(kwargs=None, call=None):
@ -1155,17 +1137,7 @@ def list_datastore_clusters(kwargs=None, call=None):
'-f or --function.'
)
datastore_clusters = []
datastore_cluster_properties = ["name"]
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"])
return {'Datastore Clusters': datastore_clusters}
return {'Datastore Clusters': salt.utils.vmware.list_datastore_clusters(_get_si())}
def list_datastores(kwargs=None, call=None):
@ -1184,15 +1156,7 @@ def list_datastores(kwargs=None, call=None):
'-f or --function.'
)
datastores = []
datastore_properties = ["name"]
datastore_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Datastore, datastore_properties)
for datastore in datastore_list:
datastores.append(datastore["name"])
return {'Datastores': datastores}
return {'Datastores': salt.utils.vmware.list_datastores(_get_si())}
def list_hosts(kwargs=None, call=None):
@ -1211,15 +1175,7 @@ def list_hosts(kwargs=None, call=None):
'-f or --function.'
)
hosts = []
host_properties = ["name"]
host_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.HostSystem, host_properties)
for host in host_list:
hosts.append(host["name"])
return {'Hosts': hosts}
return {'Hosts': salt.utils.vmware.list_hosts(_get_si())}
def list_resourcepools(kwargs=None, call=None):
@ -1238,17 +1194,7 @@ def list_resourcepools(kwargs=None, call=None):
'-f or --function.'
)
resource_pools = []
resource_pool_properties = ["name"]
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"])
return {'Resource Pools': resource_pools}
return {'Resource Pools': salt.utils.vmware.list_resourcepools(_get_si())}
def list_networks(kwargs=None, call=None):
@ -1267,15 +1213,7 @@ def list_networks(kwargs=None, call=None):
'-f or --function.'
)
networks = []
network_properties = ["name"]
network_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Network, network_properties)
for network in network_list:
networks.append(network["name"])
return {'Networks': networks}
return {'Networks': salt.utils.vmware.list_networks(_get_si())}
def list_nodes_min(kwargs=None, call=None):
@ -1661,15 +1599,7 @@ def list_folders(kwargs=None, call=None):
'-f or --function.'
)
folders = []
folder_properties = ["name"]
folder_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.Folder, folder_properties)
for folder in folder_list:
folders.append(folder["name"])
return {'Folders': folders}
return {'Folders': salt.utils.vmware.list_folders(_get_si())}
def list_snapshots(kwargs=None, call=None):
@ -2846,15 +2776,7 @@ def list_dvs(kwargs=None, call=None):
'-f or --function.'
)
distributed_vswitches = []
dvs_properties = ["name"]
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"])
return {'Distributed Virtual Switches': distributed_vswitches}
return {'Distributed Virtual Switches': salt.utils.vmware.list_dvs(_get_si())}
def list_vapps(kwargs=None, call=None):
@ -2873,15 +2795,7 @@ def list_vapps(kwargs=None, call=None):
'-f or --function.'
)
vapps = []
vapp_properties = ["name"]
vapp_list = salt.utils.vmware.get_mors_with_properties(_get_si(), vim.VirtualApp, vapp_properties)
for vapp in vapp_list:
vapps.append(vapp["name"])
return {'vApps': vapps}
return {'vApps': salt.utils.vmware.list_vapps(_get_si())}
def enter_maintenance_mode(kwargs=None, call=None):

View file

@ -243,3 +243,137 @@ def get_network_adapter_type(adapter_type):
return vim.vm.device.VirtualE1000()
elif adapter_type == "e1000e":
return vim.vm.device.VirtualE1000e()
def list_objects(service_instance, vim_object, properties=None):
'''
Returns a simple list of objects from a given service instance.
service_instance
The Service Instance for which to obtain a list of objects.
object_type
The type of content for which to obtain information.
property_list
An optional list of object properties used to return reference results.
If not provided, defaults to ``name``.
'''
if properties is None:
properties = ['name']
items = []
item_list = get_mors_with_properties(service_instance, vim_object, properties)
for item in item_list:
items.append(item['name'])
return items
def list_datacenters(service_instance):
'''
Returns a list of datacenters associated with a given service instance.
service_instance
The Service Instance Object from which to obtain datacenters.
'''
return list_objects(service_instance, vim.Datacenter)
def list_clusters(service_instance):
'''
Returns a list of clusters associated with a given service instance.
service_instance
The Service Instance Object from which to obtain clusters.
'''
return list_objects(service_instance, vim.ClusterComputeResource)
def list_datastore_clusters(service_instance):
'''
Returns a list of datastore clusters associated with a given service instance.
service_instance
The Service Instance Object from which to obtain datastore clusters.
'''
return list_objects(service_instance, vim.StoragePod)
def list_datastores(service_instance):
'''
Returns a list of datastores associated with a given service instance.
service_instance
The Service Instance Object from which to obtain datastores.
'''
return list_objects(service_instance, vim.Datastore)
def list_hosts(service_instance):
'''
Returns a list of hosts associated with a given service instance.
service_instance
The Service Instance Object from which to obtain hosts.
'''
return list_objects(service_instance, vim.HostSystem)
def list_resourcepools(service_instance):
'''
Returns a list of resource pools associated with a given service instance.
service_instance
The Service Instance Object from which to obtain resource pools.
'''
return list_objects(service_instance, vim.ResourcePool)
def list_networks(service_instance):
'''
Returns a list of networks associated with a given service instance.
service_instance
The Service Instance Object from which to obtain networks.
'''
return list_objects(service_instance, vim.Network)
def list_vms(service_instance):
'''
Returns a list of VMs associated with a given service instance.
service_instance
The Service Instance Object from which to obtain VMs.
'''
return list_objects(service_instance, vim.VirtualMachine)
def list_folders(service_instance):
'''
Returns a list of folders associated with a given service instance.
service_instance
The Service Instance Object from which to obtain folders.
'''
return list_objects(service_instance, vim.Folder)
def list_dvs(service_instance):
'''
Returns a list of distributed virtual switches associated with a given service instance.
service_instance
The Service Instance Object from which to obtain distributed virtual switches.
'''
return list_objects(service_instance, vim.DistributedVirtualSwitch)
def list_vapps(service_instance):
'''
Returns a list of vApps associated with a given service instance.
service_instance
The Service Instance Object from which to obtain vApps.
'''
return list_objects(service_instance, vim.VirtualApp)