Am 29. August 2011 18:21 schrieb Agata Murawska <[email protected]>:
> + if network_ganeti_data:
> + ganeti_data["mode"] = network_ganeti_data.findtext("{%s}Mode" %
> + GANETI_SCHEMA)
constants.INIC_MODE
> + ganeti_data["mac"] = network_ganeti_data.findtext("{%s}MACAddress" %
> + GANETI_SCHEMA)
constants.INIC_MAC
> + ganeti_data["ip"] = network_ganeti_data.findtext("{%s}IPAddress" %
> + GANETI_SCHEMA)
constants.INIC_IP
> + ganeti_data["link"] = network_ganeti_data.findtext("{%s}Link" %
> + GANETI_SCHEMA)
constants.INIC_LINK
> + data = {}
> + if network_data:
> + data["mac"] = network_data.findtext("{%s}Address" % RASD_SCHEMA)
Why use a dictionary instead of a single variable?
> + network_name = network_name.lower()
> +
> + if constants.NIC_MODE_BRIDGED in network_name:
> + results["nic%s_mode" % str(counter)] = "bridged"
No need for str() if you use %s. constants.NIC_MODE_BRIDGED
> + elif constants.NIC_MODE_ROUTED in network_name:
> + results["nic%s_mode" % str(counter)] = "routed"
constants.NIC_MODE_ROUTED
You get the idea. There are other places where you should use existing
constants.
> + if data.get("mac"):
> + results["nic%s_mac" % str(counter)] = data["mac"]
> + for name, value in ganeti_data.iteritems():
> + results["nic%s_%s" % (str(counter), name)] = value
> + if results.get("nic%s_mode" % str(counter)) == "bridged":
> + if not results.get("nic%s_ip" % str(counter)):
> + results["nic%s_ip" % str(counter)] = "None"
> + for option in required:
> + if not results.get("nic%s_%s" % (str(counter), option)):
> + results["nic%s_%s" % (str(counter), option)] = "auto"
constants.VALUE_AUTO
> + if network_names:
> + results["nic_count"] = str(len(network_names))
> + return results
Michael