vSphere PowerCLIの一部コマンドがPowerShell ISEで動作しない


2016/12/15追記

Add-Snappinは、古いPowerShellの場合だけだったようなので、新しいバージョンの場合にも対応したものを下記に記載しています。

vSphere PowerCLIの一部コマンドがPowerShell ISEで動作しない 2016/12/15版


vSphere PowerCLIで変な動作に遭遇した。
vSphere PowerCLIの一部コマンドがPowerShell ISE上だと動作しない、という問題である。
元々、PowerShell ISEの標準設定ではvSphere PowerCLIのコマンドは動かない。
「Add-PSSnapin VMware.VimAutomation.Core」を追加し、モジュールを読み込ませる必要があるのだが、それを行っても動かないものがいくつかあることが分かった。

まずは状況の確認から・・・

現在のvSphere Power CLIのバージョンを確認
Determining the build number for vSphere PowerCLI or VI Toolkit for Windows」より「Get-VIToolkitVersion」を実行。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VIToolkitVersion

PowerCLI Version
----------------
   VMware vSphere PowerCLI 6.0 Release 1 build 2548067
---------------
Component Versions
---------------
   VMWare AutoDeploy PowerCLI Component 6.0 build 2358282
   VMWare ImageBuilder PowerCLI Component 6.0 build 2358282
   VMware License PowerCLI Component 6.0 build 2315846
   VMware vSphere PowerCLI Component 6.0 build 2548068
   VMware Cloud Infrastructure Suite PowerCLI Component 6.0 build 2548068
   VMware HA PowerCLI Component 6.0 build 2510422
   VMware PowerCLI Component for Storage Management 6.0 build 2522368
   VMware VDS PowerCLI Component 6.0 build 2548068



PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

(ちなみに、この記事を書いてる時点では、これより新しいバージョンが出ている)

vCenterサーバに接続

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Connect-VIServer -Server vCenterServer -User root -Password vmware

Name                           Port  User
----                           ----  ----
vCenterServer                  443   root


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

そして、「Get-VdsCommand」を実行してvSphre PowerCLIが提供するvDS関連コマンド一覧を取得。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-VdsCommand

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Cmdlet          Add-VDSwitchPhysicalNetworkAdapter                 VMware.Vi...
Cmdlet          Add-VDSwitchVMHost                                 VMware.Vi...
Cmdlet          Export-VDPortGroup                                 VMware.Vi...
Cmdlet          Export-VDSwitch                                    VMware.Vi...
Cmdlet          Get-VDBlockedPolicy                                VMware.Vi...
Cmdlet          Get-VDPort                                         VMware.Vi...
Cmdlet          Get-VDPortgroup                                    VMware.Vi...
Cmdlet          Get-VDPortgroupOverridePolicy                      VMware.Vi...
Cmdlet          Get-VDSecurityPolicy                               VMware.Vi...
Cmdlet          Get-VDSwitch                                       VMware.Vi...
Cmdlet          Get-VDSwitchPrivateVlan                            VMware.Vi...
Cmdlet          Get-VDTrafficShapingPolicy                         VMware.Vi...
Cmdlet          Get-VDUplinkLacpPolicy                             VMware.Vi...
Cmdlet          Get-VDUplinkTeamingPolicy                          VMware.Vi...
Cmdlet          New-VDPortgroup                                    VMware.Vi...
Cmdlet          New-VDSwitch                                       VMware.Vi...
Cmdlet          New-VDSwitchPrivateVlan                            VMware.Vi...
Cmdlet          Remove-VDPortGroup                                 VMware.Vi...
Cmdlet          Remove-VDSwitch                                    VMware.Vi...
Cmdlet          Remove-VDSwitchPhysicalNetworkAdapter              VMware.Vi...
Cmdlet          Remove-VDSwitchPrivateVlan                         VMware.Vi...
Cmdlet          Remove-VDSwitchVMHost                              VMware.Vi...
Cmdlet          Set-VDBlockedPolicy                                VMware.Vi...
Cmdlet          Set-VDPort                                         VMware.Vi...
Cmdlet          Set-VDPortgroup                                    VMware.Vi...
Cmdlet          Set-VDPortgroupOverridePolicy                      VMware.Vi...
Cmdlet          Set-VDSecurityPolicy                               VMware.Vi...
Cmdlet          Set-VDSwitch                                       VMware.Vi...
Cmdlet          Set-VDTrafficShapingPolicy                         VMware.Vi...
Cmdlet          Set-VDUplinkLacpPolicy                             VMware.Vi...
Cmdlet          Set-VDUplinkTeamingPolicy                          VMware.Vi...
Cmdlet          Set-VDVlanConfiguration                            VMware.Vi...


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> 

