blob: 36f268935dc49068b7cfb5da58b8fe0feea9f4b9 [file] [log] [blame]
Scott Bakerf5208452014-01-06 16:04:58 -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
Scott Bakerf5208452014-01-06 16:04:58 -08009from 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 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 Bakerf5208452014-01-06 16:04:58 -080027 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 Baker88be16c2014-01-06 23:52:26 -080031 sp_dict = {"account": account_name, "name": sp.name, "enabled": sp.enabled}
Scott Bakerf5208452014-01-06 16:04:58 -080032 if not sp.service_provider_id:
Scott Baker88be16c2014-01-06 23:52:26 -080033 id = self.client.onev.Create("ServiceProvider", sp_dict)
Scott Bakerf5208452014-01-06 16:04:58 -080034 sp.service_provider_id = id
35 else:
Scott Baker88be16c2014-01-06 23:52:26 -080036 self.client.onev.Update("ServiceProvider", sp.service_provider_id, sp_dict)
Scott Bakerf5208452014-01-06 16:04:58 -080037
38 sp.save()
Sapan Bhatiaf49ed9c2014-07-23 10:25:21 -040039
40 def delete_record(self, m):
41 print "XXX delete service provider", m
42 self.client.onev.Delete("ServiceProvider", m.service_provider_id)