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.
15 from snaps.domain.creator import CloudObject
16 from snaps.openstack.utils import (
17 nova_utils, neutron_utils, keystone_utils, cinder_utils, magnum_utils)
19 __author__ = 'spisarski'
22 class OpenStackCloudObject(CloudObject):
24 Abstract class for all OpenStack object creators
27 def __init__(self, os_creds):
30 :param os_creds: the OpenStack credentials object
32 self._os_creds = os_creds
33 keystone = keystone_utils.keystone_client(os_creds)
34 self.project_id = keystone_utils.get_project(
35 keystone=keystone, project_name=os_creds.project_name).id
38 raise NotImplementedError('Do not override abstract method')
41 raise NotImplementedError('Do not override abstract method')
44 raise NotImplementedError('Do not override abstract method')
47 class OpenStackComputeObject(OpenStackCloudObject):
49 Abstract class for all OpenStack compute creators
52 def __init__(self, os_creds):
55 :param os_creds: the OpenStack credentials object
57 super(OpenStackComputeObject, self).__init__(os_creds)
61 self._nova = nova_utils.nova_client(self._os_creds)
64 raise NotImplementedError('Do not override abstract method')
67 raise NotImplementedError('Do not override abstract method')
70 class OpenStackNetworkObject(OpenStackCloudObject):
72 Abstract class for all OpenStack compute creators
75 def __init__(self, os_creds):
78 :param os_creds: the OpenStack credentials object
80 super(OpenStackNetworkObject, self).__init__(os_creds)
84 self._neutron = neutron_utils.neutron_client(self._os_creds)
87 raise NotImplementedError('Do not override abstract method')
90 raise NotImplementedError('Do not override abstract method')
93 class OpenStackIdentityObject(OpenStackCloudObject):
95 Abstract class for all OpenStack compute creators
98 def __init__(self, os_creds):
101 :param os_creds: the OpenStack credentials object
103 super(OpenStackIdentityObject, self).__init__(os_creds)
104 self._keystone = None
106 def initialize(self):
107 self._keystone = keystone_utils.keystone_client(self._os_creds)
110 raise NotImplementedError('Do not override abstract method')
113 raise NotImplementedError('Do not override abstract method')
116 class OpenStackVolumeObject(OpenStackCloudObject):
118 Abstract class for all OpenStack compute creators
121 def __init__(self, os_creds):
124 :param os_creds: the OpenStack credentials object
126 super(OpenStackVolumeObject, self).__init__(os_creds)
129 def initialize(self):
130 self._cinder = cinder_utils.cinder_client(self._os_creds)
133 raise NotImplementedError('Do not override abstract method')
136 raise NotImplementedError('Do not override abstract method')
139 class OpenStackMagnumObject(OpenStackCloudObject):
141 Abstract class for all OpenStack compute creators
144 def __init__(self, os_creds):
147 :param os_creds: the OpenStack credentials object
149 super(OpenStackMagnumObject, self).__init__(os_creds)
152 def initialize(self):
153 self._magnum = magnum_utils.magnum_client(self._os_creds)
156 raise NotImplementedError('Do not override abstract method')
159 raise NotImplementedError('Do not override abstract method')