summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2018-12-17 11:53:45 -0500
committerDan Radez <dradez@redhat.com>2018-12-21 15:17:33 -0500
commit61cf9d9f491aa5fd8e3609e04318282d2ab24ba7 (patch)
treed8a2de132005cd6173bf00bcc74157375c9c2fc0
parent5c346b9865332073daeba88adfa001fb2a85e1df (diff)
api docs update and vlan_name handling
Notes
Notes (review): Code-Review+2: Dan Radez <dradez@redhat.com> Workflow+1: Dan Radez <dradez@redhat.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Wed, 02 Jan 2019 20:34:01 +0000 Reviewed-on: https://review.openstack.org/625662 Project: openstack/networking-ansible Branch: refs/heads/master
-rw-r--r--networking_ansible/api.py45
-rw-r--r--networking_ansible/tests/unit/test_api.py3
2 files changed, 33 insertions, 15 deletions
diff --git a/networking_ansible/api.py b/networking_ansible/api.py
index 3443298..291073c 100644
--- a/networking_ansible/api.py
+++ b/networking_ansible/api.py
@@ -28,20 +28,22 @@ class NetworkingAnsible(object):
28 def __init__(self, inventory): 28 def __init__(self, inventory):
29 self.inventory = inventory 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 """Run a task. 33 """Run a task.
33 34
34 :param task: name of task in openstack-ml2 ansible role 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 hostname: name of a host defined in ml2 conf ini files
36 :param vlan_id: vlan id of the network 37 :param port: switchport name on the switch (optional)
37 :param switch_port: port 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 See etc/ansible/roles/openstack-ml2/README.md for an exmaple playbook 41 See etc/ansible/roles/openstack-ml2/README.md for an exmaple playbook
40 """ 42 """
41 43
42 # build out the ansible playbook 44 # build out the ansible playbook
43 playbook = [{ 45 playbook = [{
44 'name': 'Openstack networking-ansible playbook', 46 'name': 'Openstack Networking-Ansible: '.format(task.capitalize()),
45 'hosts': hostname, 47 'hosts': hostname,
46 'gather_facts': 'no', # no need to gather facts every run 48 'gather_facts': 'no', # no need to gather facts every run
47 'tasks': [{ 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 if port: 62 if port:
59 playbook[0]['tasks'][0]['vars']['port'] = port 63 playbook[0]['tasks'][0]['vars']['port'] = port
60 playbook[0]['tasks'][0]['vars']['port_description'] = port 64 playbook[0]['tasks'][0]['vars']['port_description'] = port
@@ -69,26 +73,39 @@ class NetworkingAnsible(object):
69 raise exceptions.AnsibleRunnerException(' '.join(result.stdout)) 73 raise exceptions.AnsibleRunnerException(' '.join(result.stdout))
70 return result 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 return self._run_task('create_vlan', hostname, vlan_id=vlan_id) 83 return self._run_task('create_vlan', hostname, vlan_id=vlan_id)
74 84
75 def delete_vlan(self, hostname, vlan_id): 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 return self._run_task('delete_vlan', hostname, vlan_id=vlan_id) 91 return self._run_task('delete_vlan', hostname, vlan_id=vlan_id)
77 92
78 def update_access_port(self, hostname, port, vlan_id): 93 def update_access_port(self, hostname, port, vlan_id):
79 """Configure access port on a vlan or shutdown the port. 94 """Configure access port on a vlan.
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.
84 95
85 :param hostname: The name of the host in Ansible inventory. 96 :param hostname: The name of the host in Ansible inventory.
86 :param port: The port to configure. 97 :param port: The port to configure.
87 :param lan_id: The vlan_id to assign to the port. 98 :param vlan_id: The vlan_id to assign to the port.
88 An empty is will get translated in Ansible to the 99 An empty or None value will default to the
89 target device's default VLAN assignment. 100 target device's default VLAN assignment. This
101 default is assigned in the ansible role
90 """ 102 """
91 return self._run_task('update_access_port', hostname, port, vlan_id) 103 return self._run_task('update_access_port', hostname, port, vlan_id)
92 104
93 def delete_port(self, hostname, port): 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 return self._run_task('delete_port', hostname, port) 111 return self._run_task('delete_port', hostname, port)
diff --git a/networking_ansible/tests/unit/test_api.py b/networking_ansible/tests/unit/test_api.py
index 0c9b53a..ad22496 100644
--- a/networking_ansible/tests/unit/test_api.py
+++ b/networking_ansible/tests/unit/test_api.py
@@ -45,7 +45,8 @@ class TestRunTask(base.NetworkingAnsibleTestCase):
45 mock_result.stats = {'failures': []} 45 mock_result.stats = {'failures': []}
46 46
47 self.mech.ansnet._run_task('fake_task', 47 self.mech.ansnet._run_task('fake_task',
48 self.testhost) 48 self.testhost,
49 vlan_name='test_vlan')
49 # Assert switch_port is not set 50 # Assert switch_port is not set
50 self.assertNotIn('port', 51 self.assertNotIn('port',
51 mock_ans_runner.run.call_args[1]['playbook'][0] 52 mock_ans_runner.run.call_args[1]['playbook'][0]