Skip to content

Commit

Permalink
Fixes for vcenter proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
cro committed Jun 14, 2019
1 parent eb3d8b8 commit c9da89e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 77 deletions.
171 changes: 98 additions & 73 deletions salt/modules/vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,7 +2011,8 @@ def system_info(host, username, password, protocol=None, port=None):

@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_datacenters(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_datacenters(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of datacenters for the the specified host.
Expand Down Expand Up @@ -2039,17 +2040,19 @@ def list_datacenters(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_datacenters 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_datacenters(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_clusters(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_clusters(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of clusters for the the specified host.
Expand Down Expand Up @@ -2077,17 +2080,19 @@ def list_clusters(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_clusters 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_clusters(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_datastore_clusters(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_datastore_clusters(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of datastore clusters for the the specified host.
Expand All @@ -2114,17 +2119,19 @@ def list_datastore_clusters(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_datastore_clusters 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_datastore_clusters(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_datastores(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_datastores(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of datastores for the the specified host.
Expand All @@ -2151,17 +2158,19 @@ def list_datastores(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_datastores 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_datastores(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_hosts(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_hosts(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of hosts for the the specified VMware environment.
Expand All @@ -2188,17 +2197,19 @@ def list_hosts(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_hosts 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_hosts(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_resourcepools(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_resourcepools(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of resource pools for the the specified host.
Expand All @@ -2225,17 +2236,19 @@ def list_resourcepools(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_resourcepools 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_resourcepools(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_networks(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_networks(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of networks for the the specified host.
Expand All @@ -2262,17 +2275,19 @@ def list_networks(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_networks 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_networks(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_vms(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_vms(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of VMs for the the specified host.
Expand All @@ -2299,17 +2314,19 @@ def list_vms(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_vms 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_vms(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_folders(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_folders(host, username, password, protocol=None, port=None, service_instance=None):
'''
Returns a list of folders for the the specified host.
Expand All @@ -2336,17 +2353,19 @@ def list_folders(host, username, password, protocol=None, port=None):
salt '*' vsphere.list_folders 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_folders(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_dvs(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_dvs(host, username, password, protocol=None, port=None, service_instance=None):
'''
Returns a list of distributed virtual switches for the the specified host.
Expand Down Expand Up @@ -2383,7 +2402,8 @@ def list_dvs(host, username, password, protocol=None, port=None):

@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_vapps(host, username, password, protocol=None, port=None):
@gets_service_instance_via_proxy
def list_vapps(host=None, username=None, password=None, protocol=None, port=None, service_instance=None):
'''
Returns a list of vApps for the the specified host.
Expand Down Expand Up @@ -2411,17 +2431,19 @@ def list_vapps(host, username, password, protocol=None, port=None):
# List vapps from all minions
salt '*' vsphere.list_vapps 1.2.3.4 root bad-password
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([host, username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
return salt.utils.vmware.list_vapps(service_instance)


@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_ssds(host, username, password, protocol=None, port=None, host_names=None):
@gets_service_instance_via_proxy
def list_ssds(host, username=None, password=None, protocol=None, port=None, host_names=None, service_instance=None):
'''
Returns a list of SSDs for the given host or list of host_names.
Expand Down Expand Up @@ -2462,11 +2484,12 @@ def list_ssds(host, username, password, protocol=None, port=None, host_names=Non
salt '*' vsphere.list_ssds my.vcenter.location root bad-password \
host_names='[esxi-1.host.com, esxi-2.host.com]'
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
host_names = _check_hosts(service_instance, host, host_names)
ret = {}
names = []
Expand All @@ -2482,7 +2505,8 @@ def list_ssds(host, username, password, protocol=None, port=None, host_names=Non

@depends(HAS_PYVMOMI)
@ignores_kwargs('credstore')
def list_non_ssds(host, username, password, protocol=None, port=None, host_names=None):
@gets_service_instance_via_proxy
def list_non_ssds(host, username=None, password=None, protocol=None, port=None, host_names=None, service_instance=None):
'''
Returns a list of Non-SSD disks for the given host or list of host_names.
Expand Down Expand Up @@ -2530,11 +2554,12 @@ def list_non_ssds(host, username, password, protocol=None, port=None, host_names
salt '*' vsphere.list_non_ssds my.vcenter.location root bad-password \
host_names='[esxi-1.host.com, esxi-2.host.com]'
'''
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
if any([username, password, protocol, port]):
service_instance = salt.utils.vmware.get_service_instance(host=host,
username=username,
password=password,
protocol=protocol,
port=port)
host_names = _check_hosts(service_instance, host, host_names)
ret = {}
names = []
Expand Down
6 changes: 3 additions & 3 deletions salt/proxy/vcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def init(opts):
log.info('Retrieving credentials and testing vCenter connection for '
'mehchanism \'userpass\'')
try:
username, password = find_credentials()
username, password = find_credentials(proxy_conf)
DETAILS['password'] = password
except salt.exceptions.SaltSystemExit as err:
log.critical('Error: %s', err)
Expand Down Expand Up @@ -306,7 +306,7 @@ def shutdown():
log.debug('VCenter proxy shutdown() called...')


def find_credentials():
def find_credentials(proxy_conf):
'''
Cycle through all the possible credentials and return the first one that
works.
Expand All @@ -317,7 +317,7 @@ def find_credentials():
if 'username' in DETAILS and 'password' in DETAILS:
return DETAILS['username'], DETAILS['password']

passwords = __pillar__['proxy']['passwords']
passwords = proxy_conf['passwords']
for password in passwords:
DETAILS['password'] = password
if not __salt__['vsphere.test_vcenter_connection']():
Expand Down
Loading

0 comments on commit c9da89e

Please sign in to comment.