Skip to content

Commit

Permalink
updated method documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel W. King committed Aug 19, 2020
1 parent c916569 commit 0ccbff8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
43 changes: 28 additions & 15 deletions plugins/module_utils/Pensando.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
#
# Copyright (c) 2020 World Wide Technology, LLC
# All rights reserved.

#
# author: Joel W. King @joelwking
#
# linter: flake8
# [flake8]
# max-line-length = 160
# ignore = E402
#
import time
import json
import requests
Expand Down Expand Up @@ -56,7 +63,7 @@ def login(self, tenant='default'):
try:
r = requests.request('POST', 'https://{}/{}/login'.format(self.hostname, self.api_version), headers=self.headers, data=payload, verify=self.verify)
except requests.ConnectionError as e:
return ConnectionError(text='Timeout in Login: {}'.format(e))
return ConnectionError(text='Timeout in Login: {}'.format(e))

if r.ok:
self.cookie = dict(sid=r.cookies.get('sid'))
Expand All @@ -79,7 +86,7 @@ def rate_limit(self, verb, url, **kwargs):
return ConnectionError(text='Timeout in rate_limit: {}'.format(e))

if r.status_code == requests.codes.TOO_MANY_REQUESTS:
time.sleep(int(r.headers.get("Retry-After", 1))) # TODO, verify, this is from Meraki
time.sleep(int(r.headers.get("Retry-After", 1))) # TODO, verify
else:
return r
return r
Expand All @@ -94,8 +101,8 @@ def query_policy(self, policy_name=None):
url = '/configs/security/{}/networksecuritypolicies'

if policy_name:
url = '/configs/security/{}/networksecuritypolicies{}'.format('{}', '/'+ policy_name)
url = '/configs/security/{}/networksecuritypolicies{}'.format('{}', '/' + policy_name)

return self.rate_limit('GET', url)

def manage_policy(self, params):
Expand All @@ -117,8 +124,8 @@ def manage_policy(self, params):
"tenant": params.get('tenant'),
"namespace": params.get('namespace')
},
"spec": {"attach-tenant": params.get('attach_tenant'),
"rules": params.get('rules')
"spec": {"attach-tenant": params.get('attach_tenant'),
"rules": params.get('rules')
}
}

Expand All @@ -138,7 +145,7 @@ def manage_policy(self, params):

if policy.status_code == requests.codes.OK:
self.changed = True

return policy

def policy_payload(self, params, payload, policy):
Expand All @@ -156,9 +163,16 @@ def policy_payload(self, params, payload, policy):

def manage_app(self, params):
"""
Logic to apply or update an App
Logic to create an App. We have not implemented updating existing apps. If you need to update an app,
create a new app with a unique name, then update the network security policy to reference the new app,
then delete the old app.
This is a similar approach to the method used to update ACLs on Cisco routers, create a new ACL, then
refrence the new ACL on the interface.
We check for an existing app name and payload, but at this point allow the API to fail.
TODO this method is only preliminary code !!!
Return the Requests object which contains the details of the app.
"""

url = '/configs/security/{}/apps'
Expand All @@ -169,20 +183,19 @@ def manage_app(self, params):
"tenant": params.get('tenant'),
"namespace": params.get('namespace')
},
"spec": {}
"spec": {}
}

if params.get('alg'):
payload['spec']['alg'] = params.get('alg')
if params.get('proto_ports'):
payload['spec']['proto-ports'] = self.remove_dups(params.get('proto_ports'))

# Verify the user specified 'alg' or 'proto_ports', (both is also acceptable)
if len(payload['spec']) == 0:
pass # Allow POST to fail, with RC=400 ["app doesn't have at least one of ProtoPorts and ALG"]
if len(payload['spec']) == 0: # Verify the user specified 'alg' or 'proto_ports', (both is also acceptable)
pass # Allow POST to fail, with RC=400 ["app doesn't have at least one of ProtoPorts and ALG"]

if self.existing_app(params.get('app_name')):
pass # Allow POST to fail, with RC=409 ["already exists in cache"]
pass # Allow POST to fail, with RC=409 ["already exists in cache"]

app = self.rate_limit('POST', url, data=json.dumps(payload))

Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Copyright (c) 2020 World Wide Technology, LLC
# All rights reserved.
#
# author: Joel W. King @joelwking
#
# linter: flake8
# [flake8]
# max-line-length = 160
Expand Down
2 changes: 2 additions & 0 deletions plugins/modules/network_security_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Copyright (c) 2020 World Wide Technology, LLC
# All rights reserved.
#
# author: Joel W. King @joelwking
#
# linter: flake8
# [flake8]
# max-line-length = 160
Expand Down

0 comments on commit 0ccbff8

Please sign in to comment.