2c71db8835c37addb48d4ae3e452207d18bfff02
[snaps.git] / snaps / domain / network.py
1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 #                    and others.  All rights reserved.
3 #
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:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16
17 class Network:
18     """
19     SNAPS domain object for interface routers. Should contain attributes that
20     are shared amongst cloud providers
21     """
22     def __init__(self, **kwargs):
23         """
24         Constructor
25         """
26         self.name = kwargs.get('name')
27         self.id = kwargs.get('id')
28         self.type = kwargs.get('provider:network_type')
29
30     def __eq__(self, other):
31         return (self.name == other.name and self.id == other.id and
32                 self.type == other.type)
33
34
35 class Subnet:
36     """
37     SNAPS domain object for interface routers. Should contain attributes that
38     are shared amongst cloud providers
39     """
40     def __init__(self, **kwargs):
41         """
42         Constructor
43         """
44         self.name = kwargs.get('name')
45         self.id = kwargs.get('id')
46         self.cidr = kwargs.get('cidr')
47
48     def __eq__(self, other):
49         return (self.name == other.name and self.id == other.id and
50                 self.cidr == other.cidr)
51
52
53 class Port:
54     """
55     SNAPS domain object for ports. Should contain attributes that
56     are shared amongst cloud providers
57     """
58     def __init__(self, **kwargs):
59         """
60         Constructor
61         :param name: the security group's name
62         :param id: the security group's id
63         :param ips: a list of IP addresses
64         """
65         self.name = kwargs.get('name')
66         self.id = kwargs.get('id')
67         self.ips = kwargs.get('ips')
68         self.mac_address = kwargs.get('mac_address')
69         self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
70
71     def __eq__(self, other):
72         return (self.name == other.name and self.id == other.id and
73                 self.ips == other.ips, self.mac_address == other.mac_address)
74
75
76 class Router:
77     """
78     SNAPS domain object for routers. Should contain attributes that are shared
79     amongst cloud providers
80     """
81     def __init__(self, **kwargs):
82         """
83         Constructor
84         :param name: the router's name
85         :param id: the router's id
86         """
87         self.name = kwargs.get('name')
88         self.id = kwargs.get('id')
89         self.status = kwargs.get('status')
90         self.tenant_id = kwargs.get('tenant_id')
91         self.admin_state_up = kwargs.get('admin_state_up')
92         self.external_gateway_info = kwargs.get('external_gateway_info')
93
94     def __eq__(self, other):
95         return (self.name == other.name and self.id == other.id and
96                 self.status == other.status and
97                 self.tenant_id == other.tenant_id and
98                 self.admin_state_up == other.admin_state_up and
99                 self.external_gateway_info == other.external_gateway_info)
100
101
102 class InterfaceRouter:
103     """
104     SNAPS domain object for interface routers. Should contain attributes that
105     are shared amongst cloud providers
106     """
107     def __init__(self, **kwargs):
108         """
109         Constructor
110         """
111         self.id = kwargs.get('id')
112         self.subnet_id = kwargs.get('subnet_id')
113         self.port_id = kwargs.get('port_id')
114
115     def __eq__(self, other):
116         return (self.id == other.id and self.subnet_id == other.subnet_id and
117                 self.port_id == other.port_id)
118
119
120 class SecurityGroup:
121     """
122     SNAPS domain object for SecurityGroups. Should contain attributes that
123     are shared amongst cloud providers
124     """
125     def __init__(self, **kwargs):
126         """
127         Constructor
128         :param name: the security group's name
129         :param id: the security group's id
130         """
131         self.name = kwargs.get('name')
132         self.id = kwargs.get('id')
133         self.description = kwargs.get('description')
134         self.project_id = kwargs.get('project_id', kwargs.get('tenant_id'))
135
136     def __eq__(self, other):
137         return (self.name == other.name and self.id == other.id and
138                 self.project_id == other.project_id)
139
140
141 class SecurityGroupRule:
142     """
143     SNAPS domain object for Security Group Rules. Should contain attributes
144     that are shared amongst cloud providers
145     """
146     def __init__(self, **kwargs):
147         """
148         Constructor
149         :param id: the security group rule's id
150         :param sec_grp_id: the ID of the associated security group
151         :param description: the security group rule's description
152         :param direction: the security group rule's direction
153         :param ethertype: the security group rule's ethertype
154         :param port_range_min: the security group rule's port_range_min
155         :param port_range_max: the security group rule's port_range_max
156         :param protocol: the security group rule's protocol
157         :param remote_group_id: the security group rule's remote_group_id
158         :param remote_ip_prefix: the security group rule's remote_ip_prefix
159         """
160         self.id = kwargs.get('id')
161         self.security_group_id = kwargs.get('security_group_id')
162         self.description = kwargs.get('description')
163         self.direction = kwargs.get('direction')
164         self.ethertype = kwargs.get('ethertype')
165         self.port_range_min = kwargs.get('port_range_min')
166         self.port_range_max = kwargs.get('port_range_max')
167         self.protocol = kwargs.get('protocol')
168         self.remote_group_id = kwargs.get('remote_group_id')
169         self.remote_ip_prefix = kwargs.get('remote_ip_prefix')
170
171     def __eq__(self, other):
172         return (self.id == other.id and
173                 self.security_group_id == other.security_group_id and
174                 self.description == other.description and
175                 self.direction == other.direction and
176                 self.ethertype == other.ethertype and
177                 self.port_range_min == other.port_range_min and
178                 self.port_range_max == other.port_range_max and
179                 self.protocol == other.protocol and
180                 self.remote_group_id == other.remote_group_id and
181                 self.remote_ip_prefix == other.remote_ip_prefix)