Beispiel #1
0
def return_file(filename):
    WebtoolsUtils.handle_excel(os.path.join(UPLOAD_FOLDER, filename))
    #Utils.run_shell('ssh 10.34.70.220 /dfcxact/workarea/Complex/Microsoft/node_status/run_tst_status')
    # Utils.run_shell('scp 10.34.70.220:/dfcxact/workarea/Complex/Microsoft/node_status/status/summary_status.csv '
    #                '/data/webtools/nodes_status')
    #return send_from_directory('/data/webtools/nodes_status', 'summary_status.csv')
    return render_template('TEWebtools/node_status/get_results.jinja2')
Beispiel #2
0
    def set_node_macs(hostname, macs, vm):
        """
        Use this function to set the MACs registered in xml, so it could be
        discovered by mac without switch/switchport definition
        """
        # Create stanza file of the defined node and add the macs

        # cmd = " lsdef {0} > /tmp/{0}".format(hostname)
        # Utils.run_shell('ssh ' + vm + ' ' + cmd)
        if WebtoolsUtils.run_shell('ls /tmp/{}'.format(hostname)) != 0:
            path = '/tmp/{0}'.format(hostname)
            lines = [
                '{}:'.format(hostname) + '\n', '   objtype=node' + '\n',
                '   mac={0}'.format(macs) + '\n'
            ]
            stanzafile = open(path, 'x')
            stanzafile.writelines(lines)
            stanzafile.close()
        else:
            WebtoolsUtils.run_shell('rm -rf /tmp/{}'.format(hostname))
            path = '/tmp/{0}'.format(hostname)
            lines = [
                '{}:'.format(hostname) + '\n', '   objtype=node' + '\n',
                '   mac={0}'.format(macs) + '\n'
            ]
            stanzafile = open(path, 'x')
            stanzafile.writelines(lines)
            stanzafile.close()
        # Copy stanza file created to the VM
        copy_stanzafile = "scp /tmp/{0} {1}:/tmp/".format(hostname, vm)
        # Change def of the node using the edited stanza file with macs info
        if WebtoolsUtils.run_shell(copy_stanzafile) == 0:
            return WebtoolsUtils.run_shell(
                'ssh ' + vm + ' chdef_node_macs {}'.format(hostname))
Beispiel #3
0
 def restart_discovery_services(vm):
     cmnds = list()
     cmnds.append(' makedns -n')
     cmnds.append(' makedhcp -n')
     cmnds.append(' service dhcpd restart')
     cmnds.append(' service network restart')
     for cmd in cmnds:
         WebtoolsUtils.run_shell('ssh ' + vm + cmd)
Beispiel #4
0
 def check_progress(so, serial):
     mtm = serial[2:].split("J", 1)[0]
     sn = serial[2:].replace(mtm, '')
     cmd = 'ls /data/CSC/truven/units/{0}/{1}/'.format(so, sn)
     if WebtoolsUtils.stdout_shell(cmd) != '':
         return "Finish"
     else:
         return "Waiting"
Beispiel #5
0
 def set_node_switch(hostname, switch, switchport, vm):
     """
     Use this function to set switch/switchport definition,
     in order to test P2P requirements
     """
     create_node = ' chdef -t node {0} switch={1} switchport={2}'.format(
         hostname, switch, switchport)
     return WebtoolsUtils.run_shell('ssh ' + vm + create_node)
Beispiel #6
0
 def write_stdoutput_file(output_list, pathfile):
     """
     :param output_list: list of strings generated by r.stdout (subprocess.run(args).stdout.decode()
     :param pathfile: path and filename, example: '/data/webtools/nodes_list/{}'.format(file)
     :return: 0 if ran well
     """
     file = open(pathfile, 'w+')
     for line in output_list:
         file.writelines(line + "\n")
     file.close()
     return WebtoolsUtils.run_shell('ls {}'.format(pathfile))
