def create_serializer(cluster): """Returns a serializer depends on a given `cluster`. :param cluster: a cluster to process :returns: a serializer for a given cluster """ # env-version serializer map serializers_map = { '5.0': { 'multinode': (DeploymentMultinodeSerializer, ps.PriorityMultinodeSerializer50), 'ha': (DeploymentHASerializer, ps.PriorityHASerializer50), }, '5.1': { 'multinode': (DeploymentMultinodeSerializer51, ps.PriorityMultinodeSerializer51), 'ha': (DeploymentHASerializer51, ps.PriorityHASerializer51), }, } env_version = extract_env_version(cluster.release.version) env_mode = 'ha' if cluster.is_ha_mode else 'multinode' # choose serializer for version, serializers in six.iteritems(serializers_map): if env_version.startswith(version): serializer, priority = serializers[env_mode] if cluster.pending_release_id: priority = { 'ha': ps.PriorityHASerializerPatching, 'multinode': ps.PriorityMultinodeSerializerPatching, }.get(env_mode) return serializer(priority()) raise errors.UnsupportedSerializer()
def _get_env_version(cls, instance): """Returns environment's version. Returns current Fuel version by default. """ if instance.node.cluster: return extract_env_version(instance.node.cluster.release.version) return settings.VERSION["release"]
def get_serializer_for_cluster(cluster): """Returns a serializer depends on a given `cluster`. :param cluster: cluster to process :returns: a serializer for a given cluster """ serializers_map = { '5.0': { 'multinode': DeploymentMultinodeSerializer, 'ha': DeploymentHASerializer, }, '5.1': { 'multinode': DeploymentMultinodeSerializer51, 'ha': DeploymentHASerializer51, }, '6.0': { 'multinode': DeploymentMultinodeSerializer60, 'ha': DeploymentHASerializer60, }, '6.1': { 'multinode': DeploymentMultinodeSerializer61, 'ha': DeploymentHASerializer61, }, } env_version = extract_env_version(cluster.release.version) env_mode = 'ha' if cluster.is_ha_mode else 'multinode' for version, serializers in six.iteritems(serializers_map): if env_version.startswith(version): return serializers[env_mode] raise errors.UnsupportedSerializer()
def get_deployment_tasks(cls, instance): """Get deployment graph based on release version.""" env_version = extract_env_version(instance.version) if env_version.startswith('5.0'): return yaml.load(graph_configuration.DEPLOYMENT_50) elif env_version.startswith('5.1') or env_version.startswith('6.0'): return yaml.load(graph_configuration.DEPLOYMENT_51_60)
def get_deployment_tasks(cls, instance): """Get deployment graph based on release version.""" env_version = extract_env_version(instance.version) if instance.deployment_tasks: return instance.deployment_tasks elif env_version.startswith('5.0'): return yaml.load(graph_configuration.DEPLOYMENT_50) else: return yaml.load(graph_configuration.DEPLOYMENT_CURRENT)
def create_serializer(cluster): """Returns a serializer depends on a given `cluster`. :param cluster: a cluster to process :returns: a serializer for a given cluster """ # env-version serializer map serializers_map = { '5.0': { 'multinode': ( DeploymentMultinodeSerializer, ps.PriorityMultinodeSerializer50, ), 'ha': ( DeploymentHASerializer, ps.PriorityHASerializer50, ), }, '5.1': { 'multinode': ( DeploymentMultinodeSerializer51, ps.PriorityMultinodeSerializer51, ), 'ha': ( DeploymentHASerializer51, ps.PriorityHASerializer51, ), }, '6.0': { 'multinode': ( DeploymentMultinodeSerializer60, ps.PriorityMultinodeSerializer60, ), 'ha': ( DeploymentHASerializer60, ps.PriorityHASerializer60, ), }, } env_version = extract_env_version(cluster.release.version) env_mode = 'ha' if cluster.is_ha_mode else 'multinode' # choose serializer for version, serializers in six.iteritems(serializers_map): if env_version.startswith(version): serializer, priority = serializers[env_mode] if cluster.pending_release_id: priority = { 'ha': ps.PriorityHASerializerPatching, 'multinode': ps.PriorityMultinodeSerializerPatching, }.get(env_mode) return serializer(priority()) raise errors.UnsupportedSerializer()
def test_extract_env_version(self): # format: input, output pairs test_cases = [ ('2014.1', '5.0'), ('2014.1-5.0', '5.0'), ('2014.1.1-5.0.1', '5.0.1'), ('2014.1.1-5.0.1-X', '5.0.1'), ('2014.1.1-5.1', '5.1'), ] for input_, output in test_cases: self.assertEqual(extract_env_version(input_), output)
def serialize(orchestrator_graph, cluster, nodes, ignore_customized=False): """Serialization depends on deployment mode """ objects.Cluster.set_primary_roles(cluster, nodes) env_version = utils.extract_env_version(cluster.release.version) # Only assign IPs for private (GRE) network in 6.1+ if any([env_version.startswith(v) for v in ['5.0', '5.1', '6.0']]): objects.NodeCollection.prepare_for_lt_6_1_deployment(cluster.nodes) else: nst = cluster.network_config.get('segmentation_type') objects.NodeCollection.prepare_for_deployment(cluster.nodes, nst) serializer = get_serializer_for_cluster(cluster)(orchestrator_graph) return serializer.serialize( cluster, nodes, ignore_customized=ignore_customized)
def get_serializer_for_cluster(cluster): """Returns a serializer depends on a given `cluster`. :param cluster: cluster to process :returns: a serializer for a given cluster """ serializers_map = { '5': ProvisioningSerializer, '6.0': ProvisioningSerializer, } env_version = extract_env_version(cluster.release.version) for version, serializer in six.iteritems(serializers_map): if env_version.startswith(version): return serializer # by default, we should return latest serializer return ProvisioningSerializer61
def get_serializer_for_cluster(cluster): """Returns a serializer depends on a given `cluster`. :param cluster: cluster to process :returns: a serializer for a given cluster """ serializers_map = { '5.0': { 'multinode': DeploymentMultinodeSerializer50, 'ha': DeploymentHASerializer50, }, '5.1': { 'multinode': DeploymentMultinodeSerializer51, 'ha': DeploymentHASerializer51, }, '6.0': { 'multinode': DeploymentMultinodeSerializer60, 'ha': DeploymentHASerializer60, }, '6.1': { 'multinode': DeploymentMultinodeSerializer61, 'ha': DeploymentHASerializer61, }, '7.0': { # Multinode is not supported anymore 'ha': DeploymentHASerializer70, } } env_version = utils.extract_env_version(cluster.release.version) env_mode = 'ha' if cluster.is_ha_mode else 'multinode' for version, serializers in six.iteritems(serializers_map): if env_version.startswith(version): return serializers[env_mode] # return latest serializer by default latest_version = sorted(six.iterkeys(serializers_map))[-1] return serializers_map[latest_version][env_mode]