Browse Source

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
Sergey Abramov 2 years ago
parent
commit
17ab5a3aaa
2 changed files with 45 additions and 0 deletions
  1. 3
    0
      cluster_upgrade/extension.py
  2. 42
    0
      cluster_upgrade/handlers.py

+ 3
- 0
cluster_upgrade/extension.py View File

@@ -33,6 +33,9 @@ class ClusterUpgradeExtension(extensions.BaseExtension):
33 33
          'handler': handlers.NodeReassignHandler},
34 34
         {'uri': r'/clusters/(?P<cluster_id>\d+)/upgrade/vips/?$',
35 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 41
     @classmethod

+ 42
- 0
cluster_upgrade/handlers.py View File

@@ -143,3 +143,45 @@ class CopyVIPsHandler(base.BaseHandler):
143 143
 
144 144
         upgrade.UpgradeHelper.copy_vips(orig_cluster_adapter,
145 145
                                         seed_cluster_adapter)
146
+
147
+
148
+class 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()

Loading…
Cancel
Save