Browse Source

Add VIPs transformer

Move upgrade vips code to the transformer

Change-Id: Ia6935521b8b90b73fb74ba92859e7febf74c4ced
Nikita Zubkov 2 years ago
parent
commit
8de47e0dbf
3 changed files with 72 additions and 43 deletions
  1. 62
    0
      cluster_upgrade/transformations/vip.py
  2. 8
    43
      cluster_upgrade/upgrade.py
  3. 2
    0
      setup.cfg

+ 62
- 0
cluster_upgrade/transformations/vip.py View File

@@ -0,0 +1,62 @@
1
+# coding: utf-8
2
+
3
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+#    not use this file except in compliance with the License. You may obtain
5
+#    a copy of the License at
6
+#
7
+#         http://www.apache.org/licenses/LICENSE-2.0
8
+#
9
+#    Unless required by applicable law or agreed to in writing, software
10
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+#    License for the specific language governing permissions and limitations
13
+#    under the License.
14
+
15
+import collections
16
+
17
+from cluster_upgrade import transformations
18
+
19
+
20
+def transform_vips(data):
21
+    """Rename or remove types of VIPs for 7.0 network groups.
22
+
23
+    This method renames types of VIPs from older releases (<7.0) to
24
+    be compatible with network groups of the 7.0 release according
25
+    to the rules:
26
+
27
+        management: haproxy -> management
28
+        public: haproxy -> public
29
+        public: vrouter -> vrouter_pub
30
+
31
+    Note, that in the result VIPs are present only those IPs that
32
+    correspond to the given rules.
33
+    """
34
+    rename_vip_rules = {
35
+        "management": {
36
+            "haproxy": "management",
37
+            "vrouter": "vrouter",
38
+        },
39
+        "public": {
40
+            "haproxy": "public",
41
+            "vrouter": "vrouter_pub",
42
+        },
43
+    }
44
+    renamed_vips = collections.defaultdict(dict)
45
+    for ng_name, vips_obj in data.items():
46
+
47
+        ng_vip_rules = rename_vip_rules[ng_name]
48
+        for vip_name, vip_addr in vips_obj.items():
49
+            if vip_name not in ng_vip_rules:
50
+                continue
51
+
52
+            new_vip_name = ng_vip_rules[vip_name]
53
+            renamed_vips[ng_name][new_vip_name] = vip_addr
54
+
55
+    return renamed_vips
56
+
57
+
58
+class Manager(transformations.Manager):
59
+    default_config = {
60
+        '7.0': ['transform_vips']
61
+    }
62
+    name = 'vip'

+ 8
- 43
cluster_upgrade/upgrade.py View File

@@ -14,9 +14,7 @@
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16 16
 
17
-import collections
18 17
 import copy
19
-from distutils import version
20 18
 import six
21 19
 
22 20
 from nailgun import consts
@@ -28,6 +26,7 @@ from nailgun import utils
28 26
 from . import transformations  # That's weird, but that's how hacking likes
29 27
 from .objects import adapters
30 28
 from .transformations import cluster as cluster_trs
29
+from .transformations import vip
31 30
 from .transformations import volumes as volumes_trs
32 31
 
33 32
 
@@ -76,6 +75,7 @@ class UpgradeHelper(object):
76 75
         network_configuration.NovaNetworkConfigurationSerializer,
77 76
     }
78 77
     cluster_transformations = transformations.Lazy(cluster_trs.Manager)
78
+    vip_transformations = transformations.Lazy(vip.Manager)
79 79
     volumes_transformations = transformations.Lazy(volumes_trs.Manager)
80 80
 
81 81
     @classmethod
@@ -124,41 +124,6 @@ class UpgradeHelper(object):
124 124
         attrs = new_cluster.attributes
125 125
         attrs['editable']['provision']['method']['value'] = 'image'
126 126
 
127
-    @classmethod
128
-    def transform_vips_for_net_groups_70(cls, vips):
129
-        """Rename or remove types of VIPs for 7.0 network groups.
130
-
131
-        This method renames types of VIPs from older releases (<7.0) to
132
-        be compatible with network groups of the 7.0 release according
133
-        to the rules:
134
-
135
-            management: haproxy -> management
136
-            public: haproxy -> public
137
-            public: vrouter -> vrouter_pub
138
-
139
-        Note, that in the result VIPs are present only those IPs that
140
-        correspond to the given rules.
141
-        """
142
-        rename_vip_rules = {
143
-            "management": {
144
-                "haproxy": "management",
145
-                "vrouter": "vrouter",
146
-            },
147
-            "public": {
148
-                "haproxy": "public",
149
-                "vrouter": "vrouter_pub",
150
-            },
151
-        }
152
-        renamed_vips = collections.defaultdict(dict)
153
-        for ng_name, vips in six.iteritems(vips):
154
-            ng_vip_rules = rename_vip_rules[ng_name]
155
-            for vip_name, vip_addr in six.iteritems(vips):
156
-                if vip_name not in ng_vip_rules:
157
-                    continue
158
-                new_vip_name = ng_vip_rules[vip_name]
159
-                renamed_vips[ng_name][new_vip_name] = vip_addr
160
-        return renamed_vips
161
-
162 127
     @classmethod
163 128
     def copy_network_config(cls, orig_cluster, new_cluster):
164 129
         nets_serializer = cls.network_serializers[orig_cluster.net_provider]
@@ -179,12 +144,12 @@ class UpgradeHelper(object):
179 144
         assigned_vips = orig_net_manager.get_assigned_vips()
180 145
         for ng_name in (consts.NETWORKS.public, consts.NETWORKS.management):
181 146
             vips[ng_name] = assigned_vips[ng_name]
182
-        # NOTE(akscram): In the 7.0 release was introduced networking
183
-        #                templates that use the vip_name column as
184
-        #                unique names of VIPs.
185
-        if version.LooseVersion(orig_cluster.release.environment_version) < \
186
-                version.LooseVersion("7.0"):
187
-            vips = cls.transform_vips_for_net_groups_70(vips)
147
+
148
+        vips = cls.vip_transformations.apply(
149
+            orig_cluster.release.environment_version,
150
+            new_cluster.release.environment_version,
151
+            vips
152
+        )
188 153
         new_net_manager.assign_given_vips_for_net_groups(vips)
189 154
         new_net_manager.assign_vips_for_net_groups()
190 155
 

+ 2
- 0
setup.cfg View File

@@ -31,3 +31,5 @@ nailgun.cluster_upgrade.transformations.cluster.9.0 =
31 31
     dns_list = cluster_upgrade.transformations.cluster:transform_dns_list
32 32
     ntp_list = cluster_upgrade.transformations.cluster:transform_ntp_list
33 33
     drop_provision = cluster_upgrade.transformations.cluster:drop_generated_provision
34
+nailgun.cluster_upgrade.transformations.vip.7.0 =
35
+    transform_vips = cluster_upgrade.transformations.vip:transform_vips

Loading…
Cancel
Save