【vSphere | Python】vSphere Automation SDK for Python Ⅳ—— Topology APIs (Linked Mode)增强型链接模式

目录

  • 11. Topology APIs
    • 11.1 List nodes
    • 11.2 Get nodes
    • 11.3 List Replication Status
  • 参考资料

11. Topology APIs

vCenter拓扑包提供了检索拓扑中所有vCenter和Platform Services Controller节点和复制状态的服务。

11.1 List nodes

关键方法topology.Nodes.list()

方法说明:返回所有vCenter和Platform Services Controller节点的信息。

方法返回值

  • node:vCenter或Platform Services Controller节点的标识符。标识符可以是节点的 IP 地址或 DNS 可解析名称。

  • type:Nodes.ApplianceType 枚举类型定义了 vCenter 和Platform Services Controller节点的有效设备类型的值。

    • VCSA_EMBEDDED : 具有嵌入式Platform Services Controller的 VCSA。
    • VCSA_EXTERNAL : 带有外部Platform Services Controller的 VCSA。
    • PSC_EXTERNAL : 一个外部Platform Services Controller。

    可能的值是: VCSA_EMBEDDED , VCSA_EXTERNAL , PSC_EXTERNAL

  • client_affinity:亲和Platform Services Controller节点的标识符。标识符可以是亲和节点的 IP 地址或 DNS 可解析名称。这个字段是可选的,只有当Nodes.Summary.type的值为VCSA_EXTERNAL时,它才有意义。

  • replication_partners:复制伙伴的节点标识符的列表。标识符可以是伙伴节点的IP地址或DNS可解析名称。这个字段是可选的,只有当Nodes.Summary.type的值是VCSA_EMBEDDEDPSC_EXTERNAL时,它才有意义。

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client

start_time = time.time()
try:
    list_topo = vsphere_client.vcenter.topology.Nodes.list()
    for i in list_topo:
        print(
            "Node:".ljust(37), i.node,
            "\nType:".ljust(39), i.type,
            "\nReplication Partners:".ljust(30), *i.replication_partners,
            "\nClient Affinity:".ljust(35), i.client_affinity,
            "\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:".ljust(33), run_time)

脚本效果:

星型拓扑:vc7-1为主节点
【vSphere | Python】vSphere Automation SDK for Python Ⅳ—— Topology APIs (Linked Mode)增强型链接模式_第1张图片

环形拓扑:

【vSphere | Python】vSphere Automation SDK for Python Ⅳ—— Topology APIs (Linked Mode)增强型链接模式_第2张图片

11.2 Get nodes

关键方法topology.Nodes.get("node_name")

方法说明:检索vCenter或Platform Services Controller节点的给定标识符的详细信息。

方法返回值

  • domain:vCenter或Platform Services Controller节点的标识符。标识符可以是节点的 IP 地址或 DNS 可解析名称。

  • type:Nodes.ApplianceType 枚举类型定义了 vCenter 和Platform Services Controller节点的有效设备类型的值。

    • VCSA_EMBEDDED : 具有嵌入式Platform Services Controller的 VCSA。
    • VCSA_EXTERNAL : 带有外部Platform Services Controller的 VCSA。
    • PSC_EXTERNAL : 一个外部Platform Services Controller。

    可能的值是: VCSA_EMBEDDED , VCSA_EXTERNAL , PSC_EXTERNAL

  • client_affinity:亲和Platform Services Controller节点的标识符。标识符可以是亲和节点的 IP 地址或 DNS 可解析名称。这个字段是可选的,只有当Nodes.Summary.type的值为VCSA_EXTERNAL时,它才有意义。

  • replication_partners:复制伙伴的节点标识符的列表。标识符可以是伙伴节点的IP地址或DNS可解析名称。这个字段是可选的,只有当Nodes.Summary.type的值是VCSA_EMBEDDEDPSC_EXTERNAL时,它才有意义。

import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client

start_time = time.time()
try:
    get_topo = vsphere_client.vcenter.topology.Nodes.get("vc7-1.yz.local")
    print(
        "Domain:".ljust(35), get_topo.domain,
        "\nType:".ljust(38), get_topo.type,
        "\nReplication Partners:".ljust(30), *get_topo.replication_partners,
        "\nClient Affinity:".ljust(34), get_topo.client_affinity,
    )

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(33), run_time)

脚本效果:

【vSphere | Python】vSphere Automation SDK for Python Ⅳ—— Topology APIs (Linked Mode)增强型链接模式_第3张图片

11.3 List Replication Status

关键方法topology.ReplicationStatus.list()

方法说明:返回VCSA_EMBEDDED/PSC_EXTERNAL类型的vCenter和 Platform Services Controller 节点的复制信息。

返回值说明

  • node:vCenter 或 Platform Services Controller 节点的标识符。标识符可以是节点的 IP 地址或 DNS 可解析名称。字符串。
  • partner_available:指示合作伙伴上的 VMware 目录服务是否可达。布尔值。
  • replication_partner:vCenter或 Platform Services Controller 复制伙伴的标识符。标识符可以是复制伙伴的 IP 地址或 DNS 可解析的名称。字符串。
  • status_available:表示是否可以检索到节点与复制伙伴有关的复制状态。布尔值。
  • Change_lag:复制变化的节点在复制伙伴后面的数量。如果伙伴主机或复制状态不可用,这个字段将不设置。整数。
  • replicating:指示节点是否正在处理来自复制伙伴的复制变化。如果合作伙伴主机或复制状态不可用,这个字段将不设置,即partner_available值为false。布尔值。
import time
from vSphere_Automation_SDK.Connect_to_vCenter_Server import vsphere_client

start_time = time.time()
try:
    list_topo = vsphere_client.vcenter.topology.ReplicationStatus.list()
    for i in list_topo:
        print(
            "Node:".ljust(36), i.node,
            "\nReplication Partner:".ljust(30), i.replication_partner,
            "\nPartner Available:".ljust(31), i.partner_available,
            "\nStatus Available:".ljust(32), i.status_available,
            "\nReplicating:".ljust(35), i.replicating,
            "\nChange Lag:".ljust(33), i.change_lag,
            "\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:".ljust(43), run_time)

脚本效果:

【vSphere | Python】vSphere Automation SDK for Python Ⅳ—— Topology APIs (Linked Mode)增强型链接模式_第4张图片

参考资料

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

关于本专栏其它博文,请关注专栏,会有更多关于vSphere Python自动化的内容:vSphere python自动化

你可能感兴趣的:(vSphere,python自动化,python,开发语言,服务器,自动化,vSphere)