Serializers Conversion extension for Fuel Nailgun
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extension.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2015 Mirantis, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. import logging
  16. from nailgun import extensions
  17. from nailgun import objects
  18. from nailgun.orchestrator.deployment_serializers import \
  19. get_serializer_for_cluster
  20. logger = logging.getLogger(__name__)
  21. class ConvertPreLCMtoLCM(extensions.BasePipeline):
  22. @classmethod
  23. def pre_process_data(cls, data, cluster, nodes, **kwargs):
  24. return data
  25. @classmethod
  26. def post_process_data(cls, data, cluster, nodes, **kwargs):
  27. return data
  28. @classmethod
  29. def serialize(cls, data, cluster, nodes, **kwargs):
  30. if objects.Release.is_lcm_supported(cluster.release):
  31. return data
  32. serializer = get_serializer_for_cluster(cluster)()
  33. real_data = serializer.serialize(cluster, nodes, **kwargs)
  34. return real_data
  35. @classmethod
  36. def process_deployment(cls, data, cluster, nodes, **kwargs):
  37. pre_processed_data = cls.pre_process_data(data,
  38. cluster, nodes, **kwargs)
  39. real_data = cls.serialize(pre_processed_data, cluster, nodes, **kwargs)
  40. post_processed_data = cls.post_process_data(real_data,
  41. cluster, nodes, **kwargs)
  42. # copypaste cluster specific values from LCM serializer.
  43. # This is needed for tasks paramters interpolation like CLUSTER_ID
  44. cluster_data = data[0]['cluster']
  45. for node_data in post_processed_data:
  46. node_data['cluster'] = cluster_data
  47. return post_processed_data
  48. @classmethod
  49. def process_provisioning(cls, data, cluster, nodes, **kwargs):
  50. return data
  51. class ConvertedSerializersExtension(extensions.BaseExtension):
  52. name = 'converted_serializers'
  53. version = '0.0.1'
  54. description = "Serializers Conversion extension"
  55. weight = 100
  56. data_pipelines = [
  57. ConvertPreLCMtoLCM,
  58. ]