vHoge

VMwareのアレコレ備忘録。CLIでがんばるネタ多め。

PowerCLI13 で VMware.ImageBuilder がマルチプラットフォーム対応にしたので試してみる

PowerCLI 13 is now GA!

blogs.vmware.com vdc-repo.vmware.com 世間的には vSphere8 対応、vSAN ESA 対応、Horizon 8 2209 辺りが大きそうですが、
個人的な注目は…

・The VMware.ImageBuilder and VMware.DeployAutomation modules have been ported to work on macOS and Linux.

全 homelab ユーザ待望、VMware.ImageBuilder がようやく Mac/Linux に対応!

Prerequirements

そんな VMware.ImageBuilder ですが、現状では前提が。

・The VMware.ImageBuilder module now requires Python 3.7 and the six, psutil, lxml, and pyopenssl Python packages as a prerequisite.

要件として Python 3.7 Python の Package として

  • six
  • psutil
  • lxml
  • pyopenssl

が必要とのこと。Python を利用する形なのね…
また、PowerCLI に対し、Python3.7 のパスを設定しておく必要がある。

We have also introduced a PowerCLI setting that allows you to set the path to the Python 3.7 installation. For this setting you can use
Set-PowerCLIConfiguration -PythonPath "<path to the Python installation>"

Ubuntu 20.04 on WSL2 で試してみる

PowerCLI 環境作成

Ubuntu 上に PowerShell 入っていなかったのでインストールから。

% sudo apt install powershell

PowerShell Core になって apt で入れられるのは楽になりました…
PowerShell を起動する。

% pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

   A new PowerShell stable release is available: v7.3.0
   Upgrade now, or check out the release page at:
     https://aka.ms/PowerShell-Release?tag=v7.3.0

PS /home/mirie>

# v7.3.0 リリースされてるでと出てくるが、一旦スルー
PowerCLI をインストールする。

PS /home/mirie> Install-Module VMware.PowerCLI

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS /home/mirie>

インストール完了。
バージョンを確認してみる。

PS /home/mirie> Get-InstalledModule VMware.PowerCLI

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
13.0.0.20829139      VMware.PowerCLI                     PSGallery            This Windows PowerShell module contains …

PS /home/mirie> Get-InstalledModule VMware.ImageBuilder

Version              Name                                Repository           Description
-------              ----                                ----------           -----------
8.0.0.20817746       VMware.ImageBuilder                 PSGallery            This Windows PowerShell module contains …

PowerCLI は 13 系に対し、VMware.ImageBuilder は 8 系になるんですね。

CEIP の確認が毎回出てくるのは邪魔なので true で設定しておく。

PS /home/mirie> Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true

Python 3.8 環境で強行突破してみる

Ubuntu 20.04 にデフォルトで入っている Python は 3.8.10...

% python3 --version
Python 3.8.10

3.7 より新しいし、実はイケるんじゃないかな…試してみる。

PS /home/mirie> Set-PowerCLIConfiguration -PythonPath /usr/bin/python3

Perform operation?
Performing operation 'Update VMware.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            Unset                     True                       300
User
AllUsers

PS /home/mirie> Add-EsxSoftwareDepot /mnt/c/Engneering/vsphere/VMware-ESXi-7.0U3g-20328353-depot.zip
RuntimeError: Bad magic number in .pyc file
Add-EsxSoftwareDepot: Could not initialize the VMware.ImageBuilder PowerCLI module. Make sure that Python 3.7 is installed and that you have set the path to the Python executable by using Set-PowerCLIConfiguration -PythonPath. See the PowerCLI Compatibility Matrixes for information on the Python requirements.

案の定失敗…
(Bad magic number in .pyc filePython のテンポラリなバイトコードらしく、これがバージョン依存になっているぽい?)
(テンポラリなので .pyc を探して消してしまえば良さそうな気もするが…)

Python3.7 環境を作る

大人しく Python 3.7 環境を作るか…
↓を参考に apt で Python3.7 をインストール。 qiita.com

# リポジトリの追加
% sudo apt install -y software-properties-common
% sudo add-apt-repository ppa:deadsnakes/ppa

# 追加したリポジトリのパッケージ情報更新
% sudo apt update

# Python3.7 のインストール
% sudo apt install -y python3.7

# python3.7 で追加されているはず
% python3.7 --version
Python 3.7.15

これだけだと Prerequirement の Package が入っていないので、
Python 3.7 用の pip をインストールし、Package を追加していく。

# distutils が無いと pip のインストールがコケるので。
% sudo apt install python3.7-distutils

# インストーラの入手
% curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

# インストールの実行
% python3.7 get-pip.py
Defaulting to user installation because normal site-packages is not writeable
Collecting pip
  Using cached pip-22.3.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  WARNING: The scripts pip, pip3 and pip3.7 are installed in '/home/mirie/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.3.1

インストールに成功すると $HOME/.local/bin 下に pip のバイナリができる。
それを使って Package をインストール。

