code for exposing country & city for a site
authorparmentelat <thierry.parmentelat@inria.fr>
Fri, 16 Mar 2018 08:50:09 +0000 (09:50 +0100)
committerparmentelat <thierry.parmentelat@inria.fr>
Fri, 16 Mar 2018 09:29:51 +0000 (10:29 +0100)
this applies only to sites that have a latitude and longitude
in this case, the 'country' and 'city' site tags are used; they are set to 'unknown' otherwise

sfa/planetlab/plaggregate.py
sfa/planetlab/plshell.py
sfa/rspecs/elements/location.py

index 8095291..a6b76da 100644 (file)
@@ -272,8 +272,21 @@ class PlAggregate:
         # add site/interface info to nodes.
         # assumes that sites, interfaces and tags have already been prepared.
         if site['longitude'] and site['latitude']:
-            location = Location({'longitude': site['longitude'], 'latitude': site[
-                                'latitude'], 'country': 'unknown'})
+            location_dict = {
+                'longitude': site['longitude'],
+                'latitude': site['latitude'],
+            }
+            for extra in ('country', 'city'):
+                try:
+                    tts = self.driver.shell.GetSiteTags({
+                        'site_id' : site['site_id'],
+                        'tagname' : extra,
+                    })
+                    location_dict[extra] = tts[0]['value']
+                except:
+                    logger.log_exc('extra = {}'.format(extra))
+                    location_dict[extra] = 'unknown'
+            location = Location(location_dict)
             rspec_node['location'] = location
         # Granularity
         granularity = Granularity({'grain': grain})
index 8877f41..94b66ea 100644 (file)
@@ -23,7 +23,7 @@ class PlShell:
                     'UnBindObjectFromPeer', 'UpdateNode', 'UpdatePerson', 'UpdateSite',
                     'UpdateSlice', 'UpdateSliceTag',
                     # also used as-is in importer
-                    'GetSites', 'GetNodes',
+                    'GetSites', 'GetNodes', 'GetSiteTags',
                     # Lease management methods
                     'GetLeases', 'GetLeaseGranularity', 'DeleteLeases', 'UpdateLeases',
                     'AddLeases',
index f99c543..e42e160 100644 (file)
@@ -7,4 +7,5 @@ class Location(Element):
         'country',
         'longitude',
         'latitude',
+        'city',
     ]