Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import base64 |
| 4 | from django.db.models import F, Q |
| 5 | from planetstack.config import Config |
| 6 | from observer.syncstep import SyncStep |
| 7 | from core.models import Service |
| 8 | from hpc.models import ServiceProvider, ContentProvider |
| 9 | from util.logger import Logger, logging |
| 10 | |
| 11 | # hpclibrary will be in steps/.. |
| 12 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 13 | sys.path.insert(0,parentdir)
|
| 14 | |
| 15 | from hpclib import HpcLibrary |
| 16 | |
| 17 | logger = Logger(level=logging.INFO) |
| 18 | |
| 19 | class SyncContentProvider(SyncStep, HpcLibrary): |
| 20 | provides=[ContentProvider] |
| 21 | requested_interval=0 |
| 22 | |
| 23 | def __init__(self, **args): |
| 24 | SyncStep.__init__(self, **args) |
| 25 | HpcLibrary.__init__(self) |
| 26 | |
Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 27 | def sync_record(self, cp): |
Scott Baker | 533d543 | 2014-01-22 00:08:50 -0800 | [diff] [blame] | 28 | logger.info("sync'ing content provider %s" % str(cp)) |
Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 29 | account_name = self.make_account_name(cp.name) |
| 30 | print "XXX", cp.name, account_name |
| 31 | |
| 32 | if (not cp.serviceProvider) or (not cp.serviceProvider.service_provider_id): |
| 33 | return |
| 34 | |
| 35 | spid = cp.serviceProvider.service_provider_id |
| 36 | |
Scott Baker | 533d543 | 2014-01-22 00:08:50 -0800 | [diff] [blame] | 37 | cp_dict = {"account": account_name, "name": cp.name, "enabled": cp.enabled} |
Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 38 | |
Scott Baker | 88be16c | 2014-01-06 23:52:26 -0800 | [diff] [blame] | 39 | #print cp_dict |
| 40 | |
| 41 | if not cp.content_provider_id: |
Scott Baker | 533d543 | 2014-01-22 00:08:50 -0800 | [diff] [blame] | 42 | cp_dict["service_provider_id"] = spid |
Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 43 | id = self.client.onev.Create("ContentProvider", cp_dict) |
| 44 | cp.content_provider_id = id |
| 45 | else: |
Scott Baker | 88be16c | 2014-01-06 23:52:26 -0800 | [diff] [blame] | 46 | self.client.onev.Update("ContentProvider", cp.content_provider_id, cp_dict) |
Scott Baker | cd96a8c | 2014-01-06 16:31:58 -0800 | [diff] [blame] | 47 | |
| 48 | cp.save() |
Sapan Bhatia | c7de778 | 2014-07-23 10:13:10 -0400 | [diff] [blame] | 49 | |
Sapan Bhatia | b2b4484 | 2014-07-23 10:17:28 -0400 | [diff] [blame] | 50 | def delete_record(self, m): |
Sapan Bhatia | c7de778 | 2014-07-23 10:13:10 -0400 | [diff] [blame] | 51 | self.client.onev.Delete("ContentProvider", m.content_provider_id) |
| 52 | |