Add openvpn TUN and TAP interfaces support, change type to Virtual and remove mac address (#132)
* Add Tun and Tap support, change type to Virtual and remove mac address * Simplify * Resimplify
This commit is contained in:
parent
683e6cacb1
commit
754a284fd1
1 changed files with 22 additions and 6 deletions
|
@ -90,6 +90,12 @@ class Network(object):
|
||||||
bonding_slaves = open(
|
bonding_slaves = open(
|
||||||
'/sys/class/net/{}/bonding/slaves'.format(interface)
|
'/sys/class/net/{}/bonding/slaves'.format(interface)
|
||||||
).read().split()
|
).read().split()
|
||||||
|
|
||||||
|
# Tun and TAP support
|
||||||
|
virtual = os.path.isfile(
|
||||||
|
'/sys/class/net/{}/tun_flags'.format(interface)
|
||||||
|
)
|
||||||
|
|
||||||
nic = {
|
nic = {
|
||||||
'name': interface,
|
'name': interface,
|
||||||
'mac': mac if mac != '00:00:00:00:00:00' else None,
|
'mac': mac if mac != '00:00:00:00:00:00' else None,
|
||||||
|
@ -100,6 +106,7 @@ class Network(object):
|
||||||
) for x in ip_addr
|
) for x in ip_addr
|
||||||
] if ip_addr else None, # FIXME: handle IPv6 addresses
|
] if ip_addr else None, # FIXME: handle IPv6 addresses
|
||||||
'ethtool': Ethtool(interface).parse(),
|
'ethtool': Ethtool(interface).parse(),
|
||||||
|
'virtual': virtual,
|
||||||
'vlan': vlan,
|
'vlan': vlan,
|
||||||
'bonding': bonding,
|
'bonding': bonding,
|
||||||
'bonding_slaves': bonding_slaves,
|
'bonding_slaves': bonding_slaves,
|
||||||
|
@ -159,6 +166,10 @@ class Network(object):
|
||||||
|
|
||||||
if nic.get('bonding'):
|
if nic.get('bonding'):
|
||||||
return self.dcim_choices['interface:type']['Link Aggregation Group (LAG)']
|
return self.dcim_choices['interface:type']['Link Aggregation Group (LAG)']
|
||||||
|
|
||||||
|
if nic.get('virtual'):
|
||||||
|
return self.dcim_choices['interface:type']['Virtual']
|
||||||
|
|
||||||
if nic.get('ethtool') is None:
|
if nic.get('ethtool') is None:
|
||||||
return self.dcim_choices['interface:type']['Other']
|
return self.dcim_choices['interface:type']['Other']
|
||||||
|
|
||||||
|
@ -237,13 +248,18 @@ class Network(object):
|
||||||
name=nic['name'], mac=nic['mac'], device=self.device.name))
|
name=nic['name'], mac=nic['mac'], device=self.device.name))
|
||||||
|
|
||||||
nb_vlan = None
|
nb_vlan = None
|
||||||
interface = self.nb_net.interfaces.create(
|
|
||||||
name=nic['name'],
|
params = {
|
||||||
mac_address=nic['mac'],
|
'name': nic['name'],
|
||||||
type=type,
|
'type': type,
|
||||||
mgmt_only=mgmt,
|
'mgmt_only': mgmt,
|
||||||
**self.custom_arg,
|
**self.custom_arg,
|
||||||
)
|
}
|
||||||
|
|
||||||
|
if not nic.get('virtual', False):
|
||||||
|
params['mac_address'] = nic['mac']
|
||||||
|
|
||||||
|
interface = self.nb_net.interfaces.create(**params)
|
||||||
|
|
||||||
if nic['vlan']:
|
if nic['vlan']:
|
||||||
nb_vlan = self.get_or_create_vlan(nic['vlan'])
|
nb_vlan = self.get_or_create_vlan(nic['vlan'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue