def test_continue_retrieval(self, get_token): token = mock.Mock() get_token.return_value = token vim = mock.Mock() retrieve_result = mock.Mock() vim_util.continue_retrieval(vim, retrieve_result) get_token.assert_called_once_with(retrieve_result) vim.ContinueRetrievePropertiesEx.assert_called_once_with( vim.service_content.propertyCollector, token=token)
def get_mob_by_mobid(self, vim_type, mob_id): results = self.get_all_objects_of_type(vim_type) while results: for _mob in results.objects: if _mob.obj.value == mob_id: vim_util.cancel_retrieval(self.session.vim, results) return _mob results = vim_util.continue_retrieval(self.session.vim, results)
def get_mob_by_name(self, vim_type, obj_name): results = self.get_all_objects_of_type(vim_type) while results: for _mob in results.objects: for prop in _mob.propSet: if prop.name == 'name' and obj_name == prop.val: vim_util.cancel_retrieval(self.session.vim, results) return _mob results = vim_util.continue_retrieval(self.session.vim, results)
def _get_dvs_moref_by_name(self, session, dvs_name): """Get the moref of the configured DVS.""" results = session.invoke_api(vim_util, 'get_objects', session.vim, 'DistributedVirtualSwitch', 100) while results: for dvs in results.objects: for prop in dvs.propSet: if dvs_name == prop.val: vim_util.cancel_retrieval(session.vim, results) return dvs.obj results = vim_util.continue_retrieval(session.vim, results) raise nsx_exc.DvsNotFound(dvs=dvs_name)
def _get_dvs_moref(self, session, dvs_name): """Get the moref of the configured DVS.""" results = session.invoke_api(vim_util, 'get_objects', session.vim, 'DistributedVirtualSwitch', 100) while results: for dvs in results.objects: for prop in dvs.propSet: if dvs_name == prop.val: vim_util.cancel_retrieval(session.vim, results) return dvs.obj results = vim_util.continue_retrieval(session.vim, results) raise nsx_exc.DvsNotFound(dvs=dvs_name)
def _get_portgroup(self, net_id): """Get the port group moref of the net_id.""" results = self._session.invoke_api(vim_util, 'get_objects', self._session.vim, 'DistributedVirtualPortgroup', 100) while results: for pg in results.objects: for prop in pg.propSet: if net_id == prop.val: vim_util.cancel_retrieval(self._session.vim, results) return pg.obj results = vim_util.continue_retrieval(self._session.vim, results) raise exceptions.NetworkNotFound(net_id=net_id)
def get_dvs_moref_by_name(self, dvs_name, session=None): """Get the moref of DVS.""" if not session: session = self.get_vc_session() results = session.invoke_api(vim_util, 'get_objects', session.vim, 'DistributedVirtualSwitch', 100) while results: for dvs in results.objects: for prop in dvs.propSet: if dvs_name == prop.val: vim_util.cancel_retrieval(session.vim, results) return dvs.obj results = vim_util.continue_retrieval(session.vim, results) raise nsx_exc.DvsNotFound(dvs=dvs_name)