Commit 81c717cd authored by Jose A. Lopes's avatar Jose A. Lopes
Browse files

Generate TAP names ('') for instance comm NICs

* Add helper function that generates names of the form ''
  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: default avatarJose A. Lopes <>
Reviewed-by: default avatarMichele Tartara <>
parent 89473be8
......@@ -1819,6 +1819,54 @@ class KVMHypervisor(hv_base.BaseHypervisor):
if not self._InstancePidAlive(name)[2]:
raise errors.HypervisorError("Failed to start instance %s" % name)
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 '', 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 is None or not \
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:
if idxs:
idx = max(idxs) + 1
idx = 0
return "" % 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 =
for nic_seq, nic in enumerate(kvm_nics):
tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr)
tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr,
if kvm_supports_netdev:
......@@ -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:"
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