42 |
42 |
|
43 |
43 |
"""
|
44 |
44 |
ht_kind = ssconf.SimpleStore().GetHypervisorType()
|
45 |
|
if ht_kind == constants.HT_XEN30:
|
46 |
|
cls = XenHypervisor
|
|
45 |
if ht_kind == constants.HT_XEN_PVM30:
|
|
46 |
cls = XenPvmHypervisor
|
47 |
47 |
elif ht_kind == constants.HT_FAKE:
|
48 |
48 |
cls = FakeHypervisor
|
49 |
49 |
else:
|
... | ... | |
124 |
124 |
|
125 |
125 |
|
126 |
126 |
class XenHypervisor(BaseHypervisor):
|
127 |
|
"""Xen hypervisor interface"""
|
|
127 |
"""Xen generic hypervisor interface
|
|
128 |
|
|
129 |
This is the Xen base class used for both Xen PVM and HVM. It contains
|
|
130 |
all the functionality that is identical for both.
|
|
131 |
|
|
132 |
"""
|
128 |
133 |
|
129 |
134 |
@staticmethod
|
130 |
135 |
def _WriteConfigFile(instance, block_devices, extra_args):
|
131 |
|
"""Create a Xen 3.0 config file.
|
|
136 |
"""A Xen instance config file.
|
132 |
137 |
|
133 |
138 |
"""
|
134 |
|
config = StringIO()
|
135 |
|
config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
|
136 |
|
config.write("kernel = '%s'\n" % constants.XEN_KERNEL)
|
137 |
|
if os.path.exists(constants.XEN_INITRD):
|
138 |
|
config.write("ramdisk = '%s'\n" % constants.XEN_INITRD)
|
139 |
|
config.write("memory = %d\n" % instance.memory)
|
140 |
|
config.write("vcpus = %d\n" % instance.vcpus)
|
141 |
|
config.write("name = '%s'\n" % instance.name)
|
142 |
|
|
143 |
|
vif_data = []
|
144 |
|
for nic in instance.nics:
|
145 |
|
nic_str = "mac=%s, bridge=%s" % (nic.mac, nic.bridge)
|
146 |
|
ip = getattr(nic, "ip", None)
|
147 |
|
if ip is not None:
|
148 |
|
nic_str += ", ip=%s" % ip
|
149 |
|
vif_data.append("'%s'" % nic_str)
|
150 |
|
|
151 |
|
config.write("vif = [%s]\n" % ",".join(vif_data))
|
152 |
|
|
153 |
|
disk_data = ["'phy:%s,%s,w'" % (rldev.dev_path, cfdev.iv_name)
|
154 |
|
for cfdev, rldev in block_devices]
|
155 |
|
config.write("disk = [%s]\n" % ",".join(disk_data))
|
156 |
|
|
157 |
|
config.write("root = '/dev/sda ro'\n")
|
158 |
|
config.write("on_poweroff = 'destroy'\n")
|
159 |
|
config.write("on_reboot = 'restart'\n")
|
160 |
|
config.write("on_crash = 'restart'\n")
|
161 |
|
if extra_args:
|
162 |
|
config.write("extra = '%s'\n" % extra_args)
|
163 |
|
# just in case it exists
|
164 |
|
utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
|
165 |
|
f = open("/etc/xen/%s" % instance.name, "w")
|
166 |
|
f.write(config.getvalue())
|
167 |
|
f.close()
|
168 |
|
return True
|
|
139 |
raise NotImplementedError
|
169 |
140 |
|
170 |
141 |
@staticmethod
|
171 |
142 |
def _RemoveConfigFile(instance):
|
... | ... | |
324 |
295 |
"""Return a command for connecting to the console of an instance.
|
325 |
296 |
|
326 |
297 |
"""
|
327 |
|
return "xm console %s" % instance.name
|
|
298 |
raise NotImplementedError
|
328 |
299 |
|
329 |
300 |
|
330 |
301 |
def Verify(self):
|
... | ... | |
337 |
308 |
return "xend daemon is not running"
|
338 |
309 |
|
339 |
310 |
|
|
311 |
class XenPvmHypervisor(XenHypervisor):
|
|
312 |
"""Xen PVM hypervisor interface"""
|
|
313 |
|
|
314 |
@staticmethod
|
|
315 |
def _WriteConfigFile(instance, block_devices, extra_args):
|
|
316 |
"""Create a Xen instance config file.
|
|
317 |
|
|
318 |
"""
|
|
319 |
config = StringIO()
|
|
320 |
config.write("# this is autogenerated by Ganeti, please do not edit\n#\n")
|
|
321 |
config.write("kernel = '%s'\n" % constants.XEN_KERNEL)
|
|
322 |
if os.path.exists(constants.XEN_INITRD):
|
|
323 |
config.write("ramdisk = '%s'\n" % constants.XEN_INITRD)
|
|
324 |
config.write("memory = %d\n" % instance.memory)
|
|
325 |
config.write("vcpus = %d\n" % instance.vcpus)
|
|
326 |
config.write("name = '%s'\n" % instance.name)
|
|
327 |
|
|
328 |
vif_data = []
|
|
329 |
for nic in instance.nics:
|
|
330 |
nic_str = "mac=%s, bridge=%s" % (nic.mac, nic.bridge)
|
|
331 |
ip = getattr(nic, "ip", None)
|
|
332 |
if ip is not None:
|
|
333 |
nic_str += ", ip=%s" % ip
|
|
334 |
vif_data.append("'%s'" % nic_str)
|
|
335 |
|
|
336 |
config.write("vif = [%s]\n" % ",".join(vif_data))
|
|
337 |
|
|
338 |
disk_data = ["'phy:%s,%s,w'" % (rldev.dev_path, cfdev.iv_name)
|
|
339 |
for cfdev, rldev in block_devices]
|
|
340 |
config.write("disk = [%s]\n" % ",".join(disk_data))
|
|
341 |
|
|
342 |
config.write("root = '/dev/sda ro'\n")
|
|
343 |
config.write("on_poweroff = 'destroy'\n")
|
|
344 |
config.write("on_reboot = 'restart'\n")
|
|
345 |
config.write("on_crash = 'restart'\n")
|
|
346 |
if extra_args:
|
|
347 |
config.write("extra = '%s'\n" % extra_args)
|
|
348 |
# just in case it exists
|
|
349 |
utils.RemoveFile("/etc/xen/auto/%s" % instance.name)
|
|
350 |
f = open("/etc/xen/%s" % instance.name, "w")
|
|
351 |
f.write(config.getvalue())
|
|
352 |
f.close()
|
|
353 |
return True
|
|
354 |
|
|
355 |
@staticmethod
|
|
356 |
def GetShellCommandForConsole(instance):
|
|
357 |
"""Return a command for connecting to the console of an instance.
|
|
358 |
|
|
359 |
"""
|
|
360 |
return "xm console %s" % instance.name
|
|
361 |
|
|
362 |
|
340 |
363 |
class FakeHypervisor(BaseHypervisor):
|
341 |
364 |
"""Fake hypervisor interface.
|
342 |
365 |
|