def __init__(self, fake_resource_pools=None, fake_host_system=None, fake_datastore=None, fake_virtual_machines=None, fake_network=None, fake_datacenter=None, fake_cluster=None, fake_vm_folder=None, ret=None): self.resource_pools = fake_resource_pools self.host_system = fake_host_system self.datastore = fake_datastore self.virtual_machines = fake_virtual_machines self.network = fake_network self.datacenter = fake_datacenter self.cluster = fake_cluster self.vm_folder = fake_vm_folder self.ret = ret self.vim = fake.FakeVim()
def fake_get_vim_object(arg): """Stubs out the VMwareAPISession's get_vim_object method.""" return fake.FakeVim()
def setUp(self): super(VMwareVIMUtilTestCase, self).setUp() fake.reset() self.vim = fake.FakeVim() self.vim._login()
def _call_method(self, *args, **kwargs): if args[1] == "get_dynamic_property": fake_objects = self.return_objects_of_type(args[3]) objectRef = args[2] objectProperty = args[4] for object in fake_objects.objects: if object.obj == objectRef: for p in object.propSet: if p.name == objectProperty: return p.val elif args[1] == 'get_dynamic_properties': return_dict = dict() fake_objects = self.return_objects_of_type(args[3]) objectRef = args[2] objectProperties = args[4] for object in fake_objects.objects: if object.obj == objectRef: for p in object.propSet: if p.name in objectProperties: return_dict[p.name] = p.val return return_dict elif args[1] == "get_vc_properties_pf9": fake_vim = fake.FakeVim() fake_vim._login() return vim_util.get_vc_properties_pf9(fake_vim, args[2], args[3], args[4], args[5], None) elif args[1] == "get_object_properties": obj_ref = args[3] obj_type = args[4] prop_list = args[5] lst_return_objects = fake.FakeRetrieveResult() prop_vals = fake.ManagedObject() for prop in prop_list: prop_val = self._call_method(None, "get_dynamic_property", obj_ref, obj_type, prop) elem = fake.Prop() elem.name = prop elem.val = prop_val prop_vals.propSet.append(elem) lst_return_objects.add_object(prop_vals) return lst_return_objects elif args[1] == "get_object_properties_dict": obj_ref = args[2] obj_type = args[2].type prop_list = args[3] prop_dict = {} for prop in prop_list: prop_val = self._call_method(None, "get_dynamic_property", obj_ref, obj_type, prop) prop_dict[prop] = prop_val return prop_dict elif args[1] == "get_object_property": obj_ref = args[2] obj_type = args[2].type property = args[3] return_object = fake.FakeRetrieveResult() prop_val = self._call_method(None, "get_dynamic_property", obj_ref, obj_type, property) return prop_val elif args[1] == "get_properties_for_objects_pf9": obj_refs = args[3] obj_type = args[4] prop_list = args[5] lst_return_objects = fake.FakeRetrieveResult() for obj_ref in obj_refs: prop_vals = fake.ManagedObject() for prop in prop_list: prop_val = self._call_method(None, "get_dynamic_property", obj_ref, obj_type, prop) elem = fake.Prop() elem.name = prop elem.val = prop_val prop_vals.propSet.append(elem) lst_return_objects.add_object(prop_vals) return lst_return_objects elif args[1] == "FindAllByUuid": return self._get_vim()._find_all_by_uuid(self, args, kwargs) else: return self.return_objects_of_type(args[2])