blob: 35b34b274a50c654f47a2a788c9dd9d9ee13b9de [file] [log] [blame]
Matteo Scandolo7781b5b2017-08-08 13:05:26 -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 Baker7a327592016-06-20 17:34:06 -070017import hashlib
18import os
19import socket
20import sys
21import base64
22import time
Scott Baker91ee5e42017-03-14 10:33:52 -070023from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
24from synchronizers.new_base.modelaccessor import *
Scott Baker7a327592016-06-20 17:34:06 -070025from xos.logger import Logger, logging
26
Scott Baker7a327592016-06-20 17:34:06 -070027logger = Logger(level=logging.INFO)
28
29class SyncONOSService(SyncInstanceUsingAnsible):
30 provides=[ONOSService]
31 observes=ONOSService
32 requested_interval=0
33 template_name = "sync_onosservice.yaml"
Scott Baker7a327592016-06-20 17:34:06 -070034
35 def __init__(self, *args, **kwargs):
36 super(SyncONOSService, self).__init__(*args, **kwargs)
37
Scott Baker7a327592016-06-20 17:34:06 -070038 def get_instance(self, o):
39 # We assume the ONOS service owns a slice, so pick one of the instances
40 # inside that slice to sync to.
41
42 serv = o
43
44 if serv.slices.exists():
45 slice = serv.slices.all()[0]
46 if slice.instances.exists():
47 return slice.instances.all()[0]
48
49 return None
50
51 def get_extra_attributes(self, o):
52 fields={}
53 fields["instance_hostname"] = self.get_instance(o).instance_name.replace("_","-")
54 fields["appname"] = o.name
55 fields["ONOS_container"] = "ONOS"
56 return fields
57
58 def sync_record(self, o):
59 if o.no_container:
60 logger.info("no work to do for onos service, because o.no_container is set",extra=o.tologdict())
61 o.save()
62 else:
63 super(SyncONOSService, self).sync_record(o)
64
65 def sync_fields(self, o, fields):
66 # the super causes the playbook to be run
67 super(SyncONOSService, self).sync_fields(o, fields)
68
69 def run_playbook(self, o, fields):
70 instance = self.get_instance(o)
71 if (instance.isolation=="container"):
72 # If the instance is already a container, then we don't need to
73 # install ONOS.
74 return
75 super(SyncONOSService, self).run_playbook(o, fields)
76
77 def delete_record(self, m):
78 pass