LoginSignup
0
0

More than 1 year has passed since last update.

govcの小ネタ: ポートグループの各ポートを確認する

Posted at

(こちらは、個人ブログの記事の再投稿です)

前回に引き続き、govcの小ネタです。今回はポートグループ内の各ポートを確認する方法を紹介します。

TL; DR

# 分散ポートグループのポート一覧

# アクティブなポート
$ govc dvs.portgroup.info -active -connected -pg ${portgroup} ${switch}
PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      0

# アクティブでない(でも接続はされている)ポート
$ govc dvs.portgroup.info -connected -pg ${portgroup} ${switch}
# 空いているポート
$ govc dvs.portgroup.info -pg ${portgroup} ${switch}
# アクティブなアップリンクポート
$ govc dvs.portgroup.info -active -connected -uplinkPort -pg ${portgroup} ${switch}

はじめに

govc のポートグループ取得コマンドは少し癖があるので、オプションを適切に指定する必要があります。

分散スイッチのポートグループの各ポートは govc dvs.portgroup.info -pg ${portgroup} ${switch} の形式で取得可能です。
(ポートグループを指定しなければ、分散スイッチの全ポートグループが返ってきます)

...が、指定した条件をすべて満たすものしか表示されません!

  • 指定できる条件
    • 接続しているか (true/false)
    • アクティブかどうか (true/false)
    • アップリンクポートかどうか (true/false)

デフォルトでは「接続していない」「アクティブでない」「アップリンクポートでない」ポートだけが取得されます
文章ではわかりづらいので、実際にvSphere Clientの表示と見比べながら紹介します。

実際に試してみる

前提条件

分散スイッチ DVS0 のポートグループ DC0_DVPG0 は以下のポートを持っています。

image.png

ポート0はホストのvmkernelアダプタ、ポート1はvm(パワーオフ)のNICに接続しています。

オプションなし

この状態でgovcを使ってみます。オプションなしだと、デフォルトの「接続していない」「アクティブでない」「アップリンクポートでない」ポートが取得されます。空いているポート2~7が取得できました。

$ govc dvs.portgroup.info -pg DC0_DVPG0 DVS0
PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      2

PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      3

PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      4

PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      5

PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      6

PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      7

-connected

-connected を指定すると、「接続している」「アクティブでない」「アップリンクポートでない」ポートが取得されます。パワーオフのVMに接続しているポート1だけが取得できました。

# 接続している、アクティブでない(デフォルト)、アップリンクポートでない(デフォルト)ポート
$ govc dvs.portgroup.info -connected -pg DC0_DVPG0 DVS0
PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      1

-active

-connected-active を指定すると、「接続している」「アクティブな」「アップリンクポートでない」ポートが取得されます。こちらはホストに接続しているポート0が取得できました。

# 接続している、アクティブな、アップリンクポートでない(デフォルト)ポート
$ govc dvs.portgroup.info -active -connected DVS0
PortgroupKey: dvportgroup-28
DvsUuid:      50 21 44 2c 15 ff a7 d2-28 b0 2a c5 2c 26 45 5d
VlanId:       0
PortKey:      0

(-active だけ指定すると「接続していない」「アクティブな」「アップリンクポートでない」ポートが取れますが、そんなポートは(おそらく)ありえないので意味なし)

-uplinkPort

また、-connected-active-uplinkPort をすべて指定すると、「接続している」「アクティブな」「アップリンクポート」、つまり今使っているアップリンクポートが確認できます。
ちなみに自宅ラボではVMNICを標準スイッチに取られているのでアップリンクポートはすべて未接続です

# 接続している、アクティブな、アップリンクポート
$ govc dvs.portgroup.info -uplinkPort -active -connected DVS0

ポートグループ自体の設定を確認する

ポートグループ自体の設定は、object.collect で確認できます。

$ govc object.collect DistributedVirtualPortgroup:dvportgroup-28
alarmActionsEnabled  bool                            true
availableField       []types.CustomFieldDef
config               types.DVPortgroupConfigInfo     ...
configIssue          []types.BaseEvent
configStatus         types.ManagedEntityStatus       green
customValue          []types.BaseCustomFieldValue
declaredAlarmState   []types.AlarmState
disabledMethod       []string
effectiveRole        []int32                         -1
host                 []types.ManagedObjectReference  HostSystem:host-11
key                  string                          dvportgroup-28
name                 string                          DC0_DVPG0
overallStatus        types.ManagedEntityStatus       green
parent               types.ManagedObjectReference    Folder:group-n8
permission           []types.Permission
portKeys             []string                        0,1,2,3,4,5,6,7
recentTask           []types.ManagedObjectReference
summary              types.NetworkSummary            ...
tag                  []types.Tag
triggeredAlarmState  []types.AlarmState
value                []types.BaseCustomFieldValue
vm                   []types.ManagedObjectReference  VirtualMachine:vm-15

おわりに

以上、govc dvs.portgroup.info の使い方でした。コマンド実行前にちゃんとhelpを読むのが大事ですね...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0