Revision 81c717cd lib/hypervisor/hv_kvm.py
b/lib/hypervisor/hv_kvm.py | ||
---|---|---|
1819 | 1819 |
if not self._InstancePidAlive(name)[2]: |
1820 | 1820 |
raise errors.HypervisorError("Failed to start instance %s" % name) |
1821 | 1821 |
|
1822 |
@staticmethod |
|
1823 |
def _GenerateTapName(nic): |
|
1824 |
"""Generate a TAP network interface name for a NIC. |
|
1825 |
|
|
1826 |
This helper function generates a special TAP network interface |
|
1827 |
name for NICs that are meant to be used in instance communication. |
|
1828 |
This function checks the existing TAP interfaces in order to find |
|
1829 |
a unique name for the new TAP network interface. The TAP network |
|
1830 |
interface names are of the form 'gnt.com.%d', where '%d' is a |
|
1831 |
unique number within the node. |
|
1832 |
|
|
1833 |
@type nic: ganeti.objects.NIC |
|
1834 |
@param nic: NIC object for the name should be generated |
|
1835 |
|
|
1836 |
@rtype: string |
|
1837 |
@return: TAP network interface name, or the empty string if the |
|
1838 |
NIC is not used in instance communication |
|
1839 |
|
|
1840 |
""" |
|
1841 |
if nic.name is None or not \ |
|
1842 |
nic.name.startswith(constants.INSTANCE_COMMUNICATION_NIC_PREFIX): |
|
1843 |
return "" |
|
1844 |
|
|
1845 |
result = utils.RunCmd(["ip", "tuntap", "list"]) |
|
1846 |
|
|
1847 |
if result.failed: |
|
1848 |
raise errors.HypervisorError("Failed to list TUN/TAP interfaces") |
|
1849 |
|
|
1850 |
idxs = set() |
|
1851 |
|
|
1852 |
for line in result.output.splitlines(): |
|
1853 |
parts = line.split(": ", 1) |
|
1854 |
|
|
1855 |
if len(parts) < 2: |
|
1856 |
raise errors.HypervisorError("Failed to parse TUN/TAP interfaces") |
|
1857 |
|
|
1858 |
r = re.match(r"gnt\.com\.([0-9]+)", parts[0]) |
|
1859 |
|
|
1860 |
if r is not None: |
|
1861 |
idxs.add(int(r.group(1))) |
|
1862 |
|
|
1863 |
if idxs: |
|
1864 |
idx = max(idxs) + 1 |
|
1865 |
else: |
|
1866 |
idx = 0 |
|
1867 |
|
|
1868 |
return "gnt.com.%d" % idx |
|
1869 |
|
|
1822 | 1870 |
# too many local variables |
1823 | 1871 |
# pylint: disable=R0914 |
1824 | 1872 |
def _ExecuteKVMRuntime(self, instance, kvm_runtime, kvmhelp, incoming=None): |
... | ... | |
1904 | 1952 |
kvm_supports_netdev = self._NETDEV_RE.search(kvmhelp) |
1905 | 1953 |
|
1906 | 1954 |
for nic_seq, nic in enumerate(kvm_nics): |
1907 |
tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr) |
|
1955 |
tapname, tapfd = _OpenTap(vnet_hdr=vnet_hdr, |
|
1956 |
name=self._GenerateTapName(nic)) |
|
1908 | 1957 |
tapfds.append(tapfd) |
1909 | 1958 |
taps.append(tapname) |
1910 | 1959 |
if kvm_supports_netdev: |
Also available in: Unified diff