summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-08-17 15:21:37 -0600
committerSteven Pisarski <s.pisarski@cablelabs.com>2017-08-24 21:12:02 +0000
commit1342eb17df248ec75cc57e9c380a7753fc432194 (patch)
tree72a3b065394b7bcaaddb801e3321edc1ba4b8818 /snaps/domain
parent49aaa5d61e87e11c5d5b9ce7dd2fa598f16b82a7 (diff)
Added method to return OpenStackVmInstance from Heat.
OpenStackHeatStack now can introspect the VMs that the template was responsible for deploying and return an instanitated instance of OpenStackVmInstance for each VM deployed. When the VM has a Floating IP, these instances have the ability to connect via SSH just like one created from scratch. JIRA: SNAPS-172 Change-Id: I5a7ed3a09bb871afc55c718aa80a9069b1eb4da7 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/domain')
-rw-r--r--snaps/domain/keypair.py9
-rw-r--r--snaps/domain/network.py23
-rw-r--r--snaps/domain/stack.py17
-rw-r--r--snaps/domain/test/keypair_tests.py7
-rw-r--r--snaps/domain/test/network_tests.py91
-rw-r--r--snaps/domain/test/stack_tests.py23
-rw-r--r--snaps/domain/test/vm_inst_tests.py81
-rw-r--r--snaps/domain/vm_inst.py47
8 files changed, 264 insertions, 34 deletions
diff --git a/snaps/domain/keypair.py b/snaps/domain/keypair.py
index 2865125..5e169fb 100644
--- a/snaps/domain/keypair.py
+++ b/snaps/domain/keypair.py
@@ -19,15 +19,18 @@ class Keypair:
SNAPS domain object for Keypairs. Should contain attributes that
are shared amongst cloud providers
"""
- def __init__(self, name, id, public_key):
+ def __init__(self, name, kp_id, public_key, fingerprint=None):
"""
Constructor
:param name: the keypair's name
- :param id: the keypair's id
+ :param kp_id: the keypair's id
+ :param public_key: the keypair's public key
+ :param fingerprint: the keypair's host fingerprint
"""
self.name = name
- self.id = id
+ self.id = kp_id
self.public_key = public_key
+ self.fingerprint = fingerprint
def __eq__(self, other):
return (self.name == other.name and self.id == other.id and
diff --git a/snaps/domain/network.py b/snaps/domain/network.py
index 0b56c43..9cc1dd1 100644
--- a/snaps/domain/network.py
+++ b/snaps/domain/network.py
@@ -92,13 +92,32 @@ class Port:
Constructor
:param name: the security group's name
:param id: the security group's id
- :param ips: a list of IP addresses
+ :param description: description
+ :param ips|fixed_ips: a list of IP addresses
+ :param mac_address: the port's MAC addresses
+ :param allowed_address_pairs: the port's allowed_address_pairs value
+ :param admin_state_up: T|F whether or not the port is up
+ :param device_id: device's ID
+ :param device_owner: device's owner
+ :param network_id: associated network ID
+ :param port_security_enabled: T|F whether or not the port security is
+ enabled
+ :param security_groups: the security group IDs associated with port
+ :param project_id: the associated project/tenant ID
"""
self.name = kwargs.get('name')
self.id = kwargs.get('id')
- self.ips = kwargs.get('ips')
+ self.description = kwargs.get('description')
+ self.ips = kwargs.get('ips', kwargs.get('fixed_ips'))
self.mac_address = kwargs.get('mac_address')
self.allowed_address_pairs = kwargs.get('allowed_address_pairs')
+ self.admin_state_up = kwargs.get('admin_state_up')
+ self.device_id = kwargs.get('device_id')
+ self.device_owner = kwargs.get('device_owner')
+ self.network_id = kwargs.get('network_id')
+ self.port_security_enabled = kwargs.get('port_security_enabled')
+ self.security_groups = kwargs.get('security_groups')
+ self.project_id = kwargs.get('tenant_id', kwargs.get('project_id'))
def __eq__(self, other):
return (self.name == other.name and self.id == other.id and
diff --git a/snaps/domain/stack.py b/snaps/domain/stack.py
index df4d4e4..543c78b 100644
--- a/snaps/domain/stack.py
+++ b/snaps/domain/stack.py
@@ -35,7 +35,7 @@ class Stack:
class Resource:
"""
- SNAPS domain object for resources created by a heat template
+ SNAPS domain object for a resource created by a heat template
"""
def __init__(self, resource_type, resource_id):
"""
@@ -45,3 +45,18 @@ class Resource:
"""
self.type = resource_type
self.id = resource_id
+
+
+class Output:
+ """
+ SNAPS domain object for an output defined by a heat template
+ """
+ def __init__(self, **kwargs):
+ """
+ Constructor
+ :param description: the output description
+ :param output_key: the output's key
+ """
+ self.description = kwargs.get('description')
+ self.key = kwargs.get('output_key')
+ self.value = kwargs.get('output_value')
diff --git a/snaps/domain/test/keypair_tests.py b/snaps/domain/test/keypair_tests.py
index 93f99ff..1cb9f91 100644
--- a/snaps/domain/test/keypair_tests.py
+++ b/snaps/domain/test/keypair_tests.py
@@ -23,13 +23,16 @@ class KeypairDomainObjectTests(unittest.TestCase):
"""
def test_construction_positional(self):
- keypair = Keypair('foo', '123-456', 'foo-bar')
+ keypair = Keypair('foo', '123-456', 'foo-bar', '01:02:03')
self.assertEqual('foo', keypair.name)
self.assertEqual('123-456', keypair.id)
self.assertEqual('foo-bar', keypair.public_key)
+ self.assertEqual('01:02:03', keypair.fingerprint)
def test_construction_named(self):
- keypair = Keypair(public_key='foo-bar', id='123-456', name='foo')
+ keypair = Keypair(fingerprint='01:02:03', public_key='foo-bar',
+ kp_id='123-456', name='foo')
self.assertEqual('foo', keypair.name)
self.assertEqual('123-456', keypair.id)
self.assertEqual('foo-bar', keypair.public_key)
+ self.assertEqual('01:02:03', keypair.fingerprint)
diff --git a/snaps/domain/test/network_tests.py b/snaps/domain/test/network_tests.py
index 0534b49..24a60c9 100644
--- a/snaps/domain/test/network_tests.py
+++ b/snaps/domain/test/network_tests.py
@@ -107,20 +107,95 @@ class PortDomainObjectTests(unittest.TestCase):
Tests the construction of the snaps.domain.network.Port class
"""
- def test_construction_kwargs(self):
+ def test_construction_ips_kwargs(self):
ips = ['10', '11']
port = Port(
- **{'name': 'name', 'id': 'id', 'ips': ips})
- self.assertEqual('name', port.name)
- self.assertEqual('id', port.id)
+ **{'name': 'foo', 'id': 'bar', 'description': 'test desc',
+ 'ips': ips, 'mac_address': 'abc123',
+ 'allowed_address_pairs': list(), 'admin_state_up': False,
+ 'device_id': 'def456', 'device_owner': 'joe',
+ 'network_id': 'ghi789', 'port_security_enabled': False,
+ 'security_groups': list(), 'tenant_id': 'jkl098'})
+ self.assertEqual('foo', port.name)
+ self.assertEqual('bar', port.id)
+ self.assertEqual('test desc', port.description)
self.assertEqual(ips, port.ips)
+ self.assertEqual('abc123', port.mac_address)
+ self.assertEqual(list(), port.allowed_address_pairs)
+ self.assertFalse(port.admin_state_up)
+ self.assertEqual('def456', port.device_id)
+ self.assertEqual('joe', port.device_owner)
+ self.assertEqual('ghi789', port.network_id)
+ self.assertFalse(port.port_security_enabled)
+ self.assertEqual(list(), port.security_groups)
+ self.assertEqual(list(), port.security_groups)
- def test_construction_named(self):
+ def test_construction_fixed_ips_kwargs(self):
+ ips = ['10', '11']
+ port = Port(
+ **{'name': 'foo', 'id': 'bar', 'description': 'test desc',
+ 'fixed_ips': ips, 'mac_address': 'abc123',
+ 'allowed_address_pairs': list(), 'admin_state_up': False,
+ 'device_id': 'def456', 'device_owner': 'joe',
+ 'network_id': 'ghi789', 'port_security_enabled': False,
+ 'security_groups': list(), 'tenant_id': 'jkl098'})
+ self.assertEqual('foo', port.name)
+ self.assertEqual('bar', port.id)
+ self.assertEqual('test desc', port.description)
+ self.assertEqual(ips, port.ips)
+ self.assertEqual('abc123', port.mac_address)
+ self.assertEqual(list(), port.allowed_address_pairs)
+ self.assertFalse(port.admin_state_up)
+ self.assertEqual('def456', port.device_id)
+ self.assertEqual('joe', port.device_owner)
+ self.assertEqual('ghi789', port.network_id)
+ self.assertFalse(port.port_security_enabled)
+ self.assertEqual(list(), port.security_groups)
+ self.assertEqual(list(), port.security_groups)
+
+ def test_construction_named_ips(self):
ips = ['10', '11']
- port = Port(ips=ips, id='id', name='name')
- self.assertEqual('name', port.name)
- self.assertEqual('id', port.id)
+ port = Port(
+ mac_address='abc123', description='test desc', ips=ips, id='bar',
+ name='foo', allowed_address_pairs=list(), admin_state_up=False,
+ device_id='def456', device_owner='joe', network_id='ghi789',
+ port_security_enabled=False, security_groups=list(),
+ tenant_id='jkl098')
+ self.assertEqual('foo', port.name)
+ self.assertEqual('bar', port.id)
+ self.assertEqual('test desc', port.description)
+ self.assertEqual(ips, port.ips)
+ self.assertEqual('abc123', port.mac_address)
+ self.assertEqual(list(), port.allowed_address_pairs)
+ self.assertFalse(port.admin_state_up)
+ self.assertEqual('def456', port.device_id)
+ self.assertEqual('joe', port.device_owner)
+ self.assertEqual('ghi789', port.network_id)
+ self.assertFalse(port.port_security_enabled)
+ self.assertEqual(list(), port.security_groups)
+ self.assertEqual(list(), port.security_groups)
+
+ def test_construction_named_fixed_ips(self):
+ ips = ['10', '11']
+ port = Port(
+ mac_address='abc123', description='test desc', fixed_ips=ips,
+ id='bar', name='foo', allowed_address_pairs=list(),
+ admin_state_up=False, device_id='def456', device_owner='joe',
+ network_id='ghi789', port_security_enabled=False,
+ security_groups=list(), tenant_id='jkl098')
+ self.assertEqual('foo', port.name)
+ self.assertEqual('bar', port.id)
+ self.assertEqual('test desc', port.description)
self.assertEqual(ips, port.ips)
+ self.assertEqual('abc123', port.mac_address)
+ self.assertEqual(list(), port.allowed_address_pairs)
+ self.assertFalse(port.admin_state_up)
+ self.assertEqual('def456', port.device_id)
+ self.assertEqual('joe', port.device_owner)
+ self.assertEqual('ghi789', port.network_id)
+ self.assertFalse(port.port_security_enabled)
+ self.assertEqual(list(), port.security_groups)
+ self.assertEqual(list(), port.security_groups)
class RouterDomainObjectTests(unittest.TestCase):
diff --git a/snaps/domain/test/stack_tests.py b/snaps/domain/test/stack_tests.py
index e0e1ae7..f816ef8 100644
--- a/snaps/domain/test/stack_tests.py
+++ b/snaps/domain/test/stack_tests.py
@@ -14,7 +14,7 @@
# limitations under the License.
import unittest
-from snaps.domain.stack import Stack, Resource
+from snaps.domain.stack import Stack, Resource, Output
class StackDomainObjectTests(unittest.TestCase):
@@ -47,3 +47,24 @@ class ResourceDomainObjectTests(unittest.TestCase):
resource = Resource(resource_id='bar', resource_type='foo')
self.assertEqual('foo', resource.type)
self.assertEqual('bar', resource.id)
+
+
+class OutputDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.Resource class
+ """
+
+ def test_construction_kwargs(self):
+ kwargs = {'description': 'foo', 'output_key': 'test_key',
+ 'output_value': 'bar'}
+ resource = Output(**kwargs)
+ self.assertEqual('foo', resource.description)
+ self.assertEqual('test_key', resource.key)
+ self.assertEqual('bar', resource.value)
+
+ def test_construction_named(self):
+ resource = Output(description='foo', output_key='test_key',
+ output_value='bar')
+ self.assertEqual('foo', resource.description)
+ self.assertEqual('test_key', resource.key)
+ self.assertEqual('bar', resource.value)
diff --git a/snaps/domain/test/vm_inst_tests.py b/snaps/domain/test/vm_inst_tests.py
index c3de8ba..d293373 100644
--- a/snaps/domain/test/vm_inst_tests.py
+++ b/snaps/domain/test/vm_inst_tests.py
@@ -23,16 +23,26 @@ class VmInstDomainObjectTests(unittest.TestCase):
"""
def test_construction_positional(self):
- vm_inst = VmInst('name', 'id', dict())
+ vm_inst = VmInst('name', 'id', '456', '123', dict(), 'kp-name', list())
self.assertEqual('name', vm_inst.name)
self.assertEqual('id', vm_inst.id)
+ self.assertEqual('456', vm_inst.image_id)
+ self.assertEqual('123', vm_inst.flavor_id)
self.assertEqual(dict(), vm_inst.networks)
+ self.assertEqual('kp-name', vm_inst.keypair_name)
+ self.assertEqual(list(), vm_inst.sec_grp_names)
def test_construction_named(self):
- vm_inst = VmInst(networks=dict(), inst_id='id', name='name')
+ vm_inst = VmInst(sec_grp_names=list(), networks=dict(), inst_id='id',
+ name='name', flavor_id='123', image_id='456',
+ keypair_name='kp-name')
self.assertEqual('name', vm_inst.name)
self.assertEqual('id', vm_inst.id)
+ self.assertEqual('456', vm_inst.image_id)
+ self.assertEqual('123', vm_inst.flavor_id)
self.assertEqual(dict(), vm_inst.networks)
+ self.assertEqual('kp-name', vm_inst.keypair_name)
+ self.assertEqual(list(), vm_inst.sec_grp_names)
class FloatingIpDomainObjectTests(unittest.TestCase):
@@ -40,12 +50,63 @@ class FloatingIpDomainObjectTests(unittest.TestCase):
Tests the construction of the snaps.domain.test.Image class
"""
- def test_construction_positional(self):
- vm_inst = FloatingIp('id-123', '10.0.0.1')
- self.assertEqual('id-123', vm_inst.id)
- self.assertEqual('10.0.0.1', vm_inst.ip)
+ def test_construction_kwargs_ip_proj(self):
+ kwargs = {'id': 'foo', 'description': 'bar', 'ip': '192.168.122.3',
+ 'fixed_ip_address': '10.0.0.3',
+ 'floating_network_id': 'id_of_net', 'port_id': 'id_of_port',
+ 'router_id': 'id_of_router', 'project_id': 'id_of_proj'}
+ vm_inst = FloatingIp(**kwargs)
+ self.assertEqual('foo', vm_inst.id)
+ self.assertEqual('bar', vm_inst.description)
+ self.assertEqual('192.168.122.3', vm_inst.ip)
+ self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
+ self.assertEqual('id_of_net', vm_inst.floating_network_id)
+ self.assertEqual('id_of_port', vm_inst.port_id)
+ self.assertEqual('id_of_router', vm_inst.router_id)
+ self.assertEqual('id_of_proj', vm_inst.project_id)
- def test_construction_named(self):
- vm_inst = FloatingIp(ip='10.0.0.1', inst_id='id-123')
- self.assertEqual('id-123', vm_inst.id)
- self.assertEqual('10.0.0.1', vm_inst.ip)
+ def test_construction_kwargs_fixed_ip_tenant(self):
+ kwargs = {'id': 'foo', 'description': 'bar',
+ 'floating_ip_address': '192.168.122.3',
+ 'fixed_ip_address': '10.0.0.3',
+ 'floating_network_id': 'id_of_net', 'port_id': 'id_of_port',
+ 'router_id': 'id_of_router', 'tenant_id': 'id_of_proj'}
+ vm_inst = FloatingIp(**kwargs)
+ self.assertEqual('foo', vm_inst.id)
+ self.assertEqual('bar', vm_inst.description)
+ self.assertEqual('192.168.122.3', vm_inst.ip)
+ self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
+ self.assertEqual('id_of_net', vm_inst.floating_network_id)
+ self.assertEqual('id_of_port', vm_inst.port_id)
+ self.assertEqual('id_of_router', vm_inst.router_id)
+ self.assertEqual('id_of_proj', vm_inst.project_id)
+
+ def test_construction_named_ip_proj(self):
+ vm_inst = FloatingIp(
+ id='foo', description='bar', ip='192.168.122.3',
+ fixed_ip_address='10.0.0.3', floating_network_id='id_of_net',
+ port_id='id_of_port', router_id='id_of_router',
+ project_id='id_of_proj')
+ self.assertEqual('foo', vm_inst.id)
+ self.assertEqual('bar', vm_inst.description)
+ self.assertEqual('192.168.122.3', vm_inst.ip)
+ self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
+ self.assertEqual('id_of_net', vm_inst.floating_network_id)
+ self.assertEqual('id_of_port', vm_inst.port_id)
+ self.assertEqual('id_of_router', vm_inst.router_id)
+ self.assertEqual('id_of_proj', vm_inst.project_id)
+
+ def test_construction_kwargs_named_fixed_ip_tenant(self):
+ vm_inst = FloatingIp(
+ id='foo', description='bar', floating_ip_address='192.168.122.3',
+ fixed_ip_address='10.0.0.3', floating_network_id='id_of_net',
+ port_id='id_of_port', router_id='id_of_router',
+ tenant_id='id_of_proj')
+ self.assertEqual('foo', vm_inst.id)
+ self.assertEqual('bar', vm_inst.description)
+ self.assertEqual('192.168.122.3', vm_inst.ip)
+ self.assertEqual('10.0.0.3', vm_inst.fixed_ip_address)
+ self.assertEqual('id_of_net', vm_inst.floating_network_id)
+ self.assertEqual('id_of_port', vm_inst.port_id)
+ self.assertEqual('id_of_router', vm_inst.router_id)
+ self.assertEqual('id_of_proj', vm_inst.project_id)
diff --git a/snaps/domain/vm_inst.py b/snaps/domain/vm_inst.py
index ae01cf0..ca38143 100644
--- a/snaps/domain/vm_inst.py
+++ b/snaps/domain/vm_inst.py
@@ -19,17 +19,35 @@ class VmInst:
SNAPS domain object for Images. Should contain attributes that
are shared amongst cloud providers
"""
- def __init__(self, name, inst_id, networks):
+ def __init__(self, name, inst_id, image_id, flavor_id, networks,
+ keypair_name, sec_grp_names):
"""
Constructor
:param name: the image's name
:param inst_id: the instance's id
- :param networks: dict of networks where the key is the subnet name and
+ :param image_id: the instance's image id
+ :param flavor_id: the ID used to spawn this instance
+ :param networks: dict of networks where the key is the network name and
value is a list of associated IPs
+ :param keypair_name: the name of the associated keypair
+ :param sec_grp_names: list of security group names
"""
self.name = name
self.id = inst_id
+ self.image_id = image_id
+ self.flavor_id = flavor_id
self.networks = networks
+ self.keypair_name = keypair_name
+ self.sec_grp_names = sec_grp_names
+
+ def __eq__(self, other):
+ return (self.name == other.name and
+ self.id == other.id and
+ self.image_id == other.image_id and
+ self.flavor_id == other.flavor_id and
+ self.networks == other.networks and
+ self.keypair_name == other.keypair_name and
+ self.sec_grp_names == other.sec_grp_names)
class FloatingIp:
@@ -37,11 +55,26 @@ class FloatingIp:
SNAPS domain object for Images. Should contain attributes that
are shared amongst cloud providers
"""
- def __init__(self, inst_id, ip):
+ def __init__(self, **kwargs):
"""
Constructor
- :param inst_id: the floating ip's id
- :param ip: the IP address
+ :param id: the floating ip's id
+ :param description: the description
+ :param ip|floating_ip_address: the Floating IP address mapped to the
+ 'ip' attribute
+ :param fixed_ip_address: the IP address of the tenant network
+ :param floating_network_id: the ID of the external network
+ :param port_id: the ID of the associated port
+ :param router_id: the ID of the associated router
+ :param project_id|tenant_id: the ID of the associated project mapped to
+ the attribute 'project_id'
+ :param
"""
- self.id = inst_id
- self.ip = ip
+ self.id = kwargs.get('id')
+ self.description = kwargs.get('description')
+ self.ip = kwargs.get('ip', kwargs.get('floating_ip_address'))
+ self.fixed_ip_address = kwargs.get('fixed_ip_address')
+ self.floating_network_id = kwargs.get('floating_network_id')
+ self.port_id = kwargs.get('port_id')
+ self.router_id = kwargs.get('router_id')
+ self.project_id = kwargs.get('project_id', kwargs.get('tenant_id'))