sync steps for hpc
diff --git a/planetstack/hpc_observer/steps/sync_cdnprefix.py b/planetstack/hpc_observer/steps/sync_cdnprefix.py
new file mode 100644
index 0000000..01bb687
--- /dev/null
+++ b/planetstack/hpc_observer/steps/sync_cdnprefix.py
@@ -0,0 +1,48 @@
+import os
+import sys
+import base64
+from django.db.models import F, Q
+from planetstack.config import Config
+from observer.syncstep import SyncStep
+from core.models import Service
+from hpc.models import ServiceProvider, ContentProvider, CDNPrefix
+from util.logger import Logger, logging
+
+# hpclibrary will be in steps/..
+parentdir = os.path.join(os.path.dirname(__file__),"..")
+sys.path.insert(0,parentdir)

+
+from hpclib import HpcLibrary
+
+logger = Logger(level=logging.INFO)
+
+class SyncCDNPrefix(SyncStep, HpcLibrary):
+    provides=[CDNPrefix]
+    requested_interval=0
+
+    def __init__(self, **args):
+        SyncStep.__init__(self, **args)
+        HpcLibrary.__init__(self)
+
+    def fetch_pending(self):
+        return CDNPrefix.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
+
+    def sync_record(self, cp):
+        logger.info("sync'ing cdn prefix %s" % str(cp))
+
+        if (not cp.contentProvider) or (not cp.contentProvider.content_provider_id):
+            return
+
+        cpid = cp.contentProvider.content_provider_id
+
+        cp_dict = {"service": "HyperCache", "enabled": cp.enabled, "content_provider_id": cpid, "cdn_prefix": cp.prefix}
+
+        #print cp_dict
+
+        if not cp.cdn_prefix_id:
+            id = self.client.onev.Create("CDNPrefix", cp_dict)
+            cp.cdn_prefix_id = id
+        else:
+            self.client.onev.Update("CDNPrefix", cp.cdn_prefix_id, cp_dict)
+
+        cp.save()
diff --git a/planetstack/hpc_observer/steps/sync_contentprovider.py b/planetstack/hpc_observer/steps/sync_contentprovider.py
index b78a7a8..00117b8 100644
--- a/planetstack/hpc_observer/steps/sync_contentprovider.py
+++ b/planetstack/hpc_observer/steps/sync_contentprovider.py
@@ -37,12 +37,14 @@
 
         spid = cp.serviceProvider.service_provider_id
 
-        cp_dict = {"account": account_name, "name": cp.name, "enabled": sp.enabled, "service_provider_id": spid}
+        cp_dict = {"account": account_name, "name": cp.name, "enabled": cp.enabled, "service_provider_id": spid}
 
-        if not cp.service_provider_id:
+        #print cp_dict
+
+        if not cp.content_provider_id:
             id = self.client.onev.Create("ContentProvider", cp_dict)
             cp.content_provider_id = id
         else:
-            self.client.onev.Update("ContentProvider", cp_dict)
+            self.client.onev.Update("ContentProvider", cp.content_provider_id, cp_dict)
 
         cp.save()
diff --git a/planetstack/hpc_observer/steps/sync_originserver.py b/planetstack/hpc_observer/steps/sync_originserver.py
new file mode 100644
index 0000000..e57c282
--- /dev/null
+++ b/planetstack/hpc_observer/steps/sync_originserver.py
@@ -0,0 +1,58 @@
+import os
+import sys
+import base64
+from django.db.models import F, Q
+from planetstack.config import Config
+from observer.syncstep import SyncStep
+from core.models import Service
+from hpc.models import ServiceProvider, ContentProvider, CDNPrefix, OriginServer
+from util.logger import Logger, logging
+
+# hpclibrary will be in steps/..
+parentdir = os.path.join(os.path.dirname(__file__),"..")
+sys.path.insert(0,parentdir)

+
+from hpclib import HpcLibrary
+
+logger = Logger(level=logging.INFO)
+
+class SyncOriginServer(SyncStep, HpcLibrary):
+    provides=[OriginServer]
+    requested_interval=0
+
+    def __init__(self, **args):
+        SyncStep.__init__(self, **args)
+        HpcLibrary.__init__(self)
+
+    def fetch_pending(self):
+        return OriginServer.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
+
+    def sync_record(self, ors):
+        logger.info("sync'ing origin server %s" % str(ors))
+
+        if (not ors.contentProvider) or (not ors.contentProvider.content_provider_id):
+            return
+
+        cpid = ors.contentProvider.content_provider_id
+
+        # validation requires URL start with http://
+        url = ors.url
+        if not url.startswith("http://"):
+            url = "http://" + url
+
+        ors_dict = {"authenticated_content": ors.authenticated, "zone_redirects": ors.redirects, "content_provider_id": cpid, "url": url, "service_type": "HyperCache", "caching_type": "Optimistic", "description": ors.description}
+
+        #print os_dict
+
+        if not ors.origin_server_id:
+            id = self.client.onev.Create("OriginServer", ors_dict)
+            ors.origin_server_id = id
+        else:
+            self.client.onev.Update("OriginServer", ors.origin_server_id, ors_dict)
+
+        # ... something breaks (analytics) if the URL starts with http://, so we
+        # change it in cob after we added it via onev.
+        url = url[7:]
+        self.client.cob.UpdateContent(ors.origin_server_id, {"url": url})
+
+        ors.save()
diff --git a/planetstack/hpc_observer/steps/sync_serviceprovider.py b/planetstack/hpc_observer/steps/sync_serviceprovider.py
index d6820d6..5eb991a 100644
--- a/planetstack/hpc_observer/steps/sync_serviceprovider.py
+++ b/planetstack/hpc_observer/steps/sync_serviceprovider.py
@@ -6,7 +6,6 @@
 from observer.syncstep import SyncStep
 from core.models import Service
 from hpc.models import ServiceProvider
-from requestrouter.models import RequestRouterService
 from util.logger import Logger, logging
 
 # hpclibrary will be in steps/..
@@ -32,10 +31,11 @@
         logger.info("sync'ing service provider %s" % str(sp))
         account_name = self.make_account_name(sp.name)
         print "XXX", sp.name, account_name
+        sp_dict = {"account": account_name, "name": sp.name, "enabled": sp.enabled}
         if not sp.service_provider_id:
-            id = self.client.onev.Create("ServiceProvider", {"account": account_name, "name": sp.name, "enabled": sp.enabled})
+            id = self.client.onev.Create("ServiceProvider", sp_dict)
             sp.service_provider_id = id
         else:
-            self.client.onev.Update("ServiceProvider", {"account": account_name, "name": sp.name, "enabled": sp.enabled})
+            self.client.onev.Update("ServiceProvider", sp.service_provider_id, sp_dict)
 
         sp.save()