SEBA-122
bin/client is now cmdline app, tosca is sent to xos

Change-Id: I7bbf59569b5c96062aa1c7681708a4cf39532ae2
diff --git a/models/abstract/ChassisUtils.go b/models/abstract/ChassisUtils.go
index 2377453..5e38890 100644
--- a/models/abstract/ChassisUtils.go
+++ b/models/abstract/ChassisUtils.go
@@ -19,8 +19,8 @@
 /*
 GenerateChassis - constructs a new AbstractOLT Chassis
 */
-func GenerateChassis(CLLI string) *Chassis {
-	chassis := Chassis{CLLI: CLLI}
+func GenerateChassis(CLLI string, rack int, shelf int) *Chassis {
+	chassis := Chassis{CLLI: CLLI, Rack: rack, Shelf: shelf}
 
 	var slots [16]Slot
 	for i := 0; i < 16; i++ {
@@ -32,11 +32,11 @@
 }
 
 func generateSlot(n int, c *Chassis) Slot {
-	slot := Slot{Number: n, Parent: c}
+	slot := Slot{Number: n + 3, Parent: c}
 
 	var ports [16]Port
 	for i := 0; i < 16; i++ {
-		ports[i] = generatePort(i, &slot)
+		ports[i] = generatePort(i+1, &slot)
 	}
 
 	slot.Ports = ports
@@ -46,10 +46,11 @@
 	port := Port{Number: n, Parent: s}
 
 	var onts [64]Ont
-	for i := 0; i < 64; i++ {
+	//i starts with 1 because :P Architects - blah
+	for i := 1; i < 65; i++ {
 		/* adding one because the system that provisions is 1 based on everything not 0 based*/
-		onts[i] = Ont{Number: i, Svlan: calculateSvlan(s.Number+1, n+1, i+1),
-			Cvlan: calculateCvlan(s.Number+1, n+1, i+1), Parent: &port}
+		onts[i-1] = Ont{Number: i, Svlan: calculateSvlan(s.Number, n, i),
+			Cvlan: calculateCvlan(s.Number, n, i+1), Parent: &port}
 	}
 
 	port.Onts = onts
@@ -61,8 +62,7 @@
 	ontSlotOffset := 12  //= Max(ONT_PORT) = 12
 	vlanOffset := 1      //(VID 1 is reserved)
 
-	cVid := ((ont-1)%32)*ontPortOffset +
-		(slot-1)*ontSlotOffset + port + vlanOffset
+	cVid := ((ont-2)%32)*ontPortOffset + (slot-3)*ontSlotOffset + port + vlanOffset
 
 	return cVid
 }
@@ -71,8 +71,7 @@
 	ltSlotOffset := 16
 	vlanGap := 288  // Max(LT_SLOT) * Max(ltSlotOffset) = 18 * 16 = 288
 	vlanOffset := 1 //(VID 1 is reserved)
-
-	sVid := ((slot-1)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset
+	sVid := ((slot-3)*ltSlotOffset + port) + ((ont-1)/32)*vlanGap + vlanOffset
 
 	return sVid
 }
diff --git a/models/abstract/ChassisUtils_test.go b/models/abstract/ChassisUtils_test.go
index ecc5752..d6043f4 100644
--- a/models/abstract/ChassisUtils_test.go
+++ b/models/abstract/ChassisUtils_test.go
@@ -23,17 +23,16 @@
 )
 
 func TestChassisUtils_GenerateChassis(t *testing.T) {
-	chassis := abstract.GenerateChassis("MY_CLLI")
+	chassis := abstract.GenerateChassis("MY_CLLI", 1, 1)
 	slot := chassis.Slots[6]
 	port := slot.Ports[0]
 	ont := port.Onts[3]
 	svlan := ont.Svlan
 	cvlan := ont.Cvlan
 	if svlan != 98 { // see map doc
-		t.Fail()
+		t.Errorf("SVlan should be 98 and is %d\n", svlan)
 	}
 	if cvlan != 434 { // see map doc
-		t.Fail()
+		t.Errorf("CVlan should be 434 and is %d\n", cvlan)
 	}
-
 }
diff --git a/models/abstract/chassis.go b/models/abstract/chassis.go
index 687ecae..06e0002 100644
--- a/models/abstract/chassis.go
+++ b/models/abstract/chassis.go
@@ -16,7 +16,10 @@
 
 package abstract
 
-import "errors"
+import (
+	"errors"
+	"fmt"
+)
 
 const MAX_SLOTS int = 16
 const MAX_PORTS int = 16
@@ -27,6 +30,8 @@
 type Chassis struct {
 	CLLI      string
 	Slots     [16]Slot
+	Rack      int
+	Shelf     int
 	AllocInfo PortAllocationInfo
 }
 
@@ -59,6 +64,7 @@
 	return nextPort, nil
 }
 func (chassis *Chassis) ActivateONT(slotNumber int, portNumber int, ontNumber int, serialNumber string) error {
+	fmt.Printf("chassis.ActivateONT(slot:%d,portNumber:%d,ontNumber:%d,serialNumber:%s\n", slotNumber, portNumber, ontNumber, serialNumber)
 	err := chassis.Slots[slotNumber-1].Ports[portNumber-1].provisionOnt(ontNumber, serialNumber)
 	return err
 }
diff --git a/models/abstract/port.go b/models/abstract/port.go
index 2c2e07c..e626e7c 100644
--- a/models/abstract/port.go
+++ b/models/abstract/port.go
@@ -49,15 +49,22 @@
 	return fmt.Sprintf("Port %d for olt %d on AbstractChasis  %s is not provisioned", e.portNum, e.oltNum, e.clli)
 }
 func (port *Port) provisionOnt(ontNumber int, serialNumber string) error {
+
+	fmt.Printf("My Number:%d abstract.port.provisionOnt(ontNumber:%d,serialNumber:%s\n", port.Number, ontNumber, serialNumber)
+	slot := port.Parent
+	chassis := *slot.Parent
+	baseID := fmt.Sprintf("%d/%d/%d/%d:%d.1.1", chassis.Rack, chassis.Shelf, slot.Number, port.Number, ontNumber)
+	nasPortID := fmt.Sprintf("PON %s", baseID)
+	circuitID := fmt.Sprintf("%s %s", chassis.CLLI, baseID)
+
 	if port.PhysPort == nil {
-		slot := port.Parent
 		chassis := slot.Parent
 		err := UnprovisonedPortError{oltNum: slot.Number, clli: chassis.CLLI, portNum: port.Number}
 		return &err
 	}
 	phyPort := port.PhysPort
 	ont := port.Onts[ontNumber-1]
-	err := phyPort.ActivateOnt(ontNumber, ont.Svlan, ont.Cvlan, serialNumber)
+	err := phyPort.ActivateOnt(ontNumber, ont.Svlan, ont.Cvlan, serialNumber, nasPortID, circuitID)
 	return err
 }
 func (port *Port) deleteOnt(ontNumber int, serialNumber string) error {
diff --git a/models/physical/chassis.go b/models/physical/chassis.go
index 705de80..4e0c4da 100644
--- a/models/physical/chassis.go
+++ b/models/physical/chassis.go
@@ -19,6 +19,10 @@
 import (
 	"fmt"
 	"net"
+	"net/http"
+	"strings"
+
+	"gerrit.opencord.org/abstract-olt/models/tosca"
 )
 
 /*
@@ -29,6 +33,8 @@
 	VCoreAddress net.TCPAddr
 	Dataswitch   DataSwitch
 	Linecards    []OLT
+	Rack         int
+	Shelf        int
 }
 type UnprovisionedSlotError struct {
 	CLLI       string
@@ -46,10 +52,59 @@
 	chassis.Linecards = append(chassis.Linecards, olt)
 	//TODO - api call to add olt i.e. preprovision_olt
 	fmt.Printf("chassis.AddOLTChassis(%s)\n", olt.GetHostname())
+	//S>103 func NewOltProvision(name string, deviceType string, host string, port int) OltProvsion {
+	ipString := olt.GetAddress().IP.String()
+	webServerPort := olt.GetAddress().Port
+	oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort)
+	yaml, _ := oltStruct.ToYaml()
+	fmt.Printf("yaml:%s\n", yaml)
+	client := &http.Client{}
+	requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port)
+	req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
+	req.Header.Add("xos-username", "admin@opencord.org")
+	req.Header.Add("xos-password", "letmein")
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Printf("ERROR :) %v\n", err)
+		// handle error
+	}
+	fmt.Printf("Response is %v\n", resp)
+
 }
 func (chassis *Chassis) provisionONT(ont Ont) {
 	//TODO - api call to provison s/c vlans and ont serial number etc
 	fmt.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
+	ponPort := ont.Parent
+	slot := ponPort.Parent
+
+	//func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
+	ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number)
+	yaml, _ := ontStruct.ToYaml()
+
+	fmt.Printf("yaml:%s\n", yaml)
+	client := &http.Client{}
+	requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port)
+	req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml))
+	req.Header.Add("xos-username", "admin@opencord.org")
+	req.Header.Add("xos-password", "letmein")
+	resp, err := client.Do(req)
+	if err != nil {
+		fmt.Printf("ERROR :) %v\n", err)
+		// handle error
+	}
+	fmt.Printf("Response is %v\n", resp)
+	rgName := fmt.Sprintf("%s_%d_%d_%d_RG", chassis.CLLI, slot.Number, ponPort.Number, ont.Number)
+	subStruct := tosca.NewSubscriberProvision(rgName, ont.Cvlan, ont.Svlan, ont.SerialNumber, ont.NasPortID, ont.CircuitID, chassis.CLLI)
+	yaml, _ = subStruct.ToYaml()
+	fmt.Printf("yaml:%s\n", yaml)
+	req, err = http.NewRequest("POST", requestList, strings.NewReader(yaml))
+	req.Header.Add("xos-username", "admin@opencord.org")
+	req.Header.Add("xos-password", "letmein")
+	resp, err = client.Do(req)
+	if err != nil {
+		fmt.Printf("ERROR :) %v\n", err)
+		// handle error
+	}
 }
 func (chassis *Chassis) deleteONT(ont Ont) {
 	//TODO - api call to provison s/c vlans and ont serial number etc
diff --git a/models/physical/ont.go b/models/physical/ont.go
index 3e5e659..79c21ee 100644
--- a/models/physical/ont.go
+++ b/models/physical/ont.go
@@ -26,4 +26,6 @@
 	SerialNumber string
 	Parent       *PONPort `json:"-"`
 	Active       bool
+	NasPortID    string
+	CircuitID    string
 }
diff --git a/models/physical/ponport.go b/models/physical/ponport.go
index 15b7328..ca321fd 100644
--- a/models/physical/ponport.go
+++ b/models/physical/ponport.go
@@ -16,7 +16,9 @@
 
 package physical
 
-import "fmt"
+import (
+	"fmt"
+)
 
 /*
 PONPort represents a single PON port on the OLT chassis
@@ -65,7 +67,7 @@
 /*
 ActivateOnt - passes ont information to chassis to make call to NEM to activate (whitelist) ont
 */
-func (port *PONPort) ActivateOnt(number int, sVlan int, cVlan int, serialNumber string) error {
+func (port *PONPort) ActivateOnt(number int, sVlan int, cVlan int, serialNumber string, nasPortID string, circuitID string) error {
 	slot := port.Parent
 	chassis := slot.Parent
 	fmt.Printf("Calling ActivateOnt and port state is %t\n", port.Onts[number-1].Active)
@@ -74,7 +76,7 @@
 		e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
 		return &e
 	}
-	ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port}
+	ont := Ont{Number: number, Svlan: sVlan, Cvlan: cVlan, SerialNumber: serialNumber, Parent: port, NasPortID: nasPortID, CircuitID: circuitID}
 	port.Onts[number-1] = ont
 	port.Parent.Parent.provisionONT(ont)
 	port.Onts[number-1].Active = true
diff --git a/models/tosca/addOlt.go b/models/tosca/addOlt.go
new file mode 100644
index 0000000..0005800
--- /dev/null
+++ b/models/tosca/addOlt.go
@@ -0,0 +1,124 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+package tosca
+
+import (
+	"log"
+
+	yaml "gopkg.in/yaml.v2"
+)
+
+var templateData = `
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+  - custom_types/oltdevice.yaml
+  - custom_types/onudevice.yaml
+  - custom_types/ponport.yaml
+  - custom_types/voltservice.yaml
+description: Create a simulated OLT Device in VOLTHA
+topology_template:
+  node_templates:
+      service#volt:
+        type: tosca.nodes.VOLTService
+        properties:
+          name: volt
+          must-exist: true
+      olt_device:
+        type: tosca.nodes.OLTDevice
+        properties:
+           name: test
+           type: test
+           host: test
+           port: 32
+           outer_tpid: "0x8100"
+           uplink: "65536"
+           nas_id:
+        requirements:
+          - volt_service:
+              node: service#volt
+              relationship: tosca.relationships.BelongsToOne
+`
+
+type OltProvsion struct {
+	ToscaDefinitionsVersion string   `yaml:"tosca_definitions_version"`
+	Imports                 []string `yaml:"imports"`
+	Description             string   `yaml:"description"`
+	TopologyTemplate        struct {
+		NodeTemplates struct {
+			ServiceVolt struct {
+				Type       string `yaml:"type"`
+				Properties struct {
+					Name      string `yaml:"name"`
+					MustExist bool   `yaml:"must-exist"`
+				} `yaml:"properties"`
+			} `yaml:"service#volt"`
+			OltDevice struct {
+				DeviceType string `yaml:"type"`
+				Properties struct {
+					Name      string `yaml:"name"`
+					Type      string `yaml:"device_type"`
+					Host      string `yaml:"host"`
+					Port      int    `yaml:"port"`
+					OuterTpid string `yaml:"outer_tpid"`
+					Uplink    string `yaml:"uplink"`
+					NasID     string `yaml:"nas_id"`
+				} `yaml:"properties"`
+				Requirements []struct {
+					VoltService struct {
+						Node         string `yaml:"node"`
+						Relationship string `yaml:"relationship"`
+					} `yaml:"volt_service"`
+				} `yaml:"requirements"`
+			} `yaml:"olt_device"`
+		} `yaml:"node_templates"`
+	} `yaml:"topology_template"`
+}
+
+/*var templateData = `
+tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+   - custom_types/oltdevice.yaml
+   - custom_types/onudevice.yaml
+   - custom_types/ponport.yaml
+   - custom_types/voltservice.yaml
+`
+
+type OltProvsion struct {
+	Tosca_Definitions_Version string
+	Imports                   []string
+}
+*/
+
+func NewOltProvision(clli string, name string, deviceType string, host string, port int) OltProvsion {
+	o := OltProvsion{}
+	err := yaml.Unmarshal([]byte(templateData), &o)
+	if err != nil {
+		log.Printf("Error un-marshalling template data %v\n", err)
+	}
+
+	props := &o.TopologyTemplate.NodeTemplates.OltDevice.Properties
+	props.Name = name
+	props.Type = deviceType
+	props.Host = host
+	props.Port = port
+	props.NasID = clli
+	return o
+}
+
+func (olt *OltProvsion) ToYaml() (string, error) {
+	b, err := yaml.Marshal(olt)
+	return string(b), err
+}
diff --git a/models/tosca/addOlt_test.go b/models/tosca/addOlt_test.go
new file mode 100644
index 0000000..1b2f667
--- /dev/null
+++ b/models/tosca/addOlt_test.go
@@ -0,0 +1,79 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+package tosca_test
+
+import (
+	"fmt"
+	"strings"
+	"testing"
+
+	"gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var output = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/oltdevice.yaml
+- custom_types/onudevice.yaml
+- custom_types/ponport.yaml
+- custom_types/voltservice.yaml
+description: Create a simulated OLT Device in VOLTHA
+topology_template:
+  node_templates:
+    service#volt:
+      type: tosca.nodes.VOLTService
+      properties:
+        name: volt
+        must-exist: true
+    olt_device:
+      type: tosca.nodes.OLTDevice
+      properties:
+        name: myName
+        device_type: openolt
+        host: 192.168.1.1
+        port: 9191
+        outer_tpid: "0x8100"
+        uplink: "65536"
+        nas_id: my_clli
+      requirements:
+      - volt_service:
+          node: service#volt
+          relationship: tosca.relationships.BelongsToOne
+`
+
+var olt tosca.OltProvsion
+
+func TestAddOlt_NewOltProvsion(t *testing.T) {
+	fmt.Println("In TestAddOlt_NewOltProvsion")
+	olt = tosca.NewOltProvision("my_clli", "myName", "openolt", "192.168.1.1", 9191)
+	fmt.Printf("%v\n\n", olt)
+}
+
+func TestAddOlt_ToYaml(t *testing.T) {
+	y, err := olt.ToYaml()
+	if err != nil {
+		t.Fatalf("olt.ToYaml() failed with %v\n", err)
+	}
+	x := strings.Compare(y, output)
+	if x != 0 {
+		t.Fatal("ToYaml didn't produce the expected yaml")
+	}
+	fmt.Printf("Compare is %d\n", x)
+
+	fmt.Printf(y)
+	fmt.Println("******")
+	fmt.Print(output)
+	fmt.Println("******")
+}
diff --git a/models/tosca/addSubscriber.go b/models/tosca/addSubscriber.go
new file mode 100644
index 0000000..448569c
--- /dev/null
+++ b/models/tosca/addSubscriber.go
@@ -0,0 +1,89 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+package tosca
+
+import (
+	"log"
+	"strings"
+
+	yaml "gopkg.in/yaml.v2"
+)
+
+var subSubscriberTemplate = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+  - custom_types/rcordsubscriber.yaml
+
+description: Pre-provsion a subscriber
+topology_template:
+  node_templates:
+    RG_NAME:
+      type: tosca.nodes.RCORDSubscriber
+      properties:
+        name:
+        status: pre-provisioned
+        c_tag:
+        s_tag:
+        onu_device:
+        nas_port_id:
+        circuit_id:
+        remote_id:`
+
+type SubscriberProvision struct {
+	ToscaDefinitionsVersion string   `yaml:"tosca_definitions_version"`
+	Imports                 []string `yaml:"imports"`
+	Description             string   `yaml:"description"`
+	TopologyTemplate        struct {
+		NodeTemplates struct {
+			RgName struct {
+				Type       string `yaml:"type`
+				Properties struct {
+					Name      string `yaml:"name"`
+					Status    string `yaml:"status"`
+					CTag      int    `yaml:"c_tag"`
+					STag      int    `yaml:"s_tag"`
+					OnuDevice string `yaml:"onu_device"`
+					NasPortID string `yaml:"nas_port_id"`
+					CircuitID string `yaml:"circuit_id"`
+					RemoteID  string `yaml:"remote_id"`
+				} `yaml:"properties"`
+			} `yaml:"RG_NAME"`
+		} `yaml:"node_templates"`
+	} `yaml:"topology_template"`
+}
+
+func NewSubscriberProvision(name string, cTag int, sTag int, onuDevice string, nasPortID string, circuitID string, remoteID string) SubscriberProvision {
+	s := SubscriberProvision{}
+	err := yaml.Unmarshal([]byte(subSubscriberTemplate), &s)
+	if err != nil {
+		log.Printf("Error un-marshalling template data %v\n", err)
+	}
+	props := &s.TopologyTemplate.NodeTemplates.RgName.Properties
+	props.Name = name
+	props.CTag = cTag
+	props.STag = sTag
+	props.OnuDevice = onuDevice
+	props.NasPortID = nasPortID
+	props.CircuitID = circuitID
+	props.RemoteID = remoteID
+	return s
+}
+func (sub *SubscriberProvision) ToYaml() (string, error) {
+	b, err := yaml.Marshal(sub)
+	ret := string(b)
+	name := sub.TopologyTemplate.NodeTemplates.RgName.Properties.Name
+	ret = strings.Replace(ret, "RG_NAME", name, -1)
+	return ret, err
+}
diff --git a/models/tosca/addSubscriber_test.go b/models/tosca/addSubscriber_test.go
new file mode 100644
index 0000000..0d48340
--- /dev/null
+++ b/models/tosca/addSubscriber_test.go
@@ -0,0 +1,75 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+
+package tosca_test
+
+import (
+	"fmt"
+	"strings"
+	"testing"
+
+	"gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var expectedOutput = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/rcordsubscriber.yaml
+description: Pre-provsion a subscriber
+topology_template:
+  node_templates:
+    myName:
+      type: tosca.nodes.RCORDSubscriber
+      properties:
+        name: myName
+        status: pre-provisioned
+        c_tag: 20
+        s_tag: 2
+        onu_device: onuSerialNumber
+        nas_port_id: /1/1/1/1/1.9
+        circuit_id: /1/1/1/1/1.9-CID
+        remote_id: myCilli
+`
+
+var sub tosca.SubscriberProvision
+
+func TestAddSubscriber_NewSubscriberProvision(t *testing.T) {
+	fmt.Println("Int TestAddSubscriber_NewSubscriberProvision")
+	sub = tosca.NewSubscriberProvision("myName", 20, 2, "onuSerialNumber", "/1/1/1/1/1.9", "/1/1/1/1/1.9-CID", "myCilli")
+	fmt.Printf("%v\n\n", sub)
+}
+
+func TestAddSubscriber_ToYaml(t *testing.T) {
+	y, err := sub.ToYaml()
+	if err != nil {
+		t.Fatalf("olt.ToYaml() failed with %v\n", err)
+	}
+
+	x := strings.Compare(y, expectedOutput)
+	if x != 0 {
+		fmt.Println("******")
+		fmt.Println(expectedOutput)
+		fmt.Println("******")
+		fmt.Println(y)
+		fmt.Println("******")
+		t.Fatal("ToYaml didn't produce the expected yaml")
+	}
+	fmt.Printf("Compare is %d\n", x)
+
+	fmt.Printf(y)
+	fmt.Println("******")
+	fmt.Print(output)
+	fmt.Println("******")
+}
diff --git a/models/tosca/provisionOnt.go b/models/tosca/provisionOnt.go
new file mode 100644
index 0000000..c83cc4d
--- /dev/null
+++ b/models/tosca/provisionOnt.go
@@ -0,0 +1,103 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+package tosca
+
+import (
+	"fmt"
+	"net"
+	"strings"
+
+	yaml "gopkg.in/yaml.v2"
+)
+
+var ontTemplate = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+  - custom_types/attworkflowdriverwhitelistentry.yaml
+  - custom_types/attworkflowdriverservice.yaml
+description: Create an entry in the whitelist
+topology_template:
+  node_templates:
+    service#att:
+      type: tosca.nodes.AttWorkflowDriverService
+      properties:
+        name: att-workflow-driver
+        must-exist: true
+    ont:
+      type: tosca.nodes.AttWorkflowDriverWhiteListEntry
+      properties:
+        serial_number: ALPHe3d1cf57
+        pon_port_id: 536870912
+        device_id: of:000000000a4001ce
+      requirements:
+        - owner:
+            node: service#att
+            relationship: tosca.relationships.BelongsToOne`
+
+type OntProvision struct {
+	ToscaDefinitionsVersion string   `yaml:"tosca_definitions_version"`
+	Imports                 []string `yaml:"imports"`
+	Description             string   `yaml:"description"`
+	TopologyTemplate        struct {
+		NodeTemplates struct {
+			ServiceATT struct {
+				Type       string `yaml:"type"`
+				Properties struct {
+					Name      string `yaml:"name"`
+					MustExist bool   `yaml:"must-exist"`
+				} `yaml:"properties"`
+			} `yaml:"service#att"`
+			Ont struct {
+				DeviceType string `yaml:"type"`
+				Properties struct {
+					SerialNumber string `yaml:"serial_number"`
+					PonPortID    int    `yaml:"pon_port_id"`
+					DeviceID     string `yaml:"device_id"`
+				} `yaml:"properties"`
+				Requirements []struct {
+					Owner struct {
+						Node         string `yaml:"node"`
+						Relationship string `yaml:"relationship"`
+					} `yaml:"owner"`
+				} `yaml:"requirements"`
+			} `yaml:"ont"`
+		} `yaml:"node_templates"`
+	} `yaml:"topology_template"`
+}
+
+func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
+	offset := 1 << 29
+	o := OntProvision{}
+	err := yaml.Unmarshal([]byte(ontTemplate), &o)
+	if err != nil {
+	}
+	props := &o.TopologyTemplate.NodeTemplates.Ont.Properties
+	props.PonPortID = offset + ponPortNumber
+	props.SerialNumber = serialNumber
+	ipNum := []byte(oltIP[12:16]) //only handling ipv4
+	ofID := fmt.Sprintf("of:00000000%0x", ipNum)
+	props.DeviceID = ofID
+	fmt.Printf("%v\n", o)
+	return o
+
+}
+func (ont *OntProvision) ToYaml() (string, error) {
+	b, err := yaml.Marshal(ont)
+	ret := string(b)
+	// Damn dirty hack but what are you going to do????
+	serialNumber := ont.TopologyTemplate.NodeTemplates.Ont.Properties.SerialNumber
+	ret = strings.Replace(ret, "ont", serialNumber, -1)
+	return ret, err
+}
diff --git a/models/tosca/provisionOnt_test.go b/models/tosca/provisionOnt_test.go
new file mode 100644
index 0000000..ff7cd85
--- /dev/null
+++ b/models/tosca/provisionOnt_test.go
@@ -0,0 +1,62 @@
+/*
+   Copyright 2017 the original author or authors.
+
+   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.
+*/
+
+package tosca_test
+
+import (
+	"fmt"
+	"net"
+	"testing"
+
+	"gerrit.opencord.org/abstract-olt/models/tosca"
+)
+
+var expected = `tosca_definitions_version: tosca_simple_yaml_1_0
+imports:
+- custom_types/attworkflowdriverwhitelistentry.yaml
+- custom_types/attworkflowdriverservice.yaml
+description: Create an entry in the whitelist
+topology_template:
+  node_templates:
+    service#att:
+      type: tosca.nodes.AttWorkflowDriverService
+      properties:
+        name: att-workflow-driver
+        must-exist: true
+    some_serial:
+      type: tosca.nodes.AttWorkflowDriverWhiteListEntry
+      properties:
+        serial_number: some_serial
+        pon_port_id: 536870914
+        device_id: of:00000000c0a8010b
+      requirements:
+      - owner:
+          node: service#att
+          relationship: tosca.relationships.BelongsToOne
+`
+var ont tosca.OntProvision
+
+//func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision {
+
+func TestOntProvision_NewOntProvision(t *testing.T) {
+	ont = tosca.NewOntProvision("some_serial", net.ParseIP("192.168.1.11"), 2)
+	ontYaml, _ := ont.ToYaml()
+	if ontYaml != expected {
+		t.Fatalf("Didn't generate the expected yaml\n Generated:\n%s \nExpected:\n%s\n", ontYaml, expected)
+	}
+	fmt.Println(ontYaml)
+	fmt.Println("******************")
+}