Linux で PowerCLI Core をためす。(Photon OS)

Linux で PowerCLI Core をためす。(Photon OS)

VMware Flings で、PowerCLI Core が公開されたので、

さっそく、Linux (Photon OS) で実行してみました。

PowerCLI Core は、Linux、Mac などマルチプラットフォームで実行できる PowerCLI です。

VMware Flings の PowerCLI Core のページ

PowerCLI Core

こちらもどうぞ。

PowerCLI Core を Docker コンテナでためしてみる。

見た目はこんな感じです・・・

powercli-core.png

PowerShell のインストール。

今回は、VMware Photon OS 1.0 にインストールします。

root@photon-ALW4IArOR [ ~ ]# cat /etc/photon-release

VMware Photon Linux 1.0

PHOTON_BUILD_NUMBER=13c08b6

root@photon-ALW4IArOR [ ~ ]# uname -r

4.4.8-esx

キーマップ(日本語の ja106)、ホスト名(今回は photon-pcli) を設定しておきまます。

root@photon-ALW4IArOR [ ~ ]# localectl set-keymap jp106

root@photon-ALW4IArOR [ ~ ]# hostnamectl set-hostname photon-pcli

tdnf コマンド(yum のかわり) で、RPM を最新化しておきます。
RPM のアップグレードが終わったら、いったん OS を再起動します。

root@photon-ALW4IArOR [ ~ ]# tdnf upgrade -y

root@photon-ALW4IArOR [ ~ ]# reboot

PowerShell の Yum リポジトリの設定ファイル(.repo)を配置します。

下記のようなコマンドラインを投入して、 /etc/yum.repos.d/powershell.repo ファイルを作成します。

cat << EOF > /etc/yum.repos.d/powershell.repo

[powershell]

name=PowerShell (x86_64)

baseurl=https://vmware.bintray.com/powershell

gpgcheck=0

enabled=1

skip_if_unavailable=True

EOF

実行すると、このような感じになります。

root@photon-pcli [ ~ ]# cat << EOF > /etc/yum.repos.d/powershell.repo

> [powershell]

> name=PowerShell (x86_64)

> baseurl=https://vmware.bintray.com/powershell

> gpgcheck=0

> enabled=1

> skip_if_unavailable=True

> EOF

root@photon-pcli [ ~ ]#

あとでファイルの解凍で使用するので、unzip コマンドをインストールしておきます。

root@photon-pcli [ ~ ]# tdnf install -y unzip

PowerShell をインストールします。

root@photon-pcli [ ~ ]# tdnf install -y powershell

Installing:

libicu                          x86_64      50_rc-1              23.92 M

libunwind                      x86_64      1.2-rc1            145.17 k

powershell                      x86_64      6.0.0_alpha.10-1    120.75 M

Total installed size: 144.82 M

Downloading:

powershell                            40423534    100%

libunwind                                69686    100%

libicu                                10093052    100%

Testing transaction

Running transaction

Complete!

root@photon-pcli [ ~ ]#

PowerCLI Core のインストール。

今回はこのまま root ユーザで進めてしまいます。

Flings サイトからダウンロードしたファイル「PowerCLI_Core.zip」を /root ディレクトリに配置してあります。

root@photon-pcli [ ~ ]# pwd

/root

root@photon-pcli [ ~ ]# ls -l /root/PowerCLI_Core.zip

-rw-r----- 1 root root 10061206 Oct 18 15:59 /root/PowerCLI_Core.zip

/root で、ファイルを解凍します。
このあと、PowerCLI.ViCore.4523941.zip と PowerCLI.Vds.4523941.zip をさらに解凍します。

root@photon-pcli [ ~ ]# unzip -d  PowerCLI_Core PowerCLI_Core.zip

Archive:  PowerCLI_Core.zip

  inflating: PowerCLI_Core/Dockerfile

  creating: PowerCLI_Core/__MACOSX/

  inflating: PowerCLI_Core/__MACOSX/._Dockerfile

  inflating: PowerCLI_Core/PowerCLI.Vds.4523941.zip

  inflating: PowerCLI_Core/__MACOSX/._PowerCLI.Vds.4523941.zip

  inflating: PowerCLI_Core/PowerCLI.ViCore.4523941.zip

  inflating: PowerCLI_Core/__MACOSX/._PowerCLI.ViCore.4523941.zip

  inflating: PowerCLI_Core/README.md

  inflating: PowerCLI_Core/__MACOSX/._README.md

  inflating: PowerCLI_Core/Start-PowerCLI.ps1

  inflating: PowerCLI_Core/__MACOSX/._Start-PowerCLI.ps1