ここまでは良い。

PowerShell ISEでの動作が問題。
PowerShell ISE上部の編集画面に下記を入力。

Add-PSSnapin VMware.VimAutomation.Core
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

最初の1行はvSphere PowerCLIのコマンドを実行させるため設定。
これを実行すると・・・

PS C:\Users\osakanataro> Add-PSSnapin VMware.VimAutomation.Core
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

Get-VIToolkitVersion : 用語 'Get-VIToolkitVersion' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、
再試行してください。
発生場所 行:2 文字:1
+ Get-VIToolkitVersion
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VIToolkitVersion:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 

Name                           Port  User                          
----                           ----  ----                          
vCenterServer                  443   root                          
Get-VdsCommand : 用語 'Get-VdsCommand' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください。
発生場所 行:4 文字:1
+ Get-VdsCommand
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-VdsCommand:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 



PS C:\Users\osakanataro> 

エラーになる・・・
なぜなのか・・・

まずはPowerShell ISE内で「Get-Module」を実行し、現在使用できるコマンドを確認

PS C:\Users\osakanataro> Get-Module

ModuleType Version    Name                                ExportedCommands                                                                            
---------- -------    ----                                ----------------                                                                            
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                         
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                          
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}   
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                                   
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}             



PS C:\Users\osakanataro> 

