Skip to content

Commit

Permalink
2.9 fix and formatting changes
Browse files Browse the repository at this point in the history
- Fixes plugin to function with ansible version 2.9
- Formats modules and module_utils to pass ansible-sanity
- Syncronizes the modules available through AOS-CX collection
  • Loading branch information
tchiapuziowong committed Nov 13, 2019
1 parent ec4aee9 commit c6b90bb
Show file tree
Hide file tree
Showing 19 changed files with 820 additions and 766 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ Apache 2.0

Author Information
------------------
Madhusudan Pranav Venugopal (madhusudan-pranav-venugopal)
Yang Liu (yliu-aruba)
Tiffany Chiapuzio-Wong (tchiapuziowong)
- Madhusudan Pranav Venugopal (@madhusudan-pranav-venugopal)
- Yang Liu (@yliu-aruba)
- Tiffany Chiapuzio-Wong (@tchiapuziowong)

59 changes: 18 additions & 41 deletions httpapi_plugins/aoscx.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)


from __future__ import (absolute_import, division, print_function)
__metaclass__ = type


DOCUMENTATION = """
---
author: Aruba Networks
author: Aruba Networks (@ArubaNetworks)
httpapi: aoscx
short_description: Use REST to push configs to CX devices
description:
Expand All @@ -45,12 +38,10 @@
from ansible.module_utils.six.moves.urllib.error import HTTPError
from ansible.plugins.httpapi import HttpApiBase


try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
# Removed the exception handling as only required pre 2.8 and collection is
# supported in >= 2.9
from ansible.utils.display import Display
display = Display()


class HttpApi(HttpApiBase):
Expand All @@ -66,12 +57,14 @@ def set_no_proxy(self):

def login(self, username, password):
self.set_no_proxy()
path = '/rest/v1/login?username='+username+'&password='+password
path = ('/rest/v1/login?username={username}'
'&password={password}'.format(username=username,
password=password))
method = 'POST'
headers = {}

_ = self.send_request(data=None, path=path, method=method,
headers=headers)
self.send_request(data=None, path=path, method=method,
headers=headers)

def logout(self):
path = '/rest/v1/logout'
Expand Down Expand Up @@ -111,19 +104,3 @@ def handle_response(self, response, response_data):
self.connection._auth = auth
return response_data_json

def get_running_config(self):
if self.connection._connected:
path = '/rest/v1/fullconfigs/running-config'
method = 'GET'
data = None
response_data = self.send_request(data=data, method=method,
path=path)
display.vvvv(json.dumps(response_data))
return response_data

def put_running_config(self, updated_config):
if self.connection._connected:
path = '/rest/v1/fullconfigs/running-config'
method = 'PUT'
data = json.dumps(updated_config)
self.send_request(data=data, method=method, path=path)
38 changes: 18 additions & 20 deletions library/aoscx_acl.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#

# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)


from __future__ import (absolute_import, division, print_function)
__metaclass__ = type


ANSIBLE_METADATA = {
'metadata_version': '1.1',
Expand All @@ -28,30 +21,33 @@
version_added: "2.8"
short_description: Manage ACL configuration for AOS-CX.
description:
- This modules provides configuration management and creation of Access
Classifier Lists on AOS-CX devices.
author:
- Aruba Networks
- This modules provides configuration management and creation of Access Classifier Lists on AOS-CX devices.
author: Aruba Networks (@ArubaNetworks)
options:
name:
description: Name of the Access Classifier List
type: str
required: true
type:
description: Type of the Access Classifier List
type: str
choices: ['ipv4', 'ipv6', 'mac']
required: true
acl_entries:
description: "Dictionary of dictionaries of Access Classifier Entries
configured in Access Classifier List. Each entry key of the dictionary
should be the sequence number of the ACL entry. Each ACL entry dictionary
should have the minimum following keys - action , src_ip, dst_ip. See
below for examples of options and values."
type: dict
required: false
state:
description: Create, Update, or Delete Access Classifier List
type: str
choices: ['create', 'delete', 'update']
default: 'create'
required: false
'''
''' # NOQA

EXAMPLES = r'''
- name: Configure IPv4 ACL with entry - 1 deny tcp 10.10.12.12 10.10.12.11 count
Expand Down Expand Up @@ -137,7 +133,9 @@ def main():
name=dict(type='str', required=True),
type=dict(type='str', required=True, choices=['ipv4', 'ipv6', 'mac']),
acl_entries=dict(type='dict', default=None),
state=dict(default='create', choices=['create', 'delete', 'update'])
state=dict(type='str', default='create', choices=['create',
'delete',
'update'])
)

aruba_ansible_module = ArubaAnsibleModule(module_args=module_args)
Expand Down
61 changes: 33 additions & 28 deletions library/aoscx_acl_interface.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#

# (C) Copyright 2019 Hewlett Packard Enterprise Development LP.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)


from __future__ import (absolute_import, division, print_function)
__metaclass__ = type


ANSIBLE_METADATA = {
'metadata_version': '1.1',
Expand All @@ -29,35 +22,39 @@
short_description: Apply/Remove ACL configuration on interfaces for AOS-CX.
description:
- This modules provides application management of Access Classifier Lists
on Interfaces on AOS-CX devices.
author:
- Aruba Networks
on Interfaces on AOS-CX devices.
author: Aruba Networks (@ArubaNetworks)
options:
acl_name:
description: Name of the ACL being applied or removed from the interface.
required: true
type: str
acl_type:
description: Type of ACL being applied or removed from the interfaces.
choices: ['ipv4', 'ipv6', 'mac']
required: true
type: str
acl_interface_list:
description: List of interfaces for which the ACL is to be applied or
removed.
required: true
type: list
acl_direction:
description: Direction for which the ACL is to be applied or removed.
required: true
choices: ['in', 'out']
default: 'in'
type: str
state:
description: Create or delete the ACL configuration from the interfaces.
required: false
choices: ['create', 'delete']
default: create
type: str
'''

EXAMPLES = '''
Expand Down Expand Up @@ -110,9 +107,9 @@ def main():
for interface_name in acl_interface_list:
if not interface.check_interface_exists(aruba_ansible_module,
interface_name):
aruba_ansible_module.module.fail_json(msg="Interface {} is not "
aruba_ansible_module.module.fail_json(msg="Interface {int} is not "
"configured"
"".format(interface_name)
"".format(int=interface_name)
)

if (state == 'create') or (state == 'update'):
Expand All @@ -124,19 +121,27 @@ def main():
acl_direction, update_type)

if update_type == 'insert':
aruba_ansible_module.module.log(msg="Attached ACL {} of type "
"{} to interface {}"
"".format(acl_name,
acl_type,
interface_name))
aruba_ansible_module.module.log(msg="Attached ACL {acl} of type "
"{type} to interface {int}"
"".format(acl=acl_name,
type=acl_type,
int=interface_name))

if update_type == 'update':
aruba_ansible_module.module.log(msg="Updated ACL {} of type {} attached to interface {}".format(acl_name, acl_type, interface_name)) # NOQA
aruba_ansible_module.module.log(msg="Updated ACL {acl} of type "
"{type} attached to interface"
" {int}"
"".format(acl=acl_name,
type=acl_type,
int=interface_name)) # NOQA

if (update_type == 'absent') or (update_type == 'delete'):
aruba_ansible_module.module.log(
msg="Removed ACL {} of type {} from interface {}".format(
acl_name, acl_type, interface_name))
aruba_ansible_module.module.log(msg="Removed ACL {acl} of type"
" {type} from interface"
" {int}"
"".format(acl=acl_name,
type=acl_type,
int=interface_name))

aruba_ansible_module.update_switch_config()

Expand Down
Loading

0 comments on commit c6b90bb

Please sign in to comment.