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))
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)
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)
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))
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)
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)
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)
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)
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)
def create_work_folder(so): cmd = 'mkdir -p /data/CSC/truven/units/{}/'.format(so) return WebtoolsUtils.run_shell(cmd)
def create_serial_folder(so, serial): cmd = 'mkdir -p /data/CSC/truven/units/{}/{}'.format(so, serial) return WebtoolsUtils.run_shell(cmd)
def run_rescan_nodes_by_uuid(): return WebtoolsUtils.run_shell('ssh {} node_discover_by_uuid'.format(csc_truven_vm))
def create_settings_folder(so): cmd = 'mkdir -p /data/CSC/truven/settings/{}/'.format(so) return WebtoolsUtils.run_shell(cmd) # '0' if ran correctly
def clean_xcat(vm): # cleanXcatNodes is /home/ALLEASY/cleanXcatNodes.sh copied to /usr/bin/ cmd = 'ssh {} cleanXcatNodes'.format(vm) return WebtoolsUtils.run_shell(cmd)
def validate_so(so): cmd = 'ls -d /data/CSC/truven/settings/{}'.format(so) return WebtoolsUtils.run_shell(cmd) # '0' if ran correctly
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)
def copy_asu_to_unit(vm, sn): cmd = 'ssh {0} scp /root/asu64 {1}:/root/'.format(vm, sn) return WebtoolsUtils.run_shell(cmd)
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)
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)
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)
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)
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)