1 # Copyright (c) 2017 Cable Television Laboratories, Inc. ("CableLabs")
2 # and others. All rights reserved.
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:
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 from magnumclient.common.apiclient.exceptions import NotFound
20 from snaps.openstack.openstack_creator import OpenStackMagnumObject
21 from snaps.openstack.utils import magnum_utils
23 __author__ = 'spisarski'
25 logger = logging.getLogger('cluster_template')
28 class OpenStackClusterTemplate(OpenStackMagnumObject):
30 Class responsible for managing an volume in OpenStack
33 def __init__(self, os_creds, cluster_template_config):
36 :param os_creds: The OpenStack connection credentials
37 :param cluster_template_config: The volume type settings
40 super(self.__class__, self).__init__(os_creds)
42 self.cluster_template_config = cluster_template_config
43 self.__cluster_template = None
47 Loads the existing Volume
48 :return: The Volume domain object or None
50 super(self.__class__, self).initialize()
52 self.__cluster_template = magnum_utils.get_cluster_template(
53 self._magnum, template_config=self.cluster_template_config)
55 return self.__cluster_template
59 Creates the volume in OpenStack if it does not already exist and
60 returns the domain Volume object
61 :return: The Volume domain object or None
65 if not self.__cluster_template:
66 self.__cluster_template = magnum_utils.create_cluster_template(
67 self._magnum, self.cluster_template_config)
69 'Created volume type with name - %s',
70 self.cluster_template_config.name)
72 return self.__cluster_template
76 Cleanse environment of all artifacts
79 if self.__cluster_template:
81 magnum_utils.delete_cluster_template(
82 self._magnum, self.__cluster_template.id)
86 self.__cluster_template = None
88 super(self.__class__, self).clean()
90 def get_cluster_template(self):
92 Returns the domain Volume object as it was populated when create() was
96 return self.__cluster_template