summaryrefslogtreecommitdiffstats
path: root/snaps/domain
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-08-07 14:14:06 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-08-09 14:24:07 -0600
commit79c0075b2e3872f9cde8101403b19bd963f7f992 (patch)
treee1c57261dac38964cc851dc001eb9f35be97e214 /snaps/domain
parent430905e7f76e4a074167a49ca2bfbf727eebcefd (diff)
Added feature to update the quotas on a project/tenant.
JIRA: SNAPS-170 Change-Id: Icf494dd2bddc338b8e85259b0400c0950d2332bc Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/domain')
-rw-r--r--snaps/domain/project.py72
-rw-r--r--snaps/domain/test/project_tests.py67
2 files changed, 136 insertions, 3 deletions
diff --git a/snaps/domain/project.py b/snaps/domain/project.py
index 54407cf..aa125e3 100644
--- a/snaps/domain/project.py
+++ b/snaps/domain/project.py
@@ -16,7 +16,7 @@
class Project:
"""
- SNAPS domain object for Projects. Should contain attributes that
+ SNAPS domain class for Projects. Should contain attributes that
are shared amongst cloud providers
"""
def __init__(self, name, project_id, domain_id=None):
@@ -36,7 +36,7 @@ class Project:
class Domain:
"""
- SNAPS domain object for OpenStack Keystone v3+ domains.
+ SNAPS domain class for OpenStack Keystone v3+ domains.
"""
def __init__(self, name, domain_id=None):
"""
@@ -49,3 +49,71 @@ class Domain:
def __eq__(self, other):
return self.name == other.name and self.id == other.id
+
+
+class ComputeQuotas:
+ """
+ SNAPS domain class for holding project quotas for compute services
+ """
+ def __init__(self, nova_quotas=None, **kwargs):
+ """
+ Constructor
+ :param nova_quotas: the OS nova quota object
+ """
+ if nova_quotas:
+ self.metadata_items = nova_quotas.metadata_items
+ self.cores = nova_quotas.cores # aka. VCPUs
+ self.instances = nova_quotas.instances
+ self.injected_files = nova_quotas.injected_files
+ self.injected_file_content_bytes = nova_quotas.injected_file_content_bytes
+ self.ram = nova_quotas.ram
+ self.fixed_ips = nova_quotas.fixed_ips
+ self.key_pairs = nova_quotas.key_pairs
+ else:
+ self.metadata_items = kwargs.get('metadata_items')
+ self.cores = kwargs.get('cores') # aka. VCPUs
+ self.instances = kwargs.get('instances')
+ self.injected_files = kwargs.get('injected_files')
+ self.injected_file_content_bytes = kwargs.get(
+ 'injected_file_content_bytes')
+ self.ram = kwargs.get('ram')
+ self.fixed_ips = kwargs.get('fixed_ips')
+ self.key_pairs = kwargs.get('key_pairs')
+
+ def __eq__(self, other):
+ return (self.metadata_items == other.metadata_items and
+ self.cores == other.cores and
+ self.instances == other.instances and
+ self.injected_files == other.injected_files and
+ self.injected_file_content_bytes == other.injected_file_content_bytes and
+ self.fixed_ips == other.fixed_ips and
+ self.key_pairs == other.key_pairs)
+
+
+class NetworkQuotas:
+ """
+ SNAPS domain class for holding project quotas for networking services
+ """
+ def __init__(self, **neutron_quotas):
+ """
+ Constructor
+ :param neutron_quotas: the OS network quota object
+ """
+
+ # Networks settings here
+ self.security_group = neutron_quotas['security_group']
+ self.security_group_rule = neutron_quotas['security_group_rule']
+ self.floatingip = neutron_quotas['floatingip']
+ self.network = neutron_quotas['network']
+ self.port = neutron_quotas['port']
+ self.router = neutron_quotas['router']
+ self.subnet = neutron_quotas['subnet']
+
+ def __eq__(self, other):
+ return (self.security_group == other.security_group and
+ self.security_group_rule == other.security_group_rule and
+ self.floatingip == other.floatingip and
+ self.network == other.network and
+ self.port == other.port and
+ self.router == other.router and
+ self.subnet == other.subnet)
diff --git a/snaps/domain/test/project_tests.py b/snaps/domain/test/project_tests.py
index 3f4fca6..d0aec3a 100644
--- a/snaps/domain/test/project_tests.py
+++ b/snaps/domain/test/project_tests.py
@@ -14,7 +14,7 @@
# limitations under the License.
import unittest
-from snaps.domain.project import Project, Domain
+from snaps.domain.project import Project, Domain, ComputeQuotas, NetworkQuotas
class ProjectDomainObjectTests(unittest.TestCase):
@@ -61,3 +61,68 @@ class DomainDomainObjectTests(unittest.TestCase):
domain = Domain(domain_id='123-456', name='foo')
self.assertEqual('foo', domain.name)
self.assertEqual('123-456', domain.id)
+
+
+class ComputeQuotasDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.project.ComputeQuotas class
+ """
+
+ def test_construction_positional(self):
+ quotas = ComputeQuotas(
+ metadata_items=64, cores=5, instances= 4, injected_files= 3,
+ injected_file_content_bytes=5120,ram=25600, fixed_ips=100,
+ key_pairs=50)
+ self.assertEqual(64, quotas.metadata_items)
+ self.assertEqual(5, quotas.cores)
+ self.assertEqual(4, quotas.instances)
+ self.assertEqual(3, quotas.injected_files)
+ self.assertEqual(5120, quotas.injected_file_content_bytes)
+ self.assertEqual(25600, quotas.ram)
+ self.assertEqual(100, quotas.fixed_ips)
+ self.assertEqual(50, quotas.key_pairs)
+
+ def test_construction_named_minimal(self):
+ quotas = ComputeQuotas(
+ **{'metadata_items': 64, 'cores': 5, 'instances': 4,
+ 'injected_files': 3, 'injected_file_content_bytes': 5120,
+ 'ram': 25600, 'fixed_ips': 100, 'key_pairs': 50})
+ self.assertEqual(64, quotas.metadata_items)
+ self.assertEqual(5, quotas.cores)
+ self.assertEqual(4, quotas.instances)
+ self.assertEqual(3, quotas.injected_files)
+ self.assertEqual(5120, quotas.injected_file_content_bytes)
+ self.assertEqual(25600, quotas.ram)
+ self.assertEqual(100, quotas.fixed_ips)
+ self.assertEqual(50, quotas.key_pairs)
+
+
+class NetworkQuotasDomainObjectTests(unittest.TestCase):
+ """
+ Tests the construction of the snaps.domain.project.NetworkQuotas class
+ """
+
+ def test_construction_positional(self):
+ quotas = NetworkQuotas(
+ security_group=5, security_group_rule=50,
+ floatingip=25, network=5, port=25, router=6, subnet=7)
+ self.assertEqual(5, quotas.security_group)
+ self.assertEqual(50, quotas.security_group_rule)
+ self.assertEqual(25, quotas.floatingip)
+ self.assertEqual(5, quotas.network)
+ self.assertEqual(25, quotas.port)
+ self.assertEqual(6, quotas.router)
+ self.assertEqual(7, quotas.subnet)
+
+ def test_construction_named_minimal(self):
+ quotas = NetworkQuotas(
+ **{'security_group': 5, 'security_group_rule': 50,
+ 'floatingip': 25, 'network': 5, 'port': 25, 'router': 6,
+ 'subnet': 7})
+ self.assertEqual(5, quotas.security_group)
+ self.assertEqual(50, quotas.security_group_rule)
+ self.assertEqual(25, quotas.floatingip)
+ self.assertEqual(5, quotas.network)
+ self.assertEqual(25, quotas.port)
+ self.assertEqual(6, quotas.router)
+ self.assertEqual(7, quotas.subnet)