diff --git a/cisco-apis/iosxe/add_static_routes.py b/cisco-apis/iosxe/add_static_routes.py index b80828f..e43fa02 100644 --- a/cisco-apis/iosxe/add_static_routes.py +++ b/cisco-apis/iosxe/add_static_routes.py @@ -23,7 +23,7 @@ def add_static_routes(): config = yaml.safe_load(conf) add_static_route_url = f"{BASE_URL}/ietf-routing:routing/routing-instance=default/routing-protocols/routing-protocol=static,1/static-routes/ipv4" - + response = requests.post(url=add_static_route_url, headers=headers, auth=(DEVICE_USER, DEVICE_PASS), json=config, verify=False) if response.status_code == 201: diff --git a/cisco-nso/netdevopslive-python-and-template/vlan/python/vlan/main.py b/cisco-nso/netdevopslive-python-and-template/vlan/python/vlan/main.py index 21178f6..e57462e 100644 --- a/cisco-nso/netdevopslive-python-and-template/vlan/python/vlan/main.py +++ b/cisco-nso/netdevopslive-python-and-template/vlan/python/vlan/main.py @@ -12,20 +12,20 @@ class VLANService(Service): # must always exist. @Service.create def cb_create(self, tctx, root, service, proplist): - self.log.info('Creating VLAN {} (id {})'.format(service._path, service.id)) + self.log.info(f'Creating VLAN {service._path} (id {service.id})') vars = ncs.template.Variables() - + template = ncs.template.Template(service) # Creates the VLAN template.apply('vlan-template', vars) # Apply template to access ports in this VLAN - self.log.info('Configuring access ports for VLAN {}'.format(service.id)) + self.log.info(f'Configuring access ports for VLAN {service.id}') template.apply('access-port-template') # Apply template to trunk ports in this VLAN - self.log.info('Configuring trunk ports for VLAN {}'.format(service.id)) + self.log.info(f'Configuring trunk ports for VLAN {service.id}') template.apply('trunk-port-template') diff --git a/cli-tool/dnac_sidekick.py b/cli-tool/dnac_sidekick.py index d96a6df..b5d5648 100644 --- a/cli-tool/dnac_sidekick.py +++ b/cli-tool/dnac_sidekick.py @@ -35,7 +35,6 @@ def dnac_cli(): def get(): """ Action for read-only tasks and gathering information. """ click.echo("Getting information...") - pass @get.group() def inventory(): @@ -91,10 +90,10 @@ def devices(dnac_url, token, hostname): table.add_column("Device Type", justify="left", style="cyan") table.add_column("Serial Number", justify="center", style="green") table.add_column("Software Version", justify="right", style="red") - + for device in device_list: table.add_row(device["hostname"], device["type"], device["serialNumber"], device["softwareVersion"]) - + console = Console() console.print(table) # click.echo(f"Here's a list of devices: {console.print(table)}") @@ -124,7 +123,7 @@ def devices(dnac_url, token): table.add_column("Overall Health", justify="left", style="cyan") table.add_column("CPU Util (%)", justify="center", style="green") table.add_column("Memory Util (%)", justify="right", style="red") - + for device in device_list: if device.get("overallHealth", -1) < 0: device_overall = "N/A" @@ -133,7 +132,7 @@ def devices(dnac_url, token): device_cpu_util = str(device.get("cpuUlitilization", "N/A")) device_mem_util = str(device.get("memoryUtilization", "N/A")) table.add_row(device["name"], device_overall, device_cpu_util, device_mem_util) - + console = Console() console.print(table) elif response.status_code == 401: @@ -164,7 +163,7 @@ def clients(dnac_url, token, mac): table.add_column("Client Type", justify="left", style="purple") table.add_column("Client Count", justify="center", style="cyan") table.add_column("Client Health Score", justify="right", style="green") - + for device in device_list: if device.get("siteId") == "global": for score in device.get("scoreDetail"): @@ -173,7 +172,7 @@ def clients(dnac_url, token, mac): client_score = str(score["scoreValue"]) if score["scoreValue"] > 0 else "0" table.add_row(client_type, client_count, client_score) - + console = Console() console.print(table) elif response.status_code == 401: diff --git a/click-cli/click_ex.py b/click-cli/click_ex.py index 8cbb10a..e98f5a5 100644 --- a/click-cli/click_ex.py +++ b/click-cli/click_ex.py @@ -16,7 +16,7 @@ def cli(ctx, debug): def sync(ctx): click.echo(ctx.obj) # prints entire context object that's passed in click.echo(ctx.parent.obj) # prints entire context object of parent (cli) - click.echo('Debug is %s' % (ctx.obj['DEBUG'] and 'on' or 'off')) + click.echo(f"Debug is {ctx.obj['DEBUG'] and 'on' or 'off'}") if __name__ == '__main__': cli(obj={}) \ No newline at end of file diff --git a/flask-app/netauto/utils.py b/flask-app/netauto/utils.py index e06aecb..d66e9a6 100644 --- a/flask-app/netauto/utils.py +++ b/flask-app/netauto/utils.py @@ -19,12 +19,10 @@ def get_ios_version(hostname: str) -> str: with IOSXEDriver(**scrapli_dev) as conn: result = conn.send_command("show version") - - parsed_output = result.genie_parse_output() - ios_version = parsed_output["version"]["version"] + parsed_output = result.genie_parse_output() - return ios_version + return parsed_output["version"]["version"] # USED FOR TESTING if __name__ == "__main__": diff --git a/tqdm.py b/tqdm.py index 2dcc658..300a680 100644 --- a/tqdm.py +++ b/tqdm.py @@ -1,7 +1,8 @@ """ Simple script to showcase the tqdm library""" + from tqdm import tqdm import time i = 1 -for i in tqdm(range(int(60))): +for _ in tqdm(range(60)): time.sleep(1) \ No newline at end of file diff --git a/webhook/meraki_receiver.py b/webhook/meraki_receiver.py index 4f0da59..0fc8c18 100644 --- a/webhook/meraki_receiver.py +++ b/webhook/meraki_receiver.py @@ -39,49 +39,50 @@ def data_intake(): - Parse interesting data to be sent to user - Send interesting data to Webex Teams """ - if request.method == "POST": - # Debugging purposes - print("Data received from Webhook is: ", request.json) + if request.method != "POST": + return + # Debugging purposes + print("Data received from Webhook is: ", request.json) - # Collect Meraki JSON data - response = request.json + # Collect Meraki JSON data + response = request.json - # Parsing out interesting data from Meraki alert data and marking down for Webex payload - webex_message = f""" + # Parsing out interesting data from Meraki alert data and marking down for Webex payload + webex_message = f""" ALERT: Network {response['networkName']} in organization {response['organizationName']} had the following change occur: ``` {response['alertData']} ``` """ - # Base URL to post messages to Webex - webex_url = "https://webexapis.com/v1/messages" + # Base URL to post messages to Webex + webex_url = "https://webexapis.com/v1/messages" - # Payload for Webex Messages API - message_body = json.dumps({"roomId": WEBEX_ROOM_ID, "markdown": webex_message}) + # Payload for Webex Messages API + message_body = json.dumps({"roomId": WEBEX_ROOM_ID, "markdown": webex_message}) - # Required headers for Webex Messages API call - webex_headers = { - "Content-Type": "application/json", - "Authorization": f"Bearer {WEBEX_BOT_TOKEN}", - } + # Required headers for Webex Messages API call + webex_headers = { + "Content-Type": "application/json", + "Authorization": f"Bearer {WEBEX_BOT_TOKEN}", + } - # Send parsed data to Webex Teams room - webex_post = requests.post( - url=webex_url, headers=webex_headers, data=message_body, verify=False - ) + # Send parsed data to Webex Teams room + webex_post = requests.post( + url=webex_url, headers=webex_headers, data=message_body, verify=False + ) - # Print out response body and status code - print(webex_post.status_code) - print(webex_post.json()) + # Print out response body and status code + print(webex_post.status_code) + print(webex_post.json()) - # Indicate whether request was successful (should be a log message) - if webex_post.ok: - print("Webex message sent!") - else: - print("Error sending to Webex") + # Indicate whether request was successful (should be a log message) + if webex_post.ok: + print("Webex message sent!") + else: + print("Error sending to Webex") - return "Webhook received!" + return "Webhook received!" if __name__ == "__main__":