[ovirt-users] how update the network name of a vmnic with API SDK python ?

Nicolas Vaye nicolas.vaye at province-sud.nc
Wed Mar 21 20:50:57 UTC 2018


Thank you Dominik, it works.

-------- Message initial --------

Date: Wed, 21 Mar 2018 08:19:38 +0100
Objet: Re: [ovirt-users] how update the network name of a vmnic with API SDK python ?
Cc: users at ovirt.org <users at ovirt.org<mailto:%22users at ovirt.org%22%20%3cusers at ovirt.org%3e>>
À: Nicolas Vaye <nicolas.vaye at province-sud.nc<mailto:Nicolas%20Vaye%20%3cnicolas.vaye at province-sud.nc%3e>>
De: Dominik Holler <dholler at redhat.com<mailto:Dominik%20Holler%20%3cdholler at redhat.com%3e>>

On Wed, 21 Mar 2018 05:30:25 +0000
Nicolas Vaye <nicolas.vaye at province-sud.nc<mailto:nicolas.vaye at province-sud.nc>> wrote:



Hi,

i want to change the network name of the existing nic for a VM with
python SDK API ? Can i have some help please ?

the VM name is testnico
the nic name is nic1
the new network name is vlan_NEW

and here is the source file written by me (which doesn't work) :


#!/usr/bin/env python
# -*- coding: utf-8 -*-


import logging
import time

import ovirtsdk4 as sdk
import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='example.log')

# This example will connect to the server and start a virtual machine
# with cloud-init, in order to automatically configure the network and
# the password of the `root` user.

# Create the connection to the server:
connection = sdk.Connection(
    url='https://ocenter.province-sud.prod/ovirt-engine/api',
    username='admin at internal<mailto:username='admin at internal>',
    password='xxxx',
    ca_file='CA_ocenter.pem',
    debug=True,
    log=logging.getLogger(),
)

# Find the virtual machine:
vms_service = connection.system_service().vms_service()
vm = vms_service.list(search = 'name=testnico')[0]

# Find the service that manages the virtual machine:
vm_service = vms_service.vm_service(vm.id)




# In order to specify the network that the new interface will be
# connected to we need to specify the identifier of the virtual
network # interface profile, so we need to find it:
profiles_service = connection.system_service().vnic_profiles_service()
profile_id = None
for profile in profiles_service.list():
    print "profile "+profile.name+","+profile.id
    if profile.name == 'vlan_NEW':
        profile_id = profile.id
        break

# Locate the service that manages the network interface cards of the
# virtual machine:
nics_service = vm_service.nics_service()

#print nics_service

# Find the nic1 of the VM
for nic in nics_service.list():
    print "nic "+nic.name+","+nic.id+','+nic.vnic_profile.id
    if nic.name == 'nic1':
        nic_service = nics_service.nic_service(nic.id)
        break


print "nic_service nic1 ==>"+str(nic_service)
#pprint(vars(nic_service.network_filter_parameters_service().parameter_service()))


#nic_service.vnic_profile.id=profile_id
#nic_service.update()

nic_service.update(
    vnic_profile=types.VnicProfile(
        id=profile_id,
    )
)




nic_service.update(
    types.Nic(
        vnic_profile=types.VnicProfile(
            id=profile_id,
        )
    )
)





# Close the connection to the server:
connection.close()


The result is :

Traceback (most recent call last):
  File "start_vm_with_cloud_init.py", line 85, in <module>
    id=profile_id,
TypeError: update() got an unexpected keyword argument 'vnic_profile'


How can i do ?




update() expects a parameter of type types.Nic, which has the parameter
vnic_profile.



Thanks.

Nicolas VAYE
_______________________________________________
Users mailing list
Users at ovirt.org<mailto:Users at ovirt.org>
http://lists.ovirt.org/mailman/listinfo/users






More information about the Users mailing list