Commit 5fa55293 authored by Petr Pudlak's avatar Petr Pudlak

Assemble Xen NIC parameters into a dictionary

... instead of a string. This reduces the chance of programmer errors
and also eliminates the need to include comma separators everywhere.
Signed-off-by: default avatarPetr Pudlak <pudlak@google.com>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent d29d65e3
......@@ -588,29 +588,31 @@ class XenHypervisor(hv_base.BaseHypervisor):
(nic_type, constants.HT_HVM_VIF_IOEMU)
for idx, nic in enumerate(instance.nics):
nic_str = "mac=%s%s" % (nic.mac, nic_type_str)
nic_args = {}
nic_args["mac"] = "%s%s" % (nic.mac, nic_type_str)
ip = getattr(nic, "ip", None)
if ip is not None:
nic_str += ", ip=%s" % ip
nic_args["ip"] = ip
if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED:
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK]
nic_args["bridge"] = nic.nicparams[constants.NIC_LINK]
elif nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_OVS:
nic_str += ", bridge=%s" % nic.nicparams[constants.NIC_LINK]
nic_args["bridge"] = nic.nicparams[constants.NIC_LINK]
if nic.nicparams[constants.NIC_VLAN]:
nic_str += "%s" % nic.nicparams[constants.NIC_VLAN]
nic_args["bridge"] += nic.nicparams[constants.NIC_VLAN]
if nic.name and \
nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX):
tap = hv_base.GenerateTapName()
nic_str += ", vifname=%s" % tap
nic_args["vifname"] = tap
nic.name = tap
if hvp[constants.HV_VIF_SCRIPT]:
nic_str += ", script=%s" % hvp[constants.HV_VIF_SCRIPT]
nic_args["script"] = hvp[constants.HV_VIF_SCRIPT]
vif_data.append("'%s'" % nic_str)
nic_str = ", ".join(["%s=%s" % p for p in nic_args.items()])
vif_data.append("'%s'" % (nic_str, ))
self._WriteNICInfoFile(instance, idx, nic)
config.write("vif = [%s]\n" % ",".join(vif_data))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment