mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 22:33:25 +00:00
nmcli: Introduce VxLan (#45932)
This work enables to add vxlan via nmcli module
```
- nmcli:
type: vxlan
conn_name: vxlan_test1
vxlan_id: 16
vxlan_local: 192.168.1.2
vxlan_remote: 192.168.1.5
```
ansible 2.8.0
revision 1: Added tests
Signed-off-by: Susant Sahani <susant@redhat.com>
This commit is contained in:
@@ -53,7 +53,7 @@ options:
|
||||
description:
|
||||
- This is the type of device or network connection that you wish to create or modify.
|
||||
- "type C(generic) is added in version 2.5."
|
||||
choices: [ ethernet, team, team-slave, bond, bond-slave, bridge, bridge-slave, vlan, generic ]
|
||||
choices: [ ethernet, team, team-slave, bond, bond-slave, bridge, bridge-slave, vlan, vxlan, generic ]
|
||||
mode:
|
||||
description:
|
||||
- This is the type of device or network connection that you wish to create for a bond, team or bridge.
|
||||
@@ -174,7 +174,18 @@ options:
|
||||
egress:
|
||||
description:
|
||||
- This is only used with VLAN - VLAN egress priority mapping
|
||||
|
||||
vxlan_id:
|
||||
description:
|
||||
- This is only used with VXLAN - VXLAN ID.
|
||||
version_added: "2.8"
|
||||
vxlan_remote:
|
||||
description:
|
||||
- This is only used with VXLAN - VXLAN destination IP address.
|
||||
version_added: "2.8"
|
||||
vxlan_local:
|
||||
description:
|
||||
- This is only used with VXLAN - VXLAN local IP address.
|
||||
version_added: "2.8"
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
@@ -434,6 +445,14 @@ EXAMPLES = '''
|
||||
type: ethernet
|
||||
state: present
|
||||
|
||||
# To add VxLan, issue a command as follows:
|
||||
- nmcli:
|
||||
type: vxlan
|
||||
conn_name: vxlan_test1
|
||||
vxlan_id: 16
|
||||
vxlan_local: 192.168.1.2
|
||||
vxlan_remote: 192.168.1.5
|
||||
|
||||
# nmcli exits with status 0 if it succeeds and exits with a status greater
|
||||
# than zero when there is a failure. The following list of status codes may be
|
||||
# returned:
|
||||
@@ -505,7 +524,8 @@ class Nmcli(object):
|
||||
12: "ADSL",
|
||||
13: "Bridge",
|
||||
14: "Generic",
|
||||
15: "Team"
|
||||
15: "Team",
|
||||
16: "VxLan",
|
||||
}
|
||||
STATES = {
|
||||
0: "Unknown",
|
||||
@@ -562,6 +582,9 @@ class Nmcli(object):
|
||||
self.flags = module.params['flags']
|
||||
self.ingress = module.params['ingress']
|
||||
self.egress = module.params['egress']
|
||||
self.vxlan_id = module.params['vxlan_id']
|
||||
self.vxlan_local = module.params['vxlan_local']
|
||||
self.vxlan_remote = module.params['vxlan_remote']
|
||||
self.nmcli_bin = self.module.get_bin_path('nmcli', True)
|
||||
self.dhcp_client_id = module.params['dhcp_client_id']
|
||||
|
||||
@@ -1072,6 +1095,53 @@ class Nmcli(object):
|
||||
|
||||
return cmd
|
||||
|
||||
def create_connection_vxlan(self):
|
||||
cmd = [self.nmcli_bin, 'con', 'add', 'type', 'vxlan', 'con-name']
|
||||
|
||||
if self.conn_name is not None:
|
||||
cmd.append(self.conn_name)
|
||||
elif self.ifname is not None:
|
||||
cmd.append(self.ifname)
|
||||
else:
|
||||
cmd.append('vxlan%s' % self.vxlanid)
|
||||
|
||||
cmd.append('ifname')
|
||||
if self.ifname is not None:
|
||||
cmd.append(self.ifname)
|
||||
elif self.conn_name is not None:
|
||||
cmd.append(self.conn_name)
|
||||
else:
|
||||
cmd.append('vxan%s' % self.vxlanid)
|
||||
|
||||
params = {'vxlan.id': self.vxlan_id,
|
||||
'vxlan.local': self.vxlan_local,
|
||||
'vxlan.remote': self.vxlan_remote,
|
||||
'autoconnect': self.bool_to_string(self.autoconnect)
|
||||
}
|
||||
for k, v in params.items():
|
||||
cmd.extend([k, v])
|
||||
|
||||
return cmd
|
||||
|
||||
def modify_connection_vxlan(self):
|
||||
cmd = [self.nmcli_bin, 'con', 'mod']
|
||||
|
||||
if self.conn_name is not None:
|
||||
cmd.append(self.conn_name)
|
||||
elif self.ifname is not None:
|
||||
cmd.append(self.ifname)
|
||||
else:
|
||||
cmd.append('vxlan%s' % self.vxlanid)
|
||||
|
||||
params = {'vxlan.id': self.vxlan_id,
|
||||
'vxlan.local': self.vxlan_local,
|
||||
'vxlan.remote': self.vxlan_remote,
|
||||
'autoconnect': self.bool_to_string(self.autoconnect)
|
||||
}
|
||||
for k, v in params.items():
|
||||
cmd.extend([k, v])
|
||||
return cmd
|
||||
|
||||
def create_connection(self):
|
||||
cmd = []
|
||||
if self.type == 'team':
|
||||
@@ -1117,6 +1187,8 @@ class Nmcli(object):
|
||||
cmd = self.create_connection_bridge_slave()
|
||||
elif self.type == 'vlan':
|
||||
cmd = self.create_connection_vlan()
|
||||
elif self.type == 'vxlan':
|
||||
cmd = self.create_connection_vxlan()
|
||||
elif self.type == 'generic':
|
||||
cmd = self.create_connection_ethernet(conn_type='generic')
|
||||
|
||||
@@ -1149,6 +1221,8 @@ class Nmcli(object):
|
||||
cmd = self.modify_connection_bridge_slave()
|
||||
elif self.type == 'vlan':
|
||||
cmd = self.modify_connection_vlan()
|
||||
elif self.type == 'vxlan':
|
||||
cmd = self.modify_connection_vxlan()
|
||||
elif self.type == 'generic':
|
||||
cmd = self.modify_connection_ethernet(conn_type='generic')
|
||||
if cmd:
|
||||
@@ -1170,7 +1244,7 @@ def main():
|
||||
type=dict(required=False, default=None,
|
||||
choices=['ethernet', 'team', 'team-slave', 'bond',
|
||||
'bond-slave', 'bridge', 'bridge-slave',
|
||||
'vlan', 'generic'],
|
||||
'vlan', 'vxlan', 'generic'],
|
||||
type='str'),
|
||||
ip4=dict(required=False, default=None, type='str'),
|
||||
gw4=dict(required=False, default=None, type='str'),
|
||||
@@ -1209,6 +1283,10 @@ def main():
|
||||
flags=dict(required=False, default=None, type='str'),
|
||||
ingress=dict(required=False, default=None, type='str'),
|
||||
egress=dict(required=False, default=None, type='str'),
|
||||
# vxlan specific vars
|
||||
vxlan_id=dict(required=False, default=None, type='str'),
|
||||
vxlan_local=dict(required=False, default=None, type='str'),
|
||||
vxlan_remote=dict(required=False, default=None, type='str'),
|
||||
),
|
||||
supports_check_mode=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user