Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cisco-apis/iosxe/add_static_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Author

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:

response = requests.post(url=add_static_route_url, headers=headers, auth=(DEVICE_USER, DEVICE_PASS), json=config, verify=False)

if response.status_code == 201:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function VLANService.cb_create refactored with the following changes:

template.apply('trunk-port-template')


Expand Down
13 changes: 6 additions & 7 deletions cli-tool/dnac_sidekick.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def dnac_cli():
def get():
""" Action for read-only tasks and gathering information. """
click.echo("Getting information...")
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get refactored with the following changes:


@get.group()
def inventory():
Expand Down Expand Up @@ -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
Copy link
Author

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 devices:

console = Console()
console.print(table)
# click.echo(f"Here's a list of devices: {console.print(table)}")
Expand Down Expand Up @@ -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
Copy link
Author

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 devices:

for device in device_list:
if device.get("overallHealth", -1) < 0:
device_overall = "N/A"
Expand All @@ -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:
Expand Down Expand Up @@ -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
Copy link
Author

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 clients:

for device in device_list:
if device.get("siteId") == "global":
for score in device.get("scoreDetail"):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion click-cli/click_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function sync refactored with the following changes:


if __name__ == '__main__':
cli(obj={})
6 changes: 2 additions & 4 deletions flask-app/netauto/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_ios_version refactored with the following changes:


# USED FOR TESTING
if __name__ == "__main__":
Expand Down
3 changes: 2 additions & 1 deletion tqdm.py
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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 6-6 refactored with the following changes:

time.sleep(1)
59 changes: 30 additions & 29 deletions webhook/meraki_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function data_intake refactored with the following changes:



if __name__ == "__main__":
Expand Down