LGTM
On Wed, Jul 23, 2014 at 6:52 PM, 'Klaus Aehlig' via ganeti-devel < [email protected]> wrote: > > > commit d7326a8c2addf951116fe7c9fb3bbfd848f70fd7 > Merge: 6cfc67c e79a587 > Author: Klaus Aehlig <[email protected]> > Date: Wed Jul 23 18:46:55 2014 +0200 > > Merge branch 'stable-2.11' into stable-2.12 > > * stable-2.11 > (no changes) > > * stable-2.10 > KVM: fix NIC configuration with absent NIC VLAN > > Conflicts: > lib/hypervisor/hv_kvm/__init__.py: follow code move > to lib/hypervisor/hv_base.py > > diff --cc lib/hypervisor/hv_base.py > index 491156c,b521774..cd74ce7 > --- a/lib/hypervisor/hv_base.py > +++ b/lib/hypervisor/hv_base.py > @@@ -159,99 -144,6 +159,99 @@@ def ParamInSet(required, my_set) > return (required, fn, err, None, None) > > > +def GenerateTapName(): > + """Generate a TAP network interface name for a NIC. > + > + This helper function generates a special TAP network interface > + name for NICs that are meant to be used in instance communication. > + This function checks the existing TAP interfaces in order to find > + a unique name for the new TAP network interface. The TAP network > + interface names are of the form 'gnt.com.%d', where '%d' is a > + unique number within the node. > + > + @rtype: string > + @return: TAP network interface name, or the empty string if the > + NIC is not used in instance communication > + > + """ > + result = utils.RunCmd(["ip", "tuntap", "list"]) > + > + if result.failed: > + raise errors.HypervisorError("Failed to list TUN/TAP interfaces") > + > + idxs = set() > + > + for line in result.output.splitlines(): > + parts = line.split(": ", 1) > + > + if len(parts) < 2: > + raise errors.HypervisorError("Failed to parse TUN/TAP interfaces") > + > + r = re.match(r"gnt\.com\.([0-9]+)", parts[0]) > + > + if r is not None: > + idxs.add(int(r.group(1))) > + > + if idxs: > + idx = max(idxs) + 1 > + else: > + idx = 0 > + > + return "gnt.com.%d" % idx > + > + > +def ConfigureNIC(cmd, instance, seq, nic, tap): > + """Run the network configuration script for a specified NIC > + > + @type cmd: string > + @param cmd: command to run > + @type instance: instance object > + @param instance: instance we're acting on > + @type seq: int > + @param seq: nic sequence number > + @type nic: nic object > + @param nic: nic we're acting on > + @type tap: str > + @param tap: the host's tap interface this NIC corresponds to > + > + """ > + env = { > + "PATH": "%s:/sbin:/usr/sbin" % os.environ["PATH"], > + "INSTANCE": instance.name, > + "MAC": nic.mac, > + "MODE": nic.nicparams[constants.NIC_MODE], > + "INTERFACE": tap, > + "INTERFACE_INDEX": str(seq), > + "INTERFACE_UUID": nic.uuid, > + "TAGS": " ".join(instance.GetTags()), > + } > + > + if nic.ip: > + env["IP"] = nic.ip > + > + if nic.name: > + env["INTERFACE_NAME"] = nic.name > + > + if nic.nicparams[constants.NIC_LINK]: > + env["LINK"] = nic.nicparams[constants.NIC_LINK] > + > - if nic.nicparams[constants.NIC_VLAN]: > ++ if constants.NIC_VLAN in nic.nicparams: > + env["VLAN"] = nic.nicparams[constants.NIC_VLAN] > + > + if nic.network: > + n = objects.Network.FromDict(nic.netinfo) > + env.update(n.HooksDict()) > + > + if nic.nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED: > + env["BRIDGE"] = nic.nicparams[constants.NIC_LINK] > + > + result = utils.RunCmd(cmd, env=env) > + if result.failed: > + raise errors.HypervisorError("Failed to configure interface %s: %s;" > + " network configuration script output: > %s" % > + (tap, result.fail_reason, > result.output)) > + > + > class HvInstanceState(object): > RUNNING = 0 > SHUTDOWN = 1 > > -- > Klaus Aehlig > Google Germany GmbH, Dienerstr. 12, 80331 Muenchen > Registergericht und -nummer: Hamburg, HRB 86891 > Sitz der Gesellschaft: Hamburg > Geschaeftsfuehrer: Graham Law, Christine Elizabeth Flores >
