diff options
author | spisarski <s.pisarski@cablelabs.com> | 2017-11-22 14:55:43 -0700 |
---|---|---|
committer | spisarski <s.pisarski@cablelabs.com> | 2017-11-22 16:24:12 -0700 |
commit | fb6654aafdc5303077325691b7f468b27d7493c6 (patch) | |
tree | 68290a72557a5b3ae1ba79dda287203f7d29456a /snaps/domain | |
parent | 0e377731a20617c9cdb886a597395c61ae490e38 (diff) |
Implemented the ability to create Magnum Cluster Type objects.
This patch is the second of several necessary for the addition of
Magnum support. This one implements a create and delete function
to magnum_utils.py as well as the necessary config and domain classes
for sending and receiving Cluster Type data to OpenStack.
JIRA: SNAPS-233
Change-Id: Iad1959b98eaabc4ef5f41b70a23f6b1306259650
Signed-off-by: spisarski <s.pisarski@cablelabs.com>
Diffstat (limited to 'snaps/domain')
-rw-r--r-- | snaps/domain/cluster_template.py | 133 | ||||
-rw-r--r-- | snaps/domain/test/cluster_template_tests.py | 109 |
2 files changed, 242 insertions, 0 deletions
diff --git a/snaps/domain/cluster_template.py b/snaps/domain/cluster_template.py new file mode 100644 index 0000000..01af88a --- /dev/null +++ b/snaps/domain/cluster_template.py @@ -0,0 +1,133 @@ +# Copyright (c) 2016 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class ClusterTemplate(object): + """ + Class for OpenStack cluster template domain object + """ + + def __init__(self, **kwargs): + """ + Constructor + :param id: the cluster template's UUID + :param name: the cluster template's name + :param image: name or ID of the base image in Glance used to boot the + cluster's servers. The image must have the attribute + 'os-distro' defined as appropriate for the cluster + driver + :param keypair: name or ID of the keypair to gain cluster machine + access + :param network_driver: The name of a network driver for providing the + networks for the containers. Note that this is + different and separate from the Neutron network + for the bay/cluster. The operation and + networking model are specific to the particular + driver + :param external_net: name or IDof the external Neutron network to + provide connectivity to the cluster + :param floating_ip_enabled: Whether enable or not using the floating IP + of cloud provider. Some cloud providers + used floating IP, some used public IP, + thus Magnum provide this option for + specifying the choice of using floating IP + :param docker_volume_size: The size in GB for the local storage on each + server for the Docker daemon to cache the + images and host the containers. Cinder + volumes provide the storage. The default is + 25 GB. For the devicemapper storage driver, + the minimum value is 3GB. For the overlay + storage driver, the minimum value is 1GB. + :param server_type: server type string + :param flavor: name or ID of the nova flavor for booting the node + servers + :param master_flavor: name or ID of the nova flavor of the master node + for this cluster + :param coe: ContainerOrchestrationEngine enum instance + :param fixed_net: name of a Neutron network to provide connectivity + to the internal network for the cluster + :param fixed_subnet: Fixed subnet that are using to allocate network + address for nodes in bay/cluster + :param registry_enabled: Docker images by default are pulled from the + public Docker registry, but in some cases, + users may want to use a private registry. + This option provides an alternative registry + based on the Registry V2: Magnum will create a + local registry in the bay/cluster backed by + swift to host the images + :param insecure_registry: The URL pointing to the user's own private + insecure docker registry to deploy and run + docker containers + :param docker_storage_driver: DockerStorageDriver enum instance to + manage storage for the images and + container's writable layer + :param dns_nameserver: The DNS nameserver for the servers and + containers in the bay/cluster to use. + This is configured in the private Neutron + network for the bay/cluster. + :param public: denotes whether or not the cluster type is public + :param tls_disabled: denotes whether or not TLS should be enabled + :param http_proxy: host:port for a proxy to use when direct HTTP + access from the servers to sites on the external + internet is blocked + :param https_proxy: host:port for a proxy to use when direct HTTPS + access from the servers to sites on the external + internet is blocked + :param no_proxy: comma separated list of IPs that should not be + redirected through the proxy + :param volume_driver: The name of a volume driver for managing the + persistent storage for the containers. The + functionality supported are specific to the + driver + :param master_lb_enabled: Since multiple masters may exist in a + bay/cluster, a Neutron load balancer is + created to provide the API endpoint for the + bay/cluster and to direct requests to the + masters. In some cases, such as when the + LBaaS service is not available, this option + can be set to false to create a bay/cluster + without the load balancer. In this case, one + of the masters will serve as the API endpoint + :param labels: Arbitrary labels in the form of a dict. The accepted + keys and valid values are defined in the bay/cluster + drivers. They are used as a way to pass additional + parameters that are specific to a bay/cluster driver. + """ + self.id = kwargs.get('id') + self.name = kwargs.get('name') + self.image = kwargs.get('image') + self.keypair = kwargs.get('keypair') + self.network_driver = kwargs.get('network_driver') + self.external_net = kwargs.get('external_net') + self.floating_ip_enabled = kwargs.get('floating_ip_enabled') + self.docker_volume_size = int(kwargs.get('docker_volume_size', 3)) + self.server_type = kwargs.get('server_type') + self.flavor = kwargs.get('flavor') + self.master_flavor = kwargs.get('master_flavor') + self.coe = kwargs.get('coe') + self.fixed_net = kwargs.get('fixed_net') + self.fixed_subnet = kwargs.get('fixed_subnet') + self.registry_enabled = kwargs.get('registry_enabled') + self.insecure_registry = kwargs.get('insecure_registry') + self.docker_storage_driver = kwargs.get('docker_storage_driver') + self.dns_nameserver = kwargs.get('dns_nameserver') + self.public = kwargs.get('public', False) + self.tls_disabled = kwargs.get('tls_disabled') + self.http_proxy = kwargs.get('http_proxy') + self.https_proxy = kwargs.get('https_proxy') + self.no_proxy = kwargs.get('no_proxy') + self.volume_driver = kwargs.get('volume_driver') + self.master_lb_enabled = kwargs.get('master_lb_enabled', True) + self.labels = kwargs.get('labels') diff --git a/snaps/domain/test/cluster_template_tests.py b/snaps/domain/test/cluster_template_tests.py new file mode 100644 index 0000000..76e5663 --- /dev/null +++ b/snaps/domain/test/cluster_template_tests.py @@ -0,0 +1,109 @@ +# Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs") +# and others. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import unittest + +from snaps.config.cluster_template import ( + ContainerOrchestrationEngine, ServerType, DockerStorageDriver) +from snaps.domain.cluster_template import ClusterTemplate + + +class ClusterTemplateUnitTests(unittest.TestCase): + """ + Tests the construction of the ClusterTypeConfig class + """ + def test_all_named(self): + labels = {'foo': 'bar'} + config = ClusterTemplate( + id='tmplt-id', name='foo', image='bar', keypair='keys', + network_driver='driver', external_net='external', + docker_volume_size=99, server_type=ServerType.baremetal.value, + flavor='testFlavor', master_flavor='masterFlavor', + coe=ContainerOrchestrationEngine.kubernetes.value, + fixed_net='fixedNet', fixed_subnet='fixedSubnet', + registry_enabled=False, + docker_storage_driver=DockerStorageDriver.overlay.value, + dns_nameserver='8.8.4.4', public=True, tls=False, + http_proxy='http://foo:8080', https_proxy='https://foo:443', + no_proxy='foo,bar', volume_driver='volDriver', + master_lb_enabled=False, labels=labels) + self.assertIsNotNone(config) + self.assertEqual('tmplt-id', config.id) + self.assertEqual('foo', config.name) + self.assertEqual('bar', config.image) + self.assertEqual('keys', config.keypair) + self.assertEqual('driver', config.network_driver) + self.assertEqual('external', config.external_net) + self.assertEqual(99, config.docker_volume_size) + self.assertEqual(ServerType.baremetal.value, config.server_type) + self.assertEqual('testFlavor', config.flavor) + self.assertEqual('masterFlavor', config.master_flavor) + self.assertEqual(ContainerOrchestrationEngine.kubernetes.value, + config.coe) + self.assertEqual('fixedNet', config.fixed_net) + self.assertEqual('fixedSubnet', config.fixed_subnet) + self.assertFalse(config.registry_enabled) + self.assertEqual(DockerStorageDriver.overlay.value, + config.docker_storage_driver) + self.assertEqual('8.8.4.4', config.dns_nameserver) + self.assertTrue(config.public) + self.assertFalse(config.tls_disabled) + self.assertEqual('http://foo:8080', config.http_proxy) + self.assertEqual('https://foo:443', config.https_proxy) + self.assertEqual('foo,bar', config.no_proxy) + self.assertEqual('volDriver', config.volume_driver) + self.assertFalse(config.master_lb_enabled) + self.assertEqual(labels, config.labels) + + def test_all_config(self): + labels = {'foo': 'bar'} + config = ClusterTemplate(**{ + 'id': 'tmplt-id', 'name': 'foo', 'image': 'bar', 'keypair': 'keys', + 'network_driver': 'driver', 'external_net': 'external', + 'docker_volume_size': '99', 'server_type': 'baremetal', + 'flavor': 'testFlavor', 'master_flavor': 'masterFlavor', + 'coe': 'kubernetes', 'fixed_net': 'fixedNet', + 'fixed_subnet': 'fixedSubnet', 'registry_enabled': False, + 'docker_storage_driver': 'overlay', 'dns_nameserver': '8.8.4.4', + 'public': 'true', 'tls': 'false', 'http_proxy': 'http://foo:8080', + 'https_proxy': 'https://foo:443', 'no_proxy': 'foo,bar', + 'volume_driver': 'volDriver', 'master_lb_enabled': False, + 'labels': labels}) + self.assertIsNotNone(config) + self.assertEqual('tmplt-id', config.id) + self.assertEqual('foo', config.name) + self.assertEqual('bar', config.image) + self.assertEqual('keys', config.keypair) + self.assertEqual('driver', config.network_driver) + self.assertEqual('external', config.external_net) + self.assertEqual(99, config.docker_volume_size) + self.assertEqual(ServerType.baremetal.value, config.server_type) + self.assertEqual('testFlavor', config.flavor) + self.assertEqual('masterFlavor', config.master_flavor) + self.assertEqual(ContainerOrchestrationEngine.kubernetes.value, + config.coe) + self.assertEqual('fixedNet', config.fixed_net) + self.assertEqual('fixedSubnet', config.fixed_subnet) + self.assertFalse(config.registry_enabled) + self.assertEqual(DockerStorageDriver.overlay.value, + config.docker_storage_driver) + self.assertEqual('8.8.4.4', config.dns_nameserver) + self.assertTrue(config.public) + self.assertFalse(config.tls_disabled) + self.assertEqual('http://foo:8080', config.http_proxy) + self.assertEqual('https://foo:443', config.https_proxy) + self.assertEqual('foo,bar', config.no_proxy) + self.assertEqual('volDriver', config.volume_driver) + self.assertFalse(config.master_lb_enabled) + self.assertEqual(labels, config.labels) |