root@photon-pcli [ ~ ]# ls

PowerCLI_Core  PowerCLI_Core.zip

モジュールの配置するディレクトリを作成し、そこに解凍します。

root@photon-pcli [ ~ ]# mkdir -p ~/.local/share/powershell/Modules

root@photon-pcli [ ~ ]# unzip -d .local/share/powershell/Modules/ PowerCLI_Core/PowerCLI.ViCore.4523941.zip

root@photon-pcli [ ~ ]# unzip -d .local/share/powershell/Modules/ PowerCLI_Core/PowerCLI.Vds.4523941.zip

PowerShell の起動。

PowerShell を起動してみます。

root@photon-pcli [ ~ ]# powershell

PowerShell

Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS /root>

PowerShell のバージョンは 6.0 のようです。

PS /root> Get-Host | fl Version

Version : 6.0.0

PS /root>

PowerCLI の起動。

PowerCLI を起動してみます。
最初に zip ファイルを展開したディレクトリに含まれる、Start-PowerCLI.ps1 を実行します。

PS /root> ./PowerCLI_Core/Start-PowerCLI.ps1

          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.

PS /root>

PowerCLI のバージョンを表示してみます。

PS /root> Get-PowerCLIVersion

PowerCLI Version

----------------

  VMware PowerCLI Core 1.0 build 0

---------------

Component Versions

---------------

  VMware vSphere PowerCLI Component 1.21 build 4523941

  VMware VDS PowerCLI Component 1.21 build 4523941

PS /root>

vCenter への接続と、コマンドレットでの情報取得。

今回の環境では vCenter にちゃんとした証明書がインストールされていないので、

とりあえず証明書を無視するようにしてしまいます。

PS /root> Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false

vCenter (今回の環境の vCenter  は vc01.godc.lab) に「Connect-VIServer」 で接続してみます。

「administrator@vsphere.local」 ユーザでログインします。

PS /root> Connect-VIServer vc01.godc.lab                                    

Specify Credential

Please specify server credential

User: administrator@vsphere.local

Password for user administrator@vsphere.local: ************


Name                          Port  User

----                          ----  ----

vc01.godc.lab                  443  VSPHERE.LOCAL\Administrator

PS /root>

クラスタの情報を取得してみます。

PS /root> Get-Cluster

Name                           HAEnabled  HAFailover DrsEnabled DrsAutomationLe

                                          Level                 vel

----                           ---------  ---------- ---------- ---------------

cluster-ha01                   True       1          False      FullyAutomated

cluster-ha02                   True       1          False      FullyAutomated

cluster-ivy                    False      1          False      FullyAutomated

cluster-vsan01                 True       1          True       FullyAutomated

cluster-vsan01 クラスタに含まれる、 ESXi ホストの情報を取得してみます。

PS /root> Get-Cluster cluster-vsan01 | Get-VMHost

Name                 ConnectionState PowerState NumCpu CpuUsageMhz CpuTotalMhz

----                 --------------- ---------- ------ ----------- -----------

hv-i21.godc.lab      Connected       PoweredOn       2         887        4606

hv-i22.godc.lab      Connected       PoweredOn       2        1202        4606

hv-i23.godc.lab      Connected       PoweredOn       2         532        4608

VM の情報を取得してみます。(photon0? という名前のもの)

PS /root> Get-VM photon0? | Sort-Object Name

Name                 PowerState Num CPUs MemoryGB

----                 ---------- -------- --------

photon01             PoweredOff 1        2.000

photon02             PoweredOff 1        2.000

photon03             PoweredOff 1        2.000

photon04             PoweredOff 1        2.000

vDS(分散仮想スイッチ) のモジュールも読み込まれているので、vDS の情報を取得してみます。

PS /root> Get-VDSwitch | ft -AutoSize

Name  NumPorts Mtu  Version Vendor

----  -------- ---  ------- ------

vds01 243      1600 6.0.0   VMware, Inc.

念願の、Linux での PowerCLI が使用できるようになりました。

ただ、Windows のままは使用できないコマンドレット(というかPowerShell のエイリアス) もあったりするようで、

いろいろ実行して特徴をつかみたいと思います。

以上。Linux で PowerCLI Core を使用してみる話でした。

Version history
Revision #:
1 of 1
Last update:
‎10-18-2016 11:03 AM
Updated by: