diff --git a/qubesadmin/app.py b/qubesadmin/app.py index 7316a85..fbe16b4 100644 --- a/qubesadmin/app.py +++ b/qubesadmin/app.py @@ -109,6 +109,11 @@ class VMCollection(object): self.refresh_cache() return self._vm_list.keys() + def values(self): + '''Get list of VM objects.''' + self.refresh_cache() + return [self[name] for name in self._vm_list] + class QubesBase(qubesadmin.base.PropertyHolder): '''Main Qubes application''' diff --git a/qubesadmin/tests/app.py b/qubesadmin/tests/app.py index 21c5bd7..2d5384a 100644 --- a/qubesadmin/tests/app.py +++ b/qubesadmin/tests/app.py @@ -80,6 +80,26 @@ class TC_00_VMCollection(qubesadmin.tests.QubesTestCase): del self.app.domains['test-vm'] self.assertAllCalled() + def test_005_keys(self): + self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00test-vm class=AppVM state=Running\n' \ + b'test-vm2 class=AppVM state=Running\n' + self.assertEqual(set(self.app.domains.keys()), + set(['test-vm', 'test-vm2'])) + self.assertAllCalled() + + def test_006_values(self): + self.app.expected_calls[('dom0', 'admin.vm.List', None, None)] = \ + b'0\x00test-vm class=AppVM state=Running\n' \ + b'test-vm2 class=AppVM state=Running\n' + values = self.app.domains.values() + for obj in values: + self.assertIsInstance(obj, qubesadmin.vm.AppVM) + self.assertEqual(set([vm.name for vm in values]), + set(['test-vm', 'test-vm2'])) + self.assertAllCalled() + + class TC_10_QubesBase(qubesadmin.tests.QubesTestCase): def test_010_new_simple(self):