X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fimporter%2Fplimporter.py;h=1e04e54ca13f59c93469073bfeede4a7146205aa;hb=1db1a879ffde8991aa95dd80142d555551655e88;hp=f6ecc45c6fc46664485fb4a594e1bc93ba588c7a;hpb=98345c5b4ead0dd9e622e42afa2eb3084f37e8f3;p=sfa.git diff --git a/sfa/importer/plimporter.py b/sfa/importer/plimporter.py index f6ecc45c..1e04e54c 100644 --- a/sfa/importer/plimporter.py +++ b/sfa/importer/plimporter.py @@ -82,17 +82,20 @@ class PlImporter: def locate_by_type_pointer (self, type, pointer): return self.records_by_type_pointer.get ( (type, pointer), None) - # convenience : try to locate first based on type+pointer - # if so, the record was created already even if e.g. its hrn has changed meanwhile - # otherwise we try by type+hrn (is this truly useful ?) - def locate (self, type, hrn=None, pointer=-1): - if pointer!=-1: - attempt = self.locate_by_type_pointer (type, pointer) - if attempt : return attempt - if hrn is not None: - attempt = self.locate_by_type_hrn (type, hrn,) - if attempt : return attempt - return None + # a convenience/helper function to see if a record is already known + # a former, broken, attempt (in 2.1-9) had been made + # to try and use 'pointer' as a first, most significant attempt + # the idea being to preserve stuff as much as possible, and thus + # to avoid creating a new gid in the case of a simple hrn rename + # however this of course doesn't work as the gid depends on the hrn... + #def locate (self, type, hrn=None, pointer=-1): + # if pointer!=-1: + # attempt = self.locate_by_type_pointer (type, pointer) + # if attempt : return attempt + # if hrn is not None: + # attempt = self.locate_by_type_hrn (type, hrn,) + # if attempt : return attempt + # return None # this makes the run method a bit abtruse - out of the way def create_special_vini_record (self, interface_hrn): @@ -180,17 +183,12 @@ class PlImporter: # isolate special vini case in separate method self.create_special_vini_record (interface_hrn) - def check_hrn (record, hrn): - if record.hrn != hrn: - record.hrn=hrn - dbsession.commit() - # start importing for site in sites: site_hrn = _get_site_hrn(interface_hrn, site) # import if hrn is not in list of existing hrns or if the hrn exists # but its not a site record - site_record=self.locate ('authority', site_hrn, site['site_id']) + site_record=self.locate_by_type_hrn ('authority', site_hrn) if not site_record: try: urn = hrn_to_urn(site_hrn, 'authority') @@ -211,8 +209,6 @@ class PlImporter: self.logger.log_exc("PlImporter: failed to import site. Skipping child records") continue else: - # we might have renamed it - since we first use pointer to locate it - check_hrn(site_record, site_hrn) # xxx update the record ... pass site_record.stale=False @@ -229,7 +225,7 @@ class PlImporter: node_hrn = hostname_to_hrn(site_auth, site_name, node['hostname']) # xxx this sounds suspicious if len(node_hrn) > 64: node_hrn = node_hrn[:64] - node_record = self.locate ( 'node', node_hrn , node['node_id'] ) + node_record = self.locate_by_type_hrn ( 'node', node_hrn ) if not node_record: try: pkey = Keypair(create=True) @@ -247,7 +243,7 @@ class PlImporter: self.logger.log_exc("PlImporter: failed to import node") else: # xxx update the record ... - check_hrn(node_record, node_hrn) + pass node_record.stale=False site_pis=[] @@ -262,7 +258,7 @@ class PlImporter: if len(person_hrn) > 64: person_hrn = person_hrn[:64] person_urn = hrn_to_urn(person_hrn, 'user') - user_record = self.locate ( 'user', person_hrn, person['person_id']) + user_record = self.locate_by_type_hrn ( 'user', person_hrn) # return a tuple pubkey (a plc key object) and pkey (a Keypair object) def init_person_key (person, plc_keys): @@ -305,7 +301,6 @@ class PlImporter: # update the record ? # if user's primary key has changed then we need to update the # users gid by forcing an update here - check_hrn (user_record, person_hrn) sfa_keys = user_record.reg_keys def key_in_list (key,sfa_keys): for reg_key in sfa_keys: @@ -345,7 +340,7 @@ class PlImporter: except: self.logger.warning ("PlImporter: cannot locate slice_id %s - ignored"%slice_id) slice_hrn = slicename_to_hrn(interface_hrn, slice['name']) - slice_record = self.locate ('slice', slice_hrn, slice['slice_id']) + slice_record = self.locate_by_type_hrn ('slice', slice_hrn) if not slice_record: try: pkey = Keypair(create=True) @@ -363,7 +358,6 @@ class PlImporter: self.logger.log_exc("PlImporter: failed to import slice") else: # xxx update the record ... - check_hrn (slice_record, slice_hrn) self.logger.warning ("Slice update not yet implemented") pass # record current users affiliated with the slice