installer_checkpoint.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. Prometheus Install : Not Started
  29. Service Catalog Install : Not Started
  30. -----------------------------------------------------
  31. Example display if a failure occurs during execution:
  32. INSTALLER STATUS ***************************************************************
  33. Initialization : Complete
  34. etcd Install : Complete
  35. NFS Install : Not Started
  36. Load balancer Install : Not Started
  37. Master Install : In Progress
  38. This phase can be restarted by running: playbooks/byo/openshift-master/config.yml
  39. Master Additional Install : Not Started
  40. Node Install : Not Started
  41. GlusterFS Install : Not Started
  42. Hosted Install : Not Started
  43. Metrics Install : Not Started
  44. Logging Install : Not Started
  45. Prometheus Install : Not Started
  46. Service Catalog Install : Not Started
  47. '''
  48. class CallbackModule(CallbackBase):
  49. """This callback summarizes installation phase status."""
  50. CALLBACK_VERSION = 2.0
  51. CALLBACK_TYPE = 'aggregate'
  52. CALLBACK_NAME = 'installer_checkpoint'
  53. CALLBACK_NEEDS_WHITELIST = False
  54. def __init__(self):
  55. super(CallbackModule, self).__init__()
  56. def v2_playbook_on_stats(self, stats):
  57. # Set the order of the installer phases
  58. installer_phases = [
  59. 'installer_phase_initialize',
  60. 'installer_phase_health',
  61. 'installer_phase_etcd',
  62. 'installer_phase_nfs',
  63. 'installer_phase_loadbalancer',
  64. 'installer_phase_master',
  65. 'installer_phase_master_additional',
  66. 'installer_phase_node',
  67. 'installer_phase_glusterfs',
  68. 'installer_phase_hosted',
  69. 'installer_phase_metrics',
  70. 'installer_phase_logging',
  71. 'installer_phase_prometheus',
  72. 'installer_phase_servicecatalog',
  73. 'installer_phase_management',
  74. ]
  75. # Define the attributes of the installer phases
  76. phase_attributes = {
  77. 'installer_phase_initialize': {
  78. 'title': 'Initialization',
  79. 'playbook': ''
  80. },
  81. 'installer_phase_health': {
  82. 'title': 'Health Check',
  83. 'playbook': 'playbooks/byo/openshift-checks/pre-install.yml'
  84. },
  85. 'installer_phase_etcd': {
  86. 'title': 'etcd Install',
  87. 'playbook': 'playbooks/byo/openshift-etcd/config.yml'
  88. },
  89. 'installer_phase_nfs': {
  90. 'title': 'NFS Install',
  91. 'playbook': 'playbooks/byo/openshift-nfs/config.yml'
  92. },
  93. 'installer_phase_loadbalancer': {
  94. 'title': 'Load balancer Install',
  95. 'playbook': 'playbooks/byo/openshift-loadbalancer/config.yml'
  96. },
  97. 'installer_phase_master': {
  98. 'title': 'Master Install',
  99. 'playbook': 'playbooks/byo/openshift-master/config.yml'
  100. },
  101. 'installer_phase_master_additional': {
  102. 'title': 'Master Additional Install',
  103. 'playbook': 'playbooks/byo/openshift-master/additional_config.yml'
  104. },
  105. 'installer_phase_node': {
  106. 'title': 'Node Install',
  107. 'playbook': 'playbooks/byo/openshift-node/config.yml'
  108. },
  109. 'installer_phase_glusterfs': {
  110. 'title': 'GlusterFS Install',
  111. 'playbook': 'playbooks/byo/openshift-glusterfs/config.yml'
  112. },
  113. 'installer_phase_hosted': {
  114. 'title': 'Hosted Install',
  115. 'playbook': 'playbooks/byo/openshift-cluster/openshift-hosted.yml'
  116. },
  117. 'installer_phase_metrics': {
  118. 'title': 'Metrics Install',
  119. 'playbook': 'playbooks/byo/openshift-cluster/openshift-metrics.yml'
  120. },
  121. 'installer_phase_logging': {
  122. 'title': 'Logging Install',
  123. 'playbook': 'playbooks/byo/openshift-cluster/openshift-logging.yml'
  124. },
  125. 'installer_phase_prometheus': {
  126. 'title': 'Prometheus Install',
  127. 'playbook': 'playbooks/byo/openshift-cluster/openshift-prometheus.yml'
  128. },
  129. 'installer_phase_servicecatalog': {
  130. 'title': 'Service Catalog Install',
  131. 'playbook': 'playbooks/byo/openshift-cluster/service-catalog.yml'
  132. },
  133. 'installer_phase_management': {
  134. 'title': 'Management Install',
  135. 'playbook': 'playbooks/byo/openshift-management/config.yml'
  136. },
  137. }
  138. # Find the longest phase title
  139. max_column = 0
  140. for phase in phase_attributes:
  141. max_column = max(max_column, len(phase_attributes[phase]['title']))
  142. if '_run' in stats.custom:
  143. self._display.banner('INSTALLER STATUS')
  144. for phase in installer_phases:
  145. phase_title = phase_attributes[phase]['title']
  146. padding = max_column - len(phase_title) + 2
  147. if phase in stats.custom['_run']:
  148. phase_status = stats.custom['_run'][phase]
  149. self._display.display(
  150. '{}{}: {}'.format(phase_title, ' ' * padding, phase_status),
  151. color=self.phase_color(phase_status))
  152. if phase_status == 'In Progress' and phase != 'installer_phase_initialize':
  153. self._display.display(
  154. '\tThis phase can be restarted by running: {}'.format(
  155. phase_attributes[phase]['playbook']))
  156. self._display.display("", screen_only=True)
  157. def phase_color(self, status):
  158. """ Return color code for installer phase"""
  159. valid_status = [
  160. 'In Progress',
  161. 'Complete',
  162. ]
  163. if status not in valid_status:
  164. self._display.warning('Invalid phase status defined: {}'.format(status))
  165. if status == 'Complete':
  166. phase_color = C.COLOR_OK
  167. elif status == 'In Progress':
  168. phase_color = C.COLOR_ERROR
  169. else:
  170. phase_color = C.COLOR_WARN
  171. return phase_color