Пример #1
0
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
Пример #2
0
def form_create_keypairs():
    '''
    Create the key pairs of a region.
    '''

    # initialize the control variable
    OK = True

    # print the header and get the cluster name
    clib.clear_screen()
    clib.print_headers_with_environment('Security - Create key pairs')

    # get current region name
    region_name = xconfiguration.get_current_region_name()

    # confirm the creation of the key pairs
    print(xlib.get_separator())
    OK = clib.confirm_action('The key pairs of the region {0} are going to be created.'.format(region_name))

    # create key pairs
    if OK:
        print(xlib.get_separator())
        print('The key pairs of the region {0} are been created ...'.format(region_name))
        (OK, error_list) = xec2.create_keypairs(region_name)
        if OK:
            print('The key pairs and their corresponding local files have been created.')
        else:
            for error in error_list:
                print(error)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #3
0
def form_list_keypairs():
    '''
    List the key pairs of a region.
    '''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Security - List key pairs')

    # get the key pair dictionary and the keypair names list
    keypairs_dict = xec2.get_keypair_dict(region_name)
    keypair_keys_list = sorted(keypairs_dict.keys())
 
    # list keypairs
    print(xlib.get_separator())
    if keypair_keys_list == []:
        print('WARNING: There is not any keypair created in the region {0}.'.format(region_name))
    else:
        # set data width
        keypair_name_width = 25
        fingerprint_width = 59
        # set line template
        line_template = '{0:' + str(keypair_name_width) + '}   {1:' + str(fingerprint_width) + '}'
        # print header
        print(line_template.format('Key Pair Name', 'Fingerprint'))
        print(line_template.format('=' * keypair_name_width, '=' * fingerprint_width))
        # print detail lines
        for keypair_key in keypair_keys_list:
            keypair_name = keypairs_dict[keypair_key]['keypair_name']
            fingerprint = keypairs_dict[keypair_key]['fingerprint']
            print(line_template.format(keypair_name, fingerprint))

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #4
0
def form_manage_toa_database(process_type):
    '''
    Manage the TOA database.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    if process_type == xlib.get_toa_type_recreate():
        clib.print_headers_with_environment(
            f'{xlib.get_toa_name()} - Recreate database')
    elif process_type == xlib.get_toa_type_rebuild():
        clib.print_headers_with_environment(
            f'{xlib.get_toa_name()} - Rebuild database')

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(
            f'The {xlib.get_toa_name()} database is going to be {process_type}.'
        )

    # run the process
    if OK:
        devstdout = xlib.DevStdOut(xtoa.manage_toa_database.__name__)
        OK = xtoa.manage_toa_database(process_type, devstdout, function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #5
0
def form_edit_pipeline_config_file(pipeline_type):
    '''
    Edit a pipeline config file to change the parameters of each process.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()
    elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
        name = xlib.get_toa_process_merge_annotations_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Edit config file')

    # get the config file
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        config_file = xtoa.get_nucleotide_pipeline_config_file()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        config_file = xtoa.get_aminoacid_pipeline_config_file()
    elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
        config_file = xtoa.get_annotation_merger_config_file()

    # edit the read transfer config file
    print(xlib.get_separator())
    print(f'Editing the {name} config file ...')
    command = f'{xlib.get_editor()} {config_file}'
    rc = subprocess.call(command, shell=True)
    if rc != 0:
        print(f'*** ERROR: RC {rc} in command -> {command}')
        OK = False

    # check the config file
    if OK:
        print(xlib.get_separator())
        print(f'Checking the {name} config file ...')
        if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
            (OK, error_list) = xtoa.check_pipeline_config_file(pipeline_type,
                                                               strict=False)
        elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
            (OK, error_list) = xtoa.check_pipeline_config_file(pipeline_type,
                                                               strict=False)
        elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
            (OK, error_list) = xtoa.check_annotation_merger_config_file(
                strict=False)
        if OK:
            print('The file is OK.')
        else:
            print()
            for error in error_list:
                print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #6
