Revision 0a903309
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
320 | 320 |
XL_CONFIG_FILE, |
321 | 321 |
] |
322 | 322 |
|
323 |
@staticmethod |
|
324 |
def _ConfigFileName(instance_name): |
|
323 |
def __init__(self, _cfgdir=None): |
|
324 |
hv_base.BaseHypervisor.__init__(self) |
|
325 |
|
|
326 |
if _cfgdir is None: |
|
327 |
self._cfgdir = pathutils.XEN_CONFIG_DIR |
|
328 |
else: |
|
329 |
self._cfgdir = _cfgdir |
|
330 |
|
|
331 |
def _ConfigFileName(self, instance_name): |
|
325 | 332 |
"""Get the config file name for an instance. |
326 | 333 |
|
327 | 334 |
@param instance_name: instance name |
... | ... | |
330 | 337 |
@rtype: str |
331 | 338 |
|
332 | 339 |
""" |
333 |
return utils.PathJoin(pathutils.XEN_CONFIG_DIR, instance_name)
|
|
340 |
return utils.PathJoin(self._cfgdir, instance_name)
|
|
334 | 341 |
|
335 | 342 |
@classmethod |
336 | 343 |
def _WriteConfigFile(cls, instance, startup_memory, block_devices): |
... | ... | |
339 | 346 |
""" |
340 | 347 |
raise NotImplementedError |
341 | 348 |
|
342 |
@staticmethod |
|
343 |
def _WriteConfigFileStatic(instance_name, data): |
|
349 |
def _WriteConfigFileStatic(self, instance_name, data): |
|
344 | 350 |
"""Write the Xen config file for the instance. |
345 | 351 |
|
346 | 352 |
This version of the function just writes the config file from static data. |
347 | 353 |
|
348 | 354 |
""" |
349 | 355 |
# just in case it exists |
350 |
utils.RemoveFile(utils.PathJoin(pathutils.XEN_CONFIG_DIR, "auto", |
|
351 |
instance_name)) |
|
356 |
utils.RemoveFile(utils.PathJoin(self._cfgdir, "auto", instance_name)) |
|
352 | 357 |
|
353 |
cfg_file = XenHypervisor._ConfigFileName(instance_name)
|
|
358 |
cfg_file = self._ConfigFileName(instance_name)
|
|
354 | 359 |
try: |
355 | 360 |
utils.WriteFile(cfg_file, data=data) |
356 | 361 |
except EnvironmentError, err: |
357 | 362 |
raise errors.HypervisorError("Cannot write Xen instance configuration" |
358 | 363 |
" file %s: %s" % (cfg_file, err)) |
359 | 364 |
|
360 |
@staticmethod |
|
361 |
def _ReadConfigFile(instance_name): |
|
365 |
def _ReadConfigFile(self, instance_name): |
|
362 | 366 |
"""Returns the contents of the instance config file. |
363 | 367 |
|
364 | 368 |
""" |
365 |
filename = XenHypervisor._ConfigFileName(instance_name)
|
|
369 |
filename = self._ConfigFileName(instance_name)
|
|
366 | 370 |
|
367 | 371 |
try: |
368 | 372 |
file_content = utils.ReadFile(filename) |
... | ... | |
371 | 375 |
|
372 | 376 |
return file_content |
373 | 377 |
|
374 |
@staticmethod |
|
375 |
def _RemoveConfigFile(instance_name): |
|
378 |
def _RemoveConfigFile(self, instance_name): |
|
376 | 379 |
"""Remove the xen configuration file. |
377 | 380 |
|
378 | 381 |
""" |
379 |
utils.RemoveFile(XenHypervisor._ConfigFileName(instance_name))
|
|
382 |
utils.RemoveFile(self._ConfigFileName(instance_name))
|
|
380 | 383 |
|
381 | 384 |
@staticmethod |
382 | 385 |
def _GetXmList(include_node): |
... | ... | |
504 | 507 |
(instance.name, result.fail_reason, |
505 | 508 |
result.output)) |
506 | 509 |
cmd = ["sed", "-ie", "s/^memory.*$/memory = %s/" % mem] |
507 |
cmd.append(XenHypervisor._ConfigFileName(instance.name))
|
|
510 |
cmd.append(self._ConfigFileName(instance.name))
|
|
508 | 511 |
result = utils.RunCmd(cmd) |
509 | 512 |
if result.failed: |
510 | 513 |
raise errors.HypervisorError("Failed to update memory for %s: %s (%s)" % |
... | ... | |
713 | 716 |
(False, lambda x: 0 < x < 65536, "invalid weight", None, None), |
714 | 717 |
} |
715 | 718 |
|
716 |
@classmethod |
|
717 |
def _WriteConfigFile(cls, instance, startup_memory, block_devices): |
|
719 |
def _WriteConfigFile(self, instance, startup_memory, block_devices): |
|
718 | 720 |
"""Write the Xen config file for the instance. |
719 | 721 |
|
720 | 722 |
""" |
... | ... | |
787 | 789 |
config.write("on_reboot = 'destroy'\n") |
788 | 790 |
config.write("on_crash = 'restart'\n") |
789 | 791 |
config.write("extra = '%s'\n" % hvp[constants.HV_KERNEL_ARGS]) |
790 |
cls._WriteConfigFileStatic(instance.name, config.getvalue())
|
|
792 |
self._WriteConfigFileStatic(instance.name, config.getvalue())
|
|
791 | 793 |
|
792 | 794 |
return True |
793 | 795 |
|
... | ... | |
835 | 837 |
(False, lambda x: 0 < x < 65535, "invalid weight", None, None), |
836 | 838 |
} |
837 | 839 |
|
838 |
@classmethod |
|
839 |
def _WriteConfigFile(cls, instance, startup_memory, block_devices): |
|
840 |
def _WriteConfigFile(self, instance, startup_memory, block_devices): |
|
840 | 841 |
"""Create a Xen 3.1 HVM config file. |
841 | 842 |
|
842 | 843 |
""" |
... | ... | |
946 | 947 |
else: |
947 | 948 |
config.write("on_reboot = 'destroy'\n") |
948 | 949 |
config.write("on_crash = 'restart'\n") |
949 |
cls._WriteConfigFileStatic(instance.name, config.getvalue())
|
|
950 |
self._WriteConfigFileStatic(instance.name, config.getvalue())
|
|
950 | 951 |
|
951 | 952 |
return True |
Also available in: Unified diff