def get_default_storage_policy_of_datastore(profile_manager, datastore): ''' Returns the default storage policy reference assigned to a datastore. profile_manager Reference to the profile manager. datastore Reference to the datastore. ''' # Retrieve all datastores visible hub = pbm.placement.PlacementHub(hubId=datastore._moId, hubType='Datastore') log.trace('placement_hub = {0}'.format(hub)) try: policy_id = profile_manager.QueryDefaultRequirementProfile(hub) 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) policy_refs = get_policies_by_id(profile_manager, [policy_id]) if not policy_refs: raise VMwareObjectRetrievalError('Storage policy with id \'{0}\' was ' 'not found'.format(policy_id)) return policy_refs[0]
def get_host_vsan_system(service_instance, host_ref, hostname=None): """ Returns a host's vsan system service_instance Service instance to the host or vCenter host_ref Refernce to ESXi host hostname Name of ESXi host. Default value is None. """ if not hostname: hostname = salt.utils.vmware.get_managed_object_name(host_ref) traversal_spec = vmodl.query.PropertyCollector.TraversalSpec( path="configManager.vsanSystem", type=vim.HostSystem, skip=False) objs = salt.utils.vmware.get_mors_with_properties( service_instance, vim.HostVsanSystem, property_list=["config.enabled"], container_ref=host_ref, traversal_spec=traversal_spec, ) if not objs: raise VMwareObjectRetrievalError("Host's '{0}' VSAN system was " "not retrieved".format(hostname)) log.trace("[%s] Retrieved VSAN system", hostname) return objs[0]["object"]