Revision c3d839f5
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
340 | 340 |
return utils.PathJoin(self._cfgdir, instance_name) |
341 | 341 |
|
342 | 342 |
@classmethod |
343 |
def _WriteConfigFile(cls, instance, startup_memory, block_devices):
|
|
344 |
"""Write the Xen config file for the instance.
|
|
343 |
def _GetConfig(cls, instance, startup_memory, block_devices):
|
|
344 |
"""Build Xen configuration for an instance.
|
|
345 | 345 |
|
346 | 346 |
""" |
347 | 347 |
raise NotImplementedError |
348 | 348 |
|
349 |
def _WriteConfigFileStatic(self, instance_name, data):
|
|
349 |
def _WriteConfigFile(self, instance_name, data): |
|
350 | 350 |
"""Write the Xen config file for the instance. |
351 | 351 |
|
352 | 352 |
This version of the function just writes the config file from static data. |
... | ... | |
423 | 423 |
xm_list = self._GetXmList(False) |
424 | 424 |
return xm_list |
425 | 425 |
|
426 |
def _MakeConfigFile(self, instance, startup_memory, block_devices): |
|
427 |
"""Gather configuration details and write to disk. |
|
428 |
|
|
429 |
See L{_GetConfig} for arguments. |
|
430 |
|
|
431 |
""" |
|
432 |
buf = StringIO() |
|
433 |
buf.write("# Automatically generated by Ganeti. Do not edit!\n") |
|
434 |
buf.write("\n") |
|
435 |
buf.write(self._GetConfig(instance, startup_memory, block_devices)) |
|
436 |
buf.write("\n") |
|
437 |
|
|
438 |
self._WriteConfigFile(instance.name, buf.getvalue()) |
|
439 |
|
|
426 | 440 |
def StartInstance(self, instance, block_devices, startup_paused): |
427 | 441 |
"""Start an instance. |
428 | 442 |
|
429 | 443 |
""" |
430 | 444 |
startup_memory = self._InstanceStartupMemory(instance) |
431 |
self._WriteConfigFile(instance, startup_memory, block_devices) |
|
445 |
|
|
446 |
self._MakeConfigFile(instance, startup_memory, block_devices) |
|
447 |
|
|
432 | 448 |
cmd = [constants.XEN_CMD, "create"] |
433 | 449 |
if startup_paused: |
434 | 450 |
cmd.extend(["-p"]) |
... | ... | |
594 | 610 |
|
595 | 611 |
""" |
596 | 612 |
if success: |
597 |
self._WriteConfigFileStatic(instance.name, info)
|
|
613 |
self._WriteConfigFile(instance.name, info) |
|
598 | 614 |
|
599 | 615 |
def MigrateInstance(self, instance, target, live): |
600 | 616 |
"""Migrate an instance to a target node. |
... | ... | |
716 | 732 |
(False, lambda x: 0 < x < 65536, "invalid weight", None, None), |
717 | 733 |
} |
718 | 734 |
|
719 |
def _WriteConfigFile(self, instance, startup_memory, block_devices):
|
|
735 |
def _GetConfig(self, instance, startup_memory, block_devices):
|
|
720 | 736 |
"""Write the Xen config file for the instance. |
721 | 737 |
|
722 | 738 |
""" |
... | ... | |
789 | 805 |
config.write("on_reboot = 'destroy'\n") |
790 | 806 |
config.write("on_crash = 'restart'\n") |
791 | 807 |
config.write("extra = '%s'\n" % hvp[constants.HV_KERNEL_ARGS]) |
792 |
self._WriteConfigFileStatic(instance.name, config.getvalue()) |
|
793 | 808 |
|
794 |
return True
|
|
809 |
return config.getvalue()
|
|
795 | 810 |
|
796 | 811 |
|
797 | 812 |
class XenHvmHypervisor(XenHypervisor): |
... | ... | |
837 | 852 |
(False, lambda x: 0 < x < 65535, "invalid weight", None, None), |
838 | 853 |
} |
839 | 854 |
|
840 |
def _WriteConfigFile(self, instance, startup_memory, block_devices):
|
|
855 |
def _GetConfig(self, instance, startup_memory, block_devices):
|
|
841 | 856 |
"""Create a Xen 3.1 HVM config file. |
842 | 857 |
|
843 | 858 |
""" |
844 | 859 |
hvp = instance.hvparams |
845 | 860 |
|
846 | 861 |
config = StringIO() |
847 |
config.write("# this is autogenerated by Ganeti, please do not edit\n#\n") |
|
848 | 862 |
|
849 | 863 |
# kernel handling |
850 | 864 |
kpath = hvp[constants.HV_KERNEL_PATH] |
... | ... | |
947 | 961 |
else: |
948 | 962 |
config.write("on_reboot = 'destroy'\n") |
949 | 963 |
config.write("on_crash = 'restart'\n") |
950 |
self._WriteConfigFileStatic(instance.name, config.getvalue()) |
|
951 | 964 |
|
952 |
return True |
|
965 |
return config.getvalue() |
Also available in: Unified diff