Revision 865cdc2e 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, |
... | ... | |
383 | 388 |
return utils.PathJoin(self._cfgdir, instance_name) |
384 | 389 |
|
385 | 390 |
@classmethod |
391 |
def _WriteNICInfoFile(cls, instance_name, idx, nic): |
|
392 |
"""Write the Xen config file for the instance. |
|
393 |
|
|
394 |
This version of the function just writes the config file from static data. |
|
395 |
|
|
396 |
""" |
|
397 |
dirs = [(dname, constants.RUN_DIRS_MODE) |
|
398 |
for dname in cls._DIRS + [cls._InstanceNICDir(instance_name)]] |
|
399 |
utils.EnsureDirs(dirs) |
|
400 |
|
|
401 |
cfg_file = cls._InstanceNICFile(instance_name, idx) |
|
402 |
data = StringIO() |
|
403 |
|
|
404 |
if nic.netinfo: |
|
405 |
netinfo = objects.Network.FromDict(nic.netinfo) |
|
406 |
data.write("NETWORK_NAME=%s\n" % netinfo.name) |
|
407 |
if netinfo.network: |
|
408 |
data.write("NETWORK_SUBNET=%s\n" % netinfo.network) |
|
409 |
if netinfo.gateway: |
|
410 |
data.write("NETWORK_GATEWAY=%s\n" % netinfo.gateway) |
|
411 |
if netinfo.network6: |
|
412 |
data.write("NETWORK_SUBNET6=%s\n" % netinfo.network6) |
|
413 |
if netinfo.gateway6: |
|
414 |
data.write("NETWORK_GATEWAY6=%s\n" % netinfo.gateway6) |
|
415 |
if netinfo.mac_prefix: |
|
416 |
data.write("NETWORK_MAC_PREFIX=%s\n" % netinfo.mac_prefix) |
|
417 |
if netinfo.tags: |
|
418 |
data.write("NETWORK_TAGS=%s\n" % "\ ".join(netinfo.tags)) |
|
419 |
|
|
420 |
data.write("MAC=%s\n" % nic.mac) |
|
421 |
data.write("IP=%s\n" % nic.ip) |
|
422 |
data.write("MODE=%s\n" % nic.nicparams[constants.NIC_MODE]) |
|
423 |
data.write("LINK=%s\n" % nic.nicparams[constants.NIC_LINK]) |
|
424 |
|
|
425 |
try: |
|
426 |
utils.WriteFile(cfg_file, data=data.getvalue()) |
|
427 |
except EnvironmentError, err: |
|
428 |
raise errors.HypervisorError("Cannot write Xen instance configuration" |
|
429 |
" file %s: %s" % (cfg_file, err)) |
|
430 |
|
|
431 |
@classmethod |
|
432 |
def _InstanceNICDir(cls, instance_name): |
|
433 |
"""Returns the directory holding the tap device files for a given instance. |
|
434 |
|
|
435 |
""" |
|
436 |
return utils.PathJoin(cls._NICS_DIR, instance_name) |
|
437 |
|
|
438 |
@classmethod |
|
439 |
def _InstanceNICFile(cls, instance_name, seq): |
|
440 |
"""Returns the name of the file containing the tap device for a given NIC |
|
441 |
|
|
442 |
""" |
|
443 |
return utils.PathJoin(cls._InstanceNICDir(instance_name), str(seq)) |
|
444 |
|
|
445 |
@classmethod |
|
386 | 446 |
def _GetConfig(cls, instance, startup_memory, block_devices): |
387 | 447 |
"""Build Xen configuration for an instance. |
388 | 448 |
|
... | ... | |
423 | 483 |
|
424 | 484 |
""" |
425 | 485 |
utils.RemoveFile(self._ConfigFileName(instance_name)) |
486 |
try: |
|
487 |
shutil.rmtree(self._InstanceNICDir(instance_name)) |
|
488 |
except OSError, err: |
|
489 |
if err.errno != errno.ENOENT: |
|
490 |
raise |
|
426 | 491 |
|
427 | 492 |
def _StashConfigFile(self, instance_name): |
428 | 493 |
"""Move the Xen config file to the log directory and return its new path. |
... | ... | |
855 | 920 |
constants.HV_CPU_CAP: hv_base.OPT_NONNEGATIVE_INT_CHECK, |
856 | 921 |
constants.HV_CPU_WEIGHT: |
857 | 922 |
(False, lambda x: 0 < x < 65536, "invalid weight", None, None), |
923 |
constants.HV_VIF_SCRIPT: hv_base.OPT_FILE_CHECK, |
|
858 | 924 |
} |
859 | 925 |
|
860 | 926 |
def _GetConfig(self, instance, startup_memory, block_devices): |
... | ... | |
906 | 972 |
config.write("name = '%s'\n" % instance.name) |
907 | 973 |
|
908 | 974 |
vif_data = [] |
909 |
for nic in instance.nics:
|
|
975 |
for idx, nic in enumerate(instance.nics):
|
|
910 | 976 |
nic_str = "mac=%s" % (nic.mac) |
911 | 977 |
ip = getattr(nic, "ip", None) |
912 | 978 |
if ip is not None: |
913 | 979 |
nic_str += ", ip=%s" % ip |
914 | 980 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
915 | 981 |
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK] |
982 |
if hvp[constants.HV_VIF_SCRIPT]: |
|
983 |
nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT] |
|
916 | 984 |
vif_data.append("'%s'" % nic_str) |
985 |
self._WriteNICInfoFile(instance.name, idx, nic) |
|
917 | 986 |
|
918 | 987 |
disk_data = \ |
919 | 988 |
_GetConfigFileDiskData(block_devices, hvp[constants.HV_BLOCKDEV_PREFIX]) |
... | ... | |
978 | 1047 |
constants.HV_VIF_TYPE: |
979 | 1048 |
hv_base.ParamInSet(False, constants.HT_HVM_VALID_VIF_TYPES), |
980 | 1049 |
constants.HV_VIRIDIAN: hv_base.NO_CHECK, |
1050 |
constants.HV_VIF_SCRIPT: hv_base.OPT_FILE_CHECK, |
|
981 | 1051 |
} |
982 | 1052 |
|
983 | 1053 |
def _GetConfig(self, instance, startup_memory, block_devices): |
... | ... | |
1071 | 1141 |
# parameter 'model' is only valid with type 'ioemu' |
1072 | 1142 |
nic_type_str = ", model=%s, type=%s" % \ |
1073 | 1143 |
(nic_type, constants.HT_HVM_VIF_IOEMU) |
1074 |
for nic in instance.nics:
|
|
1144 |
for idx, nic in enumerate(instance.nics):
|
|
1075 | 1145 |
nic_str = "mac=%s%s" % (nic.mac, nic_type_str) |
1076 | 1146 |
ip = getattr(nic, "ip", None) |
1077 | 1147 |
if ip is not None: |
1078 | 1148 |
nic_str += ", ip=%s" % ip |
1079 | 1149 |
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: |
1080 | 1150 |
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK] |
1151 |
if hvp[constants.HV_VIF_SCRIPT]: |
|
1152 |
nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT] |
|
1081 | 1153 |
vif_data.append("'%s'" % nic_str) |
1154 |
self._WriteNICInfoFile(instance.name, idx, nic) |
|
1082 | 1155 |
|
1083 | 1156 |
config.write("vif = [%s]\n" % ",".join(vif_data)) |
1084 | 1157 |
|
Also available in: Unified diff