Skip to content
Open
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
40 changes: 31 additions & 9 deletions sdwan.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def login(self, vmanage_ip, username, password):
#If the vmanage has a certificate signed by a trusted authority change verify to True
login_response = sess.post(url=login_url, data=login_data, verify=False)


if b'<html>' in login_response.content:
print ("Login Failed")
sys.exit(0)
Expand Down Expand Up @@ -157,7 +157,7 @@ def attached_devices(template):

response = json.loads(sdwanp.get_request(url))
items = response['data']

headers = ["Host Name", "Device IP", "Site ID", "Host ID", "Host Type"]
table = list()

Expand Down Expand Up @@ -185,16 +185,16 @@ def attach(template, target, hostname, sysip, loopip, geip, siteid):

Example command:

./sdwan.py attach --template TemplateID --target TargetID --hostname devnet01.cisco.com
./sdwan.py attach --template TemplateID --target TargetID --hostname devnet01.cisco.com
--sysip 1.1.1.1 --loopip 2.2.2.2/24 --geip 3.3.3.3/24 --siteid 999
"""
click.secho("Attempting to attach template.")

payload = {
"deviceTemplateList":[
{
"templateId":str(template),
"device":[
"templateId":str(template),
"device":[
{
"csv-status":"complete",
"csv-deviceId":str(target),
Expand All @@ -209,8 +209,8 @@ def attach(template, target, hostname, sysip, loopip, geip, siteid):
"selected":"true"
}
],
"isEdited":"false",
"isMasterEdited":"false"
"isEdited":"false",
"isMasterEdited":"false"
}
]
}
Expand All @@ -234,7 +234,7 @@ def detach(target, sysip):

payload = {
"deviceType":"vedge",
"devices":[
"devices":[
{
"deviceId":str(target),
"deviceIP":str(sysip)
Expand All @@ -245,12 +245,34 @@ def detach(target, sysip):
response = sdwanp.post_request('template/config/device/mode/cli', payload)
print (response)

@click.command()
@click.option("--file", help="Specify .json file containing CLI Template")
def new_cli_template(file):
"""Uploads new CLI device template from json file.

Example command:

./sdwan.py new_cli_template
./sdwan.py new_cli_template --file newcli.json

"""
if not file:
file = input("Please specify filename:")

click.secho("Uploading New CLI Tempalte")

with open(file) as f:
payload = json.load(f)

response = sdwanp.post_request('template/device/cli', payload)
print(response)

cli.add_command(attach)
cli.add_command(detach)
cli.add_command(device_list)
cli.add_command(attached_devices)
cli.add_command(template_list)
cli.add_command(new_cli_template)

if __name__ == "__main__":
cli()