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:
---8<---
# 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:
network_ids.append(network.get_id())
# 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:
nic_ids.append(network_attachment.get_host_nic().get_id())
# Print the details of the nics:
for nic_id in nic_ids:
nic = host.nics.get(id=nic_id)
print(nic.get_name())
--->8---
--
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.