Bug 1614111 - Pysdk: can we search vnic profile by its name AND its datacenter
Summary: Pysdk: can we search vnic profile by its name AND its datacenter
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: ovirt-engine-sdk-python
Classification: oVirt
Component: General
Version: 4.2.4
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ovirt-4.2.7
: ---
Assignee: Ondra Machacek
QA Contact: meital avital
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2018-08-09 02:36 UTC by 曾浩
Modified: 2018-09-03 07:38 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2018-08-30 07:28:51 UTC
oVirt Team: Infra
Embargoed:
rule-engine: ovirt-4.2+


Attachments (Terms of Use)
pic (15.18 MB, application/zip)
2018-08-10 08:02 UTC, 曾浩
no flags Details


Links
System ID Private Priority Status Summary Last Updated
oVirt gerrit 94030 0 master MERGED Improve example of add vm nic 2018-09-03 07:38:45 UTC
oVirt gerrit 94108 0 sdk_4.2 MERGED Improve example of add vm nic 2018-09-03 08:30:40 UTC

Description 曾浩 2018-08-09 02:36:38 UTC
Description of problem:
ovirt4.x cluster, sharestorage and localstorage ,but this two cluster vnic is the same,use pysdk add nic is error。 

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.debug add_vm_nic.py
2.profiles_service = connection.system_service().vnic_profiles_service()
profile_id = None
for profile in profiles_service.list():
    if profile.name == 'mynetwork':
        profile_id = profile.id
cluster_network 、comment、desc and more this value is none, filter cluster vNIC is error。
3. add NIC failed

Actual results:


Expected results:


Additional info:

Comment 1 Michal Skrivanek 2018-08-09 06:28:08 UTC
I don't quite understand the description, but moving to network if it rings any bell

Comment 2 Dan Kenigsberg 2018-08-09 20:11:23 UTC
曾浩, please provide a complete script that reproduces your problem, specify your ovirt-engine.rpm version, and include engine.log. Then I may understand what is the problem that you see. 谢谢.

