VMware OVF Tool で仮想マシンをデプロイする

2021年5月3日

はじめに

無償版ESXiで仮想マシンのデプロイを自動化できないかと考えて、VMware OVF Tool を使ってみた。

VMware OVF Toolは、コマンドラインからOVFイメージのインポート/エクスポートができるツールで、WindowsとLinuxに対応している。

WEBブラウザを使用せず仮想マシン作成できるので、使えると便利な場面も多いかもしれない。

Open Virtualization Format(OVF)は、仮想マシンイメージに関するメタデータをXML形式で記述するための業界標準です。 VMware OVF Toolは、ユーザーがOVFパッケージをインポートおよびエクスポートするのに役立つコマンドラインユーティリティです。
さまざまなVMware製品との間でやり取りされます。

https://www.vmware.com/support/developer/ovf/ovf420/ovftool-420-userguide.pdf

環境

  • デプロイ先
    • ESXi6.7 (192.168.0.99)
  • クライアント (OVF Toolインストール先)
    • CentOS8
  • デプロイするイメージ
    • CnetOS8

資材準備

  • デプロイするOVF

OVFは自分でイメージを作成するか、以下のようなサイトからダウンロード

※今回はCnetOS8のOVFを使用

https://www.linuxvmimages.com/images/centos-8/

  • VMware OVF Tool インストーラ

アカウント登録が必要

https://www.vmware.com/support/developer/ovf/

https://code.vmware.com/web/tool/4.4.0/ovf

実行環境準備

1. OVFの配置

適当なディレクトリにOVFファイルとディスクイメージを配置

$ ls -l /opt/OVF_Templete/CentOS8.3
合計 961044
-rw-r--r-- 1 user user 984095232 12月 10 04:09 CentOS_8.3.2011_VMM_LinuxVMImages-disk1.vmdk
-rw-r--r-- 1 user user       231 12月 10 04:09 CentOS_8.3.2011_VMM_LinuxVMImages.mf
-rw-r--r-- 1 user user      7605 12月 10 04:09 CentOS_8.3.2011_VMM_LinuxVMImages.ovf

2. OVF Toolのインストール

適当なディレクトリにLinux用のインストーラを配置し、実行権限を付与する。

$ cd /usr/local/src/VMware
$ ls -l
-rw-r--r-- 1 user user 40460671  4月 24 22:32 VMware-ovftool-4.4.1-16812187-lin.x86_64.bundle

$ chmod 744 VMware-ovftool-4.4.0-16360108-lin.x86_64.bundle
$ ls -l
-rwxr--r-- 1 user user 40460671  4月 24 22:32 VMware-ovftool-4.4.1-16812187-lin.x86_64.bundle

root権限でインストール実行

$ sudo ./VMware-ovftool-4.4.1-16812187-lin.x86_64.bundle --console
Extracting VMware Installer...done.
You must accept the VMware OVF Tool component for Linux End User
License Agreement to continue.  Press Enter to proceed. 【Enter】

→確認事項が表示されるため、一通り目を通して【q】で閉じる

Do you agree? [yes/no]: 【yes】

The product is ready to be installed.  Press Enter to begin
installation or Ctrl-C to cancel. 【Enter】

Installing VMware OVF Tool component for Linux 4.4.1
    Configuring...
[######################################################################] 100%
Installation was successful.

インストール完了

$ which ovftool
/usr/bin/ovftool

$ ovftool --version
VMware ovftool 4.4.1 (build-16812187)

デプロイ

ovftoolコマンド使用方法

  • 書式

書式は以下。<source>でovfファイルパスを指定、<target>にはデプロイ先のvCenterやESXi情報が入る

ovftool [options] <source> <target>]
  • オプション

デプロイするデータストアやネットワークを指定可能。大量にあるけど↓の5つくらいで足りそう

項目説明
–datastore<データストア名>VMをデプロイするデータストアを指定
–name<仮想マシン名>デプロイするVMの仮想マシン名
–network<ネットワーク名>デプロイするVMが所属するNWを指定
–diskMode<ディスクフォーマット>シン/シック プロビジョニング等を指定
–powerOnデプロイ後にVMを自動起動する

↓オプション一覧

Usage: ovftool [options] <source> [<target>]
where
<source>: Source URL locator to an OVF package, VMX file, or virtual machine in
          vCenter or on ESX Server.
<target>: Target URL locator which specifies either a file location, or a
          location in the vCenter inventory or on an ESX Server.

If <target> is not specified, information about the source is displayed to the
console.

Options:
     --acceptAllEulas            : Accept all end-user licenses agreements
                                   without being prompted.
     --allowAllExtraConfig       : Whether we allow all the ExtraConfig
                                   options. These options are a security risk
                                   as they control low-level and potential
                                   unsafe options on the VM.
     --allowExtraConfig          : Whether we allow ExtraConfig options. These
                                   options are a security risk as they control
                                   low-level and potential unsafe options on
                                   the VM.
     --annotation                : Add annotation to vi, vmx, vapprun, vCloud,
                                   OVF, and OVA source locators
     --authdPortSource           : Use this to override default vmware authd
                                   port (902) when using a host as source.
     --authdPortTarget           : Use this to override default vmware authd
                                   port (902) when using a host as target.
     --chunkSize                 : Specifies the chunk size to use for files in
                                   a generated OVF package. The default is not
                                   to chunk. The chunk size without unit is
                                   assumed to be in megabytes. Accepted units
                                   are b, kb, mb, gb; e.g., 2gb or 100kb.
     --compress                  : Compress the disks in an OVF package. Value
                                   must be between 1 and 9. 1 is the fastest,
                                   but gives the worst compression, whereas 9
                                   is the slowest, but gives the best
                                   compression.
     --computerName              : Sets the computer name in the guest for a VM
                                   using the syntax --computerName:<VM
                                   ID>=<value>. Only applies to vCloud targets
                                   version 5.5 or newer.
     --configFile                : Configuration file to use to load options
                                   from.
     --coresPerSocket            : Specifies the distribution of the total
                                   number of CPUs over a number of virtual
                                   sockets using the syntax
                                   --coresPerSocket:<VM ID>=<value>. Only
                                   applies to vCloud targets version 5.5 or
                                   newer.
 -ds/--datastore                 : Target datastore name for a VI locator.
     --decodeBase64              : Decode option values with Base64.
     --defaultStorageProfile     : The storage profile for all VMs in the OVF
                                   package. The value should be an SPBM profile
                                   ID. Only applies to VI targets version 5.5
                                   or newer.
     --defaultStorageRawProfile  : The storage profile for all VMs in the OVF
                                   package. The value should be raw SPBM
                                   profile. The value will overwrite that in
                                   --defaultStorageProfile. Only applies to VI
                                   targets version 5.5 or newer.
     --deploymentOption          : Selects what deployment option to use (if
                                   the source OVF package supports multiple
                                   options.)
     --disableVerification       : Skip validation of signature and
                                   certificate.
 -dm/--diskMode                  : Select target disk format. Supported formats
                                   are: monolithicSparse, monolithicFlat,
                                   twoGbMaxExtentSparse, twoGbMaxExtentFlat,
                                   seSparse (VI target), eagerZeroedThick (VI
                                   target), thin (VI target), thick (VI
                                   target), sparse, and flat
     --diskSize                  : Sets the size of a VM disk in megabytes
                                   using the syntax --diskSize:<VM ID>,<disk
                                   instance ID>=<value>. Only applies to vCloud
                                   targets version 5.5 or newer.
     --eula                      : EULA to be inserted in the first virtual
                                   system or virtual system collection in the
                                   OVF. If the EULA is in a file, use the
                                   option --eula@=filename instead.
     --exportDeviceSubtypes      : Enables export of resource subtype for
                                   CD/Floppy/Parallel/Serial devices. This can
                                   limit portability as not all device backings
                                   are supported on all hypervisors. The
                                   default is false.
     --exportFlags               : Specifies one or more export flags to
                                   control what gets exported. The supported
                                   values for VI sources are mac, uuid, and
                                   extraconfig. Supported value for vCloud
                                   sources are preserveIdentity. One or more
                                   options can be provided, separated by
                                   commas.
     --extraConfig               : Sets an ExtraConfig element for all
                                   VirtualHardwareSections. The syntax is
                                   --extraConfig:<key>=<value>. Applies to vi,
                                   vmx, vapprun, vCloud, ovf, and ova source
                                   locators.
     --fencedMode                : If a parent network exists on the vCloud
                                   target, this property specifies the
                                   connectivity to the parent. Possible values
                                   are bridged, isolated, and natRouted.
 -h /--help                      : Prints this message.
     --hideEula                  : In OVF probe mode, hides the EULA.
     --importAsTemplate          : Import VM as a Template when deployed on a
                                   VI target.
     --ipAllocationPolicy        : IP allocation policy for a deployed OVF
                                   package.Supported values are: dhcpPolicy,
                                   transientPolicy, fixedPolicy,
                                   fixedAllocatedPolicy.
     --ipProtocol                : Select what IP protocol to use (IPv4, IPv6).
     --lax                       : Relax OVF specification conformance and
                                   virtual hardware compliance checks. Use only
                                   if you know what you are doing.
     --locale                    : Selects locale for target.
     --machineOutput             : Output OVF Tool messages in a machine
                                   friendly manner.
     --makeDeltaDisks            : Build delta disk hierarchy from the given
                                   source locator.
     --maxVirtualHardwareVersion : The maximal virtual hardware version to
                                   generate.
     --memorySize                : Sets the memory size in megabytes of a VM
                                   using the syntax --memorySize:<VM
                                   ID>=<value>. Only applies to vCloud targets
                                   version 5.5 or newer.
     --multiDatastore            : List of target datastore names for a VI
                                   locator. datastore assignment is set using
                                   the syntax

                                   --mdatastore:<ovf:diskId>=<targetdatastore-name>.
                                   multiple mds parameteres are used to specify
                                   multiple datastore mappings. e.g.
                                   --mdatastore:vmdisk1=datastore1
                                   --mdatastore:vmdisk2=datastore2
                                   The multi datastore flags can not be used
                                   along with --datastore flag.
 -n /--name                      : Specifies target name (defaults to source
                                   name).
     --net                       : Set a network assignment in the deployed OVF
                                   package. A network assignment is set using
                                   the syntax --net:<OVF name>=<target name>.
                                   If the target is vCloud 5.5 or newer, a
                                   fence mode can also be specified using the
                                   syntax --net:<OVF name>=<target name>,<fence
                                   mode>. Possible fence mode values are:
                                   bridged, isolated, and natRouted.
 -nw/--network                   : Target network for a VI deployment.
     --nic                       : Specifies NIC configuration in a VM using
                                   the syntax --nic:<VM ID>,<index>=<OVF net
                                   name>,<isPrimary>,<ipAddressingMode>,<ipAddress>.
                                   Possible values for ipAddressingMode are:
                                   DHCP, POOL, MANUAL, and NONE. ipAddress is
                                   optional and should only be used when
                                   ipAddressingMode is set to MANUAL. Only
                                   applies to vCloud targets version 5.5 or
                                   newer.
     --noDestinationSSLVerify    : Skip SSL verification for target VI
                                   connections.
     --noDisks                   : Disable disk conversion.
     --noImageFiles              : Do not include image files in destination.
     --noNvramFile               : Do not include nvram file in destination.
     --noProxyVerify             : Skip Proxy SSL verification.
     --noSSLVerify               : Skip SSL verification for VI connections.
     --noSourceSSLVerify         : Skip SSL verification for source VI
                                   connections.
     --numberOfCpus              : Sets the number of CPUs for a VM using the
                                   syntax --numberOfCpus:<VM ID>=<value>. Only
                                   applies to vCloud targets version 5.5 or
                                   newer.
 -o /--overwrite                 : Force overwrites of existing files.
     --packageCert               : Package a source OVF files with a
                                   certificate file into an OVA as is with no
                                   modifications.
     --parallelThreads           : Specifies how many threads should be used
                                   for parallel transfer.
     --powerOffSource            : Ensures a VM/vApp is powered off before
                                   importing from a VI source.
     --powerOffTarget            : Ensures a VM/vApp is powered off before
                                   overwriting a VI target.
     --powerOn                   : Powers on a VM/vApp deployed on a VI target.
     --preCheck                  : Require pre check validations before
                                   import/export, default is true
     --privateKey                : Sign OVF package with the given private key
                                   (.pem file). The file must contain a private
                                   key and a certificate.
     --privateKeyPassword        : Password for the private key. Should be used
                                   in conjunction with privateKey if the
                                   private key requires password
                                   authentication. If required and not
                                   specified, the tool will prompt for the
                                   password.
     --prop                      : Set a property in the deployed OVF package.
                                   A property is set using the syntax
                                   --prop:<key>=<value>.
     --proxy                     : Proxy used for HTTP[S] access.
     --proxyCert                 : Specify full path to Proxy Certificate.
     --proxyNTLMAuth             : Enable NTLM authentication for proxy.
     --proxyPassword             : Proxy password.
     --proxyUsername             : Proxy user name.
     --pullUploadMode            : Pull mode used in uploading files to VI
                                   target, i.e. target pulls files.
 -q /--quiet                     : No output to screen except errors.
     --requireSignature          : Require validation of signature and
                                   certificate.
     --schemaValidate            : Validate OVF descriptor against OVF schema.
     --shaAlgorithm              : Select SHA digest algorithm when creating
                                   OVF package. Supported values are SHA1,
                                   SHA256 and SHA512. Default value is SHA256.
     --skipManifestCheck         : Skip validation of OVF package manifest.
     --skipManifestGeneration    : Skip generation of OVF package manifest.
     --sourcePEM                 : File path to PEM formatted file used to
                                   verify VI connections.
     --sourceSSLThumbprint       : SSL fingerprint of SOURCE. OVF Tool verifies
                                   the SSL fingerprint it gets from SOURCE if
                                   the value is set.
 -st/--sourceType                : Explicitly express that source is OVF, OVA,
                                   VMX, VI, vCloud, ISO, FLP, vApprun
     --sslCipherList             : Use this to override default OpenSSL ciphers
                                   suite.
     --sslVersion                : Use this to set preferred TLS/SSL version
                                   for HTTPS connections. The valid values are
                                   as following:
                                     TLSv1_0: Set preferred TLS/SSL version to
                                   TLSv1.0.
                                     TLSv1_1: Set preferred TLS/SSL version to
                                   TLSv1.1.
                                     TLSv1_2: Set preferred TLS/SSL version to
                                   TLSv1.2.
     --storageProfile            : Sets the storage profile for a VM using the
                                   syntax --storageProfile:<VM ID>=<value>.
                                   Only applies to vCloud targets version 5.5
                                   or newer.
     --targetPEM                 : File path to PEM formatted file used to
                                   verify VI connections.
     --targetSSLThumbprint       : SSL fingerprint of TARGET. OVF Tool verifies
                                   the SSL fingerprint it gets from TARGET if
                                   the value is set.
 -tt/--targetType                : Explicitly express that target is OVF, OVA,
                                   VMX, VI, vCloud, ISO, FLP, vApprun
     --vCloudTemplate            : Create only a vApp template. Default value
                                   is false
     --vService                  : Set a vService assignment in the deployed
                                   OVF package. A vService assignment is set
                                   using the syntax
                                   --vService:<dependencyId>=<providerId>.
     --verifyOnly                : Do not upload the source but only verify it
                                   against the target host. Applies to VI 4
                                   targets only.
 -v /--version                   : Prints the version of this tool.
     --viCpuResource             : Specify the CPU resource settings for
                                   VI-locator targets. The syntax is
                                   --viCpuResource=<shares>:<reservation>:<limit>.
     --viMemoryResource          : Specify the CPU resource settings for
                                   VI-locator targets. The syntax is
                                   --viMemoryResource=<shares>:<reservation>:<limit>.
 -vf/--vmFolder                  : Target VM folder in VI inventory (relative
                                   to datacenter).

For more help, type: --help <topic>, where topics are:
 locators    : For detailed source and destination locator syntax
 examples    : For examples of use
 config      : For syntax of configuration files
 debug       : For debug purpose
 integration : For a list of options primarily used when ovftool is exec'ed
               from another tool or shellscript.

2. デプロイ実行

$ ovftool \
--datastore=datastore_local-02 \
--name=testvm_ova \
--network="VM Network" \
--diskMode=thin \
/opt/OVF_Templete/CentOS8.3/CentOS_8.3.2011_VMM_LinuxVMImages.ovf \
vi://root:Password@192.168.0.99

Warningが出たが、デプロイ完了

Opening OVF source: /opt/OVF_Templete/CentOS8.3/CentOS_8.3.2011_VMM_LinuxVMImages.ovf
The manifest validates
Opening VI target: vi://root@192.168.0.99:443/
Warning:
 - The specified operating system identifier '' (id: 107) is not supported on the selected host. It will be mapped to the following OS identifier: 'Other Linux (64-bit)'.
Deploying to VI: vi://root@192.168.0.99:443/
Transfer Completed
Completed successfully

エラーはゲストOSの種類に関するもので、「id: 107」に対応するものが無いとのこと

id107はCentOS(64bit)のIDだけど、なぜか識別できない

WEBブラウザ経由でデプロイした場合は正しく認識するので、OVF Tool固有の問題か。本題とは関係ないので一旦無視。。

WEB Clientから仮想マシンが作成されているか確認する

終わり