diff options
author | George Paraskevopoulos <geopar@intracom-telecom.com> | 2017-03-20 12:15:19 +0200 |
---|---|---|
committer | George Paraskevopoulos <geopar@intracom-telecom.com> | 2017-03-20 12:15:19 +0200 |
commit | 3097fef23e4ae1c89b535c1d890e44710b33eea4 (patch) | |
tree | 0cb8254f52efe82f58ac7d8ccd1d0c187772b0d8 | |
parent | a4d32bd049e4a0a6b5f17a02be375db6bcdca8db (diff) |
Cleanup IETF-ACL in OpenDaylight
Change-Id: I6914a5fbe7eb30b2d76b89d8f38b7d3d16e7b44a
Signed-off-by: George Paraskevopoulos <geopar@intracom-telecom.com>
-rw-r--r-- | sfc/lib/cleanup.py | 8 | ||||
-rw-r--r-- | sfc/lib/utils.py | 28 |
2 files changed, 36 insertions, 0 deletions
diff --git a/sfc/lib/cleanup.py b/sfc/lib/cleanup.py index 34ace201..ebcb9aa9 100644 --- a/sfc/lib/cleanup.py +++ b/sfc/lib/cleanup.py @@ -18,6 +18,13 @@ def delete_odl_resources(odl_ip, odl_port, resource): utils.delete_odl_resource_elem(odl_ip, odl_port, resource, elem) +def delete_odl_ietf_access_lists(odl_ip, odl_port): + acl_list = utils.get_odl_acl_list(odl_ip, odl_port) + acl_types_names = utils.odl_acl_types_names(acl_list) + for acl_type, acl_name in acl_types_names: + utils.delete_odl_acl(odl_ip, odl_port, acl_type, acl_name) + + def delete_vnfds(): t = os_tacker.get_tacker_client() vnfds = os_tacker.list_vnfds(t) @@ -92,6 +99,7 @@ def cleanup_odl(odl_ip, odl_port): delete_odl_resources(odl_ip, odl_port, 'service-function-chain') delete_odl_resources(odl_ip, odl_port, 'service-function-path') delete_odl_resources(odl_ip, odl_port, 'service-function') + delete_odl_ietf_access_lists(odl_ip, odl_port) def cleanup(odl_ip=None, odl_port=None): diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index 99f0bb75..f0f24338 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -522,3 +522,31 @@ def get_odl_resource_list(odl_ip, odl_port, resource): def delete_odl_resource_elem(odl_ip, odl_port, resource, elem_name): url = format_odl_resource_elem_url(odl_ip, odl_port, resource, elem_name) requests.delete(url) + + +def odl_acl_types_names(acl_json): + if len(acl_json['access-lists'].items()) == 0: + return [] + return [(acl['acl-type'], acl['acl-name']) + for acl in acl_json['access-lists']['acl']] + + +def format_odl_acl_list_url(odl_ip, odl_port, + odl_user='admin', odl_pwd='admin'): + acl_list_url = ('http://{usr}:{pwd}@{ip}:{port}/restconf/config/' + 'ietf-access-control-list:access-lists' + .format(usr=odl_user, pwd=odl_pwd, + ip=odl_ip, port=odl_port)) + return acl_list_url + + +def get_odl_acl_list(odl_ip, odl_port): + acl_list_url = format_odl_acl_list_url(odl_ip, odl_port) + r = requests.get(acl_list_url) + return r.json() + + +def delete_odl_acl(odl_ip, odl_port, acl_type, acl_name): + acl_list_url = format_odl_acl_list_url(odl_ip, odl_port) + acl_url = '{0}/acl/{1}/{2}'.format(acl_list_url, acl_type, acl_name) + requests.delete(acl_url) |