Comment 3 曾浩 2018-08-10 08:00:35 UTC
(In reply to Dan Kenigsberg from comment #2)
> 曾浩, please provide a complete script that reproduces your problem, specify
> your ovirt-engine.rpm version, and include engine.log. Then I may understand
> what is the problem that you see. 谢谢.
chinese is great

Comment 4 曾浩 2018-08-10 08:02:16 UTC
Created attachment 1474907 [details]
pic

comment description cluster data_center is None

name is vNICname。



Aug 07 15:18:27 Installed: python-ovirt-engine-sdk4-4.2.7-2.el7.x86_64
Aug 07 15:18:27 Installed: ovirt-engine-extensions-api-impl-4.2.5.2-1.el7.noarch
Aug 07 15:18:27 Installed: ovirt-engine-extension-aaa-jdbc-1.1.7-1.el7.centos.noarch
Aug 07 15:18:28 Installed: ovirt-engine-sdk-python-3.6.9.1-1.el7.noarch
Aug 07 15:19:00 Installed: ovirt-engine-wildfly-13.0.0-1.el7.x86_64
Aug 07 15:19:00 Installed: ovirt-engine-wildfly-overlay-13.0.0-1.el7.noarch
Aug 07 15:19:11 Installed: ovirt-engine-cli-3.6.9.2-1.el7.centos.noarch
Aug 07 15:19:19 Installed: ovirt-engine-lib-4.2.5.2-1.el7.noarch
Aug 07 15:19:20 Installed: ovirt-engine-setup-base-4.2.5.2-1.el7.noarch
Aug 07 15:19:59 Installed: ovirt-engine-metrics-1.1.6.1-1.el7.noarch
Aug 07 15:20:02 Installed: ovirt-engine-setup-plugin-ovirt-engine-common-4.2.5.2-1.el7.noarch
Aug 07 15:20:24 Installed: ovirt-engine-dwh-setup-4.2.4.3-1.el7.noarch
Aug 07 15:20:25 Installed: ovirt-engine-dwh-4.2.4.3-1.el7.noarch
Aug 07 15:20:25 Installed: ovirt-engine-tools-backup-4.2.5.2-1.el7.noarch
Aug 07 15:20:25 Installed: ovirt-engine-setup-plugin-websocket-proxy-4.2.5.2-1.el7.noarch
Aug 07 15:20:25 Installed: ovirt-engine-websocket-proxy-4.2.5.2-1.el7.noarch
Aug 07 15:21:26 Installed: ovirt-engine-vmconsole-proxy-helper-4.2.5.2-1.el7.noarch
Aug 07 15:21:26 Installed: ovirt-engine-setup-plugin-vmconsole-proxy-helper-4.2.5.2-1.el7.noarch
Aug 07 15:21:27 Installed: ovirt-engine-dashboard-1.2.4-1.el7.noarch
Aug 07 15:21:48 Installed: ovirt-engine-webadmin-portal-4.2.5.2-1.el7.noarch
Aug 07 15:21:49 Installed: ovirt-engine-dbscripts-4.2.5.2-1.el7.noarch
Aug 07 15:21:50 Installed: ovirt-engine-restapi-4.2.5.2-1.el7.noarch
Aug 07 15:21:50 Installed: ovirt-engine-api-explorer-0.0.2-1.el7.centos.noarch
Aug 07 15:21:51 Installed: ovirt-engine-tools-4.2.5.2-1.el7.noarch
Aug 07 15:21:53 Installed: ovirt-engine-backend-4.2.5.2-1.el7.noarch
Aug 07 15:21:54 Installed: ovirt-engine-4.2.5.2-1.el7.noarch
Aug 07 15:21:54 Installed: ovirt-engine-setup-plugin-ovirt-engine-4.2.5.2-1.el7.noarch
Aug 07 15:21:54 Installed: ovirt-engine-setup-4.2.5.2-1.el7.noarch

Comment 5 曾浩 2018-08-10 08:06:12 UTC
query cluster_network to filter cluser`s vNIC name,i cant found this items.


   def addVMNIC(self,vmname,network,nicname):

        vms_service = self.connection.system_service().vms_service()

        vm = vms_service.list(search='name=%s'%vmname)[0]

        profiles_service = self.connection.system_service().vnic_profiles_service()

        profile_id = None  # network的网卡编号UUID
        network_list = profiles_service.list()
        for profile in network_list:
            if profile.name == network:  # 判断网卡名是否是network传来的名称
                profile_id = profile.id  # 获取network对应网卡名的UUID
                try:
                    nics_service = vms_service.vm_service(vm.id).nics_service()
                    nics_service.add(
                        types.Nic(

                            name=nicname,  # 虚拟机新增网卡

                            description='My network interface',  # 描述,这里默认描述

                            vnic_profile=types.VnicProfile(

                            id=profile_id,  # 选择添加网卡关联的nic,这个与ovirt的网络关联,网络关联的是vlanid
                         ),
                        ),
                    )
                    break  # 停止查找
                except:
                    pass

Comment 6 Yaniv Lavi 2018-08-21 08:22:57 UTC
Can you please review the example?
https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/add_vm_nic.py 

I think if you follow this you should be good.

Comment 7 Dan Kenigsberg 2018-08-21 09:29:03 UTC
btw, one must never use

                except:
                    pass

in python, as it silently hides all sort of errors. You should always ignore only a limited set of exception.

Comment 8 曾浩 2018-08-21 09:41:09 UTC
(In reply to Yaniv Lavi from comment #6)
> Can you please review the example?
> https://github.com/oVirt/ovirt-engine-sdk/blob/master/sdk/examples/
> add_vm_nic.py 
> 
> I think if you follow this you should be good.

one datacenter use to example with github is success, but i have three datacenter and the vnic is the same, github use vnic name to filter,but i have three datacenter and the vnic is same, 
Exapmle:
datacenter: A B C
cluster : a b c 

cluster a with vinc: vnic1 vnic2 vnic3
cluster b with vinc: vnic1 vnic2 vnic3
cluster c with vinc: vnic1 vnic2 vnic3

now i want to add vinc1  with vm in cluster b.

but i use to examplie in github,this filter use vnic name ,when find vnic1 name in profiles_service.list() and the cluster is the clustera, and add vinc1 is error.

Comment 9 曾浩 2018-08-21 09:43:21 UTC
(In reply to Dan Kenigsberg from comment #7)
> btw, one must never use
> 
>                 except:
>                     pass
> 
> in python, as it silently hides all sort of errors. You should always ignore
> only a limited set of exception.

THS for your adv

Comment 10 Dan Kenigsberg 2018-08-29 07:30:50 UTC
Do you know if we can search vnic profile by its name AND its datacenter?

Comment 11 Ondra Machacek 2018-08-30 07:20:15 UTC
Can you please check following patch:

 https://gerrit.ovirt.org/#/c/94030/

I've edited the example, with your needs.

Comment 12 曾浩 2018-08-30 07:28:51 UTC
(In reply to Ondra Machacek from comment #11)
> Can you please check following patch:
> 
>  https://gerrit.ovirt.org/#/c/94030/
> 
> I've edited the example, with your needs.

3Q


Note You need to log in before you can comment on or make changes to this bug.