[CORD-2639] Moving Progran to 5.0

Change-Id: Ia838ade6b7cd8e7b4c04ae939e27d5b2dbf16896
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..2ccedb2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+.idea/
+*.pyc
+
+# this folders are here in case you directly mount it inside the synchronzier container
+xos/synchronizer/ansible_runner
+xos/synchronizer/sys/
\ No newline at end of file
diff --git a/samples/README.md b/samples/README.md
new file mode 100644
index 0000000..d75b705
--- /dev/null
+++ b/samples/README.md
@@ -0,0 +1,29 @@
+# Samples
+
+This directory contains sample data to create Progran related models.
+
+## Example setup
+
+Create an IMSI:
+
+```bash
+bash progran-curl.sh mcord/mcordsubscriberinstances imsi.json
+```
+
+Create an enodeb:
+
+```bash
+bash progran-curl.sh progran/enodebs enodeb.json
+```
+
+Create an handover:
+
+```bash
+bash progran-curl.sh progran/handovers handover.json
+```
+
+Create a Profile: note that you'll need to replace `enodeb_id` and `handover_id` with existing values
+
+```bash
+bash progran-curl.sh progran/progranserviceinstances profile.json
+```
\ No newline at end of file
diff --git a/samples/docker-compose.yml b/samples/docker-compose.yml
new file mode 100644
index 0000000..eca4229
--- /dev/null
+++ b/samples/docker-compose.yml
@@ -0,0 +1,13 @@
+# Progran for docker-compose
+version: '2'
+
+services:
+   progran:
+      image: cemturker/prograncontrollermcord:0.1.2
+      ports:
+       - "221:22"
+       - "6655:6653"
+       - "8103:8101"
+       - "8183:8181"
+       - "9877:9876"
+       - "4010:4010"
diff --git a/samples/enodeb.json b/samples/enodeb.json
new file mode 100644
index 0000000..3c0dc67
--- /dev/null
+++ b/samples/enodeb.json
@@ -0,0 +1,5 @@
+{
+  "description":"test-enb",
+  "enbId":"123",
+  "ipAddr":"1.1.1.1"
+}
\ No newline at end of file
diff --git a/samples/handover.json b/samples/handover.json
new file mode 100644
index 0000000..798137b
--- /dev/null
+++ b/samples/handover.json
@@ -0,0 +1,10 @@
+{
+  "A3offset":2,
+  "A5Thresh1Rsrp":-97,
+  "A5Thresh1Rsrq":-10,
+  "A5Thresh2Rsrp":-95,
+  "A5Thresh2Rsrq":-8,
+  "A5TriggerType":0,
+  "HysteresisA3":1,
+  "HysteresisA5":1
+}
\ No newline at end of file
diff --git a/samples/imsi.json b/samples/imsi.json
new file mode 100644
index 0000000..ecc682b
--- /dev/null
+++ b/samples/imsi.json
@@ -0,0 +1,4 @@
+{
+  "apn_number":"123",
+  "imsi_number":"321"
+}
\ No newline at end of file
diff --git a/samples/profile.json b/samples/profile.json
new file mode 100644
index 0000000..eb39e1d
--- /dev/null
+++ b/samples/profile.json
@@ -0,0 +1,14 @@
+{
+  "id": 1,
+  "AdmControl":"0",
+  "DlSchedType":"RR",
+  "start":1516780800,
+  "UlSchedType":"RR",
+  "end":1517385600,
+  "CellIndividualOffset":1,
+  "DlAllocRBRate":1,
+  "name":"test-profile",
+  "UlAllocRBRate":12,
+  "enodeb_id":2,
+  "handover_id":1
+}
\ No newline at end of file
diff --git a/samples/progran-curl.sh b/samples/progran-curl.sh
new file mode 100644
index 0000000..7353fd0
--- /dev/null
+++ b/samples/progran-curl.sh
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+
+XOS_URL=127.0.0.1
+XOS_PORT=9101
+XOS_USERNAME=xosadmin@opencord.org
+XOS_PWD=ORR13pBZ8yrAZ42QiKhc
+
+echo Sending file $2 to url $XOS_URL:$XOS_PORT/xosapi/v1/$1
+
+curl -H "xos-username: $XOS_USERNAME" -H "xos-password: $XOS_PWD" -X POST --data-binary @$2 http://$XOS_URL:$XOS_PORT/xosapi/v1/$1
diff --git a/xos/api/service/progran.py b/xos/api/service/progran.py
deleted file mode 100644
index f8619e0..0000000
--- a/xos/api/service/progran.py
+++ /dev/null
@@ -1,99 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from rest_framework.decorators import api_view
-from rest_framework.response import Response
-from rest_framework.reverse import reverse
-from rest_framework import serializers
-from rest_framework import generics
-from rest_framework import status
-from core.models import *
-from django.forms import widgets
-from services.progran.models import *
-from xos.apibase import XOSListCreateAPIView, XOSRetrieveUpdateDestroyAPIView, XOSPermissionDenied
-from api.xosapi_helpers import PlusModelSerializer, XOSViewSet, ReadOnlyField
-import json
-
-BASE_NAME = 'progran'
-
-
-class VProgranProfileSerializer(PlusModelSerializer):
-    id = ReadOnlyField()
-    uiid = serializers.CharField(required=False)
-    profile = serializers.CharField(required=False)
-    dlrate = serializers.CharField(required=False)
-    ulrate = serializers.CharField(required=False)
-
-
-    class Meta:
-        model = VProgranProfile
-        fields = ('uiid','id', 'profile', 'dlrate' , 'ulrate')
-
-
-
-
-class VProgranImsiSerializer(PlusModelSerializer):
-    id = ReadOnlyField()
-    uiid = serializers.CharField(required=False)
-    imsi = serializers.CharField(required=False)
-    profile  = serializers.CharField(required=False)
-
-
-    class Meta:
-        model = VProgranImsi
-        fields = ('uiid','id', 'imsi', "profile")
-
-
-class ProgranProfileViewSet(XOSViewSet):
-    base_name = "progran"
-    method_name = "profile"
-    method_kind = "viewset"
-    queryset = VProgranProfile.objects.all()
-    serializer_class = VProgranProfileSerializer
-
-    @classmethod
-    def get_urlpatterns(self, api_path="^"):
-        patterns = super(ProgranProfileViewSet, self).get_urlpatterns(api_path=api_path)
-
-        return patterns
-
-    def list(self, request):
-        object_list = self.filter_queryset(self.get_queryset())
-
-        serializer = self.get_serializer(object_list, many=True)
-
-        return Response(serializer.data)
-
-
-class ProgranImsiViewSet(XOSViewSet):
-    base_name = "progran"
-    method_name = "imsi"
-    method_kind = "viewset"
-    queryset = VProgranImsi.objects.all()
-    serializer_class = VProgranImsiSerializer
-
-    @classmethod
-    def get_urlpatterns(self, api_path="^"):
-        patterns = super(ProgranImsiViewSet, self).get_urlpatterns(api_path=api_path)
-
-        return patterns
-
-    def list(self, request):
-        object_list = self.filter_queryset(self.get_queryset())
-
-        serializer = self.get_serializer(object_list, many=True)
-
-        return Response(serializer.data)
\ No newline at end of file
diff --git a/xos/models.py b/xos/models.py
deleted file mode 100644
index c85cded..0000000
--- a/xos/models.py
+++ /dev/null
@@ -1,107 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-from django.db import models
-from core.models import Service, XOSBase, Slice, Instance, Tenant, TenantWithContainer, Node, Image, User, Flavor, Subscriber, NetworkParameter, NetworkParameterType, Port, AddressPool
-from core.models.xosbase 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
-from core.models import Tag
-from core.models.service import LeastLoadedNodeScheduler
-import traceback
-from xos.exceptions import *
-from xos.config import Config
-
-
-class ConfigurationError(Exception):
-    pass
-
-
-PROGRAN_KIND = "Progran"
-APP_LABEL = "progran"
-
-
-
-class VProgranService(Service):
-    KIND = PROGRAN_KIND
-
-    class Meta:
-        app_label = APP_LABEL
-        verbose_name = "Progran Service"
-        proxy = True
-
-    default_attributes = {
-        "rest_hostname": "10.6.0.1",
-        "rest_port": "8183",
-        "rest_user": "onos",
-        "rest_pass": "rocks"
-    }
-
-    @property
-    def rest_hostname(self):
-        return self.get_attribute("rest_hostname", self.default_attributes["rest_hostname"])
-
-    @rest_hostname.setter
-    def rest_hostname(self, value):
-        self.set_attribute("rest_hostname", value)
-
-    @property
-    def rest_port(self):
-        return self.get_attribute("rest_port", self.default_attributes["rest_port"])
-
-    @rest_port.setter
-    def rest_port(self, value):
-        self.set_attribute("rest_port", value)
-
-    @property
-    def rest_user(self):
-        return self.get_attribute("rest_user", self.default_attributes["rest_user"])
-
-    @rest_user.setter
-    def rest_user(self, value):
-        self.set_attribute("rest_user", value)
-
-    @property
-    def rest_pass(self):
-        return self.get_attribute("rest_pass", self.default_attributes["rest_pass"])
-
-
-
-
-class VProgranImsi(XOSBase):
-    class Meta:
-        app_label = APP_LABEL
-        verbose_name = "vProgran Imsi"
-
-    uiid = models.IntegerField( help_text="uiid ", null=False, blank=False)
-    imsi = models.CharField(max_length=20, help_text="imsi ", null=False, blank=False)
-    profile = models.CharField(max_length=20, help_text="profile name", null=True, blank=True)
-
-
-class VProgranProfile(XOSBase):
-
-    class Meta:
-        app_label = APP_LABEL
-        verbose_name = "vProgran Profile"
-
-    uiid = models.IntegerField( help_text="uiid ", null=False, blank=False)
-    profile = models.CharField(max_length=20, help_text="profile name", null=False, blank=False)
-    dlrate = models.IntegerField( help_text="device download rate", null=False, blank=False)
-    ulrate = models.IntegerField( help_text="device upload rate", null=False, blank=False )
-
diff --git a/xos/models/models.py b/xos/models/models.py
new file mode 100644
index 0000000..2e7df7b
--- /dev/null
+++ b/xos/models/models.py
@@ -0,0 +1,60 @@
+from core.models import Service
+from xos.exceptions import XOSValidationError
+
+from models_decl import ProgranService_decl
+from models_decl import ENodeB_decl
+from models_decl import Handover_decl
+from models_decl import ProgranServiceInstance_decl
+
+
+
+
+
+
+
+class ProgranService(ProgranService_decl):
+    class Meta:
+        proxy = True
+
+
+class ENodeB(ENodeB_decl):
+    class Meta:
+        proxy = True
+
+
+class Handover(Handover_decl):
+    class Meta:
+        proxy = True
+
+
+class ProgranServiceInstance(ProgranServiceInstance_decl):
+    class Meta:
+        proxy = True
+
+    def save(self, *args, **kwargs):
+        # NOTE someone is setting owner_id, so just override it for now
+        # if not self.owner_id:
+        services = Service.objects.all()
+        services = [s for s in services if s.name.lower() == 'progran']
+
+        # NOTE select the correct owner
+        try:
+            progran_service = services[0]
+            self.owner_id = progran_service.id
+        except IndexError:
+            raise XOSValidationError("Service Progran cannot be found, please make sure that the model exists.")
+
+        # NOTE if the instance is new, check that the name is not duplicated
+        instances_with_same_name = None
+        if self.pk is None:
+            try:
+                instances_with_same_name = ProgranServiceInstance.objects.get(name=self.name)
+            except self.DoesNotExist:
+                # it's ok not to find anything here
+                pass
+
+        if instances_with_same_name:
+            raise XOSValidationError("A ProgranServiceInstance with name '%s' already exists" % self.name)
+        super(ProgranServiceInstance, self).save(*args, **kwargs)
+
+
diff --git a/xos/models/progran.xproto b/xos/models/progran.xproto
new file mode 100644
index 0000000..14206ac
--- /dev/null
+++ b/xos/models/progran.xproto
@@ -0,0 +1,50 @@
+option app_label = "progran";
+option name = "progran";
+option legacy = "True";
+
+message ProgranService (Service){
+    option verbose_name = "Progran Service";
+    required string onos_address = 1 [help_text = "Address of the progran ONOS", default = "onos-progran",  max_length = 254, null = False, db_index = False, blank = False];
+    required string onos_port = 2 [help_text = "Port of the progran ONOS", default = "8183", max_length = 254, null = False, db_index = False, blank = False];
+    required string onos_username = 3 [help_text = "Username of the progran ONOS", default = "karaf", max_length = 254, null = False, db_index = False, blank = False];
+    required string onos_password = 4 [help_text = "Password of the progran ONOS", default = "karaf", max_length = 254, null = False, db_index = False, blank = False];
+}
+
+message ENodeB (XOSBase){
+    option verbose_name = "eNodeB";
+    required string description = 1 [db_index = False, max_length = 256, null = False, blank = False];
+    required string enbId = 2 [help_text = "ID of this enodeb", db_index = False, max_length = 256, null = False, blank = False];
+    required string ipAddr = 3 [help_text = "IP address of this enodeb", db_index = False, max_length = 256, null = False, blank = False];
+}
+
+message Handover (XOSBase){
+    option verbose_name = "Handover";
+    required int32 A3offset = 1 [default = 2, db_index = False, null = False, blank = False];
+    required int32 HysteresisA3 = 2 [default = 1, db_index = False, null = False, blank = False];
+    required int32 A3TriggerQuantity = 3 [default = 0, db_index = False, null = False, blank = False];
+    required int32 A5TriggerType = 4 [default = 0, db_index = False, null = False, blank = False];
+    required int32 A5Thresh1Rsrp = 5 [default = -97, db_index = False, null = False, blank = False];
+    required int32 A5Thresh1Rsrq = 6 [default = -10, db_index = False, null = False, blank = False];
+    required int32 A5Thresh2Rsrp = 7 [default = -95, db_index = False, null = False, blank = False];
+    required int32 A5Thresh2Rsrq = 8 [default = -8, db_index = False, null = False, blank = False];
+    required int32 HysteresisA5 = 9 [default = 1, db_index = False, null = False, blank = False];
+    required int32 A5TriggerQuantity = 10 [default = 0, db_index = False, null = False, blank = False];
+}
+
+message ProgranServiceInstance (ServiceInstance){
+    option verbose_name = "Progran Service Instance";
+    option description = "Represent a Profile in the Progran ONOS Application";
+
+    required string DlSchedType = 1 [default = "vm", choices = "(('RR', 'Round Robin'),)", max_length = 30, blank = False, null = False, db_index = False];
+    required int32 DlAllocRBRate = 2 [db_index = False, null = False, blank = False];
+    required string UlSchedType = 3 [default = "vm", choices = "(('RR', 'Round Robin'),)", max_length = 30, blank = False, null = False, db_index = False];
+    required int32 UlAllocRBRate = 4 [db_index = False, null = False, blank = False];
+    required string start = 5 [content_type = "date", null = False, blank = True];
+    required string end = 6 [content_type = "date", null = False, blank = True];
+    required string AdmControl = 7 [default = "0", choices = "(('0', 'ALL'), ('1', 'Voice Only'), ('2', 'Data Only'))", max_length = 1, blank = False, null = False, db_index = False];
+    required int32 CellIndividualOffset = 8 [db_index = False, null = False, blank = False];
+    required manytoone enodeb->ENodeB:profiles = 9 [db_index = True, null = False, blank = False];
+    required manytoone handover->Handover:profiles = 10 [db_index = True, null = True, blank = False];
+}
+
+
diff --git a/xos/progran-onboard.yaml b/xos/progran-onboard.yaml
index 1135380..87424a3 100644
--- a/xos/progran-onboard.yaml
+++ b/xos/progran-onboard.yaml
@@ -29,10 +29,4 @@
           base_url: file:///opt/xos_services/progran/xos/
           # The following will concatenate with base_url automatically, if
           # base_url is non-null.
