PBM utility method to retrieve profiles of a VM
Add method 'get_profiles' in pbm module to retrieve SPBM storage profiles associated with a VM. Change-Id: I1c96fc87ae5a24c470a67786bac5197f23c0f288
This commit is contained in:
parent
cfc7e2f95c
commit
81ae4431cd
@ -198,3 +198,21 @@ def get_pbm_wsdl_location(vc_version):
|
||||
pbm_wsdl = urlparse.urljoin('file:', urllib.pathname2url(pbm_service_wsdl))
|
||||
LOG.debug("Using PBM WSDL location: %s.", pbm_wsdl)
|
||||
return pbm_wsdl
|
||||
|
||||
|
||||
def get_profiles(session, vm):
|
||||
"""Query storage profiles associated with the given vm.
|
||||
|
||||
:param session: VMwareAPISession instance
|
||||
:param vm: vm reference
|
||||
:return: profile IDs
|
||||
"""
|
||||
pbm = session.pbm
|
||||
profile_manager = pbm.service_content.profileManager
|
||||
|
||||
object_ref = pbm.client.factory.create('ns0:PbmServerObjectRef')
|
||||
object_ref.key = vm.value
|
||||
object_ref.objectType = 'virtualMachine'
|
||||
|
||||
return session.invoke_api(pbm, 'PbmQueryAssociatedProfile',
|
||||
profile_manager, entity=object_ref)
|
||||
|
@ -171,3 +171,26 @@ class PBMUtilityTest(base.TestCase):
|
||||
path_exists.return_value = False
|
||||
wsdl = pbm.get_pbm_wsdl_location('5.5')
|
||||
self.assertIsNone(wsdl)
|
||||
|
||||
def test_get_profiles(self):
|
||||
pbm_service = mock.Mock()
|
||||
session = mock.Mock(pbm=pbm_service)
|
||||
|
||||
object_ref = mock.Mock()
|
||||
pbm_service.client.factory.create.return_value = object_ref
|
||||
|
||||
profile_id = mock.sentinel.profile_id
|
||||
session.invoke_api.return_value = profile_id
|
||||
|
||||
value = 'vm-1'
|
||||
vm = mock.Mock(value=value)
|
||||
ret = pbm.get_profiles(session, vm)
|
||||
|
||||
self.assertEqual(profile_id, ret)
|
||||
session.invoke_api.assert_called_once_with(
|
||||
pbm_service,
|
||||
'PbmQueryAssociatedProfile',
|
||||
pbm_service.service_content.profileManager,
|
||||
entity=object_ref)
|
||||
self.assertEqual(value, object_ref.key)
|
||||
self.assertEqual('virtualMachine', object_ref.objectType)
|
||||
|
Loading…
x
Reference in New Issue
Block a user