def restart_cluster(cluster_name, log, function=None): ''' Restart a cluster. ''' # initialize the control variable OK = True # warn that the log window must not be closed if not isinstance(log, xlib.DevStdOut): log.write( 'This process might take several minutes. Do not close this window, please wait!\n' ) # warn that the requirements are being verified log.write('{0}\n'.format(xlib.get_separator())) log.write('Verifying process requirements ...\n') # verify the master is stopped if OK: (master_state_code, master_state_name) = xec2.get_node_state(cluster_name, 'master') if master_state_code != 80: log.write( '*** ERROR: The cluster {0} is not stopped. Its state is {1} ({2}).\n' .format(cluster_name, master_state_code, master_state_name)) OK = False # warn that the requirements are OK if OK: log.write('Process requirements are OK.\n') # restart the cluster if OK: log.write('{0}\n'.format(xlib.get_separator())) log.write('Restarting cluster {0} using StarCluster ...\n'.format( cluster_name)) log.write('\n') command = '{0} start --no-create {1}'.format(xlib.get_starcluster(), cluster_name) rc = xlib.run_command(command, log) log.write('\n') if rc == 0: log.write('The cluster is restarted.\n') else: log.write('*** ERROR: Return code {0} in command -> {1}\n'.format( rc, command)) OK = False # warn that the log window can be closed if not isinstance(log, xlib.DevStdOut): log.write('{0}\n'.format(xlib.get_separator())) log.write('You can close this window now.\n') # execute final function if function is not None: function() # return the control variable return OK
def remove_node(cluster_name, node_name, log, function=None): ''' Remove a node in a cluster. ''' # initialize the control variable OK = True # warn that the requirements are being verified log.write('{0}\n'.format(xlib.get_separator())) log.write('Verifying process requirements ...\n') # verify the master is running if OK: (master_state_code, master_state_name) = xec2.get_node_state(cluster_name, 'master') if master_state_code != 16: log.write( '*** ERROR: The cluster {0} is not running. Its state is {1} ({2}).' .format(cluster_name, master_state_code, master_state_name)) OK = False # verify the node is running if OK: pass # warn that the requirements are OK if OK: log.write('Process requirements are OK.\n') # remove node if OK: log.write('{0}\n'.format(xlib.get_separator())) log.write( 'Removing node {0} in cluster {1} using StarCluster ...\n'.format( node_name, cluster_name)) log.write('\n') command = '{0} removenode --confirm {1} --alias={2}'.format( xlib.get_starcluster(), cluster_name, node_name) rc = xlib.run_command(command, log) log.write('\n') if rc == 0: log.write('The node is removed.\n') else: log.write('*** ERROR: Return code {0} in command -> {1}\n'.format( rc, command)) OK = False # warn that the log window can be closed if not isinstance(log, xlib.DevStdOut): log.write('{0}\n'.format(xlib.get_separator())) log.write('You can close this window now.\n') # execute final function if function is not None: function() # return the control variable return OK
def list_clusters(log, function=None): ''' List clusters. ''' # initialize the control variable OK = True # get current region region_name = xconfiguration.get_current_region_name() # warn that the log window must not be closed if not isinstance(log, xlib.DevStdOut): log.write( 'This process might take a few minutes. Do not close this window, please wait!\n' ) # warn that the requirements are being verified log.write('{0}\n'.format(xlib.get_separator())) log.write('Verifying process requirements ...\n') # verify if there are some running clusters if xec2.get_running_cluster_list(volume_creator_included=True) == []: log.write('WARNING: There is not any running cluster.\n') OK = False # warn that the requirements are OK if OK: log.write('Process requirements are OK.\n') # list clusters if OK: log.write('{0}\n'.format(xlib.get_separator())) log.write('Listing clusters using StarCluster ...\n') log.write('\n') command = '{0} --region={1} listclusters'.format( xlib.get_starcluster(), region_name) rc = xlib.run_command(command, log) if rc != 0: log.write('*** ERROR: Return code {0} in command -> {1}\n'.format( rc, command)) OK = False # warn that the log window can be closed if not isinstance(log, xlib.DevStdOut): log.write('{0}\n'.format(xlib.get_separator())) log.write('You can close this window now.\n') # execute final function if function is not None: function() # return the control variable return OK
def main(argv): ''' Main line of the program. ''' # verify the operating system. if not sys.platform.startswith('linux') and not sys.platform.startswith( 'darwin') and not sys.platform.startswith( 'win32') and not sys.platform.startswith('cygwin'): print('*** ERROR: The {1} OS is not supported.'.format(sys.platform)) sys.exit(1) # verify the Python version. if sys.version_info[0] == 3 and sys.version_info[1] >= 5: pass else: print('A Python version equal or greater than 3.5 is required.') sys.exit(1) # verify if Boto3 is set up try: import boto3 except: print('*** ERROR: The library boto3 is not installed.') print('Please, review how to set up Boto3 in the manual.') sys.exit(1) # verify if Paramiko is set up try: import paramiko except: print('*** ERROR: The library paramiko is not installed.') print('Please, review how to set up Paramiko in the manual.') sys.exit(1) # verify if Paramiko is set up try: import paramiko except: print('*** ERROR: The library paramiko is not installed.') print('Please, review how to set up Paramiko in the manual.') sys.exit(1) # get and verify the options parser = build_parser() (options, args) = parser.parse_args() verify_options(options) # verify if the required graphical libraries are setup if options.mode == 'gui' or options.mode is None: # verify if the library PIL.Image is set up try: import tkinter except: print('*** ERROR: The library tkinter is not installed.') print('Please, review how to set up Tkinter in the manual.') sys.exit(1) # verify if the library PIL.Image is set up try: import PIL.Image except: print('*** ERROR: The library PIL.Image is not installed.') print('Please, review how to set up PIL.Image in the manual.') sys.exit(1) # verify if the library PIL.ImageTk is set up try: import PIL.ImageTk except: print('*** ERROR: The library PIL.ImageTk is not installed.') print('Please, review how to set up PIL.ImageTk in the manual.') sys.exit(1) # import required application libraries import ccloud import cmenu import gmain import xlib # verify if StarCluster is set up command = '{0} --version'.format(xlib.get_starcluster()) devstdout = xlib.DevStdOut('starcluster_version', print_stdout=False) rc = xlib.run_command(command, devstdout) if rc != 0: print( '*** ERROR: The cluster-computing toolkit StarCluster 0.95.6 is not installed or excecution permissions have not set.' ) print('Please, review how to set up in the manual.') sys.exit(1) else: with open(devstdout.get_log_file(), 'r') as log_command: version_found = False for line in log_command: if line.startswith('0.95.6'): version_found = True if not version_found: print( '*** ERROR: The cluster-computing toolkit StarCluster 0.95.6 is not installed or excecution permissions have not set.' ) print('Please, review how to set up in the manual.') sys.exit(1) # start the user interface depending on the mode if options.mode == 'gui' or options.mode is None: main = gmain.Main() main.mainloop() else: ccloud.form_set_environment() cmenu.build_menu_main()
def terminate_cluster(cluster_name, force, log, function=None, is_menu_call=True): ''' Terminate a cluster. ''' # initialize the control variable OK = True # get current region region_name = xconfiguration.get_current_region_name() # warn that the log window does not have to be closed if not isinstance(log, xlib.DevStdOut) and is_menu_call: log.write( 'This process might take a few minutes. Do not close this window, please wait!\n' ) # warn that the requirements are being verified log.write(f'{xlib.get_separator()}\n') log.write('Checking process requirements ...\n') # check the cluster is running if OK: (master_state_code, master_state_name) = xec2.get_node_state(cluster_name, node_name='master') if not force and master_state_code != 16: log.write( f'*** ERROR: The cluster {cluster_name} is not running. Its state is {master_state_code} ({master_state_name}).\n' ) OK = False # warn that the requirements are OK if OK: log.write('Process requirements are OK.\n') # terminate cluster if OK: log.write(f'{xlib.get_separator()}\n') if cluster_name == xlib.get_volume_creator_name(): log.write('Terminating the volume creator using StarCluster ...\n') else: log.write( 'Terminating the cluster {0} using StarCluster ...\n'.format( cluster_name)) log.write('\n') if not force: command = '{0} --region={1} terminate --confirm {2}'.format( xlib.get_starcluster(), region_name, cluster_name) else: command = '{0} --region={1} terminate --force --confirm {2}'.format( xlib.get_starcluster(), region_name, cluster_name) rc = xlib.run_command(command, log) log.write('\n') if rc == 0: if cluster_name == xlib.get_volume_creator_name(): log.write('The volume creator is terminated.\n') else: log.write('The cluster is terminated.\n') else: log.write('*** ERROR: Return code {0} in command -> {1}\n'.format( rc, command)) OK = False # warn that the log window can be closed if not isinstance(log, xlib.DevStdOut) and is_menu_call: log.write(f'{xlib.get_separator()}\n') log.write('You can close this window now.\n') # execute final function if function is not None: function() # return the control variable return OK
def create_cluster(template_name, cluster_name, log, function=None, is_menu_call=True): ''' Create a cluster from a template name. ''' # initialize the control variable OK = True # initialize the state variables master_state_code = '' master_state_name = '' # get current region and zone names region_name = xconfiguration.get_current_region_name() zone_name = xconfiguration.get_current_zone_name() # warn that the log window does not have to be closed if not isinstance(log, xlib.DevStdOut) and is_menu_call: log.write( 'This process might take several minutes. Do not close this window, please wait!\n' ) # warn that the requirements are being verified log.write(f'{xlib.get_separator()}\n') log.write('Checking process requirements ...\n') # check that the cluster is defined in the NGScloud config file if OK: if not xconfiguration.is_template_defined(template_name): log.write( '*** ERROR: The cluster {0} is not defined in the {1} config file.\n' .format(cluster_name, xlib.get_project_name())) OK = False # check that the cluster mode is None if OK: if xec2.get_cluster_mode(cluster_name) is not None: log.write('*** ERROR: There is a cluster or a instance running.\n') OK = False # check that the zone is available if OK: if not xec2.is_zone_available(region_name, zone_name): log.write( '*** ERROR: The zone name {0} is not available.\n'.format( zone_name)) OK = False # warn that the requirements are OK if OK: log.write('Process requirements are OK.\n') # create the cluster if OK: log.write(f'{xlib.get_separator()}\n') if cluster_name == xlib.get_volume_creator_name(): log.write('Creating the volume creator using StarCluster ...\n') else: log.write( 'Creating the cluster {0} using StarCluster ...\n'.format( cluster_name)) log.write('\n') if template_name == xlib.get_volume_creator_name(): command = '{0} --region={1} start --availability-zone={2} --cluster-template={3} --disable-queue {4}'.format( xlib.get_starcluster(), region_name, zone_name, template_name, cluster_name) else: command = '{0} --region={1} start --availability-zone={2} --cluster-template={3} {4}'.format( xlib.get_starcluster(), region_name, zone_name, template_name, cluster_name) rc = xlib.run_command(command, log) log.write('\n') if rc == 0: (master_state_code, master_state_name) = xec2.get_node_state(cluster_name, node_name='master') if cluster_name == xlib.get_volume_creator_name(): log.write('The volume creator is created.\n') else: log.write('The cluster is created.\n') else: log.write('*** ERROR: Return code {0} in command -> {1}\n'.format( rc, command)) log.write('***') log.write( '*** You have to terminate {0} (option "Force termination of a cluster")\n' .format(cluster_name)) log.write('*** and create it again.\n') OK = False # install infrastructure software in every node of the cluster if OK: if cluster_name != xlib.get_volume_creator_name(): cluster_node_list = xec2.get_cluster_node_list(cluster_name) for node_name in cluster_node_list: OK = xnode.install_node_infrastructure_software( cluster_name, node_name, log) # warn that the log window can be closed if not isinstance(log, xlib.DevStdOut) and is_menu_call: log.write(f'{xlib.get_separator()}\n') log.write('You can close this window now.\n') # execute final function if function is not None: function() # return the control variable and the state return (OK, master_state_code, master_state_name)