比較のためvSphere PowerCLIの方でも「Get-Module」を実行してみる

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.0        Initialize-VMware_VimAutomation_Cis
Script     0.0        Initialize-VMware_VimAutomation_Vds
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add...
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-T...
Binary     6.0.0.0    VMware.VimAutomation.Cis.Core       {Connect-CisServer...
Manifest   6.0.0.0    VMware.VimAutomation.Core           {Add-PassthroughDe...
Binary     6.0.0.0    VMware.VimAutomation.HA             Get-DrmInfo
Manifest   6.0.0.0    VMware.VimAutomation.Sdk
Binary     6.0.0.0    VMware.VimAutomation.Storage        {Export-SpbmStorag...
Binary     6.0.0.0    VMware.VimAutomation.Vds            {Add-VDSwitchPhysi...


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

全然違う
「VMware.VimAutomation.Vds」を追加すると実行できそうな雰囲気・・・

しかし、「Add-PSSnapin VMware.VimAutomation.Vds」は下記のエラーとなる。

Add-PSSnapin : Windows PowerShell スナップイン 'VMware.VimAutomation.Vds' がこのコンピューターにインストールされていません。
発生場所 行:2 文字:1
+ Add-PSSnapin VMware.VimAutomation.Vds
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (VMware.VimAutomation.Vds:String) [Add-PSSnapin]、PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

ではどうするか?

「Get-Command -Module モジュール名」で指定したモジュールでどんなコマンドが実行できるかを表示すると実行でいるようになるらしい。

そんな馬鹿な、と思いつつ、$DUMMY環境変数に放り込むように変更。

Add-PSSnapin VMware.VimAutomation.Core
$DUMMY=Get-Command -Module VMware.VimAutomation.Vds
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand

そして実行

PS C:\Users\osakanataro> Add-PSSnapin VMware.VimAutomation.Core
$DUMMY=Get-Command -Module VMware.VimAutomation.Vds
Get-VIToolkitVersion
Connect-VIServer -Server vCenterServer -User root -Password vmware
Get-VdsCommand


PowerCLI Version
----------------
   VMware vSphere PowerCLI 6.0 Release 1 build 2548067
---------------
Component Versions
---------------
   VMWare AutoDeploy PowerCLI Component 6.0 build 2358282
   VMWare ImageBuilder PowerCLI Component 6.0 build 2358282
   VMware License PowerCLI Component 6.0 build 2315846
   VMware vSphere PowerCLI Component 6.0 build 2548068
   VMware VDS PowerCLI Component 6.0 build 2548068


IsConnected   : True
Id            : /VIServer=root@vCenterServer:443/
ServiceUri    : https://vCenterServer/sdk
SessionSecret : cb8924f9fb4b2cb6cb75a357d8127e2154376d17
Name          : vCenterServer
Port          : 443
SessionId     : cb8924f9fb4b2cb6cb75a357d8127e2154376d17
User          : root
Uid           : /VIServer=root@vCenterServer:443/
Version       : 6.0
Build         : 2776510
ProductLine   : vpx
InstanceUuid  : 1a31cfc8-0931-4752-9573-461f044cc2d4
RefCount      : 6
ExtensionData : VMware.Vim.ServiceInstance
Client        : VMware.VimAutomation.ViCore.Impl.V1.VimClient


Verb                : Add
Noun                : VDSwitchPhysicalNetworkAdapter
HelpFile            : VMware.VimAutomation.Vds.Commands.dll-Help.xml
PSSnapIn            : 
ImplementingType    : VMware.VimAutomation.Vds.Commands.Cmdlets.AddVDSwitchPhysicalNetworkAdapter
Definition          : 
                      Add-VDSwitchPhysicalNetworkAdapter [-VMHostPhysicalNic] <PhysicalNic&#91;&#93;> [-DistributedSwitch] <DistributedSwitch> [-VirtualNicPor
                      tgroup <VDPortgroup&#91;&#93;>] [-VMHostVirtualNic <HostVirtualNic&#91;&#93;>] [-Server <VIServer&#91;&#93;>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
DefaultParameterSet : 
OutputType          : {System.Void}
Options             : ReadOnly
Name                : Add-VDSwitchPhysicalNetworkAdapter
CommandType         : Cmdlet
Visibility          : Public
ModuleName          : VMware.VimAutomation.Vds
Module              : VMware.VimAutomation.Vds
RemotingCapability  : PowerShell
Parameters          : {[VMHostPhysicalNic, System.Management.Automation.ParameterMetadata], [DistributedSwitch, System.Management.Automation.Parameter
                      Metadata], [VirtualNicPortgroup, System.Management.Automation.ParameterMetadata], [VMHostVirtualNic, System.Management.Automatio
                      n.ParameterMetadata]...}
ParameterSets       : {[-VMHostPhysicalNic] <PhysicalNic&#91;&#93;> [-DistributedSwitch] <DistributedSwitch> [-VirtualNicPortgroup <VDPortgroup&#91;&#93;>] [-VMHostVi
                      rtualNic <HostVirtualNic&#91;&#93;>] [-Server <VIServer&#91;&#93;>] [-WhatIf] [-Confirm] [<CommonParameters>]}
HelpUri             : http://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/html/Add-VDSwitchPhysicalNetworkAdapter.html
DLL                 : C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VimAutomation.Vds\VMware.VimAutomation.Vds.Commands
                      .dll

<略>

Verb                : Set
Noun                : VDVlanConfiguration
HelpFile            : VMware.VimAutomation.Vds.Commands.dll-Help.xml
PSSnapIn            : 
ImplementingType    : VMware.VimAutomation.Vds.Commands.Cmdlets.Policies.SetVDVlanConfiguration
Definition          : 
                      Set-VDVlanConfiguration -VDPortgroup <VDPortgroup&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateV
                      lanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
                      Set-VDVlanConfiguration -VDSwitch <VDSwitch&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId 
                      <int>] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
                      Set-VDVlanConfiguration -VDPort <VDPort&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId <int
                      >] [-WhatIf] [-Confirm] [<CommonParameters>]
                      
DefaultParameterSet : 
OutputType          : {VMware.VimAutomation.Vds.Types.V1.VlanConfiguration}
Options             : ReadOnly
Name                : Set-VDVlanConfiguration
CommandType         : Cmdlet
Visibility          : Public
ModuleName          : VMware.VimAutomation.Vds
Module              : VMware.VimAutomation.Vds
RemotingCapability  : PowerShell
Parameters          : {[VDPortgroup, System.Management.Automation.ParameterMetadata], [VDSwitch, System.Management.Automation.ParameterMetadata], [VDP
                      ort, System.Management.Automation.ParameterMetadata], [DisableVlan, System.Management.Automation.ParameterMetadata]...}
ParameterSets       : {-VDPortgroup <VDPortgroup&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-PrivateVlanId <int>] [-WhatIf] 
                      [-Confirm] [<CommonParameters>], -VDSwitch <VDSwitch&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <VlanRangeList>] [-Priva
                      teVlanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>], -VDPort <VDPort&#91;&#93;> [-DisableVlan] [-VlanId <int>] [-VlanTrunkRange <V
                      lanRangeList>] [-PrivateVlanId <int>] [-WhatIf] [-Confirm] [<CommonParameters>]}
