Пример #1
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"])
Пример #2
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()
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
0
def create_feature_template(types, name):
    """ Usage: sdwancli template feature create banner -t '["vedge-cloud",
    "vedge-1000"]' -n VE-banner-2
    """
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/feature"
    url = base_url + api
    payload = {
        "deviceType": types,
        "templateType": "banner",
        "templateMinVersion": "15.0.0",
        "templateDefinition": {
            "login": {
                "vipObjectType": "object",
                "vipType": "constant",
                "vipValue": "This is vEdge Cloud Login banner",
                "vipVariableName": "banner_login"
            },
            "motd": {
                "vipObjectType": "object",
                "vipType": "constant",
                "vipValue": "This is vEdge Cloud MOTD banner",
                "vipVariableName": "banner_motd"
            }
        },
        "factoryDefault": "false",
        "templateName": name,
        "templateDescription": "VE-Banner"
    }
    response = requests.post(
        url=url, data=json.dumps(payload), headers=headers, verify=False)
    if response.status_code == 200:
        print(json.dumps(response.json(), indent=4))
    else:
        print("Failed to create the template ")
        exit()
Пример #7
0
def 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 create_vpn_int_feature_template(types, name, if_name, description, ip_addr_name, color):
    """ Usage: sdwancli template feature create banner -t '["vedge-cloud",
    "vedge-1000"]' -n VE-banner-2
    """
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/feature"
    url = base_url + api
    if ip_addr_name:
        payload = {
            "deviceType": types,
            "templateType": "vpn-vedge-interface",
            "templateMinVersion": "15.0.0",
            "templateDefinition": {
                "if-name": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": if_name,
                    "vipVariableName": "vpn_if_name"
                },
                "description": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": description,
                    "vipVariableName": "vpn_if_description"
                },
                "ip": {
                    "address": {
                        "vipObjectType": "object",
                        "vipType": "variableName",
                        "vipValue": "",
                        "vipVariableName": ip_addr_name
                    }
                },
                    "shutdown": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": "false",
                    "vipVariableName": "vpn_if_shutdown"
                },
                "tunnel-interface": {
                    "color": {
                        "value": {
                            "vipObjectType": "object",
                            "vipType": "constant",
                            "vipValue": color,
                            "vipVariableName": "vpn_if_tunnel_color_value"
                        },
                        "restrict": {
                            "vipObjectType": "node-only",
                            "vipType": "ignore",
                            "vipValue": "false",
                            "vipVariableName": "vpn_if_tunnel_color_restrict"
                        }
                    },
                    "allow-service": {
                        "sshd": {
                            "vipObjectType": "object",
                            "vipType": "constant",
                            "vipValue": "true",
                            "vipVariableName": "vpn_if_tunnel_sshd"
                        },
                        "all": {
                            "vipObjectType": "object",
                            "vipType": "constant",
                            "vipValue": "true",
                            "vipVariableName": "vpn_if_tunnel_all"
                        },
                        "netconf": {
                            "vipObjectType": "object",
                            "vipType": "constant",
                            "vipValue": "true",
                            "vipVariableName": "vpn_if_tunnel_netconf"
                        }
                    }
                }
            },
            "factoryDefault": "false",
            "templateName": name,
            "templateDescription": "VPN Interface Ethernet feature template"
        }
    else:
        payload = {
            "deviceType": types,
            "templateType": "vpn-vedge-interface",
            "templateMinVersion": "15.0.0",
            "templateDefinition": {
                "if-name": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": if_name,
                    "vipVariableName": "vpn_if_name"
                },
                "description": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": description,
                    "vipVariableName": "vpn_if_description"
                }
            },
            "factoryDefault": "false",
            "templateName": name,
            "templateDescription": "VPN Interface Ethernet feature template"
        }

    response = requests.post(
        url=url, data=json.dumps(payload), headers=headers, verify=False)
    if response.status_code == 200:
        print(json.dumps(response.json(), indent=4))
    else:
        print("Failed to create the template ")
        exit()
Пример #9
0
def create_vpn_feature_template(types, name, vpn_id, description, prefix, nexthops):
    """ Usage: sdwancli template feature create banner -t '["vedge-cloud",
    "vedge-1000"]' -n VE-banner-2
    """
    headers = authentication(vmanage)
    base_url = "https://" + f'{vmanage["host"]}:{vmanage["port"]}/dataservice'
    api = "/template/feature"
    url = base_url + api
    if nexthops:
        payload = {
            "deviceType": types,
            "templateType": "vpn-vedge",
            "templateMinVersion": "15.0.0",
            "templateDefinition": {
                "vpn-id": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": vpn_id
                },
                "name": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": description,
                    "vipVariableName": "vpn_name"
                },
                "ip": {
                    "route": {
                        "vipType": "constant",
                        "vipValue": [
                            {
                                "prefix": {
                                    "vipObjectType": "object",
                                    "vipType": "constant",
                                    "vipValue": prefix,
                                    "vipVariableName": "vpn_ipv4_ip_prefix"
                                },
                                "vipOptional": "false",
                                "next-hop": {
                                    "vipType": "constant",
                                    "vipValue": generate_dict_vpn_ip_nexthops(nexthops),
                                    "vipObjectType": "tree",
                                    "vipPrimaryKey": [
                                        "address"
                                    ]
                                },
                                "priority-order": [
                                    "prefix",
                                    "next-hop"
                                ]
                            }
                        ],
                        "vipObjectType": "tree",
                        "vipPrimaryKey": [
                            "prefix"
                        ]
                    },
                    "gre-route": {},
                    "ipsec-route": {},
                    "service-route": {}
                }
            },
            "factoryDefault": "false",
            "templateName": name,
            "templateDescription": "VPN feature template"
        }
    else:
        payload = {
            "deviceType": types,
            "templateType": "vpn-vedge",
            "templateMinVersion": "15.0.0",
            "templateDefinition": {
                "vpn-id": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": vpn_id
                },
                "name": {
                    "vipObjectType": "object",
                    "vipType": "constant",
                    "vipValue": description,
                    "vipVariableName": "vpn_name"
                },
            },
            "factoryDefault": "false",
            "templateName": name,
            "templateDescription": "VPN feature template"
        }
    response = requests.post(
        url=url, data=json.dumps(payload), headers=headers, verify=False)
    if response.status_code == 200:
        print(json.dumps(response.json(), indent=4))
    else:
        print("Failed to create the template ")
        exit()