diff --git a/cluster_upgrade/transformations/vip.py b/cluster_upgrade/transformations/vip.py new file mode 100644 index 0000000..417b5f6 --- /dev/null +++ b/cluster_upgrade/transformations/vip.py @@ -0,0 +1,62 @@ +# coding: utf-8 + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import collections + +from cluster_upgrade import transformations + + +def transform_vips(data): + """Rename or remove types of VIPs for 7.0 network groups. + + This method renames types of VIPs from older releases (<7.0) to + be compatible with network groups of the 7.0 release according + to the rules: + + management: haproxy -> management + public: haproxy -> public + public: vrouter -> vrouter_pub + + Note, that in the result VIPs are present only those IPs that + correspond to the given rules. + """ + rename_vip_rules = { + "management": { + "haproxy": "management", + "vrouter": "vrouter", + }, + "public": { + "haproxy": "public", + "vrouter": "vrouter_pub", + }, + } + renamed_vips = collections.defaultdict(dict) + for ng_name, vips_obj in data.items(): + + ng_vip_rules = rename_vip_rules[ng_name] + for vip_name, vip_addr in vips_obj.items(): + if vip_name not in ng_vip_rules: + continue + + new_vip_name = ng_vip_rules[vip_name] + renamed_vips[ng_name][new_vip_name] = vip_addr + + return renamed_vips + + +class Manager(transformations.Manager): + default_config = { + '7.0': ['transform_vips'] + } + name = 'vip' diff --git a/cluster_upgrade/upgrade.py b/cluster_upgrade/upgrade.py index bd2c580..dde0606 100644 --- a/cluster_upgrade/upgrade.py +++ b/cluster_upgrade/upgrade.py @@ -14,9 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -import collections import copy -from distutils import version import six from nailgun import consts @@ -28,6 +26,7 @@ from nailgun import utils from . import transformations # That's weird, but that's how hacking likes from .objects import adapters from .transformations import cluster as cluster_trs +from .transformations import vip from .transformations import volumes as volumes_trs @@ -76,6 +75,7 @@ class UpgradeHelper(object): network_configuration.NovaNetworkConfigurationSerializer, } cluster_transformations = transformations.Lazy(cluster_trs.Manager) + vip_transformations = transformations.Lazy(vip.Manager) volumes_transformations = transformations.Lazy(volumes_trs.Manager) @classmethod @@ -124,41 +124,6 @@ class UpgradeHelper(object): attrs = new_cluster.attributes attrs['editable']['provision']['method']['value'] = 'image' - @classmethod - def transform_vips_for_net_groups_70(cls, vips): - """Rename or remove types of VIPs for 7.0 network groups. - - This method renames types of VIPs from older releases (<7.0) to - be compatible with network groups of the 7.0 release according - to the rules: - - management: haproxy -> management - public: haproxy -> public - public: vrouter -> vrouter_pub - - Note, that in the result VIPs are present only those IPs that - correspond to the given rules. - """ - rename_vip_rules = { - "management": { - "haproxy": "management", - "vrouter": "vrouter", - }, - "public": { - "haproxy": "public", - "vrouter": "vrouter_pub", - }, - } - renamed_vips = collections.defaultdict(dict) - for ng_name, vips in six.iteritems(vips): - ng_vip_rules = rename_vip_rules[ng_name] - for vip_name, vip_addr in six.iteritems(vips): - if vip_name not in ng_vip_rules: - continue - new_vip_name = ng_vip_rules[vip_name] - renamed_vips[ng_name][new_vip_name] = vip_addr - return renamed_vips - @classmethod def copy_network_config(cls, orig_cluster, new_cluster): nets_serializer = cls.network_serializers[orig_cluster.net_provider] @@ -179,12 +144,12 @@ class UpgradeHelper(object): assigned_vips = orig_net_manager.get_assigned_vips() for ng_name in (consts.NETWORKS.public, consts.NETWORKS.management): vips[ng_name] = assigned_vips[ng_name] - # NOTE(akscram): In the 7.0 release was introduced networking - # templates that use the vip_name column as - # unique names of VIPs. - if version.LooseVersion(orig_cluster.release.environment_version) < \ - version.LooseVersion("7.0"): - vips = cls.transform_vips_for_net_groups_70(vips) + + vips = cls.vip_transformations.apply( + orig_cluster.release.environment_version, + new_cluster.release.environment_version, + vips + ) new_net_manager.assign_given_vips_for_net_groups(vips) new_net_manager.assign_vips_for_net_groups() diff --git a/setup.cfg b/setup.cfg index ea69fea..c88b57f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -31,3 +31,5 @@ nailgun.cluster_upgrade.transformations.cluster.9.0 = dns_list = cluster_upgrade.transformations.cluster:transform_dns_list ntp_list = cluster_upgrade.transformations.cluster:transform_ntp_list drop_provision = cluster_upgrade.transformations.cluster:drop_generated_provision +nailgun.cluster_upgrade.transformations.vip.7.0 = + transform_vips = cluster_upgrade.transformations.vip:transform_vips