summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-08-24 19:52:17 +0000
committerGerrit Code Review <review@openstack.org>2016-08-24 19:52:17 +0000
commit09a6e1c20fbd36e3bba9591917593783cbc49998 (patch)
treeaaa25acc2c934d75f965c6627e4216c79ccf484b
parent7ee7152fa4a5e1d1f8943896af3df139e9061daa (diff)
parent17ab5a3aaa7d2c4ae4652d1a4dc0410b31e7c47d (diff)
Merge "Add create upgrade release handler"
-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()