blob: adb95db75632b8ba959ed5f66741bf7a90f50282 [file] [log] [blame]
Scott Baker88be16c2014-01-06 23:52:26 -08001import os
2import sys
3import base64
4from django.db.models import F, Q
5from planetstack.config import Config
6from observer.syncstep import SyncStep
7from core.models import Service
8from hpc.models import ServiceProvider, ContentProvider, CDNPrefix
9from util.logger import Logger, logging
10
11# hpclibrary will be in steps/..
12parentdir = os.path.join(os.path.dirname(__file__),"..")
13sys.path.insert(0,parentdir)
14
15from hpclib import HpcLibrary
16
17logger = Logger(level=logging.INFO)
18
19class SyncCDNPrefix(SyncStep, HpcLibrary):
20 provides=[CDNPrefix]
21 requested_interval=0
22
23 def __init__(self, **args):
24 SyncStep.__init__(self, **args)
25 HpcLibrary.__init__(self)
26
Scott Baker88be16c2014-01-06 23:52:26 -080027 def sync_record(self, cp):
28 logger.info("sync'ing cdn prefix %s" % str(cp))
29
30 if (not cp.contentProvider) or (not cp.contentProvider.content_provider_id):
31 return
32
33 cpid = cp.contentProvider.content_provider_id
34
35 cp_dict = {"service": "HyperCache", "enabled": cp.enabled, "content_provider_id": cpid, "cdn_prefix": cp.prefix}
36
Scott Baker9713d202014-08-26 14:38:25 -070037 if cp.defaultOriginServer and cp.defaultOriginServer.origin_server_id and cp.defaultOriginServer.url:
38 cp_dict["default_origin_server"] = cp.defaultOriginServer.url
39
Scott Baker88be16c2014-01-06 23:52:26 -080040 #print cp_dict
41
42 if not cp.cdn_prefix_id:
43 id = self.client.onev.Create("CDNPrefix", cp_dict)
44 cp.cdn_prefix_id = id
45 else:
46 self.client.onev.Update("CDNPrefix", cp.cdn_prefix_id, cp_dict)
47
48 cp.save()
Sapan Bhatia6ac3ecc2014-07-23 10:12:42 -040049
50 def delete_record(self, m):
51 self.client.onev.Delete("CDNPrefix", m.cdn_prefix_id)