vm: add actual VM classes

QubesOS/qubes-issues#853
This commit is contained in:
Marek Marczykowski-Górecki 2017-02-28 01:34:09 +01:00
parent 0abff5b57a
commit 2b1ebba547
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
3 changed files with 55 additions and 4 deletions

View File

@ -29,6 +29,7 @@ import subprocess
import qubesmgmt.base import qubesmgmt.base
import qubesmgmt.vm import qubesmgmt.vm
import qubesmgmt.exc import qubesmgmt.exc
import qubesmgmt.utils
QUBESD_SOCK = '/var/run/qubesd.sock' QUBESD_SOCK = '/var/run/qubesd.sock'
BUF_SIZE = 4096 BUF_SIZE = 4096
@ -39,6 +40,7 @@ class VMCollection(object):
def __init__(self, app): def __init__(self, app):
self.app = app self.app = app
self._vm_list = None self._vm_list = None
self._vm_objects = {}
def clear_cache(self): def clear_cache(self):
'''Clear cached list of VMs''' '''Clear cached list of VMs'''
@ -61,12 +63,27 @@ class VMCollection(object):
[vm_prop.split('=', 1) for vm_prop in props]) [vm_prop.split('=', 1) for vm_prop in props])
self._vm_list = new_vm_list self._vm_list = new_vm_list
for name, vm in self._vm_objects.items():
if vm.name not in self._vm_list:
# VM no longer exists
del self._vm_objects[name]
elif vm.__class__.__name__ != self._vm_list[vm.name]['class']:
# VM class have changed
del self._vm_objects[name]
# TODO: some generation ID, to detect VM re-creation
elif name != vm.name:
# renamed
self._vm_objects[vm.name] = vm
del self._vm_objects[name]
def __getitem__(self, item): def __getitem__(self, item):
if item not in self: if item not in self:
raise KeyError(item) raise KeyError(item)
return qubesmgmt.vm.QubesVM( if item not in self._vm_objects:
self.app, item, self._vm_list[item]['class']) cls = qubesmgmt.utils.get_entry_point_one('qubesmgmt.vm',
self._vm_list[item]['class'])
self._vm_objects[item] = cls(self.app, item)
return self._vm_objects[item]
def __contains__(self, item): def __contains__(self, item):
self.refresh_cache() self.refresh_cache()

View File

@ -25,8 +25,7 @@ import qubesmgmt.base
class QubesVM(qubesmgmt.base.PropertyHolder): class QubesVM(qubesmgmt.base.PropertyHolder):
'''Qubes domain.''' '''Qubes domain.'''
def __init__(self, app, name, vm_class): def __init__(self, app, name):
self._class = vm_class
super(QubesVM, self).__init__(app, 'mgmt.vm.property.', name) super(QubesVM, self).__init__(app, 'mgmt.vm.property.', name)
@property @property
@ -112,3 +111,28 @@ class QubesVM(qubesmgmt.base.PropertyHolder):
''' '''
raise NotImplementedError raise NotImplementedError
#self.qubesd_call(self._method_dest, 'mgmt.vm.Resume') #self.qubesd_call(self._method_dest, 'mgmt.vm.Resume')
class AdminVM(QubesVM):
'''Dom0'''
pass
class AppVM(QubesVM):
'''Application VM'''
pass
class StandaloneVM(QubesVM):
'''Standalone Application VM'''
pass
class TemplateVM(QubesVM):
'''Template for AppVM'''
pass
class DispVM(QubesVM):
'''Disposable VM'''
pass

View File

@ -12,4 +12,14 @@ if __name__ == '__main__':
license='LGPL2.1+', license='LGPL2.1+',
url='https://www.qubes-os.org/', url='https://www.qubes-os.org/',
packages=setuptools.find_packages(), packages=setuptools.find_packages(),
entry_points={
'qubesmgmt.vm': [
'AppVM = qubesmgmt.vm:AppVM',
'TemplateVM = qubesmgmt.vm:TemplateVM',
'StandaloneVM = qubesmgmt.vm:StandaloneVM',
'AdminVM = qubesmgmt.vm:AdminVM',
'DispVM = qubesmgmt.vm:DispVM',
],
},
) )