2014-11-13 14:38:41 +01:00
|
|
|
#!/usr/bin/python2 -O
|
2015-01-19 18:03:23 +01:00
|
|
|
# vim: fileencoding=utf-8
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2013-2015 Marek Marczykowski-Górecki
|
|
|
|
# <marmarek@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2014-11-13 14:38:41 +01:00
|
|
|
|
2016-06-16 14:00:53 +02:00
|
|
|
''' This module contains the AdminVM implementation '''
|
|
|
|
|
2015-01-15 16:05:42 +01:00
|
|
|
import qubes
|
2015-10-14 22:02:11 +02:00
|
|
|
import qubes.exc
|
2015-01-15 16:05:42 +01:00
|
|
|
import qubes.vm.qubesvm
|
2014-11-13 14:38:41 +01:00
|
|
|
|
2015-01-15 16:05:42 +01:00
|
|
|
class AdminVM(qubes.vm.qubesvm.QubesVM):
|
2014-11-13 18:10:27 +01:00
|
|
|
'''Dom0'''
|
2015-01-15 16:05:42 +01:00
|
|
|
|
2015-09-25 16:50:09 +02:00
|
|
|
dir_path = None
|
|
|
|
|
2015-01-15 16:05:42 +01:00
|
|
|
netvm = qubes.property('netvm', setter=qubes.property.forbidden,
|
|
|
|
default=None,
|
|
|
|
doc='Dom0 cannot have netvm')
|
|
|
|
|
2015-01-20 16:16:58 +01:00
|
|
|
kernel = qubes.property('netvm', setter=qubes.property.forbidden,
|
|
|
|
default=None,
|
|
|
|
doc='There are other ways to set kernel for Dom0.')
|
|
|
|
|
2015-01-15 16:05:42 +01:00
|
|
|
@property
|
|
|
|
def xid(self):
|
|
|
|
'''Always ``0``.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:attr:`qubes.vm.qubesvm.QubesVM.xid`
|
|
|
|
'''
|
|
|
|
return 0
|
|
|
|
|
|
|
|
@property
|
|
|
|
def libvirt_domain(self):
|
|
|
|
'''Always :py:obj:`None`.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:attr:`qubes.vm.qubesvm.QubesVM.libvirt_domain`
|
|
|
|
'''
|
|
|
|
return None
|
|
|
|
|
|
|
|
def is_running(self):
|
|
|
|
'''Always :py:obj:`True`.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.is_running`
|
|
|
|
'''
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_power_state(self):
|
|
|
|
'''Always ``'Running'``.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.get_power_state`
|
|
|
|
'''
|
|
|
|
return 'Running'
|
|
|
|
|
|
|
|
def get_mem(self):
|
|
|
|
'''Get current memory usage of Dom0.
|
|
|
|
|
|
|
|
Unit is KiB.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.get_mem`
|
|
|
|
'''
|
|
|
|
|
2016-06-16 11:15:38 +02:00
|
|
|
# return psutil.virtual_memory().total/1024
|
2015-01-15 16:05:42 +01:00
|
|
|
for line in open('/proc/meminfo'):
|
|
|
|
if line.startswith('MemTotal:'):
|
|
|
|
return int(line.split(':')[1].strip().split()[0])
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
def get_mem_static_max(self):
|
|
|
|
'''Get maximum memory available to Dom0.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.get_mem_static_max`
|
|
|
|
'''
|
|
|
|
return self.app.vmm.libvirt_conn.getInfo()[1]
|
|
|
|
|
|
|
|
def verify_files(self):
|
|
|
|
'''Always :py:obj:`True`
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.verify_files`
|
|
|
|
'''
|
|
|
|
return True
|
|
|
|
|
|
|
|
def start(self, **kwargs):
|
|
|
|
'''Always raises an exception.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.start`
|
2016-06-16 11:15:38 +02:00
|
|
|
''' # pylint: disable=unused-argument
|
2015-10-14 22:27:36 +02:00
|
|
|
raise qubes.exc.QubesVMError(self, 'Cannot start Dom0 fake domain!')
|
2015-01-15 16:05:42 +01:00
|
|
|
|
|
|
|
def suspend(self):
|
|
|
|
'''Does nothing.
|
|
|
|
|
|
|
|
.. seealso:
|
|
|
|
:py:meth:`qubes.vm.qubesvm.QubesVM.suspend`
|
|
|
|
'''
|
2016-06-16 14:00:53 +02:00
|
|
|
raise qubes.exc.QubesVMError(self, 'Cannot suspend Dom0 fake domain!')
|
2015-01-15 16:05:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
# def __init__(self, **kwargs):
|
|
|
|
# super(QubesAdminVm, self).__init__(qid=0, name="dom0", netid=0,
|
|
|
|
# dir_path=None,
|
|
|
|
# private_img = None,
|
|
|
|
# template = None,
|
|
|
|
# maxmem = 0,
|
|
|
|
# vcpus = 0,
|
|
|
|
# label = defaults["template_label"],
|
|
|
|
# **kwargs)
|