[ovirt-users] python sdk v3 host nic issues

Juan Hernández jhernand at redhat.com
Sat Aug 6 12:46:15 UTC 2016


On 08/05/2016 08:08 PM, Huan He (huhe) wrote:
> Hi,
> 
> I tried the host nic and bond sample code
> in http://www.ovirt.org/develop/api/pythonapi/. In gui, I am able to
> create bond and vlan network without issues.
> 
> here is my code
> 
> 
> if __name__ == '__main__':
> 
>     url = 'https://huhe-rhev-m.cisco.com/ovirt-engine/api'
> 
>     usr = 'admin at internal'
> 
>     pwd = 'nbv12345'
> 
>     ca_file = '/home/huhe/workspace/ansible/crt/ca.der'
> 
>     
> 
>     api = API(url=url, username=usr, password=pwd, ca_file=ca_file,
> debug=True)
> 
>     print api.get_product_info().name
> 
>      
> 
>     nic0 = params.HostNIC(name = 'enp6s0', network =  params.Network(),
> boot_protocol='none', ip=params.IP(address='', netmask='', gateway=''))
> 
>     nic1 = params.HostNIC(name = 'enp7s0', network =  params.Network(),
> boot_protocol='none', ip=params.IP(address='', netmask='', gateway=''))
> 
>     nic2 = params.HostNIC(name = 'enp8s0', network =  params.Network(),
> boot_protocol='none', ip=params.IP(address='', netmask='', gateway=''))
> 
>     nic3 = params.HostNIC(name = 'enp9s0', network =  params.Network(),
> boot_protocol='none', ip=params.IP(address='', netmask='', gateway=''))
> 
>     
> 
>     bond = params.Bonding(
> 
>        slaves = params.Slaves(host_nic = [ nic0, nic1, nic2, nic3 ]),
> 
>                 options = params.Options(
> 
>                             option = [
> 
>                               params.Option(name = 'miimon', value = '100'),
> 
>                               params.Option(name = 'mode', value = '1'),
> 
>                               params.Option(name = 'primary', value =
> 'enp6s0')]
> 
>                             )
> 
>                           )
> 
>     
> 
>     managementNetwork = params.HostNIC(network = params.Network(name =
> 'ovirtmgmt'),
> 
>                           name = 'bond0',
> 
>                           boot_protocol = 'static',
> 
>                               ip = params.IP(
> 
>                               address = '20.200.10.172',
> 
>                               netmask = '255.255.255.0',
> 
>                               gateway = '20.200.10.254'),
> 
>                           override_configuration = 1,
> 
>                           bonding = bond)
> 
>     
> 
>     networkName = 'my_vm_db'
> 
>     clusterNetwork = api.clusters.get('my_cluster').networks.get(name =
> networkName)
> 
>     vlanNetwork = params.HostNIC(network = params.Network(name =
> networkName), name = "bond0.%s" % clusterNetwork.vlan.id)
> 
>     
> 
>     host = api.hosts.get('host-172')
> 
>     host.nics.setupnetworks(params.Action(force = 0,
> 
>                                           check_connectivity = 1,
> 
>                                           host_nics =
> params.HostNics(host_nic = [ managementNetwork, 
> 
>                                                                         
>           vlanNetwork])))
> 
>     
> 
>     api.disconnect()
> 
> 
> 
> The following is the console output
> 
>> <action>
> 
>>     <host_nics>
> 
>>         <host_nic>
> 
>>             <name>bond0</name>
> 
>>             <network>
> 
>>                 <name>ovirtmgmt</name>
> 
>>             </network>
> 
>>             <ip netmask="255.255.255.0" gateway="20.200.10.254"
> address="20.200.10.172"/>
> 
>>             <bonding>
> 
>>                 <options>
> 
>>                     <option name="miimon" value="100"/>
> 
>>                     <option name="mode" value="1"/>
> 
>>                     <option name="primary" value="enp6s0"/>
> 
>>                 </options>
> 
>>                 <slaves>
> 
>>                     <host_nic>
> 
>>                         <name>enp6s0</name>
> 
>>                         <network/>
> 
>>                         <ip netmask="" gateway="" address=""/>
> 
>>                         <boot_protocol>none</boot_protocol>
> 
>>                     </host_nic>
> 
>>                     <host_nic>
> 
>>                         <name>enp7s0</name>
> 
>>                         <network/>
> 
>>                         <ip netmask="" gateway="" address=""/>
> 
>>                         <boot_protocol>none</boot_protocol>
> 
>>                     </host_nic>
> 
>>                     <host_nic>
> 
>>                         <name>enp8s0</name>
> 
>>                         <network/>
> 
>>                         <ip netmask="" gateway="" address=""/>
> 
>>                         <boot_protocol>none</boot_protocol>
> 
>>                     </host_nic>
> 
>>                     <host_nic>
> 
>>                         <name>enp9s0</name>
> 
>>                         <network/>
> 
>>                         <ip netmask="" gateway="" address=""/>
> 
>>                         <boot_protocol>none</boot_protocol>
> 
>>                     </host_nic>
> 
>>                 </slaves>
> 
>>             </bonding>
> 
>>             <boot_protocol>static</boot_protocol>
> 
>>             <override_configuration>1</override_configuration>
> 
>>         </host_nic>
> 
>>         <host_nic>
> 
>>             <name>bond0.101</name>
> 
>>             <network>
> 
>>                 <name>my_vm_db</name>
> 
>>             </network>
> 
>>         </host_nic>
> 
>>     </host_nics>
> 
>>     <check_connectivity>1</check_connectivity>
> 
>>     <force>0</force>
> 
>> </action>
> 
> < HTTP/1.1 404 Not Found
> 
> < Date: Fri, 05 Aug 2016 17:55:54 GMT
> 
> < Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.1e-fips
> 
> < Content-Length: 0
> 
> < 
> 
> * Connection #0 to host huhe-rhev-m.cisco.com left intact
> 
> Traceback (most recent call last):
> 
>   File "/home/huhe/workspace/ansible/src/ovirt_hostnic.py", line 57, in
> <module>
> 
>     vlanNetwork])))
> 
>   File
> "/usr/local/lib/python2.7/site-packages/ovirtsdk/infrastructure/brokers.py",
> line 16672, in setupnetworks
> 
>     headers={"Correlation-Id":correlation_id}
> 
>   File
> "/usr/local/lib/python2.7/site-packages/ovirtsdk/infrastructure/proxy.py",
> line 122, in request
> 
>     persistent_auth=self.__persistent_auth
> 
>   File
> "/usr/local/lib/python2.7/site-packages/ovirtsdk/infrastructure/connectionspool.py",
> line 79, in do_request
> 
>     persistent_auth)
> 
>   File
> "/usr/local/lib/python2.7/site-packages/ovirtsdk/infrastructure/connectionspool.py",
> line 156, in __do_request
> 
>     raise errors.RequestError(response_code, response_reason, response_body)
> 
> ovirtsdk.infrastructure.errors.RequestError: 
> 
> status: 404
> 
> reason: Not Found
> 
> detail: 
> 
> 
> Any idea what is wrong? It is ovirt v3
> 
> 
> Thanks,
> 
> Huan
> 
> 
> <http://www.ovirt.org/develop/api/pythonapi/><http://www.ovirt.org/develop/api/pythonapi/><http://www.ovirt.org/develop/api/pythonapi/>
> 