HelpUri             : http://www.vmware.com/support/developer/PowerCLI/PowerCLI60R1/html/Set-VDVlanConfiguration.html
DLL                 : C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\VMware.VimAutomation.Vds\VMware.VimAutomation.Vds.Commands
                      .dll




PS C:\Users\osakanataro> 

ほんとに実行できたーーー
じゃぁ、この段階での「Get-Module」はどうなってるか確認してみると、ちゃんとVMware.VimAutomation.Vdsが読み込まれてる・・・
謎な動作をしてますね・・・

PS C:\Users\osakanataro> Get-Module

ModuleType Version    Name                                ExportedCommands                                                                            
---------- -------    ----                                ----------------                                                                            
Script     0.0        Initialize-VMware_VimAutomation_Vds                                                                                             
Script     1.0.0.0    ISE                                 {Get-IseSnippet, Import-IseSnippet, New-IseSnippet}                                         
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}                          
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}   
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}                                   
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}             
Manifest   6.0.0.0    VMware.VimAutomation.Core                                                                                                       
Manifest   6.0.0.0    VMware.VimAutomation.Sdk                                                                                                        
Binary     6.0.0.0    VMware.VimAutomation.Vds            {Add-VDSwitchPhysicalNetworkAdapter, Add-VDSwitchVMHost, Export-VDPortGroup, Export-VDSwi...



PS C:\Users\osakanataro> 

RHEL/CentOS6でSolarisみたいなsyslog出力を行う


Solarisからの移行ユーザからこんなことを言われた。

Solarisだとログ出力にFacitilyとPriorityがあるのに、Linuxはなんで無いの?

Solarisの例

Aug 21 18:30:26 solaris hme: [ID 517527 kern.info] SUNW,hme0 : Internal Transceiver Selected.
Aug 21 18:30:26 solaris hme: [ID 517527 kern.info] SUNW,hme0 :   100 Mbps Full-Duplex Link Up
Aug 21 18:30:54 solaris savecore: [ID 570001 auth.error] reboot after panic: [AFT1] errID 0x00090886.6bd9286c UE Error(s)
Aug 21 18:30:54 solaris     See previous message(s) for details
Aug 21 18:30:54 solaris ntpdate[175]: [ID 558275 daemon.notice] adjust time server 158.211.134.200 offset 0.350887 sec
Aug 21 18:30:58 solaris xntpd[186]: [ID 702911 daemon.notice] xntpd 3-5.93e Mon Sep 20 15:47:11 PDT 1999 (1)
Aug 21 18:30:58 solaris xntpd[186]: [ID 301315 daemon.notice] tickadj = 5, tick = 10000, tvu_maxslew = 495, est. hz = 100
Aug 21 18:30:59 solaris xntpd[186]: [ID 798731 daemon.notice] using kernel phase-lock loop 0041
Aug 21 18:30:59 solaris last message repeated 1 time
Aug 21 18:31:09 solaris pseudo: [ID 129642 kern.info] pseudo-device: tod0
Aug 21 18:31:09 solaris genunix: [ID 936769 kern.info] tod0 is /pseudo/tod@0

Linuxの例

Aug 26 17:11:52 centos6 postfix/postfix-script[32480]: stopping the Postfix mail system
Aug 26 17:11:52 centos6 postfix/master[32414]: terminating on signal 15
Aug 26 17:11:52 centos6 postfix/postfix-script[32552]: starting the Postfix mail system
Aug 26 17:11:52 centos6 postfix/master[32553]: daemon started -- version 2.6.6, configuration /etc/postfix

ふむ・・・確かに

/etc/rsyslog.confを編集して実現してみた。
参考資料
・Red Hat Enterprise Linux 6導入ガイド :「第20章 ログファイルの表示と管理

さすがにデフォルト出力を変えてしまうと、Linux側のツールでsyslogを処理した場合に問題が生じるので
Solaris互換のログファイルは別ファイルで出力させることにした。

設定を行った「/etc/rsyslog.conf」のサンプルは以下。

$template FacilityTmpl,"%timereported% %HOSTNAME% %syslogtag% [ID %MSGID% %syslogfacility-text%.%syslogseverity-text%]%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
mail.*                                         /var/log/solaris-compati.log;FacilityTmpl

その出力例

Aug 26 17:11:52 centos6 postfix/postfix-script[32480]: [ID - mail.info] stopping the Postfix mail system
Aug 26 17:11:52 centos6 postfix/master[32414]: [ID - mail.info] terminating on signal 15
Aug 26 17:11:52 centos6 postfix/postfix-script[32552]: [ID - mail.info] starting the Postfix mail system
Aug 26 17:11:52 centos6 postfix/master[32553]: [ID - mail.info] daemon started -- version 2.6.6, configuration /etc/postfix

「%MSGID%」に具体的な値が出力されず、「-」になってしまうというのは、Linux側の仕様なのかどうなのか???

まぁ、とりあえず、おおむね実現できたのでよしとした。

Win7 32bitをWin10 64bitにしたメモ


中古でWindows 7 32bitのパソコンを入手した。

まぁ、状態がよくわからんし、メモリを4GB以上にしたいから、64bitに入れ替えたいけど、Win7 64bitメディアもってないしなー、ということで、Windows10 64bitにしてみることにした。
なお、Win7 32bit上のデータは全て捨てた。

手順
1. Windows 7 32bitを起動
2. Windows 7のライセンス認証が通ってることを確認
3. 「Windows 10 のダウンロード」で32bitバージョンのツールをダウンロード
4. まずは「他のPC用にインストールメディアを作る」を選んで「アーキテクチャ 64ビット」用のメディアを作成
5. もう1回ツールを起動し「このPCを今すぐアップデートする」を実施
6. 2時間弱待つ
7. Windows10 32bitが起動してくる
8. Windows10のライセンス認証が通っていることを確認
9. シャットダウン
10. 4で作成したメディアで起動
11. Windows10 64のインストールを行う
12. 途中2回あるライセンス入力は「スキップ」を選択 ← <超重要>
13. 1時間強待つ
14. Windows10 64bitが起動してくる
15. Windows10のライセンス認証が通っていることを確認

PowerShellを使ってVMwareのテンプレートからデプロイで「既存のカスタマイズ仕様を使用してカスタマイズする」を行う方法


VMware vSphere環境にて、一度、GUI操作でテンプレートのデプロイを行い、その結果をカスタマイズ仕様として保存している、という状態で、VMware Power CLIを使用して、GUIの「既存のカスタマイズ仕様を使用してカスタマイズする」相当の操作を行う場合、どのようにするかを説明する。

手順のポイント

・カスタマイズ仕様は「OSCustomizationSpec」と「OSCustomizationNicMapping」の2つから成り立っている

・既存のカスタマイズ仕様をコピーした一時的なカスタマイズ仕様を作成し、それを編集して使用する

・仮想マシンの電源を1度入れないとカスタマイズされない(カスタマイズ後、再起動される)

・使うcmdletは以下
  カスタマイズ仕様関連
    Get-OSCustomizationSpec, New-OSCustomizationSpec
    Get-OSCustomizationNicMapping, Set-OSCustomizationNicMapping
  テンプレートデプロイ関連
    Get-VMHost
    New-VM
  仮想マシンのハードウェア構成変更
    Get-VM, Set-VM

手順解説

その1 vCenterサーバに接続

vSphere PowerCLIによる操作を行う際、まずは「Connect-VIServer」により、操作対象のvCenterサーバに接続します。

下記はvCenter vApp(VCSA)の初期設定である「root」「vmware」で接続する場合の例です。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Connect-VIServer -Server IPアドレス -User root -Password vmware

Name                           Port  User
----                           ----  ----
IPアドレス                     443   root


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その2 既存カスタマイズ仕様をコピーしたカスタマイズ仕様を作成

既存のカスタマイズ仕様を一時的に変更してデプロイする、ということができないため、コピーしたカスタマイズ仕様を変更する、という手順を取る。

ただ、コピーの際に「-Type NonPersistent」というオプションを指定すると、このセッション中のみ使用できる一時的なカスタマイズ仕様として作成することができるため、デプロイ後の削除まで考える必要はない。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationSpec cent6-dep | New-OSCustomizationSpec -Name cent6-temp -Type NonPersistent

Name                                         Description Type          OSType
----                                         ----------- ----          ------
cent6-temp                                               NonPersistent Linux


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その3 IPアドレスなど設定

IPアドレスやデフォルトゲートウェイなどネットワークに関する設定は「Get-OSCustomizationNicMapping」にて行う。

NICを増やす場合もここで行う。(ホスト名についてはここでは無い)

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationNicMapping -Spec cent6-temp | Set-OSCustomizationNicMapping -IpMode UseStaticIP -IpAddress 172.17.44.55 -SubnetMask 255.255.0.0 -DefaultGateway 172.17.44.39

Position IPMode           IPAddress       DefaultGateway
-------- ------           ---------       --------------
       1 UseStaticIP      172.17.44.55    172.17.44.39


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その4 仮想マシンホスト名の命名規則指定

仮想マシンにつけるホスト名をどのようなルールで行うかというのを指定する。

「-NamingScheme vm」は、仮想マシンの登録名とホスト名を同じとする、というものになる。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Get-OSCustomizationSpec cent6-temp | Set-OSCustomizationSpec -NamingScheme vm

Name                                         Description Type          OSType
----                                         ----------- ----          ------
cent6-temp                                               NonPersistent Linux


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その5 仮想マシンのデプロイ

今回は「nimblestorage」という名前のDataStoreを指定して、仮想マシンのデプロイを実施するという形で実行している。

先の項目で、仮想マシンの登録名とホスト名を同じとしているので「-Name cent6-ip55」で指定した「cent6-ip55」がホスト名となる。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-VM -Name cent6-ip55  -VMHost vmserver21.vmlab.local -Template cent6-deploy -OSCustomizationSpec cent6-temp -Datastore nimblestorage

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 1        2.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

なお、デプロイ中に強制終了を行うと、それ以後、動作がおかしくなることがあるようだ。

今回遭遇した事例としては、下記の様なエラーがでるが、デプロイ自体は実施されていた。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-VM -Name cent6-ip55 -VMHost vmserver21.vmlab.local -Template cent6-deploy -OSCustomizationSpec cent6-temp -Datastore nimblestorage
New-VM : 2015/07/16 18:03:02    New-VM        オブジェクトの現在の状態に問題が
あるため、操作は有効ではありません。
発生場所 行:1 文字:1
+ New-VM -Name cent6-ip55 -VMHost vmserver21.vmlab.local -Template cent6-depl
oy  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [New-VM], VimException
    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomatio
   n.ViCore.Cmdlets.Commands.NewVM

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その6 CPU/メモリの変更

作成した仮想マシンのCPUとメモリの割り当てを「Set-VM」で変更します。

なお、このSet-VMには「-Name」というオプションがありますが、仮想マシンを指定する際は「-VM 仮想マシン名」という風に指定します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Set-VM -VM cent6-ip55 -NumCpu 2 -MemoryMB 4

Confirmation
Proceed to configure the following parameters of the virtual machine with name
'cent6-ip55'?
New MemoryMB: 4MB
New NumCpu: 2
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)
[?] ヘルプ(既定値は "Y"): y

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 2        0.004


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

