From 3097fef23e4ae1c89b535c1d890e44710b33eea4 Mon Sep 17 00:00:00 2001 From: George Paraskevopoulos Date: Mon, 20 Mar 2017 12:15:19 +0200 Subject: Cleanup IETF-ACL in OpenDaylight Change-Id: I6914a5fbe7eb30b2d76b89d8f38b7d3d16e7b44a Signed-off-by: George Paraskevopoulos --- sfc/lib/cleanup.py | 8 ++++++++ sfc/lib/utils.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) 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) -- cgit 1.2.3-korg