blob: 96cfcd44da839956edfb10125677a2c7a8247638 [file] [log] [blame]
Matteo Scandoloede125b2017-08-08 13:05:25 -07001
2# Copyright 2017-present Open Networking Foundation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
Scott Baker25467ff2016-08-04 09:50:22 -070017import os
18import sys
19import base64
20from django.db.models import F, Q
21from xos.config import Config
22from synchronizers.base.syncstep import SyncStep
23from core.models import Service
24from services.hpc.models import HpcService
Scott Baker25467ff2016-08-04 09:50:22 -070025from xos.logger import Logger, logging
26
27# hpclibrary will be in steps/..
28parentdir = os.path.join(os.path.dirname(__file__),"..")
29sys.path.insert(0,parentdir)
30
31from hpclib import HpcLibrary
32
33logger = Logger(level=logging.INFO)
34
35class SyncHpcService(SyncStep, HpcLibrary):
36 provides=[HpcService]
37 observes=HpcService
38 requested_interval=0
39
40 def __init__(self, **args):
41 SyncStep.__init__(self, **args)
42 HpcLibrary.__init__(self)
43
44 def filter_hpc_service(self, objs):
45 hpcService = self.get_hpc_service()
46
47 return [x for x in objs if x == hpcService]
48
49 def fetch_pending(self, deleted):
50 # Looks like deletion is not supported for this object - Sapan
51 if (deleted):
52 return []
53 else:
54 return self.filter_hpc_service(HpcService.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None)))
55
56 def sync_record(self, hpc_service):
57 logger.info("sync'ing hpc_service %s" % str(hpc_service),extra=hpc_service.tologdict())
58 hpc_service.save()