SEBA-261
refactor to support serialize/deserialize
Change-Id: Icdc0bc2bb06a9d1c3240c0f46e1de02953a0b017
diff --git a/models/physical/chassis.go b/models/physical/chassis.go
index 5fb9a94..4392a10 100644
--- a/models/physical/chassis.go
+++ b/models/physical/chassis.go
@@ -33,16 +33,22 @@
type Chassis struct {
CLLI string
VCoreAddress net.TCPAddr
- Dataswitch DataSwitch
- Linecards []OLT
- Rack int
- Shelf int
+ // Dataswitch DataSwitch
+ Linecards []SimpleOLT
+ Rack int
+ Shelf int
}
type UnprovisionedSlotError struct {
CLLI string
SlotNumber int
}
+func (c *Chassis) Output() {
+ for _, olt := range c.Linecards {
+ olt.Output()
+ }
+}
+
func (e *UnprovisionedSlotError) Error() string {
return fmt.Sprintf("SlotNumber %d in Chassis %s is currently unprovsioned", e.SlotNumber, e.CLLI)
}
@@ -50,10 +56,10 @@
/*
AddOLTChassis - adds a reference to a new olt chassis
*/
-func (chassis *Chassis) AddOLTChassis(olt OLT) {
+func (chassis *Chassis) AddOLTChassis(olt SimpleOLT) {
+ olt.SetNumber((len(chassis.Linecards) + 1))
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
@@ -71,15 +77,15 @@
req.Header.Add("xos-password", "letmein")
resp, err := client.Do(req)
if err != nil {
- fmt.Printf("ERROR :) %v\n", err)
+ //TODO
// handle error
}
- fmt.Printf("Response is %v\n", resp)
+ log.Printf("Server response was %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)
+ log.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
ponPort := ont.Parent
slot := ponPort.Parent
@@ -99,31 +105,24 @@
req.Header.Add("xos-password", "letmein")
resp, err := client.Do(req)
if err != nil {
- fmt.Printf("ERROR :) %v\n", err)
+ log.Printf("ERROR :) %v\n", err)
// handle error
}
- fmt.Printf("Response is %v\n", resp)
+ log.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)
+ log.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)
+ log.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
- fmt.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
-}
-func (chassis *Chassis) ActivateSlot(slotNumber int) error {
- // AT&T backend systems start at 1 and not 0 :P
- if chassis.Linecards[slotNumber-1] == nil {
- return &UnprovisionedSlotError{CLLI: chassis.CLLI, SlotNumber: slotNumber}
- }
- return chassis.Linecards[slotNumber-1].activate()
+ log.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan)
}
diff --git a/models/physical/edgecore.go b/models/physical/edgecore.go
index cded2dc..0cf4479 100644
--- a/models/physical/edgecore.go
+++ b/models/physical/edgecore.go
@@ -26,12 +26,11 @@
/*
CreateEdgecore takes simple olt struct and generates Edgecore OLT
*/
-func CreateEdgecore(olt *SimpleOLT) *Edgecore {
+func (olt *SimpleOLT) CreateEdgecore() {
var newPorts [16]PONPort
- edge := Edgecore{SimpleOLT: *olt}
for i := 0; i < 16; i++ {
- newPorts[i].Parent = &edge
+ newPorts[i].Parent = olt
+ newPorts[i].Number = i + 1
}
- edge.Ports = newPorts[:]
- return &edge
+ olt.Ports = newPorts[:]
}
diff --git a/models/physical/edgecore_test.go b/models/physical/edgecore_test.go
index a7fbf68..c4a06df 100644
--- a/models/physical/edgecore_test.go
+++ b/models/physical/edgecore_test.go
@@ -34,8 +34,8 @@
switchPort := 3
olt := &physical.SimpleOLT{CLLI: clli, Hostname: hostname, Address: address, Parent: parent, DataSwitchPort: switchPort}
- edgeCoreOlt := physical.CreateEdgecore(olt)
- if edgeCoreOlt.GetCLLI() != clli {
+ olt.CreateEdgecore()
+ if olt.GetCLLI() != clli {
t.Fatal("Failed to assign CLLI in CreateEdgecore")
}
}
diff --git a/models/physical/olt.go b/models/physical/olt.go
index 121fdac..721e731 100644
--- a/models/physical/olt.go
+++ b/models/physical/olt.go
@@ -29,7 +29,9 @@
GetPorts() []PONPort
GetParent() *Chassis
GetDataSwitchPort() int
+ SetNumber(int)
activate() error
+ Output()
}
/*
@@ -47,35 +49,42 @@
DataSwitchPort int
}
-func (s *SimpleOLT) GetCLLI() string {
+func (s SimpleOLT) GetCLLI() string {
return s.CLLI
}
-func (s *SimpleOLT) GetHostname() string {
+func (s SimpleOLT) GetHostname() string {
return s.Hostname
}
-func (s *SimpleOLT) GetAddress() net.TCPAddr {
+func (s SimpleOLT) GetAddress() net.TCPAddr {
return s.Address
}
-func (s *SimpleOLT) GetNumber() int {
+func (s SimpleOLT) GetNumber() int {
return s.Number
}
+func (s SimpleOLT) SetNumber(num int) {
+ s.Number = num
+}
-func (s *SimpleOLT) GetPorts() []PONPort {
+func (s SimpleOLT) GetPorts() []PONPort {
return s.Ports
}
-func (s *SimpleOLT) GetParent() *Chassis {
+func (s SimpleOLT) GetParent() *Chassis {
return s.Parent
}
-func (s *SimpleOLT) GetDataSwitchPort() int {
+func (s SimpleOLT) GetDataSwitchPort() int {
return s.DataSwitchPort
}
-func (s *SimpleOLT) activate() error {
+func (s SimpleOLT) activate() error {
s.Active = true
//TODO make call to XOS to activate phyiscal OLT
return nil
}
+func (s SimpleOLT) Output() error {
+ //TODO make call to XOS to activate phyiscal OLT
+ return nil
+}
diff --git a/models/physical/ponport.go b/models/physical/ponport.go
index ca321fd..683489e 100644
--- a/models/physical/ponport.go
+++ b/models/physical/ponport.go
@@ -27,7 +27,7 @@
Number int
DeviceID string
Onts [64]Ont
- Parent *Edgecore `json:"-"`
+ Parent *SimpleOLT `json:"-"`
}
/*
@@ -70,7 +70,6 @@
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)
if port.Onts[number-1].Active {
e := AllReadyActiveError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
@@ -90,7 +89,6 @@
func (port *PONPort) DeleteOnt(number int, sVlan int, cVlan int, serialNumber string) error {
slot := port.Parent
chassis := slot.Parent
- fmt.Printf("Calling ActivateOnt and port state is %t\n", port.Onts[number-1].Active)
if port.Onts[number-1].Active != true {
e := AllReadyDeactivatedError{ontNumber: number, slotNum: slot.Number, ponportNum: port.Number, clli: chassis.CLLI}
return &e