Changes to support monitoring of a service

Change-Id: Ia50534c95fb88d62e8658335c1908ec55572ec8b
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 30b5d3a..2ba283d 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1030,6 +1030,14 @@
     extra = 0
     suit_classes = 'suit-tab suit-tab-serviceattrs'
 
+class ServiceMonitoringAgentInfoInline(XOSTabularInline):
+    model = ServiceMonitoringAgentInfo
+    fields = ['id', 'name', 'target_uri']
+    extra = 0
+    suit_classes = 'suit-tab suit-tab-servicemonitoringagents'
+    verbose_name = 'Monitoring agent info for this service'
+    verbose_name_plural = 'Monitoring agent info for this service'
+
 
 class ServiceAdmin(XOSBaseAdmin):
     list_display = ("backend_status_icon", "name", "kind", "enabled", "published")
@@ -1039,7 +1047,7 @@
     fieldsets = [
         (None, {'fields': fieldList, 'classes': ['suit-tab suit-tab-general']})]
     inlines = [ServiceAttrAsTabInline, SliceInline, ProviderTenantInline,
-               SubscriberTenantInline, ServicePrivilegeInline]
+               SubscriberTenantInline, ServicePrivilegeInline, ServiceMonitoringAgentInfoInline]
     readonly_fields = ('backend_status_text', )
 
     user_readonly_fields = fieldList
@@ -1048,7 +1056,8 @@
                       ('slices', 'Slices'),
                       ('serviceattrs', 'Additional Attributes'),
                       ('servicetenants', 'Tenancy'),
-                      ('serviceprivileges', 'Privileges')
+                      ('serviceprivileges', 'Privileges'),
+                      ('servicemonitoringagents', 'Monitoring Agents')
                       )
 
 class LoadableModuleResourceInline(XOSTabularInline):
diff --git a/xos/core/models/__init__.py b/xos/core/models/__init__.py
index de3a941..3162b35 100644
--- a/xos/core/models/__init__.py
+++ b/xos/core/models/__init__.py
@@ -3,7 +3,7 @@
 from .singletonmodel import SingletonModel
 from .xosmodel import XOS, XOSVolume
 from .service import Service, Tenant, TenantWithContainer, CoarseTenant, ServicePrivilege, TenantRoot, TenantRootPrivilege, TenantRootRole, TenantPrivilege, TenantRole, Subscriber, Provider
-from .service import ServiceAttribute, TenantAttribute, ServiceRole
+from .service import ServiceAttribute, TenantAttribute, ServiceRole, ServiceMonitoringAgentInfo
 from .service import ServiceController, ServiceControllerResource, LoadableModule, LoadableModuleResource, Library
 from .service import XOSComponent, XOSComponentLink, XOSComponentVolume
 from .tag import Tag
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 8f874e3..502f7a7 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -7,6 +7,7 @@
 from core.models import PlCoreBase, PlCoreBaseManager, SingletonModel, XOS
 from core.models.plcorebase import StrippedCharField
 from django.db import models
+from django.core.validators import URLValidator
 from xos.exceptions import *
 import urlparse
 
@@ -501,6 +502,13 @@
             qs = cls.objects.filter(user=user)
         return qs
 
+#Model that defines the information needed to enable monitoring agents of a service
+class ServiceMonitoringAgentInfo(PlCoreBase):
+    name = models.CharField(help_text="Monitoring Agent Name", max_length=128)
+    service = models.ForeignKey(Service, related_name='servicemonitoringagents', blank=True, null=True,
+                                help_text="The Service this attribute is associated with")
+    target_uri = models.TextField(validators=[URLValidator()], help_text="Monitoring collector URI to be used by agents to publish the data")
+
 
 class TenantRoot(PlCoreBase, AttributeMixin):
     """ A tenantRoot is one of the things that can sit at the root of a chain
diff --git a/xos/synchronizers/base/SyncInstanceUsingAnsible.py b/xos/synchronizers/base/SyncInstanceUsingAnsible.py
index 11486b7..88d636e 100644
--- a/xos/synchronizers/base/SyncInstanceUsingAnsible.py
+++ b/xos/synchronizers/base/SyncInstanceUsingAnsible.py
@@ -8,7 +8,7 @@
 from xos.config import Config
 from synchronizers.base.syncstep import SyncStep
 from synchronizers.base.ansible import run_template_ssh
-from core.models import Service, Slice, ControllerSlice, ControllerUser, ModelLink, CoarseTenant, Tenant
+from core.models import Service, Slice, ControllerSlice, ControllerUser, ModelLink, CoarseTenant, Tenant, ServiceMonitoringAgentInfo
 from xos.logger import Logger, logging
 
 logger = Logger(level=logging.INFO)
@@ -272,6 +272,8 @@
         logger.info("handle_watched_object is invoked for object %s" % (str(o)),extra=o.tologdict())
         if (type(o) is CoarseTenant):
            self.handle_service_composition_watch_notification(o)
+        elif (type(o) is ServiceMonitoringAgentInfo):
+           self.handle_service_monitoringagentinfo_watch_notification(o)
         pass
 
     def handle_service_composition_watch_notification(self, coarse_tenant):
@@ -286,6 +288,9 @@
             self.handle_service_composition_for_object(obj, coarse_tenant)
         pass
 
+    def handle_service_monitoringagentinfo_watch_notification(self, monitoring_agent_info):
+        pass
+
     def handle_service_composition_for_object(self, obj, coarse_tenant):
         try:
            instance = self.get_instance(obj)
@@ -331,7 +336,7 @@
             src_ip = instance.get_network_ip(src_network.name)
             target_subnet = target_network.controllernetworks.all()[0].subnet
   
-            #TODO: Run ansible playbook to update the routing table entries in the instance
+            #Run ansible playbook to update the routing table entries in the instance
             fields = self.get_ansible_fields(instance)
             fields["ansible_tag"] =  obj.__class__.__name__ + "_" + str(obj.id) + "_service_composition"
             fields["src_intf_ip"] = src_ip
diff --git a/xos/synchronizers/onboarding/xosbuilder.py b/xos/synchronizers/onboarding/xosbuilder.py
index fd0fe17..30a8c90 100644
--- a/xos/synchronizers/onboarding/xosbuilder.py
+++ b/xos/synchronizers/onboarding/xosbuilder.py
@@ -397,7 +397,7 @@
                     containers["xos_synchronizer_%s" % c.name] = {
                         "image": "xosproject/xos-synchronizer-%s" % c.name,
                         "command": command,
-                        "external_links": ["%s:%s" % (xos.db_container_name, "xos_db")],
+                        "external_links": external_links,
                         "extra_hosts": extra_hosts,
                         "volumes": volume_list
                     }