Browse Source

Adding API Trunk stub

Support for each provider should be added one at a time after this
patch. This patch just lays the framework for providers to be enabled.

Change-Id: I958520584f1784fa49d82778d004dced00b8a0c6
Dan Radez 4 months ago
parent
commit
2969496314

+ 4
- 0
doc/source/contributor/provider.rst View File

@@ -39,6 +39,10 @@ networking-ansible.
39 39
 
40 40
   Defines the Ansible tasks to assign a VLAN to a switchport in access mode.
41 41
 
42
+* conf_trunk_port.yaml
43
+
44
+  Defines the Ansible tasks to configure a switchport in trunk mode.
45
+
42 46
 * delete_port.yaml
43 47
 
44 48
   Defines the Ansible tasks to remove configuration from a switchport.

+ 2
- 0
doc/source/user/api.rst View File

@@ -50,6 +50,8 @@ execute switch level network configuration.
50 50
       net_ans.create_vlan(host, vlan_id)
51 51
       # configure a port in access mode on the VLAN
52 52
       net_ans.update_access_port(host, port, vlan_id)
53
+      # configure a port in trunk mode with default VLAN and additional vlan
54
+      net_ans.conf_trunk_port(host, port, vlan_id, [73])
53 55
       # shutdown the port
54 56
       net_ans.delete_port(host, port)
55 57
       # delete the VLAN

+ 3
- 0
etc/ansible/roles/openstack-ml2/defaults/main.yml View File

@@ -1,4 +1,7 @@
1 1
 ---
2
+# params to impliment trunking
3
+trunked_vlans: "{{ trunked_vlans }}"
4
+
2 5
 # params to implement port resource
3 6
 #
4 7
 port_name: "{{ port_name }}"

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/cumulus/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for cumulus

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/eos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for eos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/junos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for junos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/nxos/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for nxos

+ 3
- 0
etc/ansible/roles/openstack-ml2/providers/openvswitch/conf_trunk_port.yaml View File

@@ -0,0 +1,3 @@
1
+---
2
+- fail:
3
+    msg: Trunk port configuration is not implimented for openvswitch

+ 19
- 0
etc/ansible/roles/openstack-ml2/tasks/conf_trunk_port.yaml View File

@@ -0,0 +1,19 @@
1
+---
2
+# delegate task to localhost to avoid starting the device connection
3
+- name: "check for required fact: port"
4
+  fail:
5
+    msg: "missing required fact: port"
6
+  when: not port
7
+  delegate_to: localhost
8
+
9
+# delegate task to localhost to avoid starting the device connection
10
+- name: "check for required fact: port_description"
11
+  fail:
12
+    msg: "missing required fact: port_description"
13
+  when: not port_description
14
+  delegate_to: localhost
15
+
16
+- name: include and run device provider specific tasks
17
+  include_tasks: run.yaml
18
+  vars:
19
+    network_action: conf_trunk_port

+ 3
- 0
etc/ansible/roles/openstack-ml2/vars/main.yml View File

@@ -3,6 +3,9 @@
3 3
 vlan_id: null
4 4
 vlan_name: null
5 5
 
6
+# vars optional for managing trunk ports
7
+vlans: null
8
+
6 9
 # vars required for managing ports
7 10
 port_name: null
8 11
 port_description: null

+ 26
- 6
networking_ansible/api.py View File

@@ -29,17 +29,19 @@ class NetworkingAnsible(object):
29 29
         self.inventory = inventory
30 30
 
31 31
     def _run_task(self, task, hostname,
32
-                  port=None, vlan_id=None, vlan_name=None):
32
+                  port=None, vlan_id=None, vlan_name=None, trunked_vlans=None):
33 33
         """Run a task.
34 34
 
35 35
         :param task: name of task in openstack-ml2 ansible role
36
-        :param hostname: name of a host defined in ml2 conf ini files
36
+        :param hostname: name of a host defined in the ansible inventory
37 37
         :param port: switchport name on the switch (optional)
38
-        :param vlan_id: VLAN ID of the network
38
+        :param vlan_id: VLAN ID of the network, default VLAN for trunk ports
39 39
         :param vlan_name: VLAN's name/description
40
+        :param trunked_vlans: A list of VLAN's for trunk port configuration
40 41
 
41 42
         See etc/ansible/roles/openstack-ml2/README.md for an exmaple playbook
42 43
         """
44
+        trunked_vlans = trunked_vlans or []
43 45
 
44 46
         # build out the ansible playbook
45 47
         playbook = [{
@@ -59,6 +61,8 @@ class NetworkingAnsible(object):
59 61
         }]
60 62
         if vlan_name:
61 63
             playbook[0]['tasks'][0]['vars']['vlan_name'] = vlan_name
64
+        if trunked_vlans:
65
+            playbook[0]['tasks'][0]['vars']['trunked_vlans'] = trunked_vlans
62 66
         if port:
63 67
             playbook[0]['tasks'][0]['vars']['port_name'] = port
64 68
             playbook[0]['tasks'][0]['vars']['port_description'] = port
@@ -96,12 +100,28 @@ class NetworkingAnsible(object):
96 100
         :param hostname: The name of the host in Ansible inventory.
97 101
         :param port: The port to configure.
98 102
         :param vlan_id: The vlan_id to assign to the port.
99
-                       An empty or None value will default to the
100
-                       target device's default VLAN assignment. This
101
-                       default is assigned in the ansible role
103
+                        An empty or None value will default to the
104
+                        target device's default VLAN assignment. This
105
+                        default is assigned in the ansible role.
102 106
         """
103 107
         return self._run_task('update_access_port', hostname, port, vlan_id)
104 108
 
109
+    def conf_trunk_port(self, hostname, port, vlan_id, trunked_vlans):
110
+        """Configure trunk port w/ default vlan and optional additional vlans
111
+
112
+        :param hostname: The name of the host in Ansible inventory.
113
+        :param port: The port to configure.
114
+        :param vlan_id: the default VLAN ID to assign to the port
115
+                        An empty or None value will default to the
116
+                        target device's default VLAN assignment. This
117
+                        default is assigned in the ansible role.
118
+        :param trunked_vlans: A list of VLAN IDs to add to the port in
119
+                              addition to the default VLAN.
120
+        """
121
+        return self._run_task('conf_trunk_port',
122
+                              hostname, port, vlan_id,
123
+                              trunked_vlans=trunked_vlans)
124
+
105 125
     def delete_port(self, hostname, port):
106 126
         """Delete port configuration.
107 127
 

Loading…
Cancel
Save