-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
132 lines (109 loc) · 3.96 KB
/
models.py
File metadata and controls
132 lines (109 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
Copyright (c) 2020 Cisco and/or its affiliates.
This software is licensed to you under the terms of the Cisco Sample
Code License, Version 1.1 (the "License"). You may obtain a copy of the
License at
https://developer.cisco.com/docs/licenses
All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
reserved. Unless required by applicable law or agreed to separately in
writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
"""
import os
import sqlalchemy as db
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
database_url = os.getenv('DATABASE_URL')
db_engine = db.create_engine(database_url)
Session = sessionmaker(bind=db_engine)
Base = declarative_base(name='Model')
class User(Base):
__tablename__ = 'users'
id = Column(String, primary_key=True)
privilege = Column(String)
def is_admin(self):
return self.privilege.lower() == "admin"
def can_edit(self):
return self.privilege.lower() == "editor" or self.is_admin()
class Mapping(Base):
__tablename__ = 'mapping'
id = Column(Integer, primary_key=True)
catalyst = Column(String, ForeignKey('switch.id'))
meraki = Column(String, ForeignKey('switch.id'))
class Switch(Base):
__tablename__ = 'switch'
id = Column(String, primary_key=True)
platform = Column(String)
model = Column(String)
modular = Column(Boolean)
stackable = Column(Boolean)
network_module = Column(String)
tier = Column(String)
dl_ge = Column(Integer)
dl_ge_poe = Column(Integer)
dl_ge_poep = Column(Integer)
dl_ge_upoep = Column(Integer)
dl_ge_sfp = Column(Integer)
dl_2ge_upoe = Column(Integer)
dl_mgig_poep = Column(Integer)
dl_mgig_upoe = Column(Integer)
dl_10ge = Column(Integer)
dl_10ge_sfpp = Column(Integer)
dl_25ge_sfp28 = Column(Integer)
dl_40ge_qsfpp = Column(Integer)
dl_100ge_qsfp28 = Column(Integer)
ul_ge_sfp = Column(Integer)
ul_mgig = Column(Integer)
ul_10ge_sfpp = Column(Integer)
ul_25ge_sfp28 = Column(Integer)
ul_40ge_qsfpp = Column(Integer)
ul_100ge_qsfp28 = Column(Integer)
poe_power = Column(Integer)
switching_capacity = Column(Integer)
mac_entry = Column(Integer)
vlan = Column(Integer)
note = Column(String)
# Map some pretty names
_name_mapping = {
"id": "ID",
"platform": "Platform",
"model": "Model",
"modular": "Modular?",
"stackable": "Stackable?",
"network_module": "Network Module",
"tier": "Tier",
"dl_ge": "1GE DL",
"dl_ge_poe": "1GE-PoE DL",
"dl_ge_poep": "1GE-PoE+ DL",
"dl_ge_upoep": "1GE-UPoE+ DL",
"dl_ge_sfp": "1G-SFP DL",
"dl_2ge_upoe": "2.5GE-UPoE DL",
"dl_mgig_poep": "mGig-PoE+ DL",
"dl_mgig_upoe": "mGig-UPoE DL",
"dl_10ge": "10GE DL",
"dl_10ge_sfpp": "10G-SFP+ DL",
"dl_25ge_sfp28": "25G-SFP28 DL",
"dl_40ge_qsfpp": "40G-QSFP+ DL",
"dl_100ge_qsfp28": "100G-QSFP28 DL",
"ul_ge_sfp": "1G-SFP UL",
"ul_mgig": "mGig UL",
"ul_10ge_sfpp": "10G-SFP UL",
"ul_25ge_sfp28": "25G-SFP28 UL",
"ul_40ge_qsfpp": "40G-QSFP+ UL",
"ul_100ge_qsfp28": "100G-QSFP28 UL",
"poe_power": "PoE Power",
"switching_capacity": "Switching Capacity",
"mac_entry": "Mac Table Size",
"vlan": "VLAN",
"note": "Notes"
}
def __repr__(self):
text = "Here are the details of the equivalent switch:\n\n"
for attr, value in vars(self).items():
# Don't append null values or internal attributes
if value and value != 'null' and attr[0] != '_':
text += f"{attr}: {value}\n"
return text