上記の出力結果をよく見てみるとわかるのですが、実はメモリ容量はMB単位での指定となっています。このため、現状はなんと4MBしか割り当てられていません。これではMS-DOSぐらいしか起動できません。

「4G」と指定したいところですが、サポートされていないため、「4096」という形で指定します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Set-VM -VM cent6-ip55 -NumCpu 2 -MemoryMB 4096

Confirmation
Proceed to configure the following parameters of the virtual machine with name
'cent6-ip55'?
New MemoryMB: 4096MB
New NumCpu: 2
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)
[?] ヘルプ(既定値は "Y"): y

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOff 2        4.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

その7 仮想マシンの電源ON

デプロイ時の初期設定は仮想マシンの初回起動時に行われるため、まずはPowerShellから電源オンを行うため「Start-VM」を実行します。

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> Start-VM -VM cent6-ip55

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
cent6-ip55           PoweredOn  2        4.000


PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI>

電源投入後、初回起動時にホスト名/IPアドレスの設定スクリプトが実行されます。また、完了後、自動的に再起動も行われます。

その8 デプロイ完了

再起動が終わったらデプロイが完了です。

Orange pi2/Allwinner H3関連のメモ



SoCとしてAllwinner H3を採用しているOrange pi2/Orange pi plusについての開発メモ。