-          models: models.py
-          #admin: admin.py
-          #tosca_custom_types: progran.yaml
-          #tosca_resource: tosca/resources/progranservice.py
-          rest_service: api/service/progran.py
-          synchronizer: synchronizer/manifest
-          synchronizer_run: progran-synchronizer.py
+          xproto: models/
diff --git a/xos/progran.yaml b/xos/progran.yaml
deleted file mode 100644
index bd2f066..0000000
--- a/xos/progran.yaml
+++ /dev/null
@@ -1,289 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-tosca_definitions_version: tosca_simple_yaml_1_0
-
-# compile this with "m4 vrouter.m4 > vrouter.yaml"
-
-# include macros
-# Note: Tosca derived_from isn't working the way I think it should, it's not
-#    inheriting from the parent template. Until we get that figured out, use
-#    m4 macros do our inheritance
-
-
-# Service
-
-
-# Subscriber
-
-
-
-
-# end m4 macros
-
-
-
-node_types:
-
-    tosca.nodes.ProgranService:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The Progran Service.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            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.
-            private_key_fn:
-                type: string
-                required: false
-                description: Location of private key file
-            versionNumber:
-                type: string
-                required: false
-                description: Version number of Service.
-            rest_hostname:
-                type: string
-                required: false
-            rest_port:
-                type: string
-                required: false
-            rest_user:
-                type: string
-                required: false
-            rest_pass:
-                type: string
-                required: false
-
-    tosca.nodes.ProgranDevice:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The Progran Device.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            openflow_id:
-                type: string
-                required: true
-            config_key:
-                type: string
-                required: false
-            driver:
-                type: string
-                required: true
-
-    tosca.nodes.VRouterPort:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The vRouter Port.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            openflow_id:
-                type: string
-                required: true
-
-    tosca.nodes.VRouterInterface:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The vRouter Interface.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            name:
-                type: string
-                required: true
-            mac:
-                type: string
-                required: true
-            vlan:
-                type: string
-                required: false
-
-    tosca.nodes.VRouterIp:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The vRouter Ip.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            ip:
-                type: string
-                required: true
-
-    tosca.nodes.VRouterApp:
-        derived_from: tosca.nodes.Root
-        description: >
-            CORD: The vRouter ONOS App Config.
-        capabilities:
-            scalable:
-                type: tosca.capabilities.Scalable
-            service:
-                type: tosca.capabilities.xos.Service
-        properties:
-            no-delete:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to delete this object
-            no-create:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to create this object
-            no-update:
-                type: boolean
-                default: false
-                description: Do not allow Tosca to update this object
-            replaces:
-                type: string
-                required: false
-                descrption: Replaces/renames this object
-            name:
-                type: string
-                required: true
-            control_plane_connect_point:
-                type: string
-                required: true
-            ospf_enabled:
-                type: boolean
-                required: true
-
-    tosca.relationships.PortOfDevice:
-            derived_from: tosca.relationships.Root
-            valid_target_types: [ tosca.capabilities.xos.VRouterPort ]
-
-    tosca.relationships.InterfaceOfPort:
-            derived_from: tosca.relationships.Root
-            valid_target_types: [ tosca.capabilities.xos.VRouterInterface ]
-
-    tosca.relationships.IpOfInterface:
-            derived_from: tosca.relationships.Root
-            valid_target_types: [ tosca.capabilities.xos.VRouterIp ]
diff --git a/xos/synchronizer/Dockerfile.synchronizer b/xos/synchronizer/Dockerfile.synchronizer
new file mode 100644
index 0000000..b0c967c
--- /dev/null
+++ b/xos/synchronizer/Dockerfile.synchronizer
@@ -0,0 +1,59 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# docker build -t xosproject/progran-synchronizer:candidate -f Dockerfile.synchronizer .
+
+# xosproject/progran-synchronizer
+
+FROM xosproject/xos-synchronizer-base:candidate
+
+COPY . /opt/xos/synchronizers/progran
+
+ENTRYPOINT []
+
+WORKDIR "/opt/xos/synchronizers/progran"
+
+# Label image
+ARG org_label_schema_schema_version=1.0
+ARG org_label_schema_name=progran-synchronizer
+ARG org_label_schema_version=unknown
+ARG org_label_schema_vcs_url=unknown
+ARG org_label_schema_vcs_ref=unknown
+ARG org_label_schema_build_date=unknown
+ARG org_opencord_vcs_commit_date=unknown
+ARG org_opencord_component_chameleon_version=unknown
+ARG org_opencord_component_chameleon_vcs_url=unknown
+ARG org_opencord_component_chameleon_vcs_ref=unknown
+ARG org_opencord_component_xos_version=unknown
+ARG org_opencord_component_xos_vcs_url=unknown
+ARG org_opencord_component_xos_vcs_ref=unknown
+
+LABEL org.label-schema.schema-version=$org_label_schema_schema_version \
+      org.label-schema.name=$org_label_schema_name \
+      org.label-schema.version=$org_label_schema_version \
+      org.label-schema.vcs-url=$org_label_schema_vcs_url \
+      org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
+      org.label-schema.build-date=$org_label_schema_build_date \
+      org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
+      org.opencord.component.chameleon.version=$org_opencord_component_chameleon_version \
+      org.opencord.component.chameleon.vcs-url=$org_opencord_component_chameleon_vcs_url \
+      org.opencord.component.chameleon.vcs-ref=$org_opencord_component_chameleon_vcs_ref \
+      org.opencord.component.xos.version=$org_opencord_component_xos_version \
+      org.opencord.component.xos.vcs-url=$org_opencord_component_xos_vcs_url \
+      org.opencord.component.xos.vcs-ref=$org_opencord_component_xos_vcs_ref
+
+CMD bash -c "service filebeat start; cd /opt/xos/synchronizers/progran; ./run.sh"
+
diff --git a/xos/synchronizer/curl_sample.md b/xos/synchronizer/curl_sample.md
deleted file mode 100644
index d5c59d2..0000000
--- a/xos/synchronizer/curl_sample.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# Progran App
-
-
-## Add Profile
-`curl --user onos:rocks -v -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data '{"Name":"mme2","DlSchedType":"RR","UlSchedType":"RR","DlAllocRBRate":0,"UlAllocRBRate":0,"CellIndividualOffset":1,"AdmControl":0,"MMECfg":{"IPAddr":"10.10.2.7","Port":36412},"DlWifiRate":0,"Handover":{"A3Hysteresis":1,"A3TriggerQuantity":0,"A3offset":0,"A5Hysteresis":1,"A5Thresh1Rsrp":80,"A5Thresh1Rsrq":20,"A5Thresh2Rsrp":90,"A5Thresh2Rsrq":20,"A5TriggerQuantity":0},"Start":"","End":"","Status":1}' http://onos-fabric:8183/onos/progran/profile`
-
-
-## Add imsi to profile
-`curl --user onos:rocks -H "Content-Type: application/json" -X POST -d '{"profile":"slice1", "imsi": "1111111"}'  http://onos-fabric:8183/onos/progran/mwc/connect`
-
-## Update profile
-`curl --user onos:rocks -H "Content-Type: application/json" -X POST -d '{"profile":"slice2", "ul": "20","dl":"20"}'  http://onos-fabric:8183/onos/progran/mwc/profile`
-
-## Update Profile
-`curl --user onos:rocks -v -H "Accept: application/json" -H "Content-Type: application/json" -X GET --data ' http://onos-fabric:8183/onos/progran/mwc/list`
-
-
-
-post
-/mwc/profile
-/mwc/connect
-
-get
-/mwc/list
-
-
-curl --user onos:rocks -H "Content-Type: application/json" -X POST -d '{"profile":"slice1", "imsi": "12345678"}'  http://10.1.8.65:8181/onos/progran/mwc/connect
-
-
-curl  -sSL --user onos:rocks  -H "Accept: application/json" -H "Content-Type: application/json" -X POST --data '{"IMSI":"001010000000343"}' http://10.1.8.65:8181/onos/progran/imsi
diff --git a/xos/synchronizer/manifest b/xos/synchronizer/manifest
deleted file mode 100644
index 898c164..0000000
--- a/xos/synchronizer/manifest
+++ /dev/null
@@ -1,7 +0,0 @@
-manifest
-model_deps
-run.sh
-steps/sync_imsi.py
-steps/sync_profile.py
-progran-synchronizer.py
-progran_config
diff --git a/xos/synchronizer/progran-synchronizer.py b/xos/synchronizer/progran-synchronizer.py
index 9219702..9632c8e 100644
--- a/xos/synchronizer/progran-synchronizer.py
+++ b/xos/synchronizer/progran-synchronizer.py
@@ -21,9 +21,13 @@
 import importlib
 import os
 import sys
