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

Refactoring WIP #31

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions cosmo/graphqlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_data(self, device_config):
device_list(
name: $device_array,
) {
__typename
id
name
serial
Expand All @@ -39,15 +40,19 @@ def get_data(self, device_config):
slug
}
platform {
__typename
manufacturer {
__typename
slug
}
slug
}
primary_ip4 {
__typename
address
}
interfaces {
__typename
id
name
enabled
Expand All @@ -57,40 +62,53 @@ def get_data(self, device_config):
mac_address
description
vrf {
__typename
id
}
lag {
__typename
id
}
ip_addresses {
__typename
address
}
untagged_vlan {
__typename
id
name
vid
}
tagged_vlans {
__typename
id
name
vid
}
tags {
__typename
name
slug
}
parent {
__typename
id
}
connected_endpoints {
__typename
... on InterfaceType {
__typename
name
device {
__typename
primary_ip4 {
__typename
address
}
interfaces {
__typename
ip_addresses {
__typename
address
}
}
Expand All @@ -100,37 +118,47 @@ def get_data(self, device_config):
custom_fields
}
staticroute_set {
__typename
interface {
__typename
name
}
vrf {
__typename
name
}
prefix {
__typename
prefix
family {
__typename
value
}
}
next_hop {
__typename
address
}
metric
}
}
vrf_list {
__typename
id
name
description
rd
export_targets {
__typename
name
}
import_targets {
__typename
name
}
}
l2vpn_list {
__typename
id
name
type
Expand All @@ -143,18 +171,24 @@ def get_data(self, device_config):
id
}
... on InterfaceType {
__typename
id
device {
__typename
name
interfaces (type: "virtual") {
__typename
ip_addresses {
__typename
address
}
parent {
__typename
name
type
}
vrf {
__typename
id
}
}
Expand Down
25 changes: 25 additions & 0 deletions cosmo/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ipaddress
import re
import json
import abc
from collections import defaultdict

from cosmo.logger import Logger
Expand Down Expand Up @@ -653,6 +654,30 @@ def serialize(self):
return device_stub


class SwitchElement(abc.ABC):
@abc.abstractmethod
def serialize():
pass

class SwitchElementCompound(SwitchElement):
# children is a list
def add(c: SwitchElement):
raise NotImplemented

def remove(c: SwitchElement):
raise NotImplemented

def getChildren(c: SwitchElement):
raise NotImplemented

def serialize():
raise NotImplemented

class InterfaceSwitchElement(SwitchElement):
def serialize():
raise NotImplemented


class SwitchSerializer:
def __init__(self, device):
self.device = device
Expand Down
Loading