Add subscription event source plugin (DCNE-269)#712
Add subscription event source plugin (DCNE-269)#712jgomezve wants to merge 5 commits intoCiscoDevNet:masterfrom
Conversation
|
Fix #713 |
|
please run black and fix sanity issues |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
|
|
||
|
|
||
| def login(hostname: str, username: str, password: str) -> str: |
There was a problem hiding this comment.
is there a reason for not reusing the login functions from the ansible collection? can we reuse connection definitions from modules?
| return sub_ids | ||
|
|
||
|
|
||
| async def refresh(hostname: str, token: str, refresh_timeout: int, sub_ids: list[str]) -> NoReturn: |
There was a problem hiding this comment.
should we name the function refresh_subscription
| refresh_timeout = int(args.get("refresh_timeout", 300)) | ||
| subscriptions = args.get("subscriptions") | ||
|
|
||
| if "" in [hostname, username, password]: |
There was a problem hiding this comment.
should we also support private key as we do with modules? this would avoid the login step
| :param sub_ids: subscription ids | ||
| :return: NoReturn | ||
| """ | ||
| cookie = {"APIC-cookie": token} |
There was a problem hiding this comment.
can this token expire? or would the subscriptionRefresh also refresh the session?
| sys.exit(1) | ||
|
|
||
| if not isinstance(subscriptions, list) or subscriptions == [] or subscriptions is None: | ||
| print(f"subscriptions is empty or not a list: {subscriptions}") |
There was a problem hiding this comment.
would typically avoid or in errors, can we be more specific which case is triggering the error
|
|
||
| :param hostname: apic hostname or ip | ||
| :param token: apic session token | ||
| :param rf_timeout: refresh timeout of subscription |
There was a problem hiding this comment.
what is the metric of the timeout? seconds I assume?
| await asyncio.sleep(refresh_timeout / 2) | ||
| for sub_id in sub_ids: | ||
| refresh_url = f"https://{hostname}/api/subscriptionRefresh.json?id={sub_id}" | ||
| requests.get(refresh_url, verify=False, cookies=cookie, timeout=60) |
There was a problem hiding this comment.
should we do these request also async?
| - apic1: APIC IP or hostname | ||
| - username: APIC username | ||
| - password: APIC password | ||
| - subscriptions: query api endpoints for subscriptions |
There was a problem hiding this comment.
are there limits for amount of subscriptions, should we document this?
| An ansible-rulebook event source plugin template. | ||
|
|
||
| Arguments: | ||
| - apic1: APIC IP or hostname |
| @@ -0,0 +1,148 @@ | |||
| """ | |||
There was a problem hiding this comment.
please add author details and license info as we do for modules
No description provided.