+from xosconfig import Config
+
+config_file = os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + '/progran_config.yml')
+Config.init(config_file, 'synchronizer-config-schema.yaml')
 
 synchronizer_path = os.path.join(os.path.dirname(
-    os.path.realpath(__file__)), "../../synchronizers/base")
+    os.path.realpath(__file__)), "../../synchronizers/new_base")
 sys.path.append(synchronizer_path)
 mod = importlib.import_module("xos-synchronizer")
 mod.main()
diff --git a/xos/synchronizer/progran_config b/xos/synchronizer/progran_config
deleted file mode 100644
index 99d382f..0000000
--- a/xos/synchronizer/progran_config
+++ /dev/null
@@ -1,23 +0,0 @@
-# Required by XOS
-[db]
-name=xos
-user=postgres
-password=password
-host=xos_db
-port=5432
-
-# Required by XOS
-[api]
-nova_enabled=True
-
-# Sets options for the synchronizer
-[observer]
-name=progran
-dependency_graph=/opt/xos/synchronizers/progran/model_deps
-steps_dir=/opt/xos/synchronizers/progran/steps
-sys_dir=/opt/xos/synchronizers/progran/sys
-logfile=/var/log/xos_backend.log
-pretend=False
-backoff_disabled=True
-save_ansible_output=True
-proxy_ssh=False
diff --git a/xos/synchronizer/progran_config.yml b/xos/synchronizer/progran_config.yml
new file mode 100644
index 0000000..a624152
--- /dev/null
+++ b/xos/synchronizer/progran_config.yml
@@ -0,0 +1,50 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+name: progran
+accessor:
+  username: xosadmin@opencord.org
+  password: "@/opt/xos/services/progran/credentials/xosadmin@opencord.org"
+required_models:
+  - ProgranService
+  - ProgranServiceInstance
+  - MCordSubscriberInstance
+  - ENodeB
+  - Handover
+dependency_graph: "/opt/xos/synchronizers/progran/model_deps"
+steps_dir: "/opt/xos/synchronizers/progran/steps"
+sys_dir: "/opt/xos/synchronizers/progran/sys"
+# model_policies_dir: "/opt/xos/synchronizers/progran/model_policies"
+
+
+keep_temp_files: True
+
+logging:
+  version: 1
+  handlers:
+    console:
+      class: logging.StreamHandler
+    file:
+      class: logging.handlers.RotatingFileHandler
+      filename: /var/log/xos.log
+      maxBytes: 10485760
+      backupCount: 5
+  loggers:
+    '':
+      handlers:
+          - console
+          - file
+      level: DEBUG
\ No newline at end of file
diff --git a/xos/synchronizer/run.sh b/xos/synchronizer/run.sh
old mode 100644
new mode 100755
index a59b98d..63c8460
--- a/xos/synchronizer/run.sh
+++ b/xos/synchronizer/run.sh
@@ -14,5 +14,4 @@
 # limitations under the License.
 
 
