Browse Source

api docs update and vlan_name handling

Change-Id: I1750251e17d31d61cf61b1cea6065c138e3d6ced
changes/62/625662/4
Dan Radez 6 months ago
parent
commit
61cf9d9f49
2 changed files with 33 additions and 15 deletions
  1. 31
    14
      networking_ansible/api.py
  2. 2
    1
      networking_ansible/tests/unit/test_api.py

+ 31
- 14
networking_ansible/api.py View File

@@ -28,20 +28,22 @@ class NetworkingAnsible(object):
28 28
     def __init__(self, inventory):
29 29
         self.inventory = inventory
30 30
 
31
-    def _run_task(self, task, hostname, port=None, vlan_id=None):
31
+    def _run_task(self, task, hostname,
32
+                  port=None, vlan_id=None, vlan_name=None):
32 33
         """Run a task.
33 34
 
34 35
         :param task: name of task in openstack-ml2 ansible role
35
-        :param host_name: name of a host defined in ml2 conf ini files
36
-        :param vlan_id: vlan id of the network
37
-        :param switch_port: port name on the switch (optional)
36
+        :param hostname: name of a host defined in ml2 conf ini files
37
+        :param port: switchport name on the switch (optional)
38
+        :param vlan_id: VLAN ID of the network
39
+        :param vlan_name: VLAN's name/description
38 40
 
39 41
         See etc/ansible/roles/openstack-ml2/README.md for an exmaple playbook
40 42
         """
41 43
 
42 44
         # build out the ansible playbook
43 45
         playbook = [{
44
-            'name': 'Openstack networking-ansible playbook',
46
+            'name': 'Openstack Networking-Ansible: '.format(task.capitalize()),
45 47
             'hosts': hostname,
46 48
             'gather_facts': 'no',  # no need to gather facts every run
47 49
             'tasks': [{
@@ -55,6 +57,8 @@ class NetworkingAnsible(object):
55 57
                 }
56 58
             }]
57 59
         }]
60
+        if vlan_name:
61
+            playbook[0]['tasks'][0]['vars']['vlan_name'] = vlan_name
58 62
         if port:
59 63
             playbook[0]['tasks'][0]['vars']['port'] = port
60 64
             playbook[0]['tasks'][0]['vars']['port_description'] = port
@@ -69,26 +73,39 @@ class NetworkingAnsible(object):
69 73
             raise exceptions.AnsibleRunnerException(' '.join(result.stdout))
70 74
         return result
71 75
 
72
-    def create_vlan(self, hostname, vlan_id):
76
+    def create_vlan(self, hostname, vlan_id, vlan_name=None):
77
+        """Create VLAN.
78
+
79
+        :param hostname: The name of the host in Ansible inventory.
80
+        :param vlan_id: The VLAN's ID to create.
81
+        :param vlan_name: The VLAN's name/description.
82
+        """
73 83
         return self._run_task('create_vlan', hostname, vlan_id=vlan_id)
74 84
 
75 85
     def delete_vlan(self, hostname, vlan_id):
86
+        """Delete VLAN.
87
+
88
+        :param hostname: The name of the host in Ansible inventory.
89
+        :param vlan_id: The VLAN's ID to delete.
90
+        """
76 91
         return self._run_task('delete_vlan', hostname, vlan_id=vlan_id)
77 92
 
78 93
     def update_access_port(self, hostname, port, vlan_id):
79
-        """Configure access port on a vlan or shutdown the port.
80
-
81
-        If the configuration required to unplug the port is not present
82
-        (e.g. local link information), the port will not be unplugged and no
83
-        exception will be raised.
94
+        """Configure access port on a vlan.
84 95
 
85 96
         :param hostname: The name of the host in Ansible inventory.
86 97
         :param port: The port to configure.
87
-        :param lan_id: The vlan_id to assign to the port.
88
-                       An empty is will get translated in Ansible to the
89
-                       target device's default VLAN assignment.
98
+        :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
90 102
         """
91 103
         return self._run_task('update_access_port', hostname, port, vlan_id)
92 104
 
93 105
     def delete_port(self, hostname, port):
106
+        """Delete port configuration.
107
+
108
+        :param hostname: The name of the host in Ansible inventory.
109
+        :param port: The port to configure.
110
+        """
94 111
         return self._run_task('delete_port', hostname, port)

+ 2
- 1
networking_ansible/tests/unit/test_api.py View File

@@ -45,7 +45,8 @@ class TestRunTask(base.NetworkingAnsibleTestCase):
45 45
         mock_result.stats = {'failures': []}
46 46
 
47 47
         self.mech.ansnet._run_task('fake_task',
48
-                                   self.testhost)
48
+                                   self.testhost,
49
+                                   vlan_name='test_vlan')
49 50
         # Assert switch_port is not set
50 51
         self.assertNotIn('port',
51 52
                          mock_ans_runner.run.call_args[1]['playbook'][0]

Loading…
Cancel
Save