Scott Baker | f520845 | 2014-01-06 16:04: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 |
Scott Baker | f520845 | 2014-01-06 16:04:58 -0800 | [diff] [blame] | 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 SyncServiceProvider(SyncStep, HpcLibrary): |
| 20 | provides=[ServiceProvider] |
| 21 | requested_interval=0 |
| 22 | |
| 23 | def __init__(self, **args): |
| 24 | SyncStep.__init__(self, **args) |
| 25 | HpcLibrary.__init__(self) |
| 26 | |
Scott Baker | f520845 | 2014-01-06 16:04:58 -0800 | [diff] [blame] | 27 | def sync_record(self, sp): |
| 28 | logger.info("sync'ing service provider %s" % str(sp)) |
| 29 | account_name = self.make_account_name(sp.name) |
| 30 | print "XXX", sp.name, account_name |
Scott Baker | 88be16c | 2014-01-06 23:52:26 -0800 | [diff] [blame] | 31 | sp_dict = {"account": account_name, "name": sp.name, "enabled": sp.enabled} |
Scott Baker | f520845 | 2014-01-06 16:04:58 -0800 | [diff] [blame] | 32 | if not sp.service_provider_id: |
Scott Baker | 88be16c | 2014-01-06 23:52:26 -0800 | [diff] [blame] | 33 | id = self.client.onev.Create("ServiceProvider", sp_dict) |
Scott Baker | f520845 | 2014-01-06 16:04:58 -0800 | [diff] [blame] | 34 | sp.service_provider_id = id |
| 35 | else: |
Scott Baker | 88be16c | 2014-01-06 23:52:26 -0800 | [diff] [blame] | 36 | self.client.onev.Update("ServiceProvider", sp.service_provider_id, sp_dict) |
Scott Baker | f520845 | 2014-01-06 16:04:58 -0800 | [diff] [blame] | 37 | |
| 38 | sp.save() |
Sapan Bhatia | f49ed9c | 2014-07-23 10:25:21 -0400 | [diff] [blame] | 39 | |
| 40 | def delete_record(self, m): |
| 41 | print "XXX delete service provider", m |
| 42 | self.client.onev.Delete("ServiceProvider", m.service_provider_id) |