0
def form_restart_cluster():
    '''
    Restart a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Restart cluster')

    # get the cluster name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) == []:
        print('WARNING: There is not any running cluster.')
        OK = False
    else:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)

    # confirm the restarting of the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The cluster is going to be restarted.')

    # stop the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.restart_cluster.__name__)
        OK = xcluster.restart_cluster(cluster_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #7
0
def form_show_cluster_composing():
    '''
    Show cluster information of every node: OS, CPU number and memory.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Show cluster composing')

    # get the cluster name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) == []:
        print('WARNING: There is not any running cluster.')
        OK = False
    else:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)

    # show the status of batch jobs
    if OK:
        devstdout = xlib.DevStdOut(xcluster.show_cluster_composing.__name__)
        xcluster.show_cluster_composing(cluster_name, devstdout, function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #8
0
def form_remove_volume():
    '''
    Remove a volume in the current zone.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Remove volume')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the volume name
    print(xlib.get_separator())
    volume_name = cinputs.input_volume_name(zone_name, template_name='', help=True, help_type='created')

    # confirm the removal of the volume
    print(xlib.get_separator())
    OK = clib.confirm_action('The volume is going to be removed.')

    # remove the volume
    if OK:
        devstdout = xlib.DevStdOut(xvolume.remove_volume.__name__)
        OK = xvolume.remove_volume(volume_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #9
0
def form_open_terminal():
    '''
    Open a terminal windows of a cluster node.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cloud control - Open a terminal')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=True, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the terminal opening
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The terminal is going to be opened using StarCluster.')

    # open de terminal
    if OK:
        xcluster.open_terminal(cluster_name, node_name)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #10
0
def kill_batch_job(cluster_name, job_id, log, function=None):
    '''
    Kill a batch job in the cluster.
    '''

    # initialize the control variable
    OK = True

    # create the SSH client connection
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        log.write('Establishing connection with cluster {0} ...\n'.format(
            cluster_name))
        (OK, error_list, ssh_client) = xssh.create_ssh_client_connection(
            cluster_name, 'master')
        if OK:
            log.write('The connection is established.\n')
        else:
            for error in error_list:
                log.write('{0}\n'.format(error))

    # kill the job in the cluster
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        sge_env = get_sge_env()
        command = '{0}; qdel {1}'.format(sge_env, job_id)
        (OK, stdout,
         stderr) = xssh.execute_cluster_command(ssh_client, command)
        if OK:
            if len(stdout) > 0:
                for line in stdout:
                    log.write('{0}\n'.format(line))
            else:
                log.write('The job is been killed.\n')
            if len(stderr) > 0:
                for line in stderr:
                    log.write('{0}\n'.format(line))
        else:
            log.write('*** ERROR: Wrong command ---> {0}.\n'.format(command))

    # close the SSH client connection
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        log.write(
            'Closing connection with cluster {0} ...\n'.format(cluster_name))
        xssh.close_ssh_client_connection(ssh_client)
        log.write('The connection is closed.\n')

    # 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
Пример #11
0
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
Пример #12
0
def form_update_connection_data():
    '''
    Update the user id, access key id,  secret access key and contact e-mail address
    in the NGScloud config file corresponding to the environment.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Update connection data')

    # get basic AWS data and contact e-mail address from NGScloud config file
    (user_id, access_key_id, secret_access_key) = xconfiguration.get_basic_aws_data()
    email = xconfiguration.get_contact_data()

    # input the new AWS data and the contact e-mail address
    print(xlib.get_separator())
    user_id = cinputs.input_user_id(user_id)
    access_key_id = cinputs.input_access_key_id(access_key_id)
    secret_access_key = cinputs.input_secret_access_key(secret_access_key)
    email = cinputs.input_email(email)

    # verify the AWS access key identification and the AWS secret access key   
    print(xlib.get_separator())
    print('Verifying the AWS access key identification and the AWS secret access key')
    OK = xec2.verify_aws_credentials(access_key_id, secret_access_key)
    if OK:
        print('The credentials are OK.')
    else:
        print('ERROR: The credentials are wrong. Please review your access key identification and secret access key in the AWS web.')

    # get the NGScloud config file
    if OK:
        ngscloud_config_file = xconfiguration.get_ngscloud_config_file()
    
    # confirm the connection data update in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The file {0} is going to be update with the new connection data.'.format(ngscloud_config_file))

    # save the options dictionary in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        print('The file {0} is being update with the new connection data ...'.format(ngscloud_config_file))
        (OK, error_list) = xconfiguration.update_connection_data(user_id, access_key_id, secret_access_key)
        if OK:
            (OK, error_list) = xconfiguration.update_contact_data(email)
        if OK:
            print('The config file has been update.')
        else:
            for error in error_list:
                print(error)
            raise xlib.ProgramException('C001')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #13
0
def show_cluster_composing(cluster_name, log, function=None):
    '''
    Show cluster information of every node: OS, CPU number and memory. 
    '''

    # initialize the control variable
    OK = True

    # create the SSH client connection
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        log.write('Establishing connection with cluster {0} ...\n'.format(
            cluster_name))
        (OK, error_list, ssh_client) = xssh.create_ssh_client_connection(
            cluster_name, 'master')
        if OK:
            log.write('The connection is established.\n')
        else:
            for error in error_list:
                log.write('{0}\n'.format(error))

    # show the cluster composing
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        sge_env = get_sge_env()
        command = '{0}; qhost'.format(sge_env)
        (OK, stdout,
         stderr) = xssh.execute_cluster_command(ssh_client, command)
        if OK:
            if len(stdout) > 0:
                for line in stdout:
                    log.write('{0}\n'.format(line))
            else:
                log.write('Cluster composing not found.\n')
        else:
            log.write('*** ERROR: Wrong command ---> {0}.\n'.format(command))

    # close the SSH client connection
    if OK:
        log.write('{0}\n'.format(xlib.get_separator()))
        log.write(
            'Closing connection with cluster {0} ...\n'.format(cluster_name))
        xssh.close_ssh_client_connection(ssh_client)
        log.write('The connection is closed.\n')

    # 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
Пример #14
0
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
Пример #15
0
def form_run_pipeline_process(pipeline_type):
    '''
    Run a pipeline process with the parameters in the corresponding config file.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()

    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()

    elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
        name = xlib.get_toa_process_merge_annotations_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Run process')

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(f'The {name} process is going to be run.')

    # run the process
    if OK:

        if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
            devstdout = xlib.DevStdOut(xtoa.run_pipeline_process.__name__)
            OK = xtoa.run_pipeline_process(pipeline_type,
                                           devstdout,
                                           function=None)

        elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
            devstdout = xlib.DevStdOut(xtoa.run_pipeline_process.__name__)
            OK = xtoa.run_pipeline_process(pipeline_type,
                                           devstdout,
                                           function=None)

        elif pipeline_type == xlib.get_toa_process_merge_annotations_code():
            devstdout = xlib.DevStdOut(
                xtoa.run_annotation_merger_process.__name__)
            OK = xtoa.run_annotation_merger_process(devstdout, function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #16
0
def form_kill_batch_job():
    '''
    Kill a batch job in the cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Kill batch job')

    # get the cluster name, experiment identification, read dataset identification and the file pattern
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) == []:
        print('WARNING: There is not any running cluster.')
        OK = False
    else:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)

    # create the SSH client connection
    if OK:
        (OK, error_list, ssh_client) = xssh.create_ssh_client_connection(cluster_name, 'master')
        for error in error_list:
            print(error)

    # get the batch job identificaction
    if OK:
        batch_job_id = cinputs.input_batch_job_id(ssh_client, help=True)
        if batch_job_id == '':
            print('WARNING: There is not any batch job.')
            OK = False

    # confirm the kill of the batch job
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The batch job {0} is going to be killed.'.format(batch_job_id))

    # kill the batch job
    if OK:
        devstdout = xlib.DevStdOut(xcluster.kill_batch_job.__name__)
        xcluster.kill_batch_job(cluster_name, batch_job_id, devstdout, function=None)

    # close the SSH client connection
    if OK:
        xssh.close_ssh_client_connection(ssh_client)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #17
0
def form_list_templates():
    '''
    List the characteristics of the cluster templates.
    '''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - List cluster templates')

    # get the cluster template dictionary and the template name list
    template_dict = xconfiguration.get_template_dict()
    template_name_list = xconfiguration.get_template_name_list(volume_creator_included=False)

    # list cluster templates
    print(xlib.get_separator())
    if template_name_list == []:
        print('WARNING: There is not any cluster template defined.')
    else:
        # set data width
        template_width = 30
        instance_type_width = 13
        vcpu_width = 5
        memory_width = 12
        use_width = 17
        generation_width = 10
        # set line template
        line_template = '{0:' + str(template_width) + '}   {1:' + str(instance_type_width) + '}   {2:>' + str(vcpu_width) + '}   {3:>' + str(memory_width) + '}   {4:' + str(use_width) + '}   {5:' + str(generation_width) + '}'
        # print header
        print(line_template.format('Template name', 'Instance type', 'vCPUs', 'Memory (GiB)', 'Use', 'Generation'))
        print(line_template.format('=' * template_width, '=' * instance_type_width, '=' * vcpu_width, '=' * memory_width, '=' * use_width, '=' * generation_width))
        # print detail lines
        for template_name in template_name_list:
            instance_type = template_dict[template_name]['master_instance_type']
            vcpu = template_dict[template_name]['vcpu']
            memory = template_dict[template_name]['memory']
            use = template_dict[template_name]['use']
            generation = template_dict[template_name]['generation'] 
            print(line_template.format(template_name, instance_type, vcpu, memory, use, generation))

    # show warnings about characteristics and pricing
    print(xlib.get_separator())
    print('You can consult the characteristics of the EC2 intance types in:')
    print('    https://aws.amazon.com/ec2/instance-types/')
    print('and the EC2 pricing is detailed in:')
    print('    https://aws.amazon.com/ec2/pricing/')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #18
0
def form_edit_data_file(data_file):
    '''
    Edit a data file.
    '''

    # initialize the control variable
    OK = True

    # get the head
    if data_file == xtoa.get_dataset_file():
        head = f'{xlib.get_toa_name()} - Edit the file of genomic dataset'
    elif data_file == xtoa.get_species_file():
        head = f'{xlib.get_toa_name()} - Edit the file of species'

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(head)

    # edit the read transfer config file
    print(xlib.get_separator())
    print(f'Editing the file {data_file} ...')
    command = f'{xlib.get_editor()} {data_file}'
    rc = subprocess.call(command, shell=True)
    if rc != 0:
        print(f'*** ERROR: Return code {rc} in command -> {command}')
        OK = False

    # check the data file
    if OK:
        print(xlib.get_separator())
        print(f'Checking the file {data_file} ...')
        if data_file == xtoa.get_dataset_file():
            (OK, error_list) = xtoa.check_dataset_file(strict=False)
        elif data_file == xtoa.get_species_file():
            (OK, error_list) = xtoa.check_species_file(strict=False)
        if OK:
            print('The file is OK.')
        else:
            print()
            for error in error_list:
                print(error)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #19
0
def form_delink_volume_from_template():
    '''
    Delink a volume from a cluster template
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Delink volume in a cluster template')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the template name and the volume name
    print(xlib.get_separator())
    template_name = cinputs.input_template_name(volume_creator_included=False, help=True, is_all_possible=True)
    volume_name = cinputs.input_volume_name(zone_name, template_name, help=True, help_type='linked')
 
    # verify there is some volume linked to the cluster template
    if volume_name == '':
        print(xlib.get_separator())
        print('*** WARNING: There is not any volume linked to the cluster template.')
        OK = False
 
    # confirm the exclusion of the volume
    if OK:
        print(xlib.get_separator())
        if template_name == 'all':
            OK = clib.confirm_action('The volume {0} is going to be delinked from every template.'.format(volume_name))
        else:
            OK = clib.confirm_action('The volume {0} is going to be delinked from the template {0}.'.format(volume_name, template_name))

    # delink a volume in a cluster template
    if OK:
        print(xlib.get_separator())
        print('The volume {0} is being delinked from the cluster template {1}.'.format(volume_name, template_name))
        devstdout = xlib.DevStdOut(xconfiguration.delink_volume_from_template.__name__)
        (OK, error_list) = xconfiguration.delink_volume_from_template(template_name, volume_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #20
0
def form_mount_volume():
    '''
    Mount a volume in a node.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Mount volume in a node')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=True, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # get the volume name, AWS device file and directory path
    if OK:
        volume_name = cinputs.input_volume_name(zone_name, template_name='', help=True, help_type='created')
        aws_device_file = cinputs.input_device_file(node_name, volume_name)
        mounting_path = cinputs.input_mounting_path(node_name, aws_device_file)

    # confirm the mounting of the volume
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The volume is going to be mounted.')

    # mount the volume in the node
    if OK:
        devstdout = xlib.DevStdOut(xvolume.mount_volume.__name__)
        xvolume.mount_volume(cluster_name, node_name, volume_name, aws_device_file, mounting_path, devstdout, function=None, is_menu_call=True)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #21
0
def form_restart_pipeline_process(pipeline_type):
    '''
    Restart a pipeline process from the last step ended OK.
    '''

    # initialize the control variable
    OK = True

    # set the pipeline name
    if pipeline_type == xlib.get_toa_process_pipeline_nucleotide_code():
        name = xlib.get_toa_process_pipeline_nucleotide_name()
    elif pipeline_type == xlib.get_toa_process_pipeline_aminoacid_code():
        name = xlib.get_toa_process_pipeline_aminoacid_name()

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment(f'{name} - Run process')

    # get the pipeline dataset identification
    app_list = [pipeline_type]
    pipeline_dataset_id = cinputs.input_result_dataset_id(
        xlib.get_toa_result_pipeline_dir(), app_list)
    if pipeline_dataset_id == '':
        print(f'WARNING: There are not any {pipeline_type} result datasets.')
        OK = False

    # confirm the process run
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action(f'The {name} process is going to be run.')

    # run the process
    if OK:

        devstdout = xlib.DevStdOut(xtoa.restart_pipeline_process.__name__)
        OK = xtoa.restart_pipeline_process(pipeline_type,
                                           pipeline_dataset_id,
                                           devstdout,
                                           function=None)

    # show continuation message
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #22
0
def form_list_volumes():
    '''
    List volumes created.
    '''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - List volumes')

    # get the volume dictionary and volume key list
    volumes_dict = xec2.get_volume_dict()
    volume_keys_list = sorted(volumes_dict.keys())

    # list volume
    print(xlib.get_separator())
    if volume_keys_list == []:
        print('WARNING: There is not any volume created.')
    else:
        # set data width
        zone_name_width = 20
        volume_name_width = 20
        volume_id_width = 21
        size_width = 10
        state_width = 10
        attachments_number_width = 11
        # set line template
        line_template = '{0:' + str(zone_name_width) + '}   {1:' + str(volume_name_width) + '}   {2:' + str(volume_id_width) + '}   {3:' + str(size_width) + '}   {4:' + str(state_width) + '}   {5:' + str(attachments_number_width) + '}'
        # print header
        print(line_template.format('Zone', 'Volume Name', 'Volume Id', 'Size (GiB)', 'State', 'Attachments'))
        print(line_template.format('=' * zone_name_width, '=' * volume_name_width, '=' * volume_id_width, '=' * size_width, '=' * state_width, '=' * attachments_number_width))
        # print detail lines
        for volume_key in volume_keys_list:
            zone_name = volumes_dict[volume_key]['zone_name']
            volume_name = volumes_dict[volume_key]['volume_name'] 
            volume_id = volumes_dict[volume_key]['volume_id']
            size = volumes_dict[volume_key]['size']
            state = volumes_dict[volume_key]['state']
            attachments_number = volumes_dict[volume_key]['attachments_number']
            print(line_template.format(zone_name, volume_name, volume_id, size, state, attachments_number))

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #23
0
def form_review_volume_links():
    '''
    Review linked volumes of cluster templates in order to remove linked volumes
    that do not currently exist.
    '''

    # initialize the control variable and the error list
    OK = True
    error_list = []

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Review volumes linked to cluster templates')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # get the NGScloud confign file
    ngscloud_config_file = xconfiguration.get_ngscloud_config_file()

    # verify if there are any volumes linked
    if xconfiguration.get_volumes_dict() == {}:
        print(xlib.get_separator())
        print('WARNING: There is not any volume linked.')
        OK = False
 
    # confirm the review of volumes links
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The file {0} is going to be reviewed in order to remove volumes linked which are not currently created in the zone {1}.'.format(ngscloud_config_file, zone_name))

    # review volumen link
    if OK:
        devstdout = xlib.DevStdOut(xconfiguration.review_volume_links.__name__)
        (OK, error_list) = xconfiguration.review_volume_links(zone_name, devstdout, function=None)

    # show continuation message or exit of application
    print(xlib.get_separator())
    if not OK and error_list != []:
        raise xlib.ProgramException('C001')
    else:
        input('Press [Intro] to continue ...')
Пример #24
0
def form_terminate_cluster(force):
    '''
    Terminate a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    if not force:
        clib.print_headers_with_environment('Cluster operation - Terminate cluster')
    else:
        clib.print_headers_with_environment('Cluster operation - Force termination of a cluster')

    # get the cluster name that must be terminated
    print(xlib.get_separator())
    if not force:
        if xec2.get_running_cluster_list(volume_creator_included=False) == []:
            print('WARNING: There is not any running cluster.')
            OK = False
        else:
            cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
    else:
        cluster_name = cinputs.input_template_name(volume_creator_included=False, help=False, is_all_possible=False)

    # confirm the termination of the cluster
    if OK:
        print(xlib.get_separator())
        if not force:
            OK = clib.confirm_action('The cluster is going to be terminated.')
        else:
            OK = clib.confirm_action('The cluster is going to be forced to terminate.')

    # terminate the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.terminate_cluster.__name__)
        OK = xcluster.terminate_cluster(cluster_name, force, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #25
0
def form_create_volume():
    '''
    Create a volume in the current zone.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Volume operation - Create volume')

    # get current zone name
    zone_name = xconfiguration.get_current_zone_name()

    # show sites related to EBS volumes
    print(xlib.get_separator())
    print('You can consult the characteristics of the EBS volumes in:')
    print('    https://aws.amazon.com/ebs/details/')
    print('and the EBS pricing is detailed in:')
    print('    https://aws.amazon.com/ebs/pricing/')

    # get the cluster name, node name, volume name, volume type and volume size
    print(xlib.get_separator())
    volume_name = cinputs.input_volume_name(zone_name, template_name='', help=False, help_type='created')
    volume_type = cinputs.input_volume_type()
    volume_size = cinputs.input_volume_size(volume_type)
    terminate_indicator = cinputs.input_terminate_indicator()

    # confirm the creation of the volume
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The volume is going to be created.')

    # create the volume
    if OK:
        devstdout = xlib.DevStdOut(xvolume.create_volume.__name__)
        OK = xvolume.create_volume(volume_name, volume_type, volume_size, terminate_indicator, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #26
0
def form_list_nodes():
    '''
    List nodes running.
    '''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Node operation - List nodes')

    # get the node dictionary and node key list
    node_dict = xec2.get_node_dict()
    node_key_list = sorted(node_dict.keys())

    # list nodes
    print(xlib.get_separator())
    if node_key_list == []:
        print('WARNING: There is not any node running.')
    else:
        # set data width
        security_group_name_width = 28
        zone_name_width = 20
        node_name_width = 20
        node_id_width = 19
        state_width = 20
        # set line template
        line_template = '{0:' + str(security_group_name_width) + '}   {1:' + str(zone_name_width) + '}   {2:' + str(node_name_width) + '}   {3:' + str(node_id_width) + '}   {4:' + str(state_width) + '}'
        # print header
        print(line_template.format('Security Group', 'Zone', 'Node Name', 'Node Id', 'State'))
        print(line_template.format('=' * security_group_name_width, '=' * zone_name_width, '=' * node_name_width, '=' * node_id_width, '=' * state_width))
        # print detail lines
        for node_key in node_key_list:
            security_group_name = node_dict[node_key]['security_group_name']
            zone_name = node_dict[node_key]['zone_name']
            node_name = node_dict[node_key]['node_name']
            node_id = node_dict[node_key]['node_id'] 
            state = node_dict[node_key]['state']
            print(line_template.format(security_group_name, zone_name, node_name, node_id, state))

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #27
0
def form_create_cluster():
    '''
    Create a cluster from a template name.
    '''

    # initialize the control variable
    OK = True

    # initialize the state variables
    master_state_code = ''
    master_state_name = ''

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Cluster operation - Create cluster')

    # show sites related to EBS volumes
    print(xlib.get_separator())
    print('You can consult the characteristics of the EC2 intance types in:')
    print('    https://aws.amazon.com/ec2/instance-types/')
    print('and the EC2 pricing is detailed in:')
    print('    https://aws.amazon.com/ec2/pricing/')
    print()

    # get the template name and set the cluster name
    print(xlib.get_separator())
    template_name = cinputs.input_template_name(volume_creator_included=False, help=True, is_all_possible=False)
    cluster_name = template_name

    # confirm the creation of the cluster
    print(xlib.get_separator())
    OK = clib.confirm_action('The cluster is going to be created.')

    # create the cluster
    if OK:
        devstdout = xlib.DevStdOut(xcluster.create_cluster.__name__)
        (OK, master_state_code, master_state_name) = xcluster.create_cluster(template_name, cluster_name, devstdout, function=None, is_menu_call=True)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #28
0
def form_update_region_zone():
    '''
    Update the current region and zone names in the NGScloud config file
    corresponding to the envoronment.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Configuration - Update region and zone')

    # input new current region and zone
    print(xlib.get_separator())
    region_name = cinputs.input_region_name(region_name, help=True)
    zone_name = cinputs.input_zone_name(region_name, zone_name, help=True)
  
    # get the NGScloud config file
    ngscloud_config_file = xconfiguration.get_ngscloud_config_file()
  
    # confirm the region and zone update in the NGScloud config file
    print(xlib.get_separator())
    OK = clib.confirm_action('The file {0} is going to be update with the new region and zone.'.format(ngscloud_config_file))

    # save the options dictionary in the NGScloud config file
    if OK:
        print(xlib.get_separator())
        print('The file {0} is being update with the new region and zone ...'.format(ngscloud_config_file))
        (OK, error_list) = xconfiguration.update_region_zone_data(region_name, zone_name)
        if OK:
            print('The config file has been update.')
        else:
            for error in error_list:
                print(error)
            raise xlib.ProgramException('C001')

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #29
0
def form_add_node():
    '''
    Add a node in a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Node operation - Add node in a cluster')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        if len(xec2.get_cluster_node_list(cluster_name)) >= xec2.get_max_node_number():
            print('WARNING: The maximum number ({0}) of instances is already running.'.format(xec2.get_max_node_number()))
            OK = False
        else:
            node_name = cinputs.input_node_name(cluster_name, new=True, is_master_valid=False, help=True)
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the addition of the node in the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The node is going to be added.')

    # add node in cluster
    if OK:
        devstdout = xlib.DevStdOut(xnode.add_node.__name__)
        xnode.add_node(cluster_name, node_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')
Пример #30
0
def form_remove_node():
    '''
    Remove a node in a cluster.
    '''

    # initialize the control variable
    OK = True

    # print the header
    clib.clear_screen()
    clib.print_headers_with_environment('Node operation - Remove node in a cluster')

    # get the cluster name and node name
    print(xlib.get_separator())
    if xec2.get_running_cluster_list(volume_creator_included=False) != []:
        cluster_name = cinputs.input_cluster_name(volume_creator_included=False, help=True)
        node_name = cinputs.input_node_name(cluster_name, new=False, is_master_valid=False, help=True)
        if node_name == []:
            print('WARNING: There is not any running node besides the master.')
            OK = False
    else:
        print('WARNING: There is not any running cluster.')
        OK = False

    # confirm the removal of the node in the cluster
    if OK:
        print(xlib.get_separator())
        OK = clib.confirm_action('The node is going to be removed.')

    # remove node
    if OK:
        devstdout = xlib.DevStdOut(xnode.remove_node.__name__)
        xnode.remove_node(cluster_name, node_name, devstdout, function=None)

    # show continuation message 
    print(xlib.get_separator())
    input('Press [Intro] to continue ...')