fixing merge conflict
diff --git a/xos/core/admin.py b/xos/core/admin.py
index b3dc67d..5d2996a 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -787,6 +787,23 @@
 
         return tabs
 
+class TenantAttributeAdmin(XOSBaseAdmin):
+    model = TenantAttribute
+    list_display = ('backend_status_icon', 'tenant', 'name', 'value')
+    list_display_links = ('backend_status_icon', 'name')
+    fieldList = ('backend_status_text', 'tenant', 'name', 'value', )
+    fieldsets = [(None, {'fields': fieldList, 'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', )
+
+    suit_form_tabs =(('general', 'Tenant Root Details'),
+    )
+
+class TenantAttrAsTabInline(XOSTabularInline):
+    model = TenantAttribute
+    fields = ['name','value']
+    extra = 0
+    suit_classes = 'suit-tab suit-tab-tenantattrs'
+
 class TenantRootRoleAdmin(XOSBaseAdmin):
     model = TenantRootRole
     fields = ('role',)
@@ -2006,4 +2023,5 @@
     admin.site.register(Flavor, FlavorAdmin)
     admin.site.register(TenantRoot, TenantRootAdmin)
     admin.site.register(TenantRootRole, TenantRootRoleAdmin)
+    admin.site.register(TenantAttribute, TenantAttributeAdmin)
 
diff --git a/xos/core/models/__init__.py b/xos/core/models/__init__.py
index ad271a4..c380e9c 100644
--- a/xos/core/models/__init__.py
+++ b/xos/core/models/__init__.py
@@ -2,7 +2,7 @@
 from .project import Project
 from .singletonmodel import SingletonModel
 from .service import Service, Tenant, TenantWithContainer, CoarseTenant, ServicePrivilege, TenantRoot, TenantRootPrivilege, TenantRootRole, Subscriber, Provider
-from .service import ServiceAttribute
+from .service import ServiceAttribute, TenantAttribute
 from .tag import Tag
 from .role import Role
 from .site import Site, Deployment, DeploymentRole, DeploymentPrivilege, Controller, ControllerRole, ControllerSite, SiteDeployment
diff --git a/xos/core/models/service.py b/xos/core/models/service.py
index 9530c72..8d2180c 100644
--- a/xos/core/models/service.py
+++ b/xos/core/models/service.py
@@ -488,6 +488,11 @@
 
     KIND = "Provider"
 
+class TenantAttribute(PlCoreBase):
+    name = models.SlugField(help_text="Attribute Name", max_length=128)
+    value = models.TextField(help_text="Attribute Value")
+    tenant = models.ForeignKey(Tenant, related_name='tenantattributes', help_text="The Tenant this attribute is associated with")
+
 class TenantRootRole(PlCoreBase):
     ROLE_CHOICES = (('admin','Admin'), ('access','Access'))
 
diff --git a/xos/helloworldservice/models.py b/xos/helloworldservice/models.py
index bb35f4c..eeffbaf 100644
--- a/xos/helloworldservice/models.py
+++ b/xos/helloworldservice/models.py
@@ -43,8 +43,8 @@
             self.creator = self.caller
             if not self.creator:
                 raise XOSProgrammingError("HelloWorldTennant's self.creator was not set")
-        
-	super(HelloWorldTenant, self).save(*args, **kwargs)
+
+        super(HelloWorldTenant, self).save(*args, **kwargs)
 
     def delete(self, *args, **kwargs):
         self.cleanup_container()
@@ -57,4 +57,3 @@
     @display_message.setter
     def display_message(self, value):
         self.set_attribute("display_message", value)
-
diff --git a/xos/observers/helloworldservice/steps/sync_helloworldtenant.py b/xos/observers/helloworldservice/steps/sync_helloworldtenant.py
index 73dd185..1e33dfa 100644
--- a/xos/observers/helloworldservice/steps/sync_helloworldtenant.py
+++ b/xos/observers/helloworldservice/steps/sync_helloworldtenant.py
@@ -19,12 +19,12 @@
     requested_interval=1
 
     def sync_record(self, record):
-	logger.info("Syncing helloworldtenant");
-    open('log','w').write(record.display_message + '\n');
-    if (record.instance):
-        open('log','w').write(record.instance + '\n');
-        record.instance.userData = "packages:\n  - apache2\nruncmd:\n  - update-rc.d apache2 enable\n  - service apache2 start\nwrite_files:\n-   content: Hello %s\n    path: /var/www/html/hello.txt"%record.display_message
-        record.instance.save();
+        logger.info("Syncing helloworldtenant");
+        open('log','w').write(record.display_message + '\n');
+        if (record.instance):
+            open('log','w').write(record.instance + '\n');
+            record.instance.userData = "packages:\n  - apache2\nruncmd:\n  - update-rc.d apache2 enable\n  - service apache2 start\nwrite_files:\n-   content: Hello %s\n    path: /var/www/html/hello.txt"%record.display_message
+            record.instance.save();
 
 
     def delete_record(self, m):
diff --git a/xos/scripts/opencloud b/xos/scripts/opencloud
index 70b3d82..a34b674 100755
--- a/xos/scripts/opencloud
+++ b/xos/scripts/opencloud
@@ -148,6 +148,7 @@
     python ./manage.py makemigrations cord
     python ./manage.py makemigrations ceilometer
     python ./manage.py makemigrations helloworldservice
+    python ./manage.py makemigrations onos
     #python ./manage.py makemigrations servcomp
 }
 
diff --git a/xos/services/__init__.py b/xos/services/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/xos/services/__init__.py
@@ -0,0 +1 @@
+
diff --git a/xos/services/onos/__init__.py b/xos/services/onos/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/xos/services/onos/__init__.py
@@ -0,0 +1 @@
+
diff --git a/xos/services/onos/admin.py b/xos/services/onos/admin.py
new file mode 100644
index 0000000..b2e5349
--- /dev/null
+++ b/xos/services/onos/admin.py
@@ -0,0 +1,93 @@
+from django.contrib import admin
+
+from services.onos.models import *
+from django import forms
+from django.utils.safestring import mark_safe
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.admin.widgets import FilteredSelectMultiple
+from django.contrib.auth.forms import ReadOnlyPasswordHashField
+from django.contrib.auth.signals import user_logged_in
+from django.utils import timezone
+from django.contrib.contenttypes import generic
+from suit.widgets import LinkedSelect
+from core.admin import ServiceAppAdmin,SliceInline,ServiceAttrAsTabInline, ReadOnlyAwareAdmin, XOSTabularInline, ServicePrivilegeInline, TenantRootTenantInline, TenantRootPrivilegeInline, TenantAttrAsTabInline
+from core.middleware import get_request
+
+from functools import update_wrapper
+from django.contrib.admin.views.main import ChangeList
+from django.core.urlresolvers import reverse
+from django.contrib.admin.utils import quote
+
+class ONOSServiceAdmin(ReadOnlyAwareAdmin):
+    model = ONOSService
+    verbose_name = "ONOS Service"
+    verbose_name_plural = "ONOS Services"
+    list_display = ("backend_status_icon", "name", "enabled")
+    list_display_links = ('backend_status_icon', 'name', )
+    fieldsets = [(None, {'fields': ['backend_status_text', 'name','enabled','versionNumber', 'description',"view_url","icon_url" ], 'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', )
+    inlines = [SliceInline,ServiceAttrAsTabInline,ServicePrivilegeInline]
+
+    extracontext_registered_admins = True
+
+    user_readonly_fields = ["name", "enabled", "versionNumber", "description"]
+
+    suit_form_tabs =(('general', 'ONOS Service Details'),
+        ('administration', 'Administration'),
+        ('slices','Slices'),
+        ('serviceattrs','Additional Attributes'),
+        ('serviceprivileges','Privileges'),
+    )
+
+    suit_form_includes = (('onosadmin.html', 'top', 'administration'),
+                           )
+
+    def queryset(self, request):
+        return ONOSService.get_service_objects_by_user(request.user)
+
+class ONOSAppForm(forms.ModelForm):
+    creator = forms.ModelChoiceField(queryset=User.objects.all())
+    name = forms.CharField()
+
+    def __init__(self,*args,**kwargs):

+        super (ONOSAppForm,self ).__init__(*args,**kwargs)

+        self.fields['kind'].widget.attrs['readonly'] = True

+        self.fields['provider_service'].queryset = ONOSService.get_service_objects().all()

+        if self.instance:

+            # fields for the attributes

+            self.fields['creator'].initial = self.instance.creator

+            self.fields['name'].initial = self.instance.name

+        if (not self.instance) or (not self.instance.pk):

+            # default fields for an 'add' form

+            self.fields['kind'].initial = ONOS_KIND

+            self.fields['creator'].initial = get_request().user

+            if ONOSService.get_service_objects().exists():

+               self.fields["provider_service"].initial = ONOSService.get_service_objects().all()[0]

+

+

+    def save(self, commit=True):

+        self.instance.creator = self.cleaned_data.get("creator")

+        self.instance.name = self.cleaned_data.get("name")

+        return super(ONOSAppForm, self).save(commit=commit)

+

+    class Meta:

+        model = ONOSApp
+
+class ONOSAppAdmin(ReadOnlyAwareAdmin):
+    list_display = ('backend_status_icon', 'name', )
+    list_display_links = ('backend_status_icon', 'name')
+    fieldsets = [ (None, {'fields': ['backend_status_text', 'kind', 'name', 'provider_service', 'service_specific_attribute',
+                                     'creator'],
+                          'classes':['suit-tab suit-tab-general']})]
+    readonly_fields = ('backend_status_text', 'instance', 'service_specific_attribute')
+    inlines = [TenantAttrAsTabInline]
+    form = ONOSAppForm
+
+    suit_form_tabs = (('general','Details'), ('tenantattrs', 'Attributes'))
+
+    def queryset(self, request):
+        return ONOSApp.get_tenant_objects_by_user(request.user)
+
+admin.site.register(ONOSService, ONOSServiceAdmin)
+admin.site.register(ONOSApp, ONOSAppAdmin)
+
diff --git a/xos/services/onos/models.py b/xos/services/onos/models.py
new file mode 100644
index 0000000..018bd25
--- /dev/null
+++ b/xos/services/onos/models.py
@@ -0,0 +1,90 @@
+from django.db import models
+from core.models import Service, PlCoreBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber
+from core.models.plcorebase import StrippedCharField
+import os
+from django.db import models, transaction
+from django.forms.models import model_to_dict
+from django.db.models import Q
+from operator import itemgetter, attrgetter, methodcaller
+import traceback
+from xos.exceptions import *
+from core.models import SlicePrivilege, SitePrivilege
+from sets import Set
+
+ONOS_KIND = "onos"
+
+class ONOSService(Service):
+    KIND = ONOS_KIND
+
+    class Meta:
+        app_label = "onos"
+        verbose_name = "ONOS Service"
+        proxy = True
+
+class ONOSApp(Tenant):   # aka 'ONOSTenant'
+    class Meta:
+        proxy = True
+
+    KIND = ONOS_KIND
+
+    default_attributes = {"name": ""}
+    def __init__(self, *args, **kwargs):
+        onos_services = ONOSService.get_service_objects().all()
+        if onos_services:
+            self._meta.get_field("provider_service").default = onos_services[0].id
+        super(ONOSApp, self).__init__(*args, **kwargs)
+
+    @property
+    def creator(self):
+        from core.models import User
+        if getattr(self, "cached_creator", None):
+            return self.cached_creator
+        creator_id=self.get_attribute("creator_id")
+        if not creator_id:
+            return None
+        users=User.objects.filter(id=creator_id)
+        if not users:
+            return None
+        user=users[0]
+        self.cached_creator = users[0]
+        return user
+
+    @creator.setter
+    def creator(self, value):
+        if value:
+            value = value.id
+        if (value != self.get_attribute("creator_id", None)):
+            self.cached_creator=None
+        self.set_attribute("creator_id", value)
+
+    @property
+    def name(self):
+        return self.get_attribute("name", self.default_attributes["name"])
+
+    @name.setter
+    def name(self, value):
+        self.set_attribute("name", value)
+
+    def save(self, *args, **kwargs):
+        if not self.creator:
+            if not getattr(self, "caller", None):
+                # caller must be set when creating a vCPE since it creates a slice
+                raise XOSProgrammingError("ONOSApp's self.caller was not set")
+            self.creator = self.caller
+            if not self.creator:
+                raise XOSProgrammingError("ONOSApp's self.creator was not set")
+
+        super(ONOSApp, self).save(*args, **kwargs)
+        model_policy_onos_app(self.pk)
+
+# TODO: Probably don't need this...
+def model_policy_onos_app(pk):
+    # TODO: this should be made in to a real model_policy
+    with transaction.atomic():
+        oa = ONOSApp.objects.select_for_update().filter(pk=pk)
+        if not oa:
+            return
+        oa = oa[0]
+        #oa.manage_container()
+
+
diff --git a/xos/services/onos/templates/onosadmin.html b/xos/services/onos/templates/onosadmin.html
new file mode 100644
index 0000000..1e8d42c
--- /dev/null
+++ b/xos/services/onos/templates/onosadmin.html
@@ -0,0 +1,6 @@
+<div class = "left-nav">
+<ul>
+<li><a href="/admin/onos/onosapp/">ONOS Apps</a></li>
+</ul>
+</div>
+
diff --git a/xos/tosca/custom_types/xos.m4 b/xos/tosca/custom_types/xos.m4
index 00805e7..3d766f1 100644
--- a/xos/tosca/custom_types/xos.m4
+++ b/xos/tosca/custom_types/xos.m4
@@ -89,6 +89,35 @@
         properties:
             xos_base_service_props
 
+    tosca.nodes.ONOSService:
+        derived_from: tosca.nodes.Root
+        description: >
+            ONOS Service
+        capabilities:
+            xos_base_service_caps
+        properties:
+            xos_base_service_props
+
+    tosca.nodes.ONOSApp:
+        derived_from: tosca.nodes.Root
+        description: >
+            An ONOS Application.
+        properties:
+            xos_base_tenant_props
+
+    tosca.nodes.ONOSvBNGApp:
+        derived_from: tosca.nodes.Root
+        description: >
+            An ONOS Application.
+        properties:
+            xos_base_tenant_props
+            config_addresses_json:
+                type: string
+                required: false
+            config_virtualbng_json:
+                type: string
+                required: false
+
     tosca.nodes.VCPEService:
         description: >
             CORD: The vCPE Service.
diff --git a/xos/tosca/custom_types/xos.yaml b/xos/tosca/custom_types/xos.yaml
index 2a904c1..97031a6 100644
--- a/xos/tosca/custom_types/xos.yaml
+++ b/xos/tosca/custom_types/xos.yaml
@@ -57,6 +57,78 @@
                 required: false
                 description: Version number of Service.
 
+    tosca.nodes.ONOSService:
+        derived_from: tosca.nodes.Root
+        description: >
+            ONOS Service
+        capabilities:
+            scalable:
+                type: tosca.capabilities.Scalable
+            service:
+                type: tosca.capabilities.xos.Service
+        properties:
+            kind:
+                type: string
+                default: generic
+                description: Type of service.
+            view_url:
+                type: string
+                required: false
+                description: URL to follow when icon is clicked in the Service Directory.
+            icon_url:
+                type: string
+                required: false
+                description: ICON to display in the Service Directory.
+            enabled:
+                type: boolean
+                default: true
+            published:
+                type: boolean
+                default: true
+                description: If True then display this Service in the Service Directory.
+            public_key:
+                type: string
+                required: false
+                description: Public key to install into Instances to allows Services to SSH into them.
+            versionNumber:
+                type: string
+                required: false
+                description: Version number of Service.
+
+    tosca.nodes.ONOSApp:
+        derived_from: tosca.nodes.Root
+        description: >
+            An ONOS Application.
+        properties:
+            kind:
+                type: string
+                default: generic
+                description: Kind of tenant
+            service_specific_id:
+                type: string
+                required: false
+                description: Service specific ID opaque to XOS but meaningful to service
+
+    tosca.nodes.ONOSvBNGApp:
+        derived_from: tosca.nodes.Root
+        description: >
+            An ONOS Application.
+        properties:
+            kind:
+                type: string
+                default: generic
+                description: Kind of tenant
+            service_specific_id:
+                type: string
+                required: false
+                description: Service specific ID opaque to XOS but meaningful to service
+            config_addresses_json:
+                type: string
+                required: false
+            config_virtualbng_json:
+                type: string
+                required: false
+
     tosca.nodes.VCPEService:
         description: >
             CORD: The vCPE Service.
diff --git a/xos/tosca/resources/onosapp.py b/xos/tosca/resources/onosapp.py
new file mode 100644
index 0000000..50af543
--- /dev/null
+++ b/xos/tosca/resources/onosapp.py
@@ -0,0 +1,57 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+import pdb
+
+from core.models import User, TenantAttribute
+from services.onos.models import ONOSApp, ONOSService
+
+from xosresource import XOSResource
+
+class XOSONOSApp(XOSResource):
+    provides = ["tosca.nodes.ONOSApp", "tosca.nodes.ONOSvBNGApp"]
+    xos_model = ONOSApp
+    copyin_props = ["service_specific_id"]
+
+    def get_xos_args(self, throw_exception=True):
+        args = super(XOSONOSApp, self).get_xos_args()
+
+        provider_name = self.get_requirement("tosca.relationships.TenantOfService", throw_exception=throw_exception)
+        if provider_name:
+            args["provider_service"] = self.get_xos_object(ONOSService, throw_exception=throw_exception, name=provider_name)
+
+        return args
+
+    def get_existing_objs(self):
+        objs = ONOSApp.get_tenant_objects().all()
+        objs = [x for x in objs if x.name == self.nodetemplate.name]
+        return objs
+
+    def set_tenant_attr(self, obj, prop_name, value):
+        value = self.try_intrinsic_function(value)
+        if value:
+            attrs = TenantAttribute.objects.filter(tenant=obj, name=prop_name)
+            if attrs:
+                attr = attrs[0]
+                if attr.value != value:
+                    self.info("updating attribute %s" % k)
+                    attrs.value = value
+                    attrs.save()
+            else:
+                self.info("adding attribute %s" % prop_name)
+                ta = TenantAttribute(tenant=obj, name=prop_name, value=value)
+                ta.save()
+
+    def postprocess(self, obj):
+        props = self.nodetemplate.get_properties()
+        for (k,d) in props.items():
+            v = d.value
+            if k.startswith("config_"):
+                self.set_tenant_attr(obj, k, v)
+
+    def can_delete(self, obj):
+        return super(XOSONOSApp, self).can_delete(obj)
+
diff --git a/xos/tosca/resources/onosservice.py b/xos/tosca/resources/onosservice.py
new file mode 100644
index 0000000..1275fab
--- /dev/null
+++ b/xos/tosca/resources/onosservice.py
@@ -0,0 +1,16 @@
+import os
+import pdb
+import sys
+import tempfile
+sys.path.append("/opt/tosca")
+from translator.toscalib.tosca_template import ToscaTemplate
+
+from services.onos.models import ONOSService
+
+from service import XOSService
+
+class XOSONOSService(XOSService):
+    provides = "tosca.nodes.ONOSService"
+    xos_model = ONOSService
+    copyin_props = ["view_url", "icon_url", "enabled", "published", "public_key", "versionNumber"]
+
diff --git a/xos/tosca/samples/onos.yaml b/xos/tosca/samples/onos.yaml
new file mode 100644
index 0000000..311819e
--- /dev/null
+++ b/xos/tosca/samples/onos.yaml
@@ -0,0 +1,54 @@
+tosca_definitions_version: tosca_simple_yaml_1_0
+
+description: Setup CORD-related services -- vOLT, vCPE, vBNG.
+
+imports:
+   - custom_types/xos.yaml
+
+topology_template:
+  node_templates:
+    ONOS:
+      type: tosca.nodes.ONOSService
+      requirements:
+      properties:
+          kind: onos
+          view_url: /admin/onos/onosservice/$id$/
+
+    vBNG:
+      type: tosca.nodes.ONOSvBNGApp
+      requirements:
+          - onos_tenant:
+              node: ONOS
+              relationship: tosca.relationships.TenantOfService
+      properties:
+          config_addresses_json: >
+            {
+                "addresses" : [

+                            {

+                                "dpid" : "00:00:00:00:00:00:00:a1",

+                                "port" : "2",

+                                "ips" : ["192.0.0.1/24"],

+                                "mac" : "00:00:00:00:00:99"

+

+                            },

+                            {

+                                "dpid" : "00:00:00:00:00:00:00:a5",

+                                "port" : "4",

+                                "ips" : ["200.0.0.5/24"],

+                                "mac" : "00:00:00:00:00:98"

+                            }

+                ]

+            }
+          config_virtualbng_json: >
+            {
+                "localPublicIpPrefixes" : [

+                    "200.0.0.0/32",

+                    "201.0.0.0/30",

+                    "202.0.0.0/30"

+                ],

+                "nextHopIpAddress" : "200.0.0.5",

+                "publicFacingMac" : "00:00:00:00:00:66",

+                "xosIpAddress" : "10.11.10.1",

+                "xosRestPort" : "9999"

+            }
+
diff --git a/xos/xos/settings.py b/xos/xos/settings.py
index eb6287f..ca0eced 100644
--- a/xos/xos/settings.py
+++ b/xos/xos/settings.py
@@ -9,7 +9,7 @@
 GEOIP_PATH = "/usr/share/GeoIP"
 XOS_DIR = "/opt/xos"
  
-DEBUG = False 
+DEBUG = True 
 TEMPLATE_DEBUG = DEBUG
 
 ADMINS = (
@@ -148,7 +148,11 @@
     'core',
     'hpc',
     'cord',
+<<<<<<< HEAD
     'helloworldservice',
+=======
+    'services.onos',
+>>>>>>> e4243b659f2285c47cc71779238e142b156c88c0
     'ceilometer',
     'requestrouter',
 #    'urlfilter',