blob: 76d637e49f5772e89a1e526d11f4c2755f899fef [file] [log] [blame]
Author Namea594e632018-08-10 11:33:58 -04001/*
2 Copyright 2017 the original author or authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17package api
18
19import (
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040020 "errors"
Author Namea594e632018-08-10 11:33:58 -040021 "fmt"
Author Namea594e632018-08-10 11:33:58 -040022 "net"
donNewtonAlphac997d642018-10-17 13:22:48 -040023 "sync"
Author Namea594e632018-08-10 11:33:58 -040024
Don Newtone973d342018-10-26 16:44:12 -040025 "gerrit.opencord.org/abstract-olt/internal/pkg/impl"
donNewtonAlpha27ad20c2018-10-30 16:18:42 -040026 "gerrit.opencord.org/abstract-olt/models/inventory"
Author Namea594e632018-08-10 11:33:58 -040027 context "golang.org/x/net/context"
28)
29
30/*
31Server instance of the grpc server
32*/
33type Server struct {
34}
35
donNewtonAlphac997d642018-10-17 13:22:48 -040036var syncChan chan bool
37var isDirty bool
38
39var runOnce sync.Once
40
41func getSyncChannel() chan bool {
42 runOnce.Do(func() {
43 syncChan = make(chan bool, 1)
44 syncChan <- true
45 })
46
47 return syncChan
48}
49func done(myChan chan bool, done bool) {
50 myChan <- done
51}
52
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040053/*
54Echo - Tester function which just returns same string sent to it
55*/
donNewtonAlphab3279ea2018-09-18 15:55:32 -040056func (s *Server) Echo(ctx context.Context, in *EchoMessage) (*EchoReplyMessage, error) {
donNewtonAlphac997d642018-10-17 13:22:48 -040057 myChan := getSyncChannel()
58 <-myChan
59 defer done(myChan, true)
donNewtonAlphab3279ea2018-09-18 15:55:32 -040060 ping := in.GetPing()
61 pong := EchoReplyMessage{Pong: ping}
62 return &pong, nil
63}
64
Author Namea594e632018-08-10 11:33:58 -040065/*
66CreateChassis - allocates a new Chassis struct and stores it in chassisMap
67*/
68func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -040069 clli := in.GetCLLI()
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040070
71 xosIP := net.ParseIP(in.GetXOSIP())
72 xosPort := int(in.GetXOSPort())
73 if xosIP == nil {
74 errStr := fmt.Sprintf("Invalid IP %s supplied for XOSIP", in.GetXOSIP())
75 return nil, errors.New(errStr)
76 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040077 xosAddress := net.TCPAddr{IP: xosIP, Port: xosPort}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040078 xosUser := in.GetXOSUser()
79 xosPassword := in.GetXOSPassword()
80 if xosUser == "" || xosPassword == "" {
81 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
82 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040083 shelf := int(in.GetShelf())
84 rack := int(in.GetRack())
Don Newtone973d342018-10-26 16:44:12 -040085 deviceID, err := impl.CreateChassis(clli, xosAddress, xosUser, xosPassword, shelf, rack)
86 if err != nil {
87 return nil, err
Author Namea594e632018-08-10 11:33:58 -040088 }
Don Newtone973d342018-10-26 16:44:12 -040089 return &AddChassisReturn{DeviceID: deviceID}, nil
Author Namea594e632018-08-10 11:33:58 -040090}
91
92/*
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040093ChangeXOSUserPassword - allows update of xos credentials
94*/
95func (s *Server) ChangeXOSUserPassword(ctx context.Context, in *ChangeXOSUserPasswordMessage) (*ChangeXOSUserPasswordReturn, error) {
96 clli := in.GetCLLI()
97 xosUser := in.GetXOSUser()
98 xosPassword := in.GetXOSPassword()
99 if xosUser == "" || xosPassword == "" {
100 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
101 }
Don Newtone973d342018-10-26 16:44:12 -0400102 success, err := impl.ChangeXOSUserPassword(clli, xosUser, xosPassword)
103 return &ChangeXOSUserPasswordReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400104
105}
106
107/*
donNewtonAlphab9b85eb2018-08-14 14:28:22 -0400108CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
Author Namea594e632018-08-10 11:33:58 -0400109*/
110func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -0400111 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400112 oltType := in.GetType().String()
Don Newton5154fff2018-11-06 17:40:58 -0500113 driver := in.GetDriver().String()
Author Namea594e632018-08-10 11:33:58 -0400114 address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
Don Newtone973d342018-10-26 16:44:12 -0400115 hostname := in.GetHostname()
Don Newton5154fff2018-11-06 17:40:58 -0500116 clli, err := impl.CreateOLTChassis(clli, oltType, driver, address, hostname)
Don Newtone973d342018-10-26 16:44:12 -0400117 return &AddOLTChassisReturn{DeviceID: hostname, ChassisDeviceID: clli}, err
Author Namea594e632018-08-10 11:33:58 -0400118}
119
120/*
donNewtonAlpha5234b132018-08-16 14:12:28 -0400121ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
122*/
123func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
donNewtonAlpha5234b132018-08-16 14:12:28 -0400124 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400125 slotNumber := int(in.GetSlotNumber())
126 portNumber := int(in.GetPortNumber())
127 ontNumber := int(in.GetOntNumber())
128 serialNumber := in.GetSerialNumber()
129 success, err := impl.ProvisionOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
130 return &AddOntReturn{Success: success}, err
donNewtonAlpha5234b132018-08-16 14:12:28 -0400131}
Don Newton281e0252018-10-22 14:38:50 -0400132
Don Newtone973d342018-10-26 16:44:12 -0400133/*
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400134ProvisionOntFull - provisions ont using sTag,cTag,NasPortID, and CircuitID passed in
Don Newtone973d342018-10-26 16:44:12 -0400135*/
136func (s *Server) ProvisionOntFull(ctx context.Context, in *AddOntFullMessage) (*AddOntReturn, error) {
137 clli := in.GetCLLI()
138 slotNumber := int(in.GetSlotNumber())
139 portNumber := int(in.GetPortNumber())
140 ontNumber := int(in.GetOntNumber())
141 serialNumber := in.GetSerialNumber()
142 cTag := in.GetCTag()
143 sTag := in.GetSTag()
144 nasPortID := in.GetNasPortID()
145 circuitID := in.GetCircuitID()
146 success, err := impl.ProvisionOntFull(clli, slotNumber, portNumber, ontNumber, serialNumber, cTag, sTag, nasPortID, circuitID)
147 return &AddOntReturn{Success: success}, err
Don Newton281e0252018-10-22 14:38:50 -0400148}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400149
150/*
donNewtonAlpha292d1432018-11-08 19:01:21 -0500151PreProvisionOnt - provisions ont using sTag,cTag,NasPortID, and CircuitID passed in
152*/
153func (s *Server) PreProvisionOnt(ctx context.Context, in *PreProvisionOntMessage) (*AddOntReturn, error) {
154 clli := in.GetCLLI()
155 slotNumber := int(in.GetSlotNumber())
156 portNumber := int(in.GetPortNumber())
157 ontNumber := int(in.GetOntNumber())
158 cTag := in.GetCTag()
159 sTag := in.GetSTag()
160 nasPortID := in.GetNasPortID()
161 circuitID := in.GetCircuitID()
162 techProfile := in.GetTechProfile()
163 speedProfile := in.GetSpeedProfile()
164 success, err := impl.PreProvisionOnt(clli, slotNumber, portNumber, ontNumber, cTag, sTag, nasPortID, circuitID, techProfile, speedProfile)
165 return &AddOntReturn{Success: success}, err
166}
167
168/*
169ActivateSerial provisions an ONT on a specific Chassis/LineCard/Port
170*/
171func (s *Server) ActivateSerial(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
172 clli := in.GetCLLI()
173 slotNumber := int(in.GetSlotNumber())
174 portNumber := int(in.GetPortNumber())
175 ontNumber := int(in.GetOntNumber())
176 serialNumber := in.GetSerialNumber()
177 success, err := impl.ActivateSerial(clli, slotNumber, portNumber, ontNumber, serialNumber)
178 return &AddOntReturn{Success: success}, err
179}
180
181/*
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400182DeleteOnt - deletes a previously provision ont
183*/
184func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400185 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400186 slotNumber := int(in.GetSlotNumber())
187 portNumber := int(in.GetPortNumber())
188 ontNumber := int(in.GetOntNumber())
189 serialNumber := in.GetSerialNumber()
190 success, err := impl.DeleteOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
191 return &DeleteOntReturn{Success: success}, err
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400192}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400193
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400194/*
195Reflow - iterates through provisioning to rebuild Seba-Pod
196*/
Don Newtone973d342018-10-26 16:44:12 -0400197func (s *Server) Reflow(ctx context.Context, in *ReflowMessage) (*ReflowReturn, error) {
198 success, err := impl.Reflow()
199 return &ReflowReturn{Success: success}, err
200
201}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400202
203/*
204Output - causes an immediate backup to be created
205*/
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400206func (s *Server) Output(ctx context.Context, in *OutputMessage) (*OutputReturn, error) {
Don Newtone973d342018-10-26 16:44:12 -0400207 success, err := impl.DoOutput()
208 return &OutputReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400209
210}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400211
212/*
213GetFullInventory - gets a full json dump of the currently provisioned equipment
214*/
215func (s *Server) GetFullInventory(ctx context.Context, in *FullInventoryMessage) (*InventoryReturn, error) {
216 json := inventory.GatherAllInventory()
217 return &InventoryReturn{JsonDump: json}, nil
218}
219
220/*
221GetInventory - returns a json dump of a particular seba-pod
222*/
223func (s *Server) GetInventory(ctx context.Context, in *InventoryMessage) (*InventoryReturn, error) {
Don Newton0766ec22018-11-06 15:18:05 -0500224 json, err := inventory.GatherInventory(in.GetClli())
225 return &InventoryReturn{JsonDump: json}, err
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400226}