Beispiel #7
0
 def create_node(hostname, ip_os, ip_bmc, vm):
     """
     Use this function to create a node in xcat
     :param hostname: the name for the node
     :param ip_os: IP for the OS
     :param ip_bmc: IP defined for the node-bmc
     :param vm: it would be the IP of the VM
     :return:
     """
     cmnds = list()
     cmnds.append(
         'mkdef -t node {0} groups=all,compute,ipmi mgt=ipmi '
         'ip={1} netboot=xnba bmc={0}-bmc installnic=mac primarynic=mac'.
         format(hostname, ip_os))  # create node
     cmnds.append('mkdef -t node {0}-bmc groups=bmc ip={1}'.format(
         hostname, ip_bmc))  # create bmc
     cmnds.append('makehosts {0},{0}-bmc'.format(hostname))  # make hosts
     cmnds.append('makeconfluentcfg {}'.format(hostname))  # make confluent
     cmnds.append('nodeattrib {} console.method=ipmi'.format(
         hostname))  # config confetty
     for cmd in cmnds:
         WebtoolsUtils.run_shell('ssh ' + vm + ' ' + cmd)
Beispiel #8
0
 def set_workarea(so):
     cmd = 'cp /data/CSC/truven/settings/{}/unit_settings.csv /data/CSC/truven/workarea/'.format(so)
     if Xcat.clean_xcat(vm=csc_truven_vm) == 0:
         Xcat.create_switch(switch='switch1', ip='172.30.50.1', vm=csc_truven_vm)
         if WebtoolsUtils.run_shell(cmd) == 0:
             units = TruvenUtils.get_all_sn_by_so(so)
             for unit in units:
                 tu = TruvenUnit(unit)
                 Xcat.create_node(hostname=tu.sn, ip_os=tu.ip_os,
                                  ip_bmc=tu.ip, vm=csc_truven_vm)
                 Xcat.set_node_macs(hostname=tu.sn, macs=tu.format_mac_xcat(),
                                    vm=csc_truven_vm)
             return Xcat.restart_discovery_services(vm=csc_truven_vm)
Beispiel #9
0
 def create_switch(switch, ip, vm):
     """
     Use this function to create and config a switch in a vm
     :param switch: switch name - hostname
     :param ip: This is the IP of the switch
     :param vm: this is the IP of the VM - Management node
     :return:
     """
     cmnds = list()
     cmnds.append('mkdef -t node {0} groups=switch ip={1}'.format(
         switch, ip))  # create switch node
     cmnds.append('makehosts {}'.format(switch))  # make hosts
     cmnds.append('confetty create /nodegroups/switch')  # make confluent
     cmnds.append('confetty create /nodes/{} groups=switch'.format(switch))
     # config confetty
     cmnds.append(
         'confetty set /nodegroups/switch/attributes/current secret.hardwaremanagementpassword="******"'
     )
     cmnds.append(
         'confetty set /nodegroups/everything/attributes/current discovery.policy=open'
     )
     for cmd in cmnds:
         WebtoolsUtils.run_shell('ssh ' + vm + ' ' + cmd)
Beispiel #10
0
def upload_iso():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            flash('No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            flash('No selected file')
            return redirect(request.url)
        if file and WebtoolsUtils.allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(UPLOAD_FOLDER, filename))
            return redirect(url_for(".confirm_upload", filename=filename))
    return render_template('TEWebtools/uploader.jinja2')
Beispiel #11
0
def read_uploaded_file(filename):
    up_file = os.path.join(UPLOAD_FOLDER, filename)
    so = TruvenUtils.get_so_by_file(up_file)
    if TruvenUtils.validate_so(so) != 0:
        if TruvenUtils.create_settings_folder(so) == 0:
            cmd = 'cp {} {}/{}/unit_settings.csv'.format(
                up_file, WORK_FOLDER, so)
            if WebtoolsUtils.run_shell(cmd) == 0:
                if TruvenUtils.create_work_folder(so) == 0:
                    units = TruvenUtils.get_all_sn_by_file(up_file)
                    for serial in units:
                        mtm = serial[2:].split("J", 1)[0]
                        sn = serial[2:].replace(mtm, '')
                        TruvenUtils.create_serial_folder(so=so, serial=sn)
                        #  TruvenUtils.create_file_results(so=so, serial=sn)
                    return render_template(
                        'csc/truven/update_file_done.jinja2',
                        filename=filename,
                        so=so,
                        num_units=len(units))
    else:
        return "This SO was created before!! {}".format(so)
Beispiel #12
0
 def create_work_folder(so):
     cmd = 'mkdir -p /data/CSC/truven/units/{}/'.format(so)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #13
0
 def create_settings_folder(so):
     cmd = 'mkdir -p /data/CSC/truven/settings/{}/'.format(so)
     return WebtoolsUtils.run_shell(cmd)  # '0' if ran correctly
