On 08/13/2016 12:17 AM, Huan He (huhe) wrote:
> Assuming the logical network ovirtmgmt has been configured in host NIC
> enp6s0.
> host = api.hosts.get(‘host-123’)
> host_nic = host.nics.get(‘enp6s0’)
> How to get the logical network name ovirtmgmt?
> I basically need to find ovirtmgmt is configured in which NIC.
> Thanks,
> Huan

To do this first you need to find the identifier of the "ovirtmgmt"
network of the relevant cluster (the same network name can be used in
multiple clusters) and then iterate the network attachments to find
which network interfaces are connected to that network. Something like this:

# Find the host:
host_name = 'myhost'
host = api.hosts.get(name=host_name)

# Find the identifier of the cluster that the host belongs to:
cluster_id = host.get_cluster().get_id()

# Find the networks available in the cluster, and locate the one
# ones with the name we are looking for:
network_name = 'ovirtmgmt'
network_ids = []
networks = api.clusters.get(id=cluster_id).networks.list()
for network in networks:
    if network.get_name() == network_name:

# Find the network interface of the host that has the network attached:
nic_ids = []
network_attachments = host.networkattachments.list()
for network_attachment in network_attachments:
    if network_attachment.get_network().get_id() in network_ids:

# Print the details of the nics:
for nic_id in nic_ids:
    nic = host.nics.get(id=nic_id)

Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.
Users mailing list

Reply via email to