From: parmentelat Date: Fri, 16 Mar 2018 08:50:09 +0000 (+0100) Subject: code for exposing country & city for a site X-Git-Tag: sfa-3.1-22~3 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=22d647b3d0a3f2ba3463001c0630ae65bdb06255 code for exposing country & city for a site 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 --- diff --git a/sfa/planetlab/plaggregate.py b/sfa/planetlab/plaggregate.py index 8095291d..a6b76da2 100644 --- a/sfa/planetlab/plaggregate.py +++ b/sfa/planetlab/plaggregate.py @@ -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}) diff --git a/sfa/planetlab/plshell.py b/sfa/planetlab/plshell.py index 8877f410..94b66eac 100644 --- a/sfa/planetlab/plshell.py +++ b/sfa/planetlab/plshell.py @@ -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', diff --git a/sfa/rspecs/elements/location.py b/sfa/rspecs/elements/location.py index f99c5432..e42e1600 100644 --- a/sfa/rspecs/elements/location.py +++ b/sfa/rspecs/elements/location.py @@ -7,4 +7,5 @@ class Location(Element): 'country', 'longitude', 'latitude', + 'city', ]