#NEWLINE# @ click . command ( ) #NEWLINE# @ click . option ( '--latest-minor' , '-l' , is_flag = True , default = False ) #NEWLINE# @ click . option ( '--next-major' , '-n' , is_flag = True , default = False ) #NEWLINE# @ click . pass_context #NEWLINE# def upgrade( ctx , latest_minor , next_major ) : #NEWLINE# #INDENT# oo_cfg = ctx . obj [ 'oo_cfg' ] #NEWLINE# verbose = ctx . obj [ 'verbose' ] #NEWLINE# upgrade_mappings = { #NEWLINE# #INDENT# '3.0' : { #NEWLINE# #INDENT# 'minor_version' : '3.0' , #NEWLINE# 'minor_playbook' : 'v3_0_minor/upgrade.yml' , #NEWLINE# 'major_version' : '3.1' , #NEWLINE# 'major_playbook' : 'v3_0_to_v3_1/upgrade.yml' , #NEWLINE# #UNINDENT# } , #NEWLINE# '3.1' : { #NEWLINE# #INDENT# 'minor_version' : '3.1' , #NEWLINE# 'minor_playbook' : 'v3_1_minor/upgrade.yml' , #NEWLINE# 'major_playbook' : 'v3_1_to_v3_2/upgrade.yml' , #NEWLINE# 'major_version' : '3.2' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# if ( len ( oo_cfg . hosts ) == 0 ) : #NEWLINE# #INDENT# click . echo ( ( 'No hosts defined in: %s' % oo_cfg . config_path ) ) #NEWLINE# sys . exit ( 1 ) #NEWLINE# #UNINDENT# old_variant = oo_cfg . settings [ 'variant' ] #NEWLINE# old_version = oo_cfg . settings [ 'variant_version' ] #NEWLINE# mapping = upgrade_mappings . get ( old_version ) #NEWLINE# message = '\n        This tool will help you upgrade your existing OpenShift installation.\n' #NEWLINE# click . echo ( message ) #NEWLINE# if ( not ( latest_minor or next_major ) ) : #NEWLINE# #INDENT# click . echo ( 'Version {} found. Do you want to update to the latest version of {} or migrate to the next major release?' . format ( old_version , old_version ) ) #NEWLINE# response = click . prompt ( '(1) Update to latest {} (2) Migrate to next release' . format ( old_version ) , type = click . Choice ( [ '1' , '2' ] ) ) #NEWLINE# if ( response == '1' ) : #NEWLINE# #INDENT# latest_minor = True #NEWLINE# #UNINDENT# if ( response == '2' ) : #NEWLINE# #INDENT# next_major = True #NEWLINE# #UNINDENT# #UNINDENT# if next_major : #NEWLINE# #INDENT# playbook = mapping [ 'major_playbook' ] #NEWLINE# new_version = mapping [ 'major_version' ] #NEWLINE# oo_cfg . settings [ 'variant_version' ] = new_version #NEWLINE# if ( oo_cfg . settings [ 'variant' ] == 'enterprise' ) : #NEWLINE# #INDENT# oo_cfg . settings [ 'variant' ] = 'openshift-enterprise' #NEWLINE# #UNINDENT# #UNINDENT# if latest_minor : #NEWLINE# #INDENT# playbook = mapping [ 'minor_playbook' ] #NEWLINE# new_version = mapping [ 'minor_version' ] #NEWLINE# #UNINDENT# click . echo ( ( 'Openshift will be upgraded from %s %s to %s %s on the following hosts:\n' % ( old_variant , old_version , oo_cfg . settings [ 'variant' ] , new_version ) ) ) #NEWLINE# for host in oo_cfg . hosts : #NEWLINE# #INDENT# click . echo ( ( '  * %s' % host . connect_to ) ) #NEWLINE# #UNINDENT# if ( not ctx . obj [ 'unattended' ] ) : #NEWLINE# #INDENT# proceed = click . confirm ( '\nDo you wish to proceed?' ) #NEWLINE# if ( not proceed ) : #NEWLINE# #INDENT# click . echo ( 'Upgrade cancelled.' ) #NEWLINE# sys . exit ( 0 ) #NEWLINE# #UNINDENT# #UNINDENT# retcode = openshift_ansible . run_upgrade_playbook ( playbook , verbose ) #NEWLINE# if ( retcode > 0 ) : #NEWLINE# #INDENT# click . echo ( ( 'Errors encountered during upgrade, please check %s.' % oo_cfg . settings [ 'ansible_log_path' ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# oo_cfg . save_to_disk ( ) #NEWLINE# click . echo ( 'Upgrade completed! Rebooting all hosts is recommended.' )