The method that you are using is deprecated, you should use the
Host.setupnetworks method, and the code should be similar to this:

---8<---
from ovirtsdk.api import API
from ovirtsdk.xml import params

api = API(
  url='https://huhe-rhev-m.cisco.com/ovirt-engine/api',
  username='admin at internal',
  password='...',
  ca_file='/home/huhe/workspace/ansible/crt/ca.der',
  debug=True,
)

host = api.hosts.get(name='host-172')

host.setupnetworks(
  params.Action(
    modified_bonds=params.HostNics(
      host_nic=[
        params.HostNIC(
          name="bond0",
          bonding=params.Bonding(
            options=params.Options(
              option=[
                params.Option(name="mode", value="1"),
                params.Option(name="miimon", value="100"),
                params.Option(name="primary", value="enp6s0"),
              ],
            ),
            slaves=params.Slaves(
              host_nic=[
                params.HostNIC(name="enp6s0"),
                params.HostNIC(name="enp7s0"),
                params.HostNIC(name="enp8s0"),
                params.HostNIC(name="enp9s0"),
              ],
            ),
          ),
        ),
      ],
    ),
    modified_network_attachments=params.NetworkAttachments(
      network_attachment=[
        params.NetworkAttachment(
          network=params.Network(name="my_vm_db"),
          host_nic=params.HostNIC(name="bond0"),
          ip_address_assignments=params.IpAddressAssignments(
            ip_address_assignment=[
              params.IpAddressAssignment(
                assignment_method="static",
                ip=params.IP(
                  address="20.200.10.172",
                  netmask="255.255.255.0",
                  gateway="20.200.10.254",
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  ),
)

api.disconnect()
--->8---

It is documented here:


https://jhernand.fedorapeople.org/ovirt-engine-api-model/model.html#services/host/methods/setupnetworks

-- 
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.



More information about the Users mailing list