Beispiel #14
0
 def get_all_so():
     cmd = 'ls /data/CSC/truven/settings/'
     return WebtoolsUtils.stdout_shell(cmd).split()  # list of SOs
Beispiel #15
0
 def run_rescan_nodes_by_uuid():
     return WebtoolsUtils.run_shell('ssh {} node_discover_by_uuid'.format(csc_truven_vm))
Beispiel #16
0
 def validate_so(so):
     cmd = 'ls -d /data/CSC/truven/settings/{}'.format(so)
     return WebtoolsUtils.run_shell(cmd)  # '0' if ran correctly
Beispiel #17
0
 def get_log_value(value, so, sn):
     cmd = 'grep {0} /data/CSC/truven/units/{1}/{2}/asu_showall_{2}.log'.format(value, so, sn)
     return WebtoolsUtils.stdout_shell(cmd).split()[1].split('=')[1]  # Return the current value at file log
Beispiel #18
0
 def verify_unit_tools(vm, sn):
     asu64 = 'ssh {0} psh {1} ls /root/asu64'.format(vm, sn)
     ipmitool = 'ssh {0} psh {1} ipmitool lan print 1'.format(vm, sn)
     if WebtoolsUtils.run_shell(asu64) == 0:
         return WebtoolsUtils.run_shell(ipmitool)
Beispiel #19
0
 def get_ipmitool_lan_log(vm, sn):
     ipmitool = 'ssh {0} psh {1} ipmitool lan print 1'.format(vm, sn)
     return WebtoolsUtils.stdout_shell(ipmitool).split('\n')  # output_list
Beispiel #20
0
 def get_asu_showall_log(vm, sn):
     asu = 'ssh {0} psh {1} /root/asu64 show all --kcs'.format(vm, sn)
     return WebtoolsUtils.stdout_shell(asu).split('\n')  # output_list
Beispiel #21
0
 def clean_xcat(vm):
     # cleanXcatNodes is /home/ALLEASY/cleanXcatNodes.sh copied to /usr/bin/
     cmd = 'ssh {} cleanXcatNodes'.format(vm)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #22
0
 def get_workarea_so():
     workarea_file = '/data/CSC/truven/workarea/unit_settings.csv'
     cmd = 'ls {}'.format(workarea_file)
     if WebtoolsUtils.run_shell(cmd) == 0:
         return TruvenUtils.get_so_by_file(workarea_file)
Beispiel #23
0
 def change_xcc_netmask(vm, sn, xcc_netmask):
     cmd = 'ssh {0} psh {1} ipmitool lan set 1 netmask {2}'.format(vm, sn, xcc_netmask)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #24
0
 def change_xcc_hostname(vm, sn, xcc_hostname):
     cmd = 'ssh {0} psh {1} /root/asu64 set IMM.HostName1 {2} --kcs'.format(vm, sn, xcc_hostname)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #25
0
 def create_serial_folder(so, serial):
     cmd = 'mkdir -p /data/CSC/truven/units/{}/{}'.format(so, serial)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #26
0
 def ping_device(ip):
     return WebtoolsUtils.ping_device(vm=truven_vm_ip, ip=ip)
Beispiel #27
0
 def change_xcc_gateway(vm, sn, xcc_gateway):
     cmd = 'ssh {0} psh {1} ipmitool lan set 1 defgw ipaddr {2}'.format(vm, sn, xcc_gateway)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #28
0
 def copy_asu_to_unit(vm, sn):
     cmd = 'ssh {0} scp /root/asu64 {1}:/root/'.format(vm, sn)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #29
0
 def copy_xml_from_l2(self):
     cmd = 'scp 10.34.70.220:/dfcxact/mediabuild/UNIT_DATA_MB/{}.xml /data/CSC/mediabuild/'.format(
         self.serial)
     return WebtoolsUtils.run_shell(cmd)
Beispiel #30
0
 def create_file_results(so, serial):
     cmd_asu = 'touch /data/CSC/truven/units/{0}/{1}/asu_showall_{1}.log'.format(so, serial)
     cmd_ipmitool = 'touch /data/CSC/truven/units/{0}/{1}/ipmitool_lan_{1}.log'.format(so, serial)
     return WebtoolsUtils.run_shell(cmd_asu) + WebtoolsUtils.run_shell(cmd_ipmitool)