Open agorbachev opened 7 years ago
@agorbachev The only issue i see is the get with a filter on the ID not working for shared resources, correct. This does work (you don't have to do the array, btw):
shared_resource = vsdk.NUSharedNetworkResource(id="432d1f95-72de-46c5-8a8d-1a8ce3d15d8d")
shared_resource.fetch()
When you have the ID of an object, please don't do a get with a filter, this is highly inefficient. Instead create an object of the type, configure the id with the ID you have and do a fetch on that object. That will update the object with all the information from the VSD DB.
@pdellaert Yes, you are correct, the issue is with not working get and fetch methods by id for shared networks. At certain situation (for example, when searching parent obj) there is no way to get object type name. You have only parent_type and parent_id. in such situation I use
parrent_obj = nuage_user.fetcher_for_rest_name(child.parent_type).get_first(child.parent_id)
btw child.parent_obj
returns None
object
I second it, as this bothers me as well. In many situations when you want to streamline the code and apply recursion it is needed to know the parent in camelCase
to fetch and object by its ID.
Why do we do this? If we can't fetch an object by its ID without specifying the type of the object (performance optimization?) then having parent object camelCase
name available to its child suggests itself.
Otherwise it leaves no options but using fetchers+filters
For example the following code makes sense:
from vspk import v4_0 as vspk
# child_obj = 'NUSubnet'
parent_camelCase = child_obj.parent_camelCase
parent_obj = getattr(vspk, parent_camelCase)
Can you give me an exact use case, cause i seem to be confused... child.parent_type gives you the camelCase class name of the parent.
parent_obj is set if you do a parent.childs.get(), not necessarily when you do child = class(id='...'); child.fetch()
@pdellaert parent_type does not give camelCase. Example:
from vspk import v4_0 as vsdk
nc = vsdk.NUVSDSession(username='csproot',
password='csproot',
enterprise='csp',
api_url="https://10.166.72.100:8443")
nc.start()
nuage_user = nc.user
subnet = nuage_user.subnets.get_first()
print subnet.parent_type
print will return
u'zone'
aha, seems i was mistaken :), sorry
Well, still not sure what the use case is, but if you really need the parent_type to go into the python camelCase class name, not sure if we have something for that :s
@pdellaert i have updated my comment, showing the code that seems reasonable to me, but for it to work we need to have
vspk.zone()
will be treated as vspk.NUZone()
having vspk.zone() be treated as vspk.NUZone() is an impossibility. That would mean we need to create two classes with the same exact code. That is just bad and against PEP8
Best case is to have a method, in the me object, that does a translation from zone to NUZone. Using that, you can use getattr()
to do: new_zone = getattr(vspk, session.rest_name_to_class_name('zone'))
or something like that
No promise, and if you want to look into this, feel free to investigate and do a PR on the vspk generator. (Which will need to be very heavily tested and reviewed of course)
get and fetch methods doesn’t work for nusharednetworkresource.NUSharedNetworkResource called as method of nume.shared_network_resources
but this approach works for nusubnet object