vim-cmdは、ESXiにSSH接続の実施、もしくはDCUIから実行が可能です。
vSphere環境の基本的な操作は、vSphere Clientを使うことが多いかと思います。
vSphere Clientに接続できず、かつHost Clientにも接続できないような場合に有用な、vim-cmdでの仮想マシン操作を検証し、まとめました。
ちなみに、上記のようなケースで仮想マシンをパワーオンしたい場合、下記のKBがありますのでご参考まで。
https://kb.vmware.com/s/article/1038043?lang=ja
上記KBの、「Related Versions:」にVMware vSphere ESXi 7.0の記載がありませんが、実際にはESXi 7.0でも使用可能です。
Contents
仮想マシンの一覧確認
vim-cmd vmsvc/getallvms
ホスト上の仮想マシン一覧が確認できます。
後述のvim-cmdコマンドによる各仮想マシン操作では、vmidをオプションとして指定します。
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/getallvms
Vmid Name File Guest OS Version Annotation
2 AD [SSD] win2016/win2016.vmx windows9Server64Guest vmx-18
34 test-02 [SSD] test-02/test-02.vmx windows9_64Guest vmx-18
37 test-04 [SSD] test-04/test-04.vmx windows9_64Guest vmx-18
38 test-03 [SSD] test-03/test-03.vmx windows9_64Guest vmx-18
41 test-01 [SSD] test-01/test-01.vmx windows9_64Guest vmx-18
仮想マシンの電源操作
電源状態の確認
vim-cmd vmsvc/power.getstate <vmid>
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/power.getstate 41
Retrieved runtime info
Powered off
仮想マシンが起動していれば「Powered on」、仮想マシンが停止していれば「Powered off」のメッセージが返ってきます。
起動
vim-cmd vmsvc/power.on <vmid>
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/power.on 41
Powering on VM:
停止
vim-cmd vmsvc/power.off <vmid>
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/power.off 41
Powering off VM:
再起動
vim-cmd vmsvc/power.reboot <vmid>
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/power.reboot 41
[root@localhost:~]
このコマンドの実行結果のメッセージは出力されません。
リセット
vim-cmd vmsvc/power.reset vmid
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/power.reboot 41
[root@localhost:~]
このコマンドの実行結果のメッセージは出力されません。
インベントリ操作
インベントリ登録
vim-cmd solo/registervm <vmx_file>
インベントリ登録解除
vim-cmd vmsvc/unregister <vmid>
※事前に仮想マシンの停止が必要です
スナップショット操作
スナップショット確認
vim-cmd vmsvc/snapshot.get <vmid>
スナップショット作成
vim-cmd vmsvc/snapshot.create <vmid> <snapshot_name>
スナップショット削除
vim-cmd vmsvc/snapshot.removeall <vmid>
VM情報確認
vim-cmd vmsvc/get.guest <vmid>
fa-arrow-circle-right検証環境での実行結果
[root@localhost:~] vim-cmd vmsvc/get.guest 41
Guest information:
(vim.vm.GuestInfo) {
toolsStatus = "toolsOld",
toolsVersionStatus = "guestToolsNeedUpgrade",
toolsVersionStatus2 = "guestToolsSupportedOld",
toolsRunningStatus = "guestToolsRunning",
toolsVersion = "11297",
toolsInstallType = "guestToolsTypeMSI",
toolsUpdateStatus = (vim.vm.GuestInfo.ToolsUpdateStatus) null,
guestId = "windows9_64Guest",
guestFamily = "windowsGuest",
guestFullName = "Microsoft Windows 10 (64-bit)",
guestDetailedData = <unset>,
hostName = "test-01.test.local",
ipAddress = "192.168.1.31",
net = (vim.vm.GuestInfo.NicInfo) [
(vim.vm.GuestInfo.NicInfo) {
network = "���z�}�V�� �l�b�g���[�N",
ipAddress = (string) [
"192.168.1.31"
],
macAddress = "00:50:56:86:69:fb",
connected = true,
deviceConfigId = 4000,
dnsConfig = (vim.net.DnsConfigInfo) {
dhcp = false,
hostName = "",
domainName = "test.local",
ipAddress = (string) [
"192.168.1.1"
],
searchDomain = <unset>
},
ipConfig = (vim.net.IpConfigInfo) {
ipAddress = (vim.net.IpConfigInfo.IpAddress) [
(vim.net.IpConfigInfo.IpAddress) {
ipAddress = "192.168.1.31",
prefixLength = 24,
origin = "dhcp",
state = "preferred",
lifetime = <unset>
}
],
dhcp = (vim.net.DhcpConfigInfo) {
ipv6 = (vim.net.DhcpConfigInfo.DhcpOptions) {
enable = false,
config = <unset>
},
ipv4 = (vim.net.DhcpConfigInfo.DhcpOptions) {
enable = true,
config = <unset>
}
},
autoConfigurationEnabled = <unset>
},
netBIOSConfig = (vim.net.WinNetBIOSConfigInfo) {
mode = "unknown",
primaryWINS = "192.168.1.120",
secondaryWINS = ""
}
}
],
ipStack = (vim.vm.GuestInfo.StackInfo) [
(vim.vm.GuestInfo.StackInfo) {
dnsConfig = (vim.net.DnsConfigInfo) {
dhcp = false,
hostName = "test-01",
domainName = "test.local",
ipAddress = (string) [
"192.168.1.1"
],
searchDomain = <unset>
},
ipRouteConfig = (vim.net.IpRouteConfigInfo) {
ipRoute = (vim.net.IpRouteConfigInfo.IpRoute) [
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "0.0.0.0",
prefixLength = 0,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = "192.168.1.1",
device = "0"
}
},
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "192.168.1.0",
prefixLength = 24,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = <unset>,
device = "0"
}
},
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "192.168.1.31",
prefixLength = 32,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = <unset>,
device = "0"
}
},
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "192.168.1.255",
prefixLength = 32,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = <unset>,
device = "0"
}
},
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "224.0.0.0",
prefixLength = 4,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = <unset>,
device = "0"
}
},
(vim.net.IpRouteConfigInfo.IpRoute) {
network = "255.255.255.255",
prefixLength = 32,
gateway = (vim.net.IpRouteConfigInfo.Gateway) {
ipAddress = <unset>,
device = "0"
}
}
]
},
ipStackConfig = <unset>,
dhcpConfig = (vim.net.DhcpConfigInfo) null
}
],
disk = (vim.vm.GuestInfo.DiskInfo) [
(vim.vm.GuestInfo.DiskInfo) {
diskPath = "C:\",
capacity = 50836717568,
freeSpace = 30401667072,
filesystemType = "NTFS",
mappings = <unset>
},
(vim.vm.GuestInfo.DiskInfo) {
diskPath = "E:\",
capacity = 19918848,
freeSpace = 9576448,
filesystemType = "NTFS",
mappings = <unset>
}
],
screen = (vim.vm.GuestInfo.ScreenInfo) {
width = 1422,
height = 867
},
guestState = "running",
powerPolicy = (vim.vm.PowerPolicy) null,
appHeartbeatStatus = "appStatusGray",
guestKernelCrashed = false,
appState = "none",
guestOperationsReady = true,
interactiveGuestOperationsReady = false,
guestStateChangeSupported = true,
generationInfo = <unset>,
hwVersion = "vmx-18",
toolsHealthEvents = <unset>,
customizationInfo = (vim.vm.GuestInfo.CustomizationInfo) {
customizationStatus = "TOOLSDEPLOYPKG_IDLE",
startTime = <unset>,
endTime = <unset>,
errorMsg = <unset>
}
}