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