blob: c8abe57d0af2c26dc90537f50b7dc3369d09cdbc [file] [log] [blame]
Scott Baker7a327592016-06-20 17:34:06 -07001import hashlib
2import os
3import socket
4import sys
5import base64
6import time
Scott Baker91ee5e42017-03-14 10:33:52 -07007from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
8from synchronizers.new_base.modelaccessor import *
Scott Baker7a327592016-06-20 17:34:06 -07009from xos.logger import Logger, logging
10
Scott Baker7a327592016-06-20 17:34:06 -070011logger = Logger(level=logging.INFO)
12
13class SyncONOSService(SyncInstanceUsingAnsible):
14 provides=[ONOSService]
15 observes=ONOSService
16 requested_interval=0
17 template_name = "sync_onosservice.yaml"
Scott Baker7a327592016-06-20 17:34:06 -070018
19 def __init__(self, *args, **kwargs):
20 super(SyncONOSService, self).__init__(*args, **kwargs)
21
Scott Baker7a327592016-06-20 17:34:06 -070022 def get_instance(self, o):
23 # We assume the ONOS service owns a slice, so pick one of the instances
24 # inside that slice to sync to.
25
26 serv = o
27
28 if serv.slices.exists():
29 slice = serv.slices.all()[0]
30 if slice.instances.exists():
31 return slice.instances.all()[0]
32
33 return None
34
35 def get_extra_attributes(self, o):
36 fields={}
37 fields["instance_hostname"] = self.get_instance(o).instance_name.replace("_","-")
38 fields["appname"] = o.name
39 fields["ONOS_container"] = "ONOS"
40 return fields
41
42 def sync_record(self, o):
43 if o.no_container:
44 logger.info("no work to do for onos service, because o.no_container is set",extra=o.tologdict())
45 o.save()
46 else:
47 super(SyncONOSService, self).sync_record(o)
48
49 def sync_fields(self, o, fields):
50 # the super causes the playbook to be run
51 super(SyncONOSService, self).sync_fields(o, fields)
52
53 def run_playbook(self, o, fields):
54 instance = self.get_instance(o)
55 if (instance.isolation=="container"):
56 # If the instance is already a container, then we don't need to
57 # install ONOS.
58 return
59 super(SyncONOSService, self).run_playbook(o, fields)
60
61 def delete_record(self, m):
62 pass