On Fri, Jan 31, 2014 at 11:46 AM, Jose A. Lopes <[email protected]> wrote: > * Add helper function that generates names of the form 'gnt.com.%d' > which are the names for the TAP interfaces meant to be used by > instance communication. These names are unique within the node. > > * Use the previous helper function to actually generate the name for > the NICs of KVM instance being created. > > Signed-off-by: Jose A. Lopes <[email protected]> > --- > lib/hypervisor/hv_kvm.py | 51 > +++++++++++++++++++++++++++++++++++++++++++++++- > src/Ganeti/Constants.hs | 8 ++++++++ > 2 files changed, 58 insertions(+), 1 deletion(-) > > diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py > index 1440d1a..f13e2fe 100644 > --- a/lib/hypervisor/hv_kvm.py > +++ b/lib/hypervisor/hv_kvm.py > @@ -1819,6 +1819,54 @@ class KVMHypervisor(hv_base.BaseHypervisor): > if not self._InstancePidAlive(name)[2]: > raise errors.HypervisorError("Failed to start instance %s" % name) > > + @staticmethod > + def _GenerateTapName(nic): > + """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. > + > + @type nic: ganeti.objects.NIC > + @param nic: NIC object for the name should be generated > + > + @rtype: string > + @return: TAP network interface name, or the empty string if the > + NIC is not used in instance communication > + > + """ > + if nic.name is None or not \ > + nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX): > + return "" > + > + 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 > + > # too many local variables > # pylint: disable=R0914 > def _ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, > incoming=None): > @@ -1904,7 +1952,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): > kvm_supports_netdev = self._NETDEV_RE.search(kvmhelp) > > for nic_seq, nic in enumerate(kvm_nics): > - tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr) > + tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr, > + name=self._GenerateTapName(nic)) > tapfds.append(tapfd) > taps.append(tapname) > if kvm_supports_netdev: > diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs > index 9df4f1f..533ec6a 100644 > --- a/src/Ganeti/Constants.hs > +++ b/src/Ganeti/Constants.hs > @@ -4761,3 +4761,11 @@ glusterPort = "port" > -- | Default value of the Gluster port setting > glusterPortDefault :: Int > glusterPortDefault = 24007 > + > +-- * Instance communication > + > +instanceCommunicationNetwork :: String > +instanceCommunicationNetwork = "ganeti:network:communication" > + > +instanceCommunicationNicPrefix :: String > +instanceCommunicationNicPrefix = "ganeti:communication:" > -- > 1.8.5.3 >
LGTM, thanks. Michele -- Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores On Fri, Jan 31, 2014 at 11:46 AM, Jose A. Lopes <[email protected]> wrote: > * Add helper function that generates names of the form 'gnt.com.%d' > which are the names for the TAP interfaces meant to be used by > instance communication. These names are unique within the node. > > * Use the previous helper function to actually generate the name for > the NICs of KVM instance being created. > > Signed-off-by: Jose A. Lopes <[email protected]> > --- > lib/hypervisor/hv_kvm.py | 51 > +++++++++++++++++++++++++++++++++++++++++++++++- > src/Ganeti/Constants.hs | 8 ++++++++ > 2 files changed, 58 insertions(+), 1 deletion(-) > > diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py > index 1440d1a..f13e2fe 100644 > --- a/lib/hypervisor/hv_kvm.py > +++ b/lib/hypervisor/hv_kvm.py > @@ -1819,6 +1819,54 @@ class KVMHypervisor(hv_base.BaseHypervisor): > if not self._InstancePidAlive(name)[2]: > raise errors.HypervisorError("Failed to start instance %s" % name) > > + @staticmethod > + def _GenerateTapName(nic): > + """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. > + > + @type nic: ganeti.objects.NIC > + @param nic: NIC object for the name should be generated > + > + @rtype: string > + @return: TAP network interface name, or the empty string if the > + NIC is not used in instance communication > + > + """ > + if nic.name is None or not \ > + nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX): > + return "" > + > + 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 > + > # too many local variables > # pylint: disable=R0914 > def _ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, > incoming=None): > @@ -1904,7 +1952,8 @@ class KVMHypervisor(hv_base.BaseHypervisor): > kvm_supports_netdev = self._NETDEV_RE.search(kvmhelp) > > for nic_seq, nic in enumerate(kvm_nics): > - tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr) > + tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr, > + name=self._GenerateTapName(nic)) > tapfds.append(tapfd) > taps.append(tapname) > if kvm_supports_netdev: > diff --git a/src/Ganeti/Constants.hs b/src/Ganeti/Constants.hs > index 9df4f1f..533ec6a 100644 > --- a/src/Ganeti/Constants.hs > +++ b/src/Ganeti/Constants.hs > @@ -4761,3 +4761,11 @@ glusterPort = "port" > -- | Default value of the Gluster port setting > glusterPortDefault :: Int > glusterPortDefault = 24007 > + > +-- * Instance communication > + > +instanceCommunicationNetwork :: String > +instanceCommunicationNetwork = "ganeti:network:communication" > + > +instanceCommunicationNicPrefix :: String > +instanceCommunicationNicPrefix = "ganeti:communication:" > -- > 1.8.5.3 > -- Google Germany GmbH Dienerstr. 12 80331 München Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg Geschäftsführer: Graham Law, Christine Elizabeth Flores