% .local/bin/pip install six psutil lxml pyopenssl
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: six in /usr/lib/python3/dist-packages (1.14.0)
Collecting psutil
  Downloading psutil-5.9.4-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (280 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 280.2/280.2 kB 1.4 MB/s eta 0:00:00
Collecting lxml
  Downloading lxml-4.9.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (6.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.4/6.4 MB 3.8 MB/s eta 0:00:00
Requirement already satisfied: pyopenssl in /usr/lib/python3/dist-packages (19.0.0)
Installing collected packages: psutil, lxml
Successfully installed lxml-4.9.1 psutil-5.9.4

これで再度 PowerCLI を試す。

PS /home/mirie> Set-PowerCLIConfiguration -PythonPath /usr/bin/python3.7

Perform operation?
Performing operation 'Update VMware.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            Unset                     True                       300
User
AllUsers

PS /home/mirie> Add-EsxSoftwareDepot /mnt/c/Engneering/vsphere/VMware-ESXi-7.0U3g-20328353-depot.zip

Depot Url
---------
zip:/mnt/c/Engneering/vsphere/VMware-ESXi-7.0U3g-20328353-depot.zip?index.xml

おぉ、Add-EsxSoftwareDepot が通った(以前は通らなかった)
ISO イメージ出力するところまで試してみる。

# イメージプロファイルの一覧
PS /home/mirie> Get-EsxImageProfile

Name                           Vendor          Last Modified   Acceptance Level
----                           ------          -------------   ----------------
ESXi-7.0U3g-20328353-no-tools  VMware, Inc.    2022/08/23 3:0… PartnerSupported
ESXi-7.0U3g-20328353-standard  VMware, Inc.    2022/09/01 0:0… PartnerSupported

# イメージプロファイルから ISO の生成
PS /home/mirie> Export-EsxImageProfile -ImageProfile ESXi-7.0U3g-20328353-standard -ExportToIso ./ESXi-7.0U3g-20328353-standard.iso
PS /home/mirie>

cmdlet 通りましたわー
出力された ISO を見てみる。

# ファイルタイプ確認
% file ESXi-7.0U3g-20328353-standard.iso
ESXi-7.0U3g-20328353-standard.iso: ISO 9660 CD-ROM filesystem data 'ESXI-7.0U3G-20328353-STANDARD' (bootable)

# マウントして中身を見てみる。
% sudo mount -t iso9660 ./ESXi-7.0U3g-20328353-standard.iso /mnt/iso
mount: /mnt/iso: WARNING: device write-protected, mounted read-only.
% ls /mnt/iso/
atlantic.v00  esx_ui.v00     ixgben.v00    lsuv2_oe.v02  nvmerdma.v00  safeboot.c32  vmkusb.v00
b.b00         esxio_co.v00   jumpstrt.gz   lsuv2_sm.v00  nvmetcp.v00   sb.v00        vmw_ahci.v00
basemisc.tgz  esxupdt.v00    k.b00         mboot.c32     nvmxnet3.v00  sfvmk.v00     vmware-esx-base-osl.txt
bmcal.v00     fatbootsector  ldlinux.sys   menu.c32      nvmxnet3.v01  smartpqi.v00  vmware-esx-base-readme
bnxtnet.v00   features.gz    loadesx.v00   mtip32xx.v00  procfs.b00    tools.t00     vmware_e.v00
bnxtroce.v00  gc.v00         lpfc.v00      native_m.v00  pvscsi.v00    tpm.v00       vmx.v00
boot.cat      i40en.v00      lpnic.v00     ne1000.v00    qcnic.v00     tpmesxup.v00  vsan.v00
boot.cfg      iavmd.v00      lsi_mr3.v00   nenic.v00     qedentv.v00   trx.v00       vsanheal.v00
brcmfcoe.v00  icen.v00       lsi_msgp.v00  nfnic.v00     qedrntv.v00   uc_amd.b00    vsanmgmt.v00
btldr.v00     igbn.v00       lsi_msgp.v01  nhpsa.v00     qfle3.v00     uc_hygon.b00  weaselin.v00
crx.v00       imgdb.tgz      lsi_msgp.v02  nmlx4_co.v00  qfle3f.v00    uc_intel.b00  xorg.v00
efi           imgpayld.tgz   lsuv2_hp.v00  nmlx4_en.v00  qfle3i.v00    upgrade
efiboot.img   ionic_en.v00   lsuv2_in.v00  nmlx4_rd.v00  qflge.v00     useropts.gz
elx_esx_.v00  irdman.v00     lsuv2_ls.v00  nmlx5_co.v00  qlnative.v00  vdfs.v00
elxiscsi.v00  iser.v00       lsuv2_nv.v00  nmlx5_rd.v00  resvibs.tgz   vim.v00
elxnet.v00    isolinux.bin   lsuv2_oe.v00  ntg3.v00      rste.v00      vmkata.v00
esx_dvfi.v00  isolinux.cfg   lsuv2_oe.v01  nvme_pci.v00  s.v00         vmkfcoe.v00

いけてそう。

レガシー PowerCLI を投げ捨てろ

Mac は手元に環境無いので試してないですが、Linux がいけるならまぁ大丈夫でしょ…
ということで、今までは非 Core (PowerShell 5.1以下)環境の PowerCLI でしか動かなかった VMware.ImageBuilder がやっっっと対応してくれましたので、これでようやく 古い PowerCLI は投げ捨てられるし、非 Windows 環境の homelab な人たちもアレコレ悩むことなくカスタムイメージ作成に励めそうですね。

Have a Happy Custom Image Life!(?)