コード例 #1
0
def sla_create(name, description, loss, latency, jitter):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/policy/list/sla"
    url = base_url + api
    payload = {
        "name": name,
        "description": description,
        "entries": [{
            "latency": latency,
            "loss": loss,
            "jitter": jitter
        }]
    }
    response = requests.post(url=url,
                             data=json.dumps(payload),
                             headers=headers,
                             verify=False)
    if response.status_code == 200:
        items = response.json()
        text = Text.assemble(("Successful", "bold green"),
                             " create SLA Class with listID = ",
                             (items["listId"], "magenta"))
        console = Console()
        console.print(text)
    else:
        print(str(response.text))
        exit()
コード例 #2
0
def sla_edit(name, sla_id, loss, latency, jitter):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/template/policy/list/sla/{sla_id}"
    url = base_url + api
    payload = {
        "name": name,
        "entries": [{
            "latency": latency,
            "loss": loss,
            "jitter": jitter
        }]
    }
    response = requests.put(url=url,
                            data=json.dumps(payload),
                            headers=headers,
                            verify=False)
    if response.status_code == 200:
        text = Text.assemble(("Successful", "bold green"),
                             " edit the SLA class")
        console = Console()
        console.print(text)
    else:
        print(str(response.text))
        exit()
コード例 #3
0
def sla_list():
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/policy/list/sla"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Error:: " + str(response.text))
        exit()
    console = Console()
    table = Table("Name", "Loss (%)", "Latency (ms)", "jitter (ms)",
                  "Reference Count", "Updated by", "SLA ID", "Last Updated")

    for item in items:
        # breakpoint()
        time_date = datetime.datetime.fromtimestamp(item["lastUpdated"] /
                                                    1000).strftime('%c')
        table.add_row(f'[green]{item["name"]}[/green]',
                      f'[blue]{item["entries"][0]["loss"]}[/blue]',
                      f'[magenta]{item["entries"][0]["latency"]}[/magenta]',
                      f'[cyan]{item["entries"][0]["jitter"]}[/cyan]',
                      f'[orange1]{item["referenceCount"]}[/orange1]',
                      f'[bright_green]{item["owner"]}[/bright_green]',
                      f'[magenta]{item["listId"]}[/magenta]',
                      f'[yellow]{time_date}[/yellow]')
    console.print(table)
コード例 #4
0
def summary_device(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/bfd/summary?deviceId={system_ip}"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print(str(response.text))
        exit()
    console = Console()
    table = Table("Sessions Total", "Sessions Up", "Sessions Max",
                  "Sessions Flap", "App Route Poll Interval", "Last Updated")

    for item in items:
        time_date = datetime.datetime.fromtimestamp(
            int(item["lastupdated"]) / 1000).strftime('%c')
        table.add_row(f'[blue]{item["bfd-sessions-total"]}[/blue]',
                      f'[magenta]{item["bfd-sessions-up"]}[/magenta]',
                      f'[cyan]{item["bfd-sessions-max"]}[/cyan]',
                      f'[orange1]{item["bfd-sessions-flap"]}[/orange1]',
                      f'[bright_green]{item["poll-interval"]}[/bright_green]',
                      f'[yellow]{time_date}[/yellow]')
    console.print(table)
コード例 #5
0
def session_device(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/bfd/sessions?deviceId={system_ip}"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print(str(response.text))
        exit()
    console = Console()
    table = Table("System IP", "Site ID", "State", "Source TLOC color",
                  "Remote TLOC color", "Source IP", "Destination Public IP",
                  "Destination Public Port", "Encapsulation", "Source Port",
                  "Last Updated")

    for item in items:
        time_date = datetime.datetime.fromtimestamp(
            int(item["lastupdated"]) / 1000).strftime('%c')
        table.add_row(
            f'[green]{item["system-ip"]}[/green]',
            f'[magenta]{item["site-id"]}[/magenta]',
            f'[cyan]{item["state"]}[/cyan]',
            f'[orange1]{item["local-color"]}[/orange1]',
            f'[bright_green]{item["color"]}[/bright_green]',
            f'[magenta]{item["src-ip"]}[/magenta]',
            f'[cyan]{item["dst-ip"]}[/cyan]',
            f'[orange1]{item["dst-port"]}[/orange1]',
            f'[bright_green]{item["proto"]}[/bright_green]',
            f'[magenta]{item["src-port"]}[/magenta]',
            f'[yellow]{time_date}[/yellow]',
        )
    console.print(table)
コード例 #6
0
def connection_status(state):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/bfd/links?state={state}"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed to get list of devices " + str(response.text))
        exit()
    console = Console()
    table = Table("System IP 1", "Host-Name 1", "System IP 2", "Host-Name 2",
                  "Link", "Status", "Last Updated")

    for item in items:
        # breakpoint()
        time_date = datetime.datetime.fromtimestamp(
            int(item["lastupdated"]) / 1000).strftime('%c')
        table.add_row(f'[green]{item["asystem-ip"]}[/green]',
                      f'[blue]{item["ahost-name"]}[/blue]',
                      f'[magenta]{item["bsystem-ip"]}[/magenta]',
                      f'[cyan]{item["bhost-name"]}[/cyan]',
                      f'[orange1]{item["linkKeyDisplay"]}[/orange1]',
                      f'[bright_green]{item["state"]}[/bright_green]',
                      f'[yellow]{time_date}[/yellow]')
    console.print(table)
コード例 #7
0
def device_list(vmanage):
    """
    Get device list
    """
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/device"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed to get list of devices " + str(response.text))
        exit()
    console = Console()
    table = Table("Host-Name", "Device Type", "Device ID", "System IP",
                  "Site ID", "Version", "Device Model")

    for item in items:
        table.add_row(f'[green]{item["host-name"]}[/green]',
                      f'[blue]{item["device-type"]}[/blue]',
                      f'[magenta]{item["uuid"]}[/magenta]',
                      f'[cyan]{item["system-ip"]}[/cyan]',
                      f'[orange1]{item["site-id"]}[/orange1]',
                      f'[bright_green]{item["version"]}[/bright_green]',
                      f'[yellow]{item["device-model"]}[/yellow]')
    console.print(table)
コード例 #8
0
def template_list(vmanage):
    """
    Get template list
    """
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/device"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed to get list of devices " + str(response.text))
        exit()
    console = Console()
    table = Table("Template Name", "Device Type", "Template ID",
                  "Attached devices", "Template version")

    for item in items:
        table.add_row(
            f'[green]{item["templateName"]}[/green]',
            f'[blue]{item["deviceType"]}[/blue]',
            f'[magenta]{item["templateId"]}[/magenta]',
            f'[orange1]{item["devicesAttached"]}[/orange1]',
            f'[bright_yellow]{item["templateAttached"]}[/bright_yellow]')
    console.print(table)
コード例 #9
0
def show_template(template_id):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/template/device/object/{template_id}?api_key=/template/device"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        print(json.dumps(response.json(), indent=4))
    else:
        print("Failed to show the template " + str(template_id))
        exit()
コード例 #10
0
def delete_template(template_id):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/template/device/{template_id}?api_key=/template/device"
    url = base_url + api
    response = requests.delete(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        print("Succed to delete the template " + str(template_id))
    else:
        print("Failed to delete the template " + str(template_id))
        exit()
コード例 #11
0
def outbound_connections(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/omp/tlocs/received?deviceId={system_ip}"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed: " + str(response.text))
        exit()
    for item in items:
        print("tloc-paths entries", item["ip"], item["color"], item["encap"])
コード例 #12
0
def summary_device(sla_id):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/template/policy/list/sla/{sla_id}"
    url = base_url + api
    response = requests.delete(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        text = Text.assemble(("Successful", "bold green"),
                             " delete SLA Class with listID = ",
                             (sla_id, "magenta"))
        console = Console()
        console.print(text)
        exit()
    else:
        print(str(response.text))
        exit()
コード例 #13
0
def inbound_connections(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/omp/tlocs/received?deviceId={system_ip}"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed: " + str(response.text))
        exit()
    console = Console()
    table = Table("IP", "Color", "Encap", "From Peer", "Tloc Spi", "Public IP",
                  "Public Port", "Private IP", "Private Port", "Site ID",
                  "BFD Status", "Preference", "Weight", "Originator",
                  "Last Updated")

    for item in items:
        # breakpoint()
        time_date = datetime.datetime.fromtimestamp(
            int(item["lastupdated"]) / 1000).strftime('%c')
        table.add_row(
            f'[green]{item["ip"]}[/green]',
            f'[magenta]{item["color"]}[/magenta]',
            f'[cyan]{item["encap"]}[/cyan]',
            f'[orange1]{item["from-peer"]}[/orange1]',
            f'[bright_green]{item["tloc-spi"]}[/bright_green]',
            f'[magenta]{item["tloc-public-ip"]}[/magenta]',
            f'[cyan]{item["tloc-public-port"]}[/cyan]',
            f'[orange1]{item["tloc-private-ip"]}[/orange1]',
            f'[green]{item["tloc-private-port"]}[/green]',
            f'[magenta]{item["site-id"]}[/magenta]',
            f'[cyan]{item["bfd-status"]}[/cyan]',
            f'[orange1]{item["preference"]}[/orange1]',
            f'[bright_green]{item["weight"]}[/bright_green]',
            f'[magenta]{item["originator"]}[/magenta]',
            f'[yellow]{time_date}[/yellow]',
        )
    console.print(table)
コード例 #14
0
def control_connections(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/control/connections?deviceId={system_ip}&&"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed: " + str(response.text))
        exit()
    console = Console()
    table = Table("Peer Type", "Peer Protocol", "Peer System IP", "Site ID",
                  "Domain ID", "Private IP", "Private Port", "Public IP",
                  "Public Port", "Local Color", "Proxy", "State", "Uptime",
                  "Control Group ID", "Last Updated")

    for item in items:
        # breakpoint()
        time_date = datetime.datetime.fromtimestamp(
            int(item["lastupdated"]) / 1000).strftime('%c')
        table.add_row(
            f'[green]{item["peer-type"]}[/green]',
            f'[magenta]{item["protocol"]}[/magenta]',
            f'[cyan]{item["system-ip"]}[/cyan]',
            f'[orange1]{item["site-id"]}[/orange1]',
            f'[bright_green]{item["domain-id"]}[/bright_green]',
            f'[magenta]{item["private-ip"]}[/magenta]',
            f'[cyan]{item["private-port"]}[/cyan]',
            f'[orange1]{item["public-ip"]}[/orange1]',
            f'[green]{item["public-port"]}[/green]',
            f'[magenta]{item["local-color"]}[/magenta]',
            f'[cyan]{item["behind-proxy"]}[/cyan]',
            f'[orange1]{item["state"]}[/orange1]',
            f'[bright_green]{item["uptime"]}[/bright_green]',
            f'[magenta]{item["controller-group-id"]}[/magenta]',
            f'[yellow]{time_date}[/yellow]',
        )
    console.print(table)
コード例 #15
0
def control_connections_history(system_ip):
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = f"/device/control/connectionshistory?deviceId={system_ip}&&&"
    url = base_url + api
    response = requests.get(url=url, headers=headers, verify=False)
    if response.status_code == 200:
        items = response.json()['data']
    else:
        print("Failed: " + str(response.text))
        exit()
    console = Console()
    table = Table("Peer Type", "Peer Protocol", "Peer System IP", "Site ID",
                  "Domain ID", "Private IP", "Private Port", "Public IP",
                  "Public Port", "Local Color", "State", "Local Error",
                  "Remote Error", "Repeat Count", "Downtime")

    for item in items:
        # breakpoint()
        table.add_row(
            f'[green]{item["peer-type"]}[/green]',
            f'[magenta]{item["protocol"]}[/magenta]',
            f'[cyan]{item["system-ip"]}[/cyan]',
            f'[orange1]{item["site-id"]}[/orange1]',
            f'[bright_green]{item["domain-id"]}[/bright_green]',
            f'[magenta]{item["private-ip"]}[/magenta]',
            f'[cyan]{item["private-port"]}[/cyan]',
            f'[orange1]{item["public-ip"]}[/orange1]',
            f'[green]{item["public-port"]}[/green]',
            f'[magenta]{item["local-color"]}[/magenta]',
            f'[cyan]{item["state"]}[/cyan]',
            f'[orange1]{item["local_enum"]}[/orange1]',
            f'[bright_green]{item["remote_enum"]}[/bright_green]',
            f'[magenta]{item["rep-count"]}[/magenta]',
            f'[yellow]{item["downtime"]}[/yellow]',
        )
    console.print(table)