[Users] Python script retrieving MACs

Rami Vaknin rvaknin at redhat.com
Thu Dec 6 10:30:39 UTC 2012


On 12/06/2012 10:08 AM, Michael Pasternak wrote:
> On 12/06/2012 02:22 AM, Eli Mesika wrote:
>>
>> ----- Original Message -----
>>> From: "Vincent Van der Kussen"<vincent at vanderkussen.org>
>>> To: users at ovirt.org
>>> Sent: Wednesday, December 5, 2012 10:39:02 AM
>>> Subject: [Users] Python script retrieving MACs
>>>
>>> Hi,
>>>
>>> Im currently making a script using the Python SDK to retrieve a list
>>> of VM names + their MAC address.
>>> I currently came up with this
>>>
>>>   17 vm = api.vms.list()
>>>   18
>>>   19
>>>   20 for item in vm:
>>>   21         hostname = item.get_name()
>>>   22         nic = api.vms.get(name=hostname).nics.list()
BTW, you already have list of vm objects so you can use item.nics.list() 
instead of asking for the object again from the backend.
>>>   23         for net in nic:
>>>   24                 nicname = net.mac.get_address()
>>>   25         print "%s" % hostname
>>>   26         print "%s" % nicname
You print here only one mac per vm although you iterate over all the 
vm's nics, I think that the prints should be indented under the for loop 
too.
>>>
>>> I've noticed that retrieving the nic list during the iteration does a
>>> logon each time which slows thing down dramatically.
>>> Is there a better way to get the NICs from a list of VMs?
>> Michael P wrote in another thread :
>>
>> ##if you using>  3.1 backend, you should be using persistent authentication in api,
>> ##this way you'll have to pass JSESSIONID and login will happen only on first request.
>>
>> Michael , please elaborate on that
> persistent authentication available since 3.1 api,
> if your backend is 3.1 or higher, sdk will use it by default,
> otherwise authentication happens peer request.
>
>>> Regards,
>>> Vincent
>>>
>>> _______________________________________________
>>> Users mailing list
>>> Users at ovirt.org
>>> http://lists.ovirt.org/mailman/listinfo/users
>>>
>


-- 

Thanks,

Rami Vaknin, QE @ Red Hat, TLV, IL.




More information about the Users mailing list