blob: 3b1754f4ca91a37069328a69b6a6fdff0f49c70f [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()
Author Namea594e632018-08-10 11:33:58 -0400113 address := net.TCPAddr{IP: net.ParseIP(in.GetSlotIP()), Port: int(in.GetSlotPort())}
Don Newtone973d342018-10-26 16:44:12 -0400114 hostname := in.GetHostname()
115 clli, err := impl.CreateOLTChassis(clli, oltType, address, hostname)
116 return &AddOLTChassisReturn{DeviceID: hostname, ChassisDeviceID: clli}, err
Author Namea594e632018-08-10 11:33:58 -0400117}
118
119/*
donNewtonAlpha5234b132018-08-16 14:12:28 -0400120ProvisionOnt provisions an ONT on a specific Chassis/LineCard/Port
121*/
122func (s *Server) ProvisionOnt(ctx context.Context, in *AddOntMessage) (*AddOntReturn, error) {
donNewtonAlpha5234b132018-08-16 14:12:28 -0400123 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400124 slotNumber := int(in.GetSlotNumber())
125 portNumber := int(in.GetPortNumber())
126 ontNumber := int(in.GetOntNumber())
127 serialNumber := in.GetSerialNumber()
128 success, err := impl.ProvisionOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
129 return &AddOntReturn{Success: success}, err
donNewtonAlpha5234b132018-08-16 14:12:28 -0400130}
Don Newton281e0252018-10-22 14:38:50 -0400131
Don Newtone973d342018-10-26 16:44:12 -0400132/*
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400133ProvisionOntFull - provisions ont using sTag,cTag,NasPortID, and CircuitID passed in
Don Newtone973d342018-10-26 16:44:12 -0400134*/
135func (s *Server) ProvisionOntFull(ctx context.Context, in *AddOntFullMessage) (*AddOntReturn, error) {
136 clli := in.GetCLLI()
137 slotNumber := int(in.GetSlotNumber())
138 portNumber := int(in.GetPortNumber())
139 ontNumber := int(in.GetOntNumber())
140 serialNumber := in.GetSerialNumber()
141 cTag := in.GetCTag()
142 sTag := in.GetSTag()
143 nasPortID := in.GetNasPortID()
144 circuitID := in.GetCircuitID()
145 success, err := impl.ProvisionOntFull(clli, slotNumber, portNumber, ontNumber, serialNumber, cTag, sTag, nasPortID, circuitID)
146 return &AddOntReturn{Success: success}, err
Don Newton281e0252018-10-22 14:38:50 -0400147}
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400148
149/*
150DeleteOnt - deletes a previously provision ont
151*/
152func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400153 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400154 slotNumber := int(in.GetSlotNumber())
155 portNumber := int(in.GetPortNumber())
156 ontNumber := int(in.GetOntNumber())
157 serialNumber := in.GetSerialNumber()
158 success, err := impl.DeleteOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
159 return &DeleteOntReturn{Success: success}, err
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400160}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400161
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400162/*
163Reflow - iterates through provisioning to rebuild Seba-Pod
164*/
Don Newtone973d342018-10-26 16:44:12 -0400165func (s *Server) Reflow(ctx context.Context, in *ReflowMessage) (*ReflowReturn, error) {
166 success, err := impl.Reflow()
167 return &ReflowReturn{Success: success}, err
168
169}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400170
171/*
172Output - causes an immediate backup to be created
173*/
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400174func (s *Server) Output(ctx context.Context, in *OutputMessage) (*OutputReturn, error) {
Don Newtone973d342018-10-26 16:44:12 -0400175 success, err := impl.DoOutput()
176 return &OutputReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400177
178}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400179
180/*
181GetFullInventory - gets a full json dump of the currently provisioned equipment
182*/
183func (s *Server) GetFullInventory(ctx context.Context, in *FullInventoryMessage) (*InventoryReturn, error) {
184 json := inventory.GatherAllInventory()
185 return &InventoryReturn{JsonDump: json}, nil
186}
187
188/*
189GetInventory - returns a json dump of a particular seba-pod
190*/
191func (s *Server) GetInventory(ctx context.Context, in *InventoryMessage) (*InventoryReturn, error) {
Don Newton0766ec22018-11-06 15:18:05 -0500192 json, err := inventory.GatherInventory(in.GetClli())
193 return &InventoryReturn{JsonDump: json}, err
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400194}