Hi Juan,
Thanks! It works.
One more question, do you know how to do ³save network configuration² in
the api? I did the following
Params.Action(force=1, check_connectivity=1, host_nics=host_nics)
but the gui says the network configuration is not saved. I can¹t find any
relevant params in the Action.
Thanks,
Huan
On 8/13/16, 5:09 AM, "Juan Hernández" <jhernand(a)redhat.com> wrote:
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.