summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-07-12 11:14:57 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-07-13 08:05:14 -0600
commite6326cd5e826d19e4dd2b096c17aff35da1757b3 (patch)
treef86cbf32d0660cddc802b7cd381afe264ee78033 /snaps/domain
parentf5f0f1cbcb757a9229a92c3a7f4ea400db11dd07 (diff)
Created domain class for ports.
Create Port domain class so neutron_utils.py functions returning port objects will not be leaking out implementation details as each API version can change these data structures and this should all be handled by the SNAPS neutron utility. JIRA: SNAPS-118 Change-Id: If031a094a9da284e2838691c3b3490359f710c61 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/domain')
-rw-r--r--snaps/domain/network.py23
-rw-r--r--snaps/domain/test/network_tests.py27
2 files changed, 47 insertions, 3 deletions
diff --git a/snaps/domain/network.py b/snaps/domain/network.py
index 9e02ba6..8ac5300 100644
--- a/snaps/domain/network.py
+++ b/snaps/domain/network.py
@@ -14,6 +14,29 @@
# limitations under the License.
+class Port:
+ """
+ SNAPS domain object for ports. Should contain attributes that
+ are shared amongst cloud providers
+ """
+ def __init__(self, **kwargs):
+ """
+ Constructor
+ :param name: the security group's name
+ :param id: the security group's id
+ :param ips: a list of IP addresses
+ """
+ self.name = kwargs.get('name')
+ self.id = kwargs.get('id')
+ self.ips = kwargs.get('ips')
+ self.mac_address = kwargs.get('mac_address')
+ self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
+
+ def __eq__(self, other):
+ return (self.name == other.name and self.id == other.id and
+ self.ips == other.ips, self.mac_address == other.mac_address)
+
+
class SecurityGroup:
"""
SNAPS domain object for SecurityGroups. Should contain attributes that
diff --git a/snaps/domain/test/network_tests.py b/snaps/domain/test/network_tests.py
index a2f1374..13015b2 100644
--- a/snaps/domain/test/network_tests.py
+++ b/snaps/domain/test/network_tests.py
@@ -14,7 +14,28 @@
# limitations under the License.
import unittest
-from snaps.domain.network import SecurityGroup, SecurityGroupRule
+from snaps.domain.network import Port, SecurityGroup, SecurityGroupRule
+
+
+class PortDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.network.Port class
+ """
+
+ def test_construction_kwargs(self):
+ ips = ['10', '11']
+ port = Port(
+ **{'name': 'name', 'id': 'id', 'ips': ips})
+ self.assertEqual('name', port.name)
+ self.assertEqual('id', port.id)
+ self.assertEqual(ips, port.ips)
+
+ def test_construction_named(self):
+ ips = ['10', '11']
+ port = Port(ips=ips, id='id', name='name')
+ self.assertEqual('name', port.name)
+ self.assertEqual('id', port.id)
+ self.assertEqual(ips, port.ips)
class SecurityGroupDomainObjectTests(unittest.TestCase):
@@ -52,8 +73,8 @@ class SecurityGroupRuleDomainObjectTests(unittest.TestCase):
def test_construction_kwargs(self):
sec_grp_rule = SecurityGroupRule(
- **{'id': 'id', 'security_group_id': 'grp_id', 'description': 'desc',
- 'direction': 'dir', 'ethertype': 'eType',
+ **{'id': 'id', 'security_group_id': 'grp_id',
+ 'description': 'desc', 'direction': 'dir', 'ethertype': 'eType',
'port_range_min': '10.0.0.100', 'port_range_max': '10.0.0.200',
'protocol': 'proto', 'remote_group_id': 'group_id',
'remote_ip_prefix': 'ip_prefix'})