-export XOS_DIR=/opt/xos
-python progran-synchronizer.py  -C $XOS_DIR/synchronizers/progran/progran_config
+python progran-synchronizer.py
diff --git a/xos/synchronizer/steps/progran_curl.yaml b/xos/synchronizer/steps/progran_curl.yaml
new file mode 100644
index 0000000..f567a3b
--- /dev/null
+++ b/xos/synchronizer/steps/progran_curl.yaml
@@ -0,0 +1,37 @@
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+---
+- hosts: 127.0.0.1
+  connection: local
+  vars:
+    - profile: '{{ profile }}'
+    - endpoint: '{{ endpoint }}'
+
+  tasks:
+    - debug:
+        msg: "{{ '{{' }} profile {{ '}}' }}"
+    # NOTE that the task has a generic name as it's planned to be used for all the requests
+    - name: Call onos Progran
+      uri:
+        url: "http://{{ onos_url }}:{{ onos_port }}/onos/progran/{{ '{{' }} endpoint {{ '}}' }}"
+        method: "{{ method }}"
+        user: "{{ onos_username }}"
+        password: "{{ onos_password }}"
+        force_basic_auth: yes
+        status_code: 200
+        {% if method == "POST" or method == "PUT" -%}
+        body: "{{ '{{' }} profile {{ '}}' }}"
+        body_format: json
+        {%- endif -%}
diff --git a/xos/synchronizer/steps/sync_imsi.py b/xos/synchronizer/steps/sync_imsi.py
deleted file mode 100644
index 0149702..0000000
--- a/xos/synchronizer/steps/sync_imsi.py
+++ /dev/null
@@ -1,76 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-import os
-import sys
-import requests
-import json
-from django.db.models import Q, F
-from services.progran.models import *
-from synchronizers.base.syncstep import SyncStep
-from xos.logger import Logger, logging
-
-# from core.models import Service
-from requests.auth import HTTPBasicAuth
-
-parentdir = os.path.join(os.path.dirname(__file__), "..")
-sys.path.insert(0, parentdir)
-
-logger = Logger(level=logging.INFO)
-
-
-class SyncVImsiApp(SyncStep):
-    provides = [VProgranImsi]
-
-    observes = VProgranImsi
-
-    requested_interval = 0
-
-    def __init__(self, *args, **kwargs):
-        super(SyncVImsiApp, self).__init__(*args, **kwargs)
-
-    def get_onos_progran_addr(self):
-
-        return "http://%s:%s/onos/" % ("10.6.0.1", "8183")
-
-    def get_onos_progran_auth(self):
-
-        return HTTPBasicAuth("onos", "rocks")
-
-    def sync_record(self, app):
-
-        logger.info("Sync'ing Edited vProgran Imsi")
-
-        onos_addr = self.get_onos_progran_addr()
-
-        data = {}
-        data["imsi"] = app.imsi
-        data["profile"] = app.profile
-
-
-        url = onos_addr + "progran/mwc/connect"
-
-        print "POST %s for app %s" % (url, "Progran Imsi")
-
-        auth = self.get_onos_progran_auth()
-        r = requests.post(url, data=json.dumps(data), auth=auth)
-        if (r.status_code != 200):
-            print r
-            raise Exception("Received error from progran app update (%d)" % r.status_code)
-
-    def delete_record(self, app):
-        logger.info("Deletion is not supported yet")
-
diff --git a/xos/synchronizer/steps/sync_profile.py b/xos/synchronizer/steps/sync_profile.py
deleted file mode 100644
index 68c144d..0000000
--- a/xos/synchronizer/steps/sync_profile.py
+++ /dev/null
@@ -1,77 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-import os
-import sys
-import requests
-import json
-from django.db.models import Q, F
-from services.progran.models import *
-from synchronizers.base.syncstep import SyncStep
-from xos.logger import Logger, logging
-
-# from core.models import Service
-from requests.auth import HTTPBasicAuth
-
-parentdir = os.path.join(os.path.dirname(__file__), "..")
-sys.path.insert(0, parentdir)
-
-logger = Logger(level=logging.INFO)
-
-
-class SyncVProfileApp(SyncStep):
-    provides = [VProgranProfile]
-
-    observes = VProgranProfile
-
-    requested_interval = 0
-
-    def __init__(self, *args, **kwargs):
-        super(SyncVProfileApp, self).__init__(*args, **kwargs)
-
-    def get_onos_progran_addr(self):
-
-        return "http://%s:%s/onos/" % ("10.6.0.1", "8183")
-
-    def get_onos_progran_auth(self):
-
-        return HTTPBasicAuth("onos", "rocks")
-
-    def sync_record(self, app):
-
-        logger.info("Sync'ing Edited vProgran Profile ")
-
-        onos_addr = self.get_onos_progran_addr()
-
-        data = {}
-        data["profile"] = app.profile
-        data["dlrate"] = app.dlrate
-        data["ulrate"] = app.ulrate
-
-
-        url = onos_addr + "progran/mwc/profile"
-
-        print "POST %s for app %s" % (url, "Progran Imsi")
-
-        auth = self.get_onos_progran_auth()
-        r = requests.post(url, data=json.dumps(data), auth=auth)
-        if (r.status_code != 200):
-            print r
-            raise Exception("Received error from progran app update (%d)" % r.status_code)
-
-    def delete_record(self, app):
-        logger.info("Deletion is not supported yet")
-
diff --git a/xos/synchronizer/steps/sync_progranserviceinstance.py b/xos/synchronizer/steps/sync_progranserviceinstance.py
new file mode 100644
index 0000000..6a0d84c
--- /dev/null
+++ b/xos/synchronizer/steps/sync_progranserviceinstance.py
@@ -0,0 +1,114 @@
+
+# Copyright 2017-present Open Networking Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+import os
+import sys
+from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
+from synchronizers.new_base.ansible_helper import run_template
+from synchronizers.new_base.modelaccessor import ProgranService, ProgranServiceInstance
+
+from xosconfig import Config
+from multistructlog import create_logger
+import json
+
+log = create_logger(Config().get('logging'))
+
+parentdir = os.path.join(os.path.dirname(__file__), "..")
+sys.path.insert(0, parentdir)
+
+class SyncProgranServiceInstance(SyncInstanceUsingAnsible):
+    provides = [ProgranServiceInstance]
+
+    observes = ProgranServiceInstance
+
+    def get_onos_info(self, si):
+
+        progran_service = si.owner.leaf_model
+
+        return {
+            'url': progran_service.onos_address,
+            'port': progran_service.onos_port,
+            'username': progran_service.onos_username,
+            'password': progran_service.onos_password,
+        }
+
+    def skip_ansible_fields(self, o):
+        # FIXME This model does not have an instance, this is a workaroung to make it work,
+        # but it need to be cleaned up creating a general SyncUsingAnsible base class
+        return True
+
+    def get_handover_for_profile(self, o):
+        return {
+            "A3Hysteresis": o.handover.HysteresisA3,
+            "A3TriggerQuantity": o.handover.A3TriggerQuantity,
+            "A3offset": o.handover.A3offset,
+            "A5Hysteresis": o.handover.HysteresisA5,
+            "A5Thresh1Rsrp": o.handover.A5Thresh1Rsrp,
+            "A5Thresh1Rsrq": o.handover.A5Thresh1Rsrq,
+            "A5Thresh2Rsrp": o.handover.A5Thresh2Rsrp,
+            "A5Thresh2Rsrq": o.handover.A5Thresh2Rsrq,
+            "A5TriggerQuantity": o.handover.A5TriggerQuantity,
+        }
+
+    def get_progran_profile_field(self, o):
+
+        # basic information that we have in the service instance itself
+        profile = {
+            'AdmControl': o.AdmControl,
+            "DlSchedType": o.DlSchedType,
+            "Start": o.start,
+            "UlSchedType": o.UlSchedType,
+            "End": o.end,
+            "CellIndividualOffset": o.CellIndividualOffset,
+            "DlAllocRBRate": o.DlAllocRBRate,
+            "Name": o.name,
+            "UlAllocRBRate": o.UlAllocRBRate,
+            "Handover": self.get_handover_for_profile(o),
+        }
+        profile = json.dumps(profile)
+        return profile
+
+    def get_extra_attributes(self, o):
+        onos = self.get_onos_info(o)
+        fields = {
+            'onos_url': onos['url'],
+            'onos_username': onos['username'],
+            'onos_password': onos['password'],
+            'onos_port': onos['port'],
+            'endpoint': 'profile',
+            'profile': self.get_progran_profile_field(o),
+            'method': 'POST'
+        }
+
+        return fields
+
+    # FIXME we need to override this as the default expect to ssh into a VM
+    def run_playbook(self, o, fields):
+        run_template("progran_curl.yaml", fields, object=o)
+
+    def delete_record(self, o):
+        log.info("deleting object", object=str(o), **o.tologdict())
+        onos = self.get_onos_info(o)
+        fields = {
+            'onos_url': onos['url'],
+            'onos_username': onos['username'],
+            'onos_password': onos['password'],
+            'onos_port': onos['port'],
+            'endpoint': 'profile/%s' % o.name,
+            'profile': '',
+            'method': 'DELETE'
+        }
+        res = self.run_playbook(o, fields)
\ No newline at end of file
diff --git a/xos/synchronizer/xos-synchronizer b/xos/synchronizer/xos-synchronizer
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/xos/synchronizer/xos-synchronizer
diff --git a/xos/tosca/resources/progranservice.py b/xos/tosca/resources/progranservice.py
deleted file mode 100644
index d4e8062..0000000
--- a/xos/tosca/resources/progranservice.py
+++ /dev/null
@@ -1,16 +0,0 @@
-
-# Copyright 2017-present Open Networking Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-