・Allwinner用Linux kernelの総本山
 →Linux-sunxi
・総本山にあるOrange pi関連の資料
  Xunlong Orange Pi 2
  Xunlong Orange Pi Plus
・ビルドに必要らしい.fexのファイル
  https://github.com/vonfritz/sunxi-boards/tree/H3/sys_config/H3
・総本山にあるH3向けビルドガイド
 →H3 Manual build howto
・Allwinner H3のアーキテクチャ名は「sun8iw7p1」らしい

・Orange pi向けだけどBanana Linuxをビルドした話
  [TUTO] How to compile Kernel & Headers (from banana pi github)
  Orange piはAllwinner A20であることに注意

・Banana pi向けDebianの作り方
  https://github.com/igorpecovnik/BananaPI-Debian
  Banana piはAllwinner A20であることに注意

・Banana piの開発元Lemakerのlinux-sunxi
  https://github.com/LeMaker/linux-sunxi

・Orange pi以外のAllwinner H3搭載機 HYH-TBH3
  linux-sunxiでの情報:HYH-TBH3
  STB風のもの
  Aliexpressの販売ページ: /
・Orange pi以外のAllwinner H3搭載機 Tronsmart Draco H3
  メーカページ:Tronsmart Draco H3
  メーカのサポートページ:Category Archives: Tronsmart Draco H3
   SDKやAndroid firmwareがある
   720p用kernelと1080p用kernelがあるのが興味深い
  Linux-sunxiにはまだ情報はない(2015/06/24)