發表文章

python - auto Check in to work

a python program for auto check in to work on web site selenium need other browser driver # -*- coding: utf-8 -*- import time import random from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome() # Optional argument, if not specified will search path. driver.get( 'company url' ) # random time login(10s-30min time.sleep(random.randint( 10 , 1800 )) # Let the user actually see something! try : # find xpath of account & password driver.find_element_by_xpath( "//*[@id='userid_input']" ).send_keys( "account" ) driver.find_element_by_xpath( "//*[@id='password']" ).send_keys( "password" ) # click login button driver.find_element_by_xpath( "/html/body/form/table[2]/tbody/tr/td[2]/table/tbody/tr[3]/td[2]/div/a/img" ).click() time.sleep( 5 ) # click login page driver.find_element_by_link_text( " 今日出勤班別 " ).click() time.sl...

python - Compare & Change File Name

圖片
In response to work needs write a python script for compare & change file name from excel file the script will compare field "servicetag" data in sheet "host" & file name Reference file (demo.xlsx)formate code import os , re , pandas # rename file count count = 0 # get script root path desdir=os.getcwd() # get xlsx file path datafile = input ( "xlsx file path \n " ) #load xlsx file data df = pandas.read_excel(datafile , sheet_name = 'host' ) df_df=pandas.DataFrame(df) for i in range ( len (df_df)): for file in os.listdir(desdir): if bool (re.search(df_df[ 'servicetag' ][i] , file)): #file name check if bool (re.search(df_df[ 'host' ][i] , file)): break ; else : count =count+ 1 os.rename(os.path.join(desdir , file) , os.path.join(desdir , df_df[ 'host' ][i]+ '-' +fi...

ssh without password

圖片
just a note I want to write a scrpit to achieve the "ssh no password" function in nutanix cluster first look at the "ssh no password" part script.. maybe one day will write..just maybe for windows client to linux server ssh without password is easy simply speaking create private key and public key from windows save the windows public key in linux server and load private key file while you ssh to linux server this is setting step lab environment linux server: 10.31.1.70 windows client: 10.31.1.68 need tool: PuTTY PuTTYgen we can download from https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html windows 1. start puttygen-> generate 2. copy public key code to txt 3. save private key file linux 1. verify ssh config /etc/ssh/sshd_config sudo vi /etc/ssh/sshd_config PubkeyAuthentication yes AuthorizedKeysFile      .ssh/authorized_keys check fil...

AHV - down load file & folder from all node in cluster (powershell & pscp)

Simple script for download specific file or folder in every node (put pscp.exe and .ps1 in same path ) ---------------------------------------- $cluster=0,"cvmip1","cvmip2" $path= split-path -parent $MyInvocation.MyCommand.Definition for ($i=1;$i -le nodenumber ;$i++){ mkdir .\node$i #folder for save file $ahvhostfile="nutanix@"+ $cluster[$i] + ":/home/nutanix/data/logs/preupgrade.out" & "$path\pscp.exe" -pw "nutanix/4u" $ahvhostfile $path\node$i\ $ahvhostfile="nutanix@"+ $cluster[$i] + "/home/nutanix/data/logs/genesis.out*" & "$path\pscp.exe" -unsafe -pw "nutanix/4u" $ahvhostfile $path\node$i\ $ahvhostfile="nutanix@"+ $cluster[$i] + "/home/nutanix/data/logs/sysstats" & "$path\pscp.exe" -unsafe -r -pw "nutanix/4u" $ahvhostfile $path\node$i\ } ----------------------------------------

AHV - count how many vCPU use in one node

count how many vCPU used with power on VM in one node vCPU used = vCPU * core (the result do not containt CVM core) _________________________________________ #!/bin/bash total="0" VM=(`virsh list | gawk -F' ' '{printf("%s\n",$2);}'|awk 'NR>3{print p}{p=$0}'`) for i in ${VM[@]}; do         vmcore="$(acli vm.get $i |grep "num_cores_per_vcpu" | cut -d":" -f 2)"         vmcpu="$(acli vm.get $i |grep "num_vcpus" | cut -d":" -f 2)"         vmcpu=$((vmcore * vmcpu))         total=$((total + vmcpu)) done echo $total _________________________________________

clone VM from AHV to ESXi

圖片
clone VM from AHV to ESXi Reference article: https://acropolis.ninja/export-a-vm-from-nutanix-ahv-to-vmware-esxi/ get vmdk UUID acli vm.get {VM name} export vmdk qemu-img convert -O vmdk nfs://127.0.0.1/{container}/.acropolis/vmdisk/{vmdk UUID} nfs://127.0.0.1/{export container}/{export vmdk name.vmdk} & verify export vmdk processing ps -A |grep qemu if show nothing or done,it’s mean completed mount this comtainer to ESXi host create VM for this vmdk and copy the vmdk file to the VM directory ssh to ESXi host cp {source vmdk path} {destination path} & you can use winscp to verify the copy schedule create the vmdk disk descriptor(Nutanix default use Thin Provisioned) vmkfstools -i {source vmdk} {new vmdk} -d thin mount this vmdk on ESXi VM and it should be power on success if the OS is windows 10,need UEFI boot edi...

AHV - migrate specific VM to other node with time

because AHV GUI  can not migrate mutiple VM at one click if you want migrate mutiple VM, you only can one by one select & migrate with GUI or use script (maybe next or next next or next next next version NOS can be resolve...I hope ) this script can migrate VM with similar VM name or specifice VM _________________________ #!/bin/bash # # acli host.list echo "input the VMs that you want to migrate(ex. vm1,vm2,testvm*)" read VM echo "input the destnation host IP...(press ENTER will automatically select host)" read HOST startdate=`date` if [ ! -n "$HOST" ] ; then acli vm.migrate $VM else acli vm.migrate $VM host=$HOST fi echo "start date: $startdate" echo "  end date: `date`" _________________________