Revision cb0abdbc lib/hypervisor/hv_xen.py
b/lib/hypervisor/hv_xen.py | ||
---|---|---|
24 | 24 |
""" |
25 | 25 |
|
26 | 26 |
import logging |
27 |
import errno |
|
27 | 28 |
import string # pylint: disable=W0402 |
29 |
import shutil |
|
28 | 30 |
from cStringIO import StringIO |
29 | 31 |
|
30 | 32 |
from ganeti import constants |
... | ... | |
320 | 322 |
CAN_MIGRATE = True |
321 | 323 |
REBOOT_RETRY_COUNT = 60 |
322 | 324 |
REBOOT_RETRY_INTERVAL = 10 |
325 |
_ROOT_DIR = pathutils.RUN_DIR + "/xen-hypervisor" |
|
326 |
_NICS_DIR = _ROOT_DIR + "/nic" # contains NICs' info |
|
327 |
_DIRS = [_ROOT_DIR, _NICS_DIR] |
|
323 | 328 |
|
324 | 329 |
ANCILLARY_FILES = [ |
325 | 330 |
XEND_CONFIG_FILE, |
... | ... | |
391 | 396 |
return utils.PathJoin(self._cfgdir, instance_name) |
392 | 397 |
|
393 | 398 |
@classmethod |
399 |
def _WriteNICInfoFile(cls, instance_name, idx, nic): |
|
400 |
"""Write the Xen config file for the instance. |
|
401 |
|
|
402 |
This version of the function just writes the config file from static data. |
|
403 |
|
|
404 |
""" |
|
405 |
dirs = [(dname, constants.RUN_DIRS_MODE) |
|
406 |
for dname in cls._DIRS + [cls._InstanceNICDir(instance_name)]] |
|
407 |
utils.EnsureDirs(dirs) |
|
408 |
|
|
409 |
cfg_file = cls._InstanceNICFile(instance_name, idx) |
|
410 |
data = StringIO() |
|
411 |
|
|
412 |
if nic.netinfo: |
|
413 |
netinfo = objects.Network.FromDict(nic.netinfo) |
|
414 |
data.write("NETWORK_NAME=%s\n" % netinfo.name) |
|
415 |
if netinfo.network: |
|
416 |
data.write("NETWORK_SUBNET=%s\n" % netinfo.network) |
|
417 |
if netinfo.gateway: |
|
418 |
data.write("NETWORK_GATEWAY=%s\n" % netinfo.gateway) |
|
419 |
if netinfo.network6: |
|
420 |
data.write("NETWORK_SUBNET6=%s\n" % netinfo.network6) |
|
421 |
if netinfo.gateway6: |
|
422 |
data.write("NETWORK_GATEWAY6=%s\n" % netinfo.gateway6) |
|
423 |
if netinfo.mac_prefix: |
|
424 |
data.write("NETWORK_MAC_PREFIX=%s\n" % netinfo.mac_prefix) |
|
425 |
if netinfo.tags: |
|
426 |
data.write("NETWORK_TAGS=%s\n" % "\ ".join(netinfo.tags)) |
|
427 |
|
|
428 |
data.write("MAC=%s\n" % nic.mac) |
|
429 |
data.write("IP=%s\n" % nic.ip) |
|
430 |
data.write("MODE=%s\n" % nic.nicparams[constants.NIC_MODE]) |
|
431 |
data.write("LINK=%s\n" % nic.nicparams[constants.NIC_LINK]) |
|
432 |
|
|
433 |
try: |
|
434 |
utils.WriteFile(cfg_file, data=data.getvalue()) |
|
435 |
except EnvironmentError, err: |
|
436 |
raise errors.HypervisorError("Cannot write Xen instance configuration" |
|
437 |
" file %s: %s" % (cfg_file, err)) |
|
438 |
|
|
439 |
@classmethod |
|
440 |
def _InstanceNICDir(cls, instance_name): |
|
441 |
"""Returns the directory holding the tap device files for a given instance. |
|
442 |
|
|
443 |
""" |
|
444 |
return utils.PathJoin(cls._NICS_DIR, instance_name) |
|
445 |
|
|
446 |
@classmethod |
|
447 |
def _InstanceNICFile(cls, instance_name, seq): |
|
448 |
"""Returns the name of the file containing the tap device for a given NIC |
|
449 |
|
|
450 |
""" |
|
451 |
return utils.PathJoin(cls._InstanceNICDir(instance_name), str(seq)) |
|
452 |
|
|
453 |
@classmethod |
|
394 | 454 |
def _GetConfig(cls, instance, startup_memory, block_devices): |
395 | 455 |
"""Build Xen configuration for an instance. |
396 | 456 |
|
... | ... | |
431 | 491 |
|
432 | 492 |
""" |
433 | 493 |
utils.RemoveFile(self._ConfigFileName(instance_name)) |
494 |
try: |
|
495 |
shutil.rmtree(self._InstanceNICDir(instance_name)) |
|
496 |
except OSError, err: |
|
497 |
if err.errno != errno.ENOENT: |
|
498 |
raise |
|
434 | 499 |
|
435 | 500 |
def _StashConfigFile(self, instance_name): |
436 | 501 |
"""Move the Xen config file to the log directory and return its new path. |
... | ... | |
875 | 940 |
constants.HV_CPU_CAP: hv_base.OPT_NONNEGATIVE_INT_CHECK, |
876 | 941 |
constants.HV_CPU_WEIGHT: |
877 | 942 |
(False, lambda x: 0 < x < 65536, "invalid weight", None, None), |
943 |
constants.HV_VIF_SCRIPT: hv_base.OPT_FILE_CHECK, |
|
878 | 944 |
} |
879 | 945 |
|
880 | 946 |
def _GetConfig(self, instance, startup_memory, block_devices): |
... | ... | |
926 | 992 |
config.write("name = '%s'\n" % instance.name) |
927 | 993 |
|
928 | 994 |
vif_data = [] |
929 |
for nic in instance.nics:
|
|
995 |
for idx, nic in enumerate(instance.nics):
|
|
930 | 996 |
nic_str = "mac=%s" % (nic.mac) |
931 | 997 |
ip = getattr(nic, "ip", None) |
932 | 998 |
if ip is not None: |
933 | 999 |
nic_str += ", ip=%s" % ip |
934 | 1000 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
935 | 1001 |
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK] |
1002 |
if hvp[constants.HV_VIF_SCRIPT]: |
|
1003 |
nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT] |
|
936 | 1004 |
vif_data.append("'%s'" % nic_str) |
1005 |
self._WriteNICInfoFile(instance.name, idx, nic) |
|
937 | 1006 |
|
938 | 1007 |
disk_data = \ |
939 | 1008 |
_GetConfigFileDiskData(block_devices, hvp[constants.HV_BLOCKDEV_PREFIX]) |
... | ... | |
998 | 1067 |
constants.HV_VIF_TYPE: |
999 | 1068 |
hv_base.ParamInSet(False, constants.HT_HVM_VALID_VIF_TYPES), |
1000 | 1069 |
constants.HV_VIRIDIAN: hv_base.NO_CHECK, |
1070 |
constants.HV_VIF_SCRIPT: hv_base.OPT_FILE_CHECK, |
|
1001 | 1071 |
} |
1002 | 1072 |
|
1003 | 1073 |
def _GetConfig(self, instance, startup_memory, block_devices): |
... | ... | |
1091 | 1161 |
# parameter 'model' is only valid with type 'ioemu' |
1092 | 1162 |
nic_type_str = ", model=%s, type=%s" % \ |
1093 | 1163 |
(nic_type, constants.HT_HVM_VIF_IOEMU) |
1094 |
for nic in instance.nics:
|
|
1164 |
for idx, nic in enumerate(instance.nics):
|
|
1095 | 1165 |
nic_str = "mac=%s%s" % (nic.mac, nic_type_str) |
1096 | 1166 |
ip = getattr(nic, "ip", None) |
1097 | 1167 |
if ip is not None: |
1098 | 1168 |
nic_str += ", ip=%s" % ip |
1099 | 1169 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
1100 | 1170 |
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK] |
1171 |
if hvp[constants.HV_VIF_SCRIPT]: |
|
1172 |
nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT] |
|
1101 | 1173 |
vif_data.append("'%s'" % nic_str) |
1174 |
self._WriteNICInfoFile(instance.name, idx, nic) |
|
1102 | 1175 |
|
1103 | 1176 |
config.write("vif = [%s]\n" % ",".join(vif_data)) |
1104 | 1177 |
|
Also available in: Unified diff