installer_checkpoint.py 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. 'installer_phase_management',
  70. ]
  71. # Define the attributes of the installer phases
  72. phase_attributes = {
  73. 'installer_phase_initialize': {
  74. 'title': 'Initialization',
  75. 'playbook': ''
  76. },
  77. 'installer_phase_etcd': {
  78. 'title': 'etcd Install',
  79. 'playbook': 'playbooks/byo/openshift-etcd/config.yml'
  80. },
  81. 'installer_phase_nfs': {
  82. 'title': 'NFS Install',
  83. 'playbook': 'playbooks/byo/openshift-nfs/config.yml'
  84. },
  85. 'installer_phase_loadbalancer': {
  86. 'title': 'Load balancer Install',
  87. 'playbook': 'playbooks/byo/openshift-loadbalancer/config.yml'
  88. },
  89. 'installer_phase_master': {
  90. 'title': 'Master Install',
  91. 'playbook': 'playbooks/byo/openshift-master/config.yml'
  92. },
  93. 'installer_phase_master_additional': {
  94. 'title': 'Master Additional Install',
  95. 'playbook': 'playbooks/byo/openshift-master/additional_config.yml'
  96. },
  97. 'installer_phase_node': {
  98. 'title': 'Node Install',
  99. 'playbook': 'playbooks/byo/openshift-node/config.yml'
  100. },
  101. 'installer_phase_glusterfs': {
  102. 'title': 'GlusterFS Install',
  103. 'playbook': 'playbooks/byo/openshift-glusterfs/config.yml'
  104. },
  105. 'installer_phase_hosted': {
  106. 'title': 'Hosted Install',
  107. 'playbook': 'playbooks/byo/openshift-cluster/openshift-hosted.yml'
  108. },
  109. 'installer_phase_metrics': {
  110. 'title': 'Metrics Install',
  111. 'playbook': 'playbooks/byo/openshift-cluster/openshift-metrics.yml'
  112. },
  113. 'installer_phase_logging': {
  114. 'title': 'Logging Install',
  115. 'playbook': 'playbooks/byo/openshift-cluster/openshift-logging.yml'
  116. },
  117. 'installer_phase_servicecatalog': {
  118. 'title': 'Service Catalog Install',
  119. 'playbook': 'playbooks/byo/openshift-cluster/service-catalog.yml'
  120. },
  121. 'installer_phase_management': {
  122. 'title': 'Management Install',
  123. 'playbook': 'playbooks/byo/openshift-management/config.yml'
  124. },
  125. }
  126. # Find the longest phase title
  127. max_column = 0
  128. for phase in phase_attributes:
  129. max_column = max(max_column, len(phase_attributes[phase]['title']))
  130. if '_run' in stats.custom:
  131. self._display.banner('INSTALLER STATUS')
  132. for phase in installer_phases:
  133. phase_title = phase_attributes[phase]['title']
  134. padding = max_column - len(phase_title) + 2
  135. if phase in stats.custom['_run']:
  136. phase_status = stats.custom['_run'][phase]
  137. self._display.display(
  138. '{}{}: {}'.format(phase_title, ' ' * padding, phase_status),
  139. color=self.phase_color(phase_status))
  140. if phase_status == 'In Progress' and phase != 'installer_phase_initialize':
  141. self._display.display(
  142. '\tThis phase can be restarted by running: {}'.format(
  143. phase_attributes[phase]['playbook']))
  144. else:
  145. # Phase was not found in custom stats
  146. self._display.display(
  147. '{}{}: {}'.format(phase_title, ' ' * padding, 'Not Started'),
  148. color=C.COLOR_SKIP)
  149. self._display.display("", screen_only=True)
  150. def phase_color(self, status):
  151. """ Return color code for installer phase"""
  152. valid_status = [
  153. 'In Progress',
  154. 'Complete',
  155. ]
  156. if status not in valid_status:
  157. self._display.warning('Invalid phase status defined: {}'.format(status))
  158. if status == 'Complete':
  159. phase_color = C.COLOR_OK
  160. elif status == 'In Progress':
  161. phase_color = C.COLOR_ERROR
  162. else:
  163. phase_color = C.COLOR_WARN
  164. return phase_color