1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
19 SNAPS domain object for interface routers. Should contain attributes that
20 are shared amongst cloud providers
22 def __init__(self, **kwargs):
26 self.name = kwargs.get('name')
27 self.id = kwargs.get('id')
28 self.admin_state_up = kwargs.get('admin_state_up')
29 self.shared = kwargs.get('shared')
30 self.external = kwargs.get('router:external', kwargs.get('external'))
31 self.type = kwargs.get('provider:network_type', kwargs.get('type'))
33 def __eq__(self, other):
34 return (self.name == other.name and self.id == other.id and
35 self.admin_state_up == other.admin_state_up and
36 self.shared == other.shared and
37 self.external == other.external and self.type == other.type)
42 SNAPS domain object for interface routers. Should contain attributes that
43 are shared amongst cloud providers
45 def __init__(self, **kwargs):
49 self.name = kwargs.get('name')
50 self.id = kwargs.get('id')
51 self.network_id = kwargs.get('network_id')
52 self.cidr = kwargs.get('cidr')
53 self.ip_version = kwargs.get('ip_version')
54 self.gateway_ip = kwargs.get('gateway_ip')
55 self.enable_dhcp = kwargs.get('enable_dhcp')
56 self.dns_nameservers = kwargs.get('dns_nameservers')
57 self.host_routes = kwargs.get('host_routes')
58 self.ipv6_ra_mode = kwargs.get('ipv6_ra_mode')
59 self.ipv6_address_mode = kwargs.get('ipv6_address_mode')
63 if ('allocation_pools' in kwargs and
64 len(kwargs['allocation_pools']) > 0):
65 # Will need to ultimately support a list of pools
66 pools = kwargs['allocation_pools'][0]
68 self.start = pools['start']
70 self.end = pools['end']
72 def __eq__(self, other):
73 return (self.name == other.name and
74 self.id == other.id and
75 self.network_id == other.network_id and
76 self.cidr == other.cidr and
77 self.ip_version == other.ip_version and
78 self.gateway_ip == other.gateway_ip and
79 self.enable_dhcp == other.enable_dhcp and
80 self.dns_nameservers == other.dns_nameservers and
81 self.host_routes == other.host_routes and
82 self.ipv6_ra_mode == other.ipv6_ra_mode and
83 self.ipv6_address_mode == other.ipv6_address_mode and
84 self.start == other.start and self.end == other.end)
89 SNAPS domain object for ports. Should contain attributes that
90 are shared amongst cloud providers
92 def __init__(self, **kwargs):
95 :param name: the security group's name
96 :param id: the security group's id
97 :param description: description
98 :param ips|fixed_ips: a list of IP addresses
99 :param mac_address: the port's MAC addresses
100 :param allowed_address_pairs: the port's allowed_address_pairs value
101 :param admin_state_up: T|F whether or not the port is up
102 :param device_id: device's ID
103 :param device_owner: device's owner
104 :param network_id: associated network ID
105 :param port_security_enabled: T|F whether or not the port security is
107 :param security_groups: the security group IDs associated with port
108 :param project_id: the associated project/tenant ID
110 self.name = kwargs.get('name')
111 self.id = kwargs.get('id')
112 self.description = kwargs.get('description')
113 self.ips = kwargs.get('ips', kwargs.get('fixed_ips'))
114 self.mac_address = kwargs.get('mac_address')
115 self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
116 self.admin_state_up = kwargs.get('admin_state_up')
117 self.device_id = kwargs.get('device_id')
118 self.device_owner = kwargs.get('device_owner')
119 self.network_id = kwargs.get('network_id')
120 self.port_security_enabled = kwargs.get('port_security_enabled')
121 self.security_groups = kwargs.get('security_groups')
122 self.project_id = kwargs.get('tenant_id', kwargs.get('project_id'))
124 def __eq__(self, other):
125 return (self.name == other.name and self.id == other.id and
126 self.ips == other.ips, self.mac_address == other.mac_address)
131 SNAPS domain object for routers. Should contain attributes that are shared
132 amongst cloud providers
134 def __init__(self, **kwargs):
137 :param name: the router's name
138 :param id: the router's id
139 :param status: the router's status
140 :param tenant_id: the router's project/tenant ID
141 :param admin_state_up: Router is up when True
142 :param external_gateway_info: dict() for populating external_network_id
143 and external_fixed_ips
144 external_network_id: ID of the external network to route
145 in dict under key 'external_fixed_ips'
146 external_fixed_ips: List IP addresses associated with the
147 external_network_id found in dict under
149 :param port_subnets: list of tuples where #1 is the Port domain object
150 and #2 is a list of associated Subnet domain
153 self.name = kwargs.get('name')
154 self.id = kwargs.get('id')
155 self.status = kwargs.get('status')
156 self.tenant_id = kwargs.get('tenant_id')
157 self.admin_state_up = kwargs.get('admin_state_up')
158 self.port_subnets = kwargs.get('port_subnets')
160 if (kwargs.get('external_gateway_info') and
161 isinstance(kwargs.get('external_gateway_info'), dict) and
162 kwargs.get('external_gateway_info').get('external_fixed_ips')):
163 gateway_info = kwargs.get('external_gateway_info')
165 self.external_network_id = gateway_info.get('network_id')
166 self.external_fixed_ips = gateway_info.get('external_fixed_ips')
168 self.external_fixed_ips = kwargs.get('external_fixed_ips', None)
169 self.external_network_id = kwargs.get('external_network_id', None)
171 def __eq__(self, other):
172 return (self.name == other.name and self.id == other.id and
173 self.status == other.status and
174 self.tenant_id == other.tenant_id and
175 self.admin_state_up == other.admin_state_up and
176 self.external_network_id == other.external_network_id and
177 self.external_fixed_ips == other.external_fixed_ips and
178 self.port_subnets == other.port_subnets)
181 class InterfaceRouter:
183 SNAPS domain object for interface routers. Should contain attributes that
184 are shared amongst cloud providers
186 def __init__(self, **kwargs):
190 self.id = kwargs.get('id')
191 self.subnet_id = kwargs.get('subnet_id')
192 self.port_id = kwargs.get('port_id')
194 def __eq__(self, other):
195 return (self.id == other.id and self.subnet_id == other.subnet_id and
196 self.port_id == other.port_id)
201 SNAPS domain object for SecurityGroups. Should contain attributes that
202 are shared amongst cloud providers
204 def __init__(self, **kwargs):
207 :param name: the security group's name
208 :param id: the security group's id
210 self.name = kwargs.get('name')
211 self.id = kwargs.get('id')
212 self.description = kwargs.get('description')
213 self.project_id = kwargs.get('project_id', kwargs.get('tenant_id'))
215 def __eq__(self, other):
216 return (self.name == other.name and self.id == other.id and
217 self.project_id == other.project_id)
220 class SecurityGroupRule:
222 SNAPS domain object for Security Group Rules. Should contain attributes
223 that are shared amongst cloud providers
225 def __init__(self, **kwargs):
228 :param id: the security group rule's id
229 :param sec_grp_id: the ID of the associated security group
230 :param description: the security group rule's description
231 :param direction: the security group rule's direction
232 :param ethertype: the security group rule's ethertype
233 :param port_range_min: the security group rule's port_range_min
234 :param port_range_max: the security group rule's port_range_max
235 :param protocol: the security group rule's protocol
236 :param remote_group_id: the security group rule's remote_group_id
237 :param remote_ip_prefix: the security group rule's remote_ip_prefix
239 self.id = kwargs.get('id')
240 self.security_group_id = kwargs.get('security_group_id')
241 self.description = kwargs.get('description')
242 self.direction = kwargs.get('direction')
243 self.ethertype = kwargs.get('ethertype')
244 self.port_range_min = kwargs.get('port_range_min')
245 self.port_range_max = kwargs.get('port_range_max')
246 self.protocol = kwargs.get('protocol')
247 self.remote_group_id = kwargs.get('remote_group_id')
248 self.remote_ip_prefix = kwargs.get('remote_ip_prefix')
250 def __eq__(self, other):
251 return (self.id == other.id and
252 self.security_group_id == other.security_group_id and
253 self.description == other.description and
254 self.direction == other.direction and
255 self.ethertype == other.ethertype and
256 self.port_range_min == other.port_range_min and
257 self.port_range_max == other.port_range_max and
258 self.protocol == other.protocol and
259 self.remote_group_id == other.remote_group_id and
260 self.remote_ip_prefix == other.remote_ip_prefix)