目的
PowerCLI.coreというLinuxやDockerでもPowerCLI(の一部)を
利用することができるということで触ってみました。
中身としては.Net core上でPowerShellを動かし、その上でPowerCLI.coreを
実行するようです。この辺りはさっぱりなので今回は深くは踏み込まないようにします。
前提
環境は以下の環境を想定しています。
- Ubuntu 16.04.1
- Docker 17.03.1-ce
注意
PowerCLI自体はまだexperimentalな状態なので
本番環境でバリバリ使うのはおすすめできない様です。
(should not be run on production systemsとのこと)
想定する読者
以下の条件を満たす方
- Windows環境がないかつ、PowerCLIを触りたくなった方
インストールと起動
イメージの取得
$ sudo docker pull vmware/powerclicore:latest
イメージ名を指定して引っ張ります。
コンテナの起動
$ sudo docker run -d --name powercli vmware/powerclicore:latest /bin/bash -c 'tail -f /dev/null'
/bin/bash -c 'rail -f /dev/null
でひとまず起動しっぱなしの状態にします。
コンテナでpowershellを実行
$ sudo docker exec -it powercli powershell
PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Welcome to VMware vSphere PowerCLI!
Log in to a vCenter Server or ESX host: Connect-VIServer
To find out what commands are available, type: Get-VICommand
Once you've connected, display all virtual machines: Get-VM
Copyright (C) VMware, Inc. All rights reserved.
Loading personal and system profiles took 1204ms.
PS /powershell>
無事powershellを起動できました。
ESXiサーバへの接続
自前で保有しているESXiサーバに接続します。
PS /powershell> Connect-VIServer -Server aaa.bbb.ccc.ddd -User xxxxx -Password xxxxxxxxxx
WARNING: Invalid server certificate. Use Set-PowerCLIConfiguration to set the value for the InvalidCertificateAction option to Prompt if you'd like to
connect once or to add a permanent exception for this server.
Connect-VIServer : 06/04/2017 15:07:02 Connect-VIServer An error occurred while sending the request.
At line:1 char:1
+ Connect-VIServer -Server 192.168.0.254 -User root -Password ottoserve ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Connect-VIServer], ViError
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_Exception,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
有効な証明書を入れてないので接続できません。
証明書を設定するのも面倒(正式なサービスでもなんでもない)なので、
証明書が向こうな場合でも処理を継続するようにします。
証明書の検証設定を変更
無効な証明書の場合でも無視するように設定します。
PS /powershell> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Perform operation?
Performing operation 'Update PowerCLI configuration.'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): Y
Scope ProxyPolicy DefaultVIServerMode InvalidCertificateAction DisplayDeprecationWarnings WebOperationTimeout
Seconds
----- ----------- ------------------- ------------------------ -------------------------- -------------------
Session UseSystemProxy Multiple Ignore True 300
User Ignore
AllUsers
(再度) ESXiへの接続
無事接続できました。
PS /powershell> Connect-VIServer -Server aaa.bbb.ccc.ddd -User xxxxxx -Password xxxxxxx
Name Port User
---- ---- ----
192.168.0.254 443 root
適当にコマンドを実行
ひとまずは仮想マシンのリストを見てみましょう。
PS /powershell> Get-VM
Name PowerState Num CPUs MemoryGB
---- ---------- -------- --------
AdventCalendar PoweredOff 2 2.000
DockerHost01 PoweredOn 2 4.000
DockerHost02 PoweredOn 2 4.000
Openshift PoweredOff 2 8.000
Openshift_slave1 PoweredOff 2 4.000
NFS PoweredOn 1 4.000
DNS_DHCP PoweredOff 1 2.000
client PoweredOff 1 1.000
zabbix01 PoweredOff 1 2.000
zabbix02 PoweredOff 1 2.000
無事仮想マシンの一覧が表示されました。
まとめ
元となっているPowerCLIと比較するとできない操作も複数あるようですが、
基本的な操作は可能な様なので、ESXiに対して何かしらバッチ処理などを
行いたいけれどもWindows環境がない方などには役立ちそうです。
今後の本家本元との機能差異を埋めていくこと、または
こちらを主として開発が進むことに期待したですね。