X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fhpc_observer%2Fsteps%2Fsync_contentprovider.py;h=c7335d645cb721f6175cd66b909219dbe14fb0c3;hb=0d718ab944fcf3a7a943e3652fa9746529510d78;hp=00117b89f5f2b464ea3028dce367da9d9fc9f4b0;hpb=32fd368d804ce306160ffbea6ceb586ca60802a1;p=plstackapi.git diff --git a/planetstack/hpc_observer/steps/sync_contentprovider.py b/planetstack/hpc_observer/steps/sync_contentprovider.py index 00117b8..c7335d6 100644 --- a/planetstack/hpc_observer/steps/sync_contentprovider.py +++ b/planetstack/hpc_observer/steps/sync_contentprovider.py @@ -24,11 +24,22 @@ class SyncContentProvider(SyncStep, HpcLibrary): SyncStep.__init__(self, **args) HpcLibrary.__init__(self) - def fetch_pending(self): - return ContentProvider.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)) + def fetch_pending(self, deleted): + self.sanity_check() + + return SyncStep.fetch_pending(self, deleted) + + def sanity_check(self): + # sanity check to make sure our PS objects have CMI objects behind them + all_cp_ids = [x["content_provider_id"] for x in self.client.onev.ListAll("ContentProvider")] + for cp in ContentProvider.objects.all(): + if (cp.content_provider_id is not None) and (cp.content_provider_id not in all_cp_ids): + logger.info("Content provider %s was not found on CMI" % cp.content_provider_id) + cp.content_provider_id=None + cp.save() def sync_record(self, cp): - logger.info("sync'ing service provider %s" % str(cp)) + logger.info("sync'ing content provider %s" % str(cp)) account_name = self.make_account_name(cp.name) print "XXX", cp.name, account_name @@ -37,14 +48,19 @@ class SyncContentProvider(SyncStep, HpcLibrary): spid = cp.serviceProvider.service_provider_id - cp_dict = {"account": account_name, "name": cp.name, "enabled": cp.enabled, "service_provider_id": spid} + cp_dict = {"account": account_name, "name": cp.name, "enabled": cp.enabled} #print cp_dict if not cp.content_provider_id: + cp_dict["service_provider_id"] = spid id = self.client.onev.Create("ContentProvider", cp_dict) cp.content_provider_id = id else: self.client.onev.Update("ContentProvider", cp.content_provider_id, cp_dict) cp.save() + + def delete_record(self, m): + self.client.onev.Delete("ContentProvider", m.content_provider_id) +