installer_checkpoint.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. """Ansible callback plugin to print a summary completion status of installation
  2. phases.
  3. """
  4. from ansible.plugins.callback import CallbackBase
  5. from ansible import constants as C
  6. DOCUMENTATION = '''
  7. '''
  8. EXAMPLES = '''
  9. ---------------------------------------------
  10. Example display of a successful playbook run:
  11. PLAY RECAP *********************************************************************
  12. master01.example.com : ok=158 changed=16 unreachable=0 failed=0
  13. node01.example.com : ok=469 changed=74 unreachable=0 failed=0
  14. node02.example.com : ok=157 changed=17 unreachable=0 failed=0
  15. localhost : ok=24 changed=0 unreachable=0 failed=0
  16. INSTALLER STATUS ***************************************************************
  17. Initialization : Complete
  18. etcd Install : Complete
  19. NFS Install : Not Started
  20. Load balancer Install : Not Started
  21. Master Install : Complete
  22. Master Additional Install : Complete
  23. Node Install : Complete
  24. GlusterFS Install : Not Started
  25. Hosted Install : Complete
  26. Metrics Install : Not Started
  27. Logging Install : Not Started
  28. Service Catalog Install : Not Started
  29. -----------------------------------------------------
  30. Example display if a failure occurs during execution:
  31. INSTALLER STATUS ***************************************************************
  32. Initialization : Complete
  33. etcd Install : Complete
  34. NFS Install : Not Started
  35. Load balancer Install : Not Started
  36. Master Install : In Progress
  37. This phase can be restarted by running: playbooks/byo/openshift-master/config.yml
  38. Master Additional Install : Not Started
  39. Node Install : Not Started
  40. GlusterFS Install : Not Started
  41. Hosted Install : Not Started
  42. Metrics Install : Not Started
  43. Logging Install : Not Started
  44. Service Catalog Install : Not Started
  45. '''
  46. class CallbackModule(CallbackBase):
  47. """This callback summarizes installation phase status."""
  48. CALLBACK_VERSION = 2.0
  49. CALLBACK_TYPE = 'aggregate'
  50. CALLBACK_NAME = 'installer_checkpoint'
  51. CALLBACK_NEEDS_WHITELIST = False
  52. def __init__(self):
  53. super(CallbackModule, self).__init__()
  54. def v2_playbook_on_stats(self, stats):
  55. # Set the order of the installer phases
  56. installer_phases = [
  57. 'installer_phase_initialize',
  58. 'installer_phase_etcd',
  59. 'installer_phase_nfs',
  60. 'installer_phase_loadbalancer',
  61. 'installer_phase_master',
  62. 'installer_phase_master_additional',
  63. 'installer_phase_node',
  64. 'installer_phase_glusterfs',
  65. 'installer_phase_hosted',
  66. 'installer_phase_metrics',
  67. 'installer_phase_logging',
  68. 'installer_phase_servicecatalog',
  69. ]
  70. # Define the attributes of the installer phases
  71. phase_attributes = {
  72. 'installer_phase_initialize': {
  73. 'title': 'Initialization',
  74. 'playbook': ''
  75. },
  76. 'installer_phase_etcd': {
  77. 'title': 'etcd Install',
  78. 'playbook': 'playbooks/byo/openshift-etcd/config.yml'
  79. },
  80. 'installer_phase_nfs': {
  81. 'title': 'NFS Install',
  82. 'playbook': 'playbooks/byo/openshift-nfs/config.yml'
  83. },
  84. 'installer_phase_loadbalancer': {
  85. 'title': 'Load balancer Install',
  86. 'playbook': 'playbooks/byo/openshift-loadbalancer/config.yml'
  87. },
  88. 'installer_phase_master': {
  89. 'title': 'Master Install',
  90. 'playbook': 'playbooks/byo/openshift-master/config.yml'
  91. },
  92. 'installer_phase_master_additional': {
  93. 'title': 'Master Additional Install',
  94. 'playbook': 'playbooks/byo/openshift-master/additional_config.yml'
  95. },
  96. 'installer_phase_node': {
  97. 'title': 'Node Install',
  98. 'playbook': 'playbooks/byo/openshift-node/config.yml'
  99. },
  100. 'installer_phase_glusterfs': {
  101. 'title': 'GlusterFS Install',
  102. 'playbook': 'playbooks/byo/openshift-glusterfs/config.yml'
  103. },
  104. 'installer_phase_hosted': {
  105. 'title': 'Hosted Install',
  106. 'playbook': 'playbooks/byo/openshift-cluster/openshift-hosted.yml'
  107. },
  108. 'installer_phase_metrics': {
  109. 'title': 'Metrics Install',
  110. 'playbook': 'playbooks/byo/openshift-cluster/openshift-metrics.yml'
  111. },
  112. 'installer_phase_logging': {
  113. 'title': 'Logging Install',
  114. 'playbook': 'playbooks/byo/openshift-cluster/openshift-logging.yml'
  115. },
  116. 'installer_phase_servicecatalog': {
  117. 'title': 'Service Catalog Install',
  118. 'playbook': 'playbooks/byo/openshift-cluster/service-catalog.yml'
  119. },
  120. }
  121. # Find the longest phase title
  122. max_column = 0
  123. for phase in phase_attributes:
  124. max_column = max(max_column, len(phase_attributes[phase]['title']))
  125. if '_run' in stats.custom:
  126. self._display.banner('INSTALLER STATUS')
  127. for phase in installer_phases:
  128. phase_title = phase_attributes[phase]['title']
  129. padding = max_column - len(phase_title) + 2
  130. if phase in stats.custom['_run']:
  131. phase_status = stats.custom['_run'][phase]
  132. self._display.display(
  133. '{}{}: {}'.format(phase_title, ' ' * padding, phase_status),
  134. color=self.phase_color(phase_status))
  135. if phase_status == 'In Progress' and phase != 'installer_phase_initialize':
  136. self._display.display(
  137. '\tThis phase can be restarted by running: {}'.format(
  138. phase_attributes[phase]['playbook']))
  139. else:
  140. # Phase was not found in custom stats
  141. self._display.display(
  142. '{}{}: {}'.format(phase_title, ' ' * padding, 'Not Started'),
  143. color=C.COLOR_SKIP)
  144. self._display.display("", screen_only=True)
  145. def phase_color(self, status):
  146. """ Return color code for installer phase"""
  147. valid_status = [
  148. 'In Progress',
  149. 'Complete',
  150. ]
  151. if status not in valid_status:
  152. self._display.warning('Invalid phase status defined: {}'.format(status))
  153. if status == 'Complete':
  154. phase_color = C.COLOR_OK
  155. elif status == 'In Progress':
  156. phase_color = C.COLOR_ERROR
  157. else:
  158. phase_color = C.COLOR_WARN
  159. return phase_color