【P1248 加工生產排程】題解
阿新 • • 發佈:2021-11-21
esxi底層其實也是linux系統,可以使用shell指令碼進行一些操作,但是由於shell型別的問題,部分bash的指令碼無法執行,可以考慮使用python指令碼
[root@localhost:~] vmware -v VMware ESXi 6.7.0 build-14320388 [root@localhost:~] cat /etc/shells /bin/ash /bin/sh [root@localhost:~] python -V Python 3.5.7
常用命令:
- esxicli:主要用來做一些系統及的操作,網路、磁碟、系統等操作,同時還有vm的一些操作
[root@localhost:~] esxcli Usage: esxcli [options] {namespace}+ {cmd} [cmd options] Options: --formatter=FORMATTER Override the formatter to use for a given command. Available formatter: xml, csv, keyvalue --debug Enable debug or internal use options --version Display version information for the script-?, --help Display usage information for the script Available Namespaces: device Device manager commands esxcli Commands that operate on the esxcli system itself allowing users to get additional information. fcoe VMware FCOE commands. graphics VMware graphics commands. hardware VMKernel hardware properties and commandsfor configuring hardware. iscsi VMware iSCSI commands. network Operations that pertain to the maintenance of networking on an ESX host. This includes a wide variety of commands to manipulate virtual networking components (vswitch, portgroup, etc) as well as local host IP, DNS and general host networking settings. nvme VMware NVMe driver esxcli extensions rdma Operations that pertain to remote direct memory access (RDMA) protocol stack on an ESX host. sched VMKernel system properties and commands for configuring scheduling related functionality. software Manage the ESXi software image and packages storage VMware storage commands. system VMKernel system properties and commands for configuring properties of the kernel core system and related system services. vm A small number of operations that allow a user to Control Virtual Machine operations. vsan VMware vSAN commands
esxi 停止所有虛擬機器
for i in $(esxcli vm process list |grep World|awk -F' ' '{print $3}');do esxcli vm process kill --type=hard --world-id=$i ;done
- vim-cmd:虛擬機器相關操作
[root@localhost:~] vim-cmd Commands available under /: hbrsvc/ internalsvc/ solo/ vmsvc/ hostsvc/ proxysvc/ vimsvc/ help
[root@localhost:~] vim-cmd vmsvc/getallvms Vmid Name File Guest OS Version Annotation 1 VMware vCenter Server Appliance [90] VMware vCenter Server Appliance/VMware vCenter Server Appliance.vmx other3xLinux64Guest vmx-10 VMware vCenter Server Appliance 10 10.19.170.182 [90] 10.19.170.182/10.19.170.182.vmx centos7_64Guest vmx-14 13 10.19.170.175 [90] 10.19.170.175/10.19.170.175.vmx coreos64Guest vmx-14 14 10.19.170.101-centos76 [90] 10.19.170.101-centos76/10.19.170.101-centos76.vmx centos7_64Guest vmx-14 15 10.19.170.102-centos76 [90] 10.19.170.102-centos76/10.19.170.102-centos76.vmx centos7_64Guest vmx-14 16 10.19.170.103-centos76 [90] 10.19.170.103-centos76/10.19.170.103-centos76.vmx centos7_64Guest vmx-14 17 10.19.170.104-centos76 [90] 10.19.170.104-centos76/10.19.170.104-centos76.vmx centos7_64Guest vmx-14
建立快照,
[root@localhost:~] vim-cmd vmsvc/snapshot.create 14 testsnapshot ##14為上一步中的vmid Create Snapshot: [root@localhost:~]
批量建立快照參考指令碼,list中為主機名稱
#!/usr/bin/python磁碟掛載失敗 # 列出儲存卷資訊
# -*-coding:utf-8-*-
import os
import sys
if len(sys.argv) != 2:
print("need at least 1 params")
exit()
hostname_list = ["10.19.170.190", "10.19.170.191", "10.19.170.192", "10.19.170.193", "10.19.170.194", "10.19.170.195", "10.19.170.196"]
for a in hostname_list:
vid = os.popen("vim-cmd vmsvc/getallvms |awk '{print $1,$2}' |grep " + a + "|awk '{print $1}'").read().split("\n")[0]
print(vid)
os.system("vim-cmd vmsvc/snapshot.create {} {}".format(vid, sys.argv[1]))
esxcfg-volume -l# 掛載指定的儲存卷
esxcfg-volume -m VOLUMEID