From c790107d17ba097dcdc71cfc21b6d6cf126665bd Mon Sep 17 00:00:00 2001 From: Alexandru Bleotu Date: Tue, 19 Sep 2017 13:42:21 -0400 Subject: [PATCH] Added salt.utils.pbm.get_placement_solver --- salt/utils/pbm.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/salt/utils/pbm.py b/salt/utils/pbm.py index aec5341112..eb2cf26887 100644 --- a/salt/utils/pbm.py +++ b/salt/utils/pbm.py @@ -93,3 +93,28 @@ def get_profile_manager(service_instance): log.exception(exc) raise VMwareRuntimeError(exc.msg) return profile_manager + + +def get_placement_solver(service_instance): + ''' + Returns a placement solver + + service_instance + Service instance to the host or vCenter + ''' + stub = salt.utils.vmware.get_new_service_instance_stub( + service_instance, ns='pbm/2.0', path='/pbm/sdk') + pbm_si = pbm.ServiceInstance('ServiceInstance', stub) + try: + profile_manager = pbm_si.RetrieveContent().placementSolver + except vim.fault.NoPermission as exc: + log.exception(exc) + raise VMwareApiError('Not enough permissions. Required privilege: ' + '{0}'.format(exc.privilegeId)) + except vim.fault.VimFault as exc: + log.exception(exc) + raise VMwareApiError(exc.msg) + except vmodl.RuntimeFault as exc: + log.exception(exc) + raise VMwareRuntimeError(exc.msg) + return profile_manager