1010import re
1111
1212from .constants import (
13+ DYNAMIC_PROTOCOLS ,
14+ DYNAMIC_PROTOCOLS_ALIAS ,
1315 GLOBAL_BINDING_ARG_LIST ,
1416 HTTP_RESOURCE_ALREADY_EXISTS ,
1517 HTTP_RESOURCE_NOT_FOUND ,
@@ -94,16 +96,29 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
9496 args = get_args ,
9597 )
9698 else :
97- status_code , response_body = client .get (
98- resource = resource_name ,
99- id = resource_id ,
100- args = get_args ,
101- )
99+ if resource_name in DYNAMIC_PROTOCOLS :
100+ new_resource_name = (
101+ "routerDynamicRouting/" + DYNAMIC_PROTOCOLS_ALIAS [resource_name ]
102+ )
103+ status_code , response_body = client .get (
104+ resource = new_resource_name ,
105+ id = resource_id ,
106+ args = get_args ,
107+ )
108+ else :
109+ status_code , response_body = client .get (
110+ resource = resource_name ,
111+ id = resource_id ,
112+ args = get_args ,
113+ )
102114 if status_code in {HTTP_RESOURCE_NOT_FOUND }:
103115 return False , []
104116 if status_code in HTTP_SUCCESS_CODES :
105117 # for zero bindings and some resources, the response_body will be {'errorcode': 0, 'message': 'Done', 'severity': 'NONE'}
106- if resource_name not in response_body :
118+ if (
119+ resource_name not in response_body
120+ and resource_name not in DYNAMIC_PROTOCOLS
121+ ):
107122 if resource_name == "sslcipher" :
108123 resource_primary_key = NITRO_RESOURCE_MAP [resource_name ]["primary_key" ]
109124 return True , [
@@ -112,7 +127,12 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
112127
113128 return False , []
114129 # `update-only` resources return a dict instead of a list.
115- return_response = response_body [resource_name ]
130+ if resource_name in DYNAMIC_PROTOCOLS :
131+ return_response = response_body .get ("routerDynamicRouting" , {}).get (
132+ DYNAMIC_PROTOCOLS_ALIAS [resource_name ], {}
133+ )
134+ else :
135+ return_response = response_body [resource_name ]
116136 # FIXME: NITRO-BUG: for some resources like `policypatset_pattern_binding`, NITRO returns keys with uppercase. eg: `String` for `string`.
117137 # So, we are converting the keys to lowercase.
118138 # except for `ping` and `traceroute`, all the othe resources returns a keys with lowercase.
@@ -242,7 +262,6 @@ def _check_create_resource_params(resource_name, resource_module_params, action=
242262 key , resource_name , action .upper ()
243263 )
244264 )
245-
246265 return True , None , post_data
247266
248267
@@ -281,7 +300,11 @@ def create_resource(client, resource_name, resource_module_params, action=None):
281300 if not ok :
282301 return False , err
283302
284- post_data = {resource_name : post_data }
303+ if resource_name in DYNAMIC_PROTOCOLS :
304+ post_data = {DYNAMIC_PROTOCOLS_ALIAS [resource_name ]: post_data }
305+ post_data = {"routerDynamicRouting" : post_data }
306+ else :
307+ post_data = {resource_name : post_data }
285308 status_code , response_body = client .post (
286309 post_data = post_data ,
287310 resource = resource_name ,
@@ -355,7 +378,11 @@ def update_resource(client, resource_name, resource_module_params):
355378 if not ok :
356379 return False , err
357380
358- put_data = {resource_name : put_payload }
381+ if resource_name in DYNAMIC_PROTOCOLS :
382+ put_data = {DYNAMIC_PROTOCOLS_ALIAS [resource_name ]: put_payload }
383+ put_data = {"routerDynamicRouting" : put_data }
384+ else :
385+ put_data = {resource_name : put_payload }
359386
360387 status_code , response_body = client .put (
361388 put_data = put_data ,
0 commit comments