nuagenetworks/vspk-python

NUGroup has no ID, nor NUDomain.add_child(NUPermissions) has an effect

zerxen opened this issue · 7 comments

Trying to write a vspk script to deploy full topology, including giving USE/DEPLOY permissions to Domain/Zone to certain group and either there is a different way how to achieve this, but NUGroup object has no ID attribute that is needed to construct NUPermissions, nor does NUDomain.add_child(NUPermissions) has any effect. Here is an example code snipped:

# permission = "DEPLOY"
def assign_permission_group_to_domain(self,entname,groupname,domname,permission):
    
    filter = 'name == "' + entname + '"';
    enterprise = self.nc.user.enterprises.get_first(filter)
    
    filter = 'name == "' + groupname + '"';
    group = enterprise.groups.get_first(filter)                           
        
    filter = 'name == "' + domname + '"';
    domain = enterprise.domains.get_first(filter)
               
    if enterprise is None:
        print("No enterprise found using the filter provided")
        return 1 
    if group is None:
        print("No group found using the filter provided")
        return 1
    if domain is None:
        print("No domain found using the filter provided")
        return 1
    
    # There is no group.id ?! how to get permitted entinty ID ? Here is took it from REST API to generate a test       
    permission = vsdk.NUPermission(permitted_action="DEPLOY",permitted_entity_id="8a6f0e20-a4db-4878-ad84-9cc61756cd5e")
    domain.add_child(permission)

Also tried assign version with:

    permission = vsdk.NUPermission(permitted_action="DEPLOY",permitted_entity_id="8a6f0e20-a4db-4878-ad84-9cc61756cd5e")
    permissions = []
    permissions.append(permission)
    domain.assign(permissions,vsdk.NUPermission)

@zerxen

This all seems to work perfectly for me... what VSPK are you using, with what Nuage deployment version?

Using iPython:

In [1]: from vspk import v4_0 as vsdk

In [2]: nc = vsdk.NUVSDSession(username='csproot', password='csproot', enterprise='csp', api_url="https://10.189.1.254:8443")

In [3]: nc.start()
Out[3]: <vspk.v4_0.nuvsdsession.NUVSDSession at 0x43d7590>

In [4]: ent = nc.user.enterprises.get_first()

In [5]: dom = ent.domains.get_first()

In [6]: group = ent.groups.get_first(filter='name == "Domain1_group"')

In [7]: group.id
Out[7]: u'5409daf7-f0ac-497c-8aec-6feb7e5b8dd3'

In [8]: permission = vsdk.NUPermission()

In [9]: permission.permitted_entity_id = group.id

In [10]: permission.permitted_action = 'DEPLOY'

In [11]: dom.create_child(permission)
Out[11]:
(<vspk.v4_0.nupermission.NUPermission at 0x44ba9d0>,
 <bambou.nurest_connection.NURESTConnection at 0x44ad910>)

In [12]: permission.id
Out[12]: u'f07b5e23-fbd8-44d1-8a8d-f307a788d771'

Interesting ... running Nuage 4.0R6.1 and vspk is the one from pip repos (below), should I upgrade for github version? :

Z:\helion\SDN_devel\nextgen_tester_beta_v02>pip2 show vspk
Name: vspk
Version: 4.0.7
Summary: SDK for the VSD API
Home-page: http://nuagenetworks.net/
Author: nuage networks
Author-email: opensource@nuagenetworks.net
License: BSD-3
Location: c:\python27\lib\site-packages
Requires: bambou, tabulate, colorama

Ok, let me go double-check what my filtered seach is actually returning as object types, because following your example in shell gives me group.id while my code in the first post actually doesn't.

Z:\helion\SDN_devel\nextgen_tester_beta_v02>python2
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

from vspk import v4_0 as vsdk
nc = vsdk.NUVSDSession(username='csproot', password='csproot', enterprise='csp', api_url="https://15.163.248.11:3389")
nc.start()
<vspk.v4_0.nuvsdsession.NUVSDSession object at 0x0000000002683358>
ent = nc.user.enterprises.get_first()
dom = ent.domains.get_first()
group = ent.groups.get_first(filter='name == "Everybody"')
group.id
u'cc81010e-7493-4d9e-bdc7-99eee726c21f'

Ok, case closed, sometimes I love&hate python's flexibility on allowing me to call class methods that do not exist. This whole problem was me trying to invoke:
domain.add_child(permission)
instead of
domain.create_child(permission)

and python not complaining at all .... and it also slipped over my brains sanity check.

Thanks for feedback and sorry for bothering.

No worries, glad you figured it out (i should have noticed the add_child, but got first stuck on the group has no id thing :))