Skip to content
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

Sourcery Starbot ⭐ refactored dannywade/devnet-expert #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/devnet-expert main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Comment on lines +2 to +7

from tqdm import tqdm
import time

i = 1
for i in tqdm(range(int(60))):
for _ in tqdm(range(60)):
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:


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:

Comment on lines -15 to +28
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}')
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:

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

Comment on lines -94 to +96

for device in device_list:
table.add_row(device["hostname"], device["type"], device["serialNumber"], device["softwareVersion"])

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:

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:

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:

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:

Comment on lines -22 to +25

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"]
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:

Comment on lines -42 to +85
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!"
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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant