Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created March 13, 2018 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/041d02db03cbb9234eae0ade5007c2db to your computer and use it in GitHub Desktop.
Save gowatana/041d02db03cbb9234eae0ade5007c2db to your computer and use it in GitHub Desktop.
# HCIBench OVA Deploy Script.
#
# Public_Network_Type は "Static" で固定。
# vCenter に接続するが、デプロイ先は ESXi を指定する。
# Usage:
# PowerCLI> .\deploy_hci-bench-ova.ps1
# ------------------------------
# Setting
$ova_file_path = "D:\VMware\HCIBench_1.6.6.ova"
$vm_name = "hci-bench02"
$target_vc = "vc-sv01.go-lab.jp"
$target_esxi = "hv-d02.go-lab.jp"
$target_pg_public = "VM Network"
$target_pg_private = "pg-vlan-1012"
$target_datastore = "ds_hv-d02_01"
$public_network_ip = "192.168.1.119"
$public_network_netmask = "255.255.255.0"
$public_network_gateway = "192.168.1.1"
$dns = "192.168.1.254"
$ova_root_password = "VMware1!"
# ------------------------------
# connect VC & get OVF config.
Connect-VIServer $target_vc -Force
$ovf_config = Get-OvfConfiguration -Ovf $ova_file_path
# ------------------------------
# Pre Check
$pre_check = "ok"
$hv = Get-VMHost $target_esxi -ErrorAction:SilentlyContinue
$hv | Out-Null; echo $?
if($? -ne $true){"デプロイ先 ESXi を確認して下さい。"; $pre_check = "NG"}
$hv | Get-VirtualPortGroup -Name $target_pg_public -ErrorAction:SilentlyContinue | Out-Null; echo $?
if($? -ne $true){"デプロイ先 Public PG を確認して下さい。"; $pre_check = "NG"}
$hv | Get-VirtualPortGroup -Name $target_pg_private -ErrorAction:SilentlyContinue | Out-Null; echo $?
if($? -ne $true){"デプロイ先 Private PG を確認して下さい。"; $pre_check = "NG"}
$hv | Get-Datastore $target_datastore -ErrorAction:SilentlyContinue | Out-Null; echo $?
if($? -ne $true){"デプロイ先 Datastore を確認して下さい。"; $pre_check = "NG"}
if($pre_check -ne "ok"){"デプロイを実行せず終了します。"; exit 1}
# ------------------------------
# Configure & Deploy
$ovf_config.Common.Public_Network_Type.Value = "Static"
$ovf_config.NetworkMapping.Public_Network.Value = $target_pg_public
$ovf_config.NetworkMapping.Private_Network.Value = $target_pg_private
$ovf_config.Common.Public_Network_IP.Value = $public_network_ip
$ovf_config.Common.Public_Network_Netmask.Value = $public_network_netmask
$ovf_config.Common.Public_Network_Gateway.Value = $public_network_gateway
$ovf_config.Common.DNS.Value = $dns
$ovf_config.Common.System_Password.Value = $ova_root_password
Import-VApp -OvfConfiguration $ovf_config -Source $ovf_config.Source `
-Name $vm_name `
-VMHost $target_esxi `
-Datastore $target_datastore -StorageFormat Thin |
select Name,PowerState
Get-VM $vm_name | Start-VM | select Name,PowerState
Disconnect-VIServer $target_vc -Confirm:$false
@gowatana
Copy link
Author

下記の投稿むけ。

HCIBench の OVA を PowerCLI でデプロイする。
https://communities.vmware.com/people/gowatana/blog/2018/03/13/powercli-hcibench-deploy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment