【vSphere | Python】vSphere Automation SDK for Python Ⅴ—— vCenter フォルダ & データストア & クラスタ API

6.vCenter フォルダー API

フォルダー サービス (フォルダー サービス) は、vCenter Server フォルダーを操作するための操作を提供します。

6.1 リストフォルダ

キー方式:Folder.list()

メソッドの説明: vCenter で最大 1000 個の表示可能なフォルダーに関する情報を返します。

メソッドの戻り値:

  • Floder ID: フォルダー ID、フォルダーの識別子。

  • Name: vCenter Server フォルダの名前。

  • Type:タイプ。

    • DATACENTER: データセンターを含むことができるフォルダー。
    • DATASTORE: データストアを格納できるフォルダー。
    • HOST: コンピューティング リソース (ホストとクラスター) を格納できるフォルダー。
    • NETWORK: ネットワークを含むことができるフォルダー。
    • VIRTUAL_MACHINE: 仮想マシンを格納できるフォルダー。

    可能な値は次のとおりです: DATACENTER, DATASTORE, HOST, NETWORK,VIRTUAL_MACHINE

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client
start_time = time.time()
try:
    list_folder = vsphere_client.vcenter.Folder.list()
    print("Floder ID".ljust(40),"Type".ljust(50),"Name")
    for i in list_folder:
        print(i.folder.ljust(40),
               i.name.ljust(50),
               i.type,
              )
except Exception as err:
    for i in err.messages:
        id = i.id,
        default_message = i.default_message
        args = i.args
        params = i.params
        localized = i.localized
    print("\033[1;31m Encountered an error, Please see the following information \033[0m" ,
          "\n\tError Class:", id,
          "\n\tMessage:", default_message,
          "\n\tArgs:", args,
          "\n\tParams:", params,
          "\n\tLocalized:", localized,
          "\nError Data:", err.data,
          "\nError Type:", err.error_type
          )
end_time = time.time()
run_time = end_time - start_time
print("Used Time:".ljust(43), run_time)

スクリプトのレンダリング:

ここに画像の説明を挿入

7.vCenter データストア API

データストア サービスは、データストアを操作するための操作を提供します。

7.1 リストデータストア

キー方式:Datastore.list()

メソッド 説明: List Datastores vCenter で最大 2500 の可視データストアに関する情報を返します。

メソッドの戻り値:

  • datastore: データ ストアの識別子。

  • name: データストア名

  • type: 列挙タイプは、サポートされている vCenter データ ストレージのタイプを定義します。

    • VMFS: VMware ファイル システム (ESX サーバーのみ)。
    • NFS: Network File System v3 (Linux および ESX サーバーのみ)。
    • NFS41: Network File System v4.1 (Linux および ESX サーバーのみ)。
    • CIFS: 共通インターネット ファイル システム。
    • VSAN: Virtual SAN (ESX サーバーのみ)。
    • VFFS: フラッシュ読み取りキャッシュ (ESX サーバーのみ)。
    • VVOL: vSphere 仮想ボリューム (ESX サーバーのみ)。

    列挙: vmfs, nfs, nfs41, cifs, vsan,vffsvvol

  • capacity: データ ストアの容量 (バイト単位)。サーバーはこの値を定期的に更新します。

  • free_space: データストアに使用可能なスペース (バイト単位)。サーバーはこの値を定期的に更新します。

脚本:

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client,byte_to_gb
start_time = time.time()
try:
      ds = vsphere_client.vcenter.Datastore.list()
      if ds == []:
          print("---------Empty---------")
      else:
          for i in ds:
              print("Datastore ID:".ljust(30),i.datastore,
                    "\nDatastore Name:".ljust(28),i.name,
                    "\nDatastore Type:".ljust(29),i.type,
                    "\nDatastore Free Space:".ljust(25),byte_to_gb(i.free_space),  #Byte
                    "\nDatastore Capacity".ljust(26), byte_to_gb(i.capacity),         #Byte
                    "\n=======================")
except Exception as err:
    for i in err.messages:
        id = i.id,
        default_message = i.default_message
        args = i.args
        params = i.params
        localized = i.localized
    print("\033[1;31m Encountered an error, Please see the following information \033[0m" ,
          "\n\tError Class:", id,
          "\n\tMessage:", default_message,
          "\n\tArgs:", args,
          "\n\tParams:", params,
          "\n\tLocalized:", localized,
          "\nError Data:", err.data,
          "\nError Type:", err.error_type
          )
end_time = time.time()
run_time = end_time - start_time
print("Used Time:", run_time)

スクリプトのレンダリング:

ここに画像の説明を挿入

7.2 データストアの取得

キー方式:vcenter.Datastore.get('datastore-ID')

メソッドの説明: 指定されたデータ ストアに関する情報を取得します。

メソッドの戻り値:

  • accessible: データストアにアクセスできるかどうか。ブール値。

  • name: データストア名。

  • thin_provisioning_supported: データストアがファイルごとのシン準備をサポートするかどうか。シン準備を使用すると、バッキング ストアが遅延して割り当てられます。ブール値。

  • type: 列挙タイプは、サポートされている vCenter データ ストレージのタイプを定義します。

    • VMFS: VMware ファイル システム (ESX サーバーのみ)。
    • NFS: Network File System v3 (Linux および ESX サーバーのみ)。
    • NFS41: Network File System v4.1 (Linux および ESX サーバーのみ)。
    • CIFS: 共通インターネット ファイル システム。
    • VSAN: Virtual SAN (ESX サーバーのみ)。
    • VFFS: フラッシュ読み取りキャッシュ (ESX サーバーのみ)。
    • VVOL: vSphere 仮想ボリューム (ESX サーバーのみ)。

    列挙: vmfs, nfs, nfs41, cifs, vsan,vffsvvol

  • free_space: データストアに使用可能なスペース (バイト単位)。サーバーはこの値を定期的に更新します。

脚本:

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client,byte_to_gb
start_time = time.time()
try:
      get_ds = vsphere_client.vcenter.Datastore.get('datastore-68')
      print("Datastore Name:".ljust(38),get_ds.name,
      "\nDatastore Type:".ljust(40),get_ds.type,
      "\nAccessible:".ljust(44),get_ds.accessible,
      "\nDatastore Free Space:".ljust(37),byte_to_gb(get_ds.free_space) ,
      "\nMultiple Host Access:".ljust(37),get_ds.multiple_host_access,
      "\nThin Provisioning Supported:".ljust(33),get_ds.thin_provisioning_supported
            )
except Exception as err:
    for i in err.messages:
        id = i.id,
        default_message = i.default_message
        args = i.args
        params = i.params
        localized = i.localized
    print("\033[1;31m Encountered an error, Please see the following information \033[0m" ,
          "\n\tError Class:", id,
          "\n\tMessage:", default_message,
          "\n\tArgs:", args,
          "\n\tParams:", params,
          "\n\tLocalized:", localized,
          "\nError Data:", err.data,
          "\nError Type:", err.error_type
          )
end_time = time.time()
run_time = end_time - start_time
print("Used Time:".ljust(43), run_time)

スクリプトのレンダリング:

ここに画像の説明を挿入

8.vCenter クラスター API

クラスター サービス (クラスター サービス) は、vCenter Server でクラスターを管理するための操作を提供します。

8.1 リストクラスタ

キー方式:Cluster.list()

メソッド 説明: List Clusters vCenter で最大 1000 個の表示可能なクラスターに関する情報を返します。

メソッドの戻り値:

  • cluster: クラスターの識別子。
  • drs_enabled: vSphere DRS サービスがクラスタに対して有効になっているかどうかを示すフラグ。ブール値。
  • ha_enabled: vSphere HA 機能がクラスタに対して有効になっているかどうかを示すフラグ。ブール値。
  • name: クラスター名
import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client

print("Cluster ID".ljust(33),"HA Enabled".ljust(20),"DRS Enabled".ljust(17),"Cluster Name")
start_time = time.time()
try:
    list_cluster = vsphere_client.vcenter.Cluster.list()
    for i in list_cluster:
        if i.ha_enabled == True:
            i.ha_enabled = "True"
        else:
            i.ha_enabled = "False"
        if i.drs_enabled == True:
            i.drs_enabled = "True"
        else:
            i.drs_enabled = "False"
        print(i.cluster.ljust(25),
              i.ha_enabled.ljust(25),
              i.drs_enabled.ljust(25),
              i.name)

except Exception as err:
    for i in err.messages:
        id = i.id,
        default_message = i.default_message
        args = i.args
        params = i.params
        localized = i.localized

    print("\033[1;31m Encountered an error, Please see the following information \033[0m",
          "\n\tError Class:", id,
          "\n\tMessage:", default_message,
          "\n\tArgs:", args,
          "\n\tParams:", params,
          "\n\tLocalized:", localized,
          "\nError Data:", err.data,
          "\nError Type:", err.error_type
          )
end_time = time.time()
run_time = end_time - start_time
print("Used Time:".ljust(30), run_time)

スクリプトのレンダリング:

ここに画像の説明を挿入

8.2 クラスターを取得する

キー方式:Cluster.get(cluster="domain-ID")

メソッドの説明: 指定されたクラスターに対応するクラスターに関する情報を取得します。

メソッドの戻り値:

  • name: クラスター名
  • resource_pool: クラスタのルート リソース プールの識別子。

脚本:

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client

start_time = time.time()
try:
    get_cluster = vsphere_client.vcenter.Cluster.get(cluster="domain-c13239852")
    print("Name:".ljust(30),get_cluster.name,
          "\nResource Pool:".ljust(27),get_cluster.resource_pool)

except Exception as err:
    for i in err.messages:
        id = i.id,
        default_message = i.default_message
        args = i.args
        params = i.params
        localized = i.localized

    print("\033[1;31m Encountered an error, Please see the following information \033[0m",
          "\n\tError Class:", id,
          "\n\tMessage:", default_message,
          "\n\tArgs:", args,
          "\n\tParams:", params,
          "\n\tLocalized:", localized,
          "\nError Data:", err.data,
          "\nError Type:", err.error_type
          )
end_time = time.time()
run_time = end_time - start_time
print("Used Time:".ljust(30), run_time)

スクリプトのレンダリング:

ここに画像の説明を挿入

参考文献

vCenter REST API v7.0U3
vSphere-Python-Automation-Scripts/v1/

このコラムの他のブログ投稿については、次のコラムに注目してください。vSphere Python 自動化に関するコンテンツがさらに増える予定です。vSphere Python 自動化

おすすめ

転載: blog.csdn.net/NOWSHUT/article/details/130037660