Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.

Commit 287acf3

Browse files
committed
Add a proper 'Clock' class for building <clock> XML
1 parent faf9cb3 commit 287acf3

4 files changed

Lines changed: 69 additions & 17 deletions

File tree

virtinst/Clock.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#
2+
# Copyright 2010 Red Hat, Inc.
3+
# Cole Robinson <crobinso@redhat.com>
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License as published by
7+
# the Free Software Foundation; either version 2 of the License, or
8+
# (at your option) any later version.
9+
#
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18+
# MA 02110-1301 USA.
19+
20+
class Clock(object):
21+
"""
22+
Class for generating <clock> XML
23+
"""
24+
25+
def __init__(self, conn):
26+
self.conn = conn
27+
28+
self._offset = None
29+
30+
def get_offset(self):
31+
return self._offset
32+
def set_offset(self, val):
33+
self._offset = val
34+
offset = property(get_offset, set_offset)
35+
36+
def get_xml_config(self):
37+
if not self.offset:
38+
return ""
39+
40+
return """ <clock offset="%s"/>""" % self.offset

virtinst/FullVirtGuest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ def _get_input_device(self):
8686
dev.bus = bus
8787
return dev
8888

89-
def _get_clock_xml(self):
90-
val = self._lookup_osdict_key("clock")
91-
return """ <clock offset="%s"/>""" % val
92-
9389
def _get_device_xml(self, install=True):
9490
emu_xml = ""
9591
if self.emulator is not None:
@@ -110,5 +106,8 @@ def _set_defaults(self, devlist_func):
110106
disk.device == VirtualDisk.DEVICE_DISK):
111107
disk.bus = disk_bus
112108

109+
if self.clock.offset == None:
110+
self.clock.offset = self._lookup_osdict_key("clock")
111+
113112
# Run this last, so we get first crack at disk attributes
114113
Guest._set_defaults(self, devlist_func)

virtinst/Guest.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import support
3131
from VirtualDevice import VirtualDevice
3232
from VirtualDisk import VirtualDisk
33+
from Clock import Clock
3334

3435
import osdict
3536
from virtinst import _virtinst as _
@@ -109,9 +110,22 @@ def cpuset_str_to_tuple(conn, cpuset):
109110

110111
def __init__(self, type=None, connection=None, hypervisorURI=None,
111112
installer=None):
113+
114+
# Set up the connection, since it is fundamental for other init
115+
self.conn = connection
116+
if self.conn == None:
117+
logging.debug("No conn passed to Guest, opening URI '%s'" % \
118+
hypervisorURI)
119+
self.conn = libvirt.open(hypervisorURI)
120+
121+
if self.conn == None:
122+
raise RuntimeError, _("Unable to connect to hypervisor, aborting "
123+
"installation!")
124+
112125
# We specifically ignore the 'type' parameter here, since
113126
# it has been replaced by installer.type, and child classes can
114127
# use it when creating a default installer.
128+
ignore = type
115129
self._installer = installer
116130
self._name = None
117131
self._uuid = None
@@ -123,6 +137,7 @@ def __init__(self, type=None, connection=None, hypervisorURI=None,
123137
self._consolechild = None
124138
self._os_autodetect = False
125139
self._autostart = False
140+
self._clock = Clock(self.conn)
126141
self.features = None
127142

128143
self._os_type = None
@@ -155,15 +170,6 @@ def __init__(self, type=None, connection=None, hypervisorURI=None,
155170
self._default_console_assigned = None
156171
self._default_input_assigned = None
157172

158-
self.conn = connection
159-
if self.conn == None:
160-
logging.debug("No conn passed to Guest, opening URI '%s'" % \
161-
hypervisorURI)
162-
self.conn = libvirt.open(hypervisorURI)
163-
if self.conn == None:
164-
raise RuntimeError, _("Unable to connect to hypervisor, aborting "
165-
"installation!")
166-
167173
self._caps = CapabilitiesParser.parse(self.conn.getCapabilities())
168174

169175

@@ -175,6 +181,10 @@ def set_installer(self, val):
175181
self._installer = val
176182
installer = property(get_installer, set_installer)
177183

184+
def get_clock(self):
185+
return self._clock
186+
clock = property(get_clock)
187+
178188
# Domain name of the guest
179189
def get_name(self):
180190
return self._name
@@ -667,12 +677,14 @@ def _get_features_xml(self):
667677

668678
def _get_clock_xml(self):
669679
"""
670-
Return <clock/> xml (currently only relevant for FV guests)
680+
Return <clock/> xml
671681
"""
672-
return ""
682+
return self.clock.get_xml_config()
673683

674684
def _get_osblob(self, install):
675-
"""Return os, features, and clock xml (Implemented in subclass)"""
685+
"""
686+
Return os, features, and clock xml (Implemented in subclass)
687+
"""
676688
xml = ""
677689

678690
osxml = self.installer.get_install_xml(self, install)

virtinst/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def _virtinst(msg):
4949
from ImageInstaller import ImageInstaller
5050
from CloneManager import CloneDesign
5151
from User import User
52+
from Clock import Clock
5253
import util
5354
import support
5455

@@ -59,6 +60,6 @@ def _virtinst(msg):
5960
"VirtualDisk", "XenDisk", "FullVirtGuest", "ParaVirtGuest",
6061
"DistroInstaller", "PXEInstaller", "LiveCDInstaller",
6162
"ImportInstaller", "ImageInstaller", "CloneDesign", "Storage",
62-
"User", "util", "support", "VirtualDevice",
63+
"User", "util", "support", "VirtualDevice", "Clock",
6364
"VirtualHostDevice", "VirtualHostDeviceUSB", "VirtualVideoDevice",
6465
"VirtualHostDevicePCI", "VirtualCharDevice", "VirtualInputDevice"]

0 commit comments

Comments
 (0)