summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Abramov <sabramov@mirantis.com>2016-08-24 18:32:39 +0300
committerIlya Kharin <akscram@gmail.com>2016-08-24 22:36:40 +0300
commit17ab5a3aaa7d2c4ae4652d1a4dc0410b31e7c47d (patch)
tree85e9428c0ac00ef690c17a77c0ea0db47f2b0cfe
parent7cf3fe9b3aa0965514e4370e908909e548ff918e (diff)
Add create upgrade release handler
Required for create new release just for upgrade, that have overwrited params. This params are valid for orig cluster release. Change-Id: Ib2387b9c2b74902c7289ee8f69a5f5d323ec82ca
Notes
Notes (review): Code-Review+2: Yuriy Taraday <yorik.sar@gmail.com> Workflow+1: Yuriy Taraday <yorik.sar@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 24 Aug 2016 19:52:17 +0000 Reviewed-on: https://review.openstack.org/359968 Project: openstack/fuel-nailgun-extension-cluster-upgrade Branch: refs/heads/master
-rw-r--r--cluster_upgrade/extension.py3
-rw-r--r--cluster_upgrade/handlers.py42
2 files changed, 45 insertions, 0 deletions
diff --git a/cluster_upgrade/extension.py b/cluster_upgrade/extension.py
index 66df106..79bdca4 100644
--- a/cluster_upgrade/extension.py
+++ b/cluster_upgrade/extension.py
@@ -33,6 +33,9 @@ class ClusterUpgradeExtension(extensions.BaseExtension):
33 'handler': handlers.NodeReassignHandler}, 33 'handler': handlers.NodeReassignHandler},
34 {'uri': r'/clusters/(?P<cluster_id>\d+)/upgrade/vips/?$', 34 {'uri': r'/clusters/(?P<cluster_id>\d+)/upgrade/vips/?$',
35 'handler': handlers.CopyVIPsHandler}, 35 'handler': handlers.CopyVIPsHandler},
36 {'uri': r'/clusters/(?P<cluster_id>\d+)/upgrade/clone_release/'
37 r'(?P<release_id>\d+)/?$',
38 'handler': handlers.CreateUpgradeReleaseHandler},
36 ] 39 ]
37 40
38 @classmethod 41 @classmethod
diff --git a/cluster_upgrade/handlers.py b/cluster_upgrade/handlers.py
index 9a89a61..d4b7f71 100644
--- a/cluster_upgrade/handlers.py
+++ b/cluster_upgrade/handlers.py
@@ -143,3 +143,45 @@ class CopyVIPsHandler(base.BaseHandler):
143 143
144 upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter, 144 upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
145 seed_cluster_adapter) 145 seed_cluster_adapter)
146
147
148class CreateUpgradeReleaseHandler(base.BaseHandler):
149 @staticmethod
150 def merge_network_roles(base_nets, orig_nets):
151 """Create network metadata based on two releases.
152
153 Overwrite base default_mapping by orig default_maping values.
154 """
155 orig_network_dict = {n['id']: n for n in orig_nets}
156 for base_net in base_nets:
157 orig_net = orig_network_dict.get(base_net['id'])
158 if orig_net is None:
159 orig_net = base_net
160 base_net['default_mapping'] = orig_net['default_mapping']
161 return base_net
162
163 @base.serialize
164 def POST(self, cluster_id, release_id):
165 """Create release for upgrade purposes.
166
167 Creates a new release with network_roles_metadata based the given
168 release and re-use network parameters from the given cluster.
169
170 :returns: JSON representation of the created cluster
171 :http: * 200 (OK)
172 * 404 (Cluster or release not found.)
173 """
174 base_release = self.get_object_or_404(objects.Release, release_id)
175 orig_cluster = self.get_object_or_404(objects.Cluster, cluster_id)
176 orig_release = orig_cluster.release
177
178 network_metadata = self.merge_network_roles(
179 base_release.network_roles_metadata,
180 orig_release.network_roles_metadata)
181 data = objects.Release.to_dict(base_release)
182 data['network_roles_metadata'] = network_metadata
183 data['name'] = '{0} Upgrade ({1})'.format(
184 base_release.name, orig_release.id)
185 del data['id']
186 new_release = objects.Release.create(data)
187 return new_release.to_dict()