Closed EtienneMILON closed 5 years ago
Hi Etienne,
I'll try to help you, but maybe David will have a better way to do.
You can access to engine geolocation using "data.data":
In [13]: from smc.core.engines import Engine
In [14]: engine = Engine('myfw')
In [15]: engine.data.data['geolocation_ref']
Out[15]: 'http://smc:8082/6.5/elements/geolocation/5'
You can get a Geolocation object:
In [18]: from smc.elements.other import Geolocation
In [19]: Geolocation.from_href(engine.data.data['geolocation_ref'])
Out[19]: Geolocation(name=Lyon)
You need to use last develop branch version (0.7.0-b12
)
Hope that help,
Best regards,
Thanks Sebastien,
You are absolutely correct. All elements will store metadata (name, href, type) which indicates where in the SMC API the element resides as well as a lazy loaded dict cache, like you mentioned is stored in the element's data
attribute.
The geolocation_ref was not available until 6.5.x so it may fail if you are on earlier versions. I just posted a helper method on the engine itself and pushed an update.
You can access this way:
>>> from smc import session
>>> session.login()
>>> from smc.core.engine import Engine
>>> engine = Engine('azure')
>>> print(engine.geolocation)
None
>>> from smc.elements.other import Geolocation
>>> geo = Geolocation.create(name='MyGeo', latitude='44.97997', longitude='-93.26384')
>>> geo
Geolocation(name=MyGeo)
>>> engine.geolocation = geo
>>> engine.update()
'http://172.18.1.26:8082/6.5/elements/single_fw/610'
>>> engine.geolocation
Geolocation(name=MyGeo)
>>>
Otherwise you can always use the low level data dict to update an element like sebbbastien mentions.
Hi, Thank you both for answers, it helps. Best Regards,
Hello David,
How can I retrieve the geolocation from engine with smc-python? I found nothing in doc.
Etienne