-
Notifications
You must be signed in to change notification settings - Fork 18
Sourcery Starbot ⭐ refactored dannywade/devnet-expert #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}') | ||
|
Comment on lines
-15
to
+28
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| template.apply('trunk-port-template') | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,6 @@ def dnac_cli(): | |
| def get(): | ||
| """ Action for read-only tasks and gathering information. """ | ||
| click.echo("Getting information...") | ||
| pass | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @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"]) | ||
|
|
||
|
Comment on lines
-94
to
+96
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the following improvement in Function |
||
| 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") | ||
|
|
||
|
Comment on lines
-127
to
+126
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the following improvement in Function |
||
| 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") | ||
|
|
||
|
Comment on lines
-167
to
+166
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found the following improvement in Function |
||
| 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: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'}") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| if __name__ == '__main__': | ||
| cli(obj={}) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"] | ||
|
Comment on lines
-22
to
+25
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # USED FOR TESTING | ||
| if __name__ == "__main__": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)): | ||
|
Comment on lines
+2
to
+7
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| time.sleep(1) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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!" | ||
|
Comment on lines
-42
to
+85
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the following improvement in Function
add_static_routes: