do a better job with default_origin_server; fix update
diff --git a/planetstack/hpc_observer/steps/sync_cdnprefix.py b/planetstack/hpc_observer/steps/sync_cdnprefix.py
index b887e84..55b2326 100644
--- a/planetstack/hpc_observer/steps/sync_cdnprefix.py
+++ b/planetstack/hpc_observer/steps/sync_cdnprefix.py
@@ -32,12 +32,27 @@
def sanity_check(self):
# sanity check to make sure our PS objects have CMI objects behind them
all_p_ids = [x["cdn_prefix_id"] for x in self.client.onev.ListAll("CDNPrefix")]
+
+ all_p_ids = []
+ all_origins = {}
+ for x in self.client.onev.ListAll("CDNPrefix"):
+ id = x["cdn_prefix_id"]
+ all_p_ids.append(id)
+ all_origins[id] = x.get("default_origin_server", None)
+
for p in CDNPrefix.objects.all():
- if (p.cdn_prefix_id is not None) and (p.cdn_prefix_id not in all_p_ids):
+ if (p.cdn_prefix_id is None):
+ continue
+
+ if (p.cdn_prefix_id not in all_p_ids):
logger.info("CDN Prefix %s was not found on CMI" % p.cdn_prefix_id)
p.cdn_prefix_id=None
p.save()
+ if (p.defaultOriginServer!=None) and (all_origins.get(p.cdn_prefix_id,None) != p.defaultOriginServer.url):
+ logger.info("CDN Prefix %s does not have default origin server on CMI" % str(p))
+ p.save() # this will set updated>enacted and force run
+
def sync_record(self, cp):
logger.info("sync'ing cdn prefix %s" % str(cp))
@@ -48,7 +63,13 @@
cp_dict = {"service": "HyperCache", "enabled": cp.enabled, "content_provider_id": cpid, "cdn_prefix": cp.prefix}
- if cp.defaultOriginServer and cp.defaultOriginServer.origin_server_id and cp.defaultOriginServer.url:
+ if cp.defaultOriginServer and cp.defaultOriginServer.url:
+ if (not cp.defaultOriginServer.origin_server_id):
+ # It's probably a bad idea to try to set defaultOriginServer before
+ # we've crated defaultOriginServer.
+ logger.info(" cdn prefix %s is waiting for it's default origin server to get an id" % str(cp))
+ return
+
cp_dict["default_origin_server"] = cp.defaultOriginServer.url
#print cp_dict
@@ -57,6 +78,8 @@
id = self.client.onev.Create("CDNPrefix", cp_dict)
cp.cdn_prefix_id = id
else:
+ del cp_dict["content_provider_id"] # this can't be updated
+ del cp_dict["cdn_prefix"] # this can't be updated either
self.client.onev.Update("CDNPrefix", cp.cdn_prefix_id, cp_dict)
cp.save()