blob: f2e832ee25fd988b9fc0c6434a208cca4f4f0a1d [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)
donNewtonAlphab8f30752018-10-04 11:57:41 -040060 fmt.Println("HELLO WTF")
donNewtonAlphab3279ea2018-09-18 15:55:32 -040061 ping := in.GetPing()
62 pong := EchoReplyMessage{Pong: ping}
63 return &pong, nil
64}
65
Author Namea594e632018-08-10 11:33:58 -040066/*
67CreateChassis - allocates a new Chassis struct and stores it in chassisMap
68*/
69func (s *Server) CreateChassis(ctx context.Context, in *AddChassisMessage) (*AddChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -040070 clli := in.GetCLLI()
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040071
72 xosIP := net.ParseIP(in.GetXOSIP())
73 xosPort := int(in.GetXOSPort())
74 if xosIP == nil {
75 errStr := fmt.Sprintf("Invalid IP %s supplied for XOSIP", in.GetXOSIP())
76 return nil, errors.New(errStr)
77 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040078 xosAddress := net.TCPAddr{IP: xosIP, Port: xosPort}
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040079 xosUser := in.GetXOSUser()
80 xosPassword := in.GetXOSPassword()
81 if xosUser == "" || xosPassword == "" {
82 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
83 }
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040084 shelf := int(in.GetShelf())
85 rack := int(in.GetRack())
Don Newtone973d342018-10-26 16:44:12 -040086 deviceID, err := impl.CreateChassis(clli, xosAddress, xosUser, xosPassword, shelf, rack)
87 if err != nil {
88 return nil, err
Author Namea594e632018-08-10 11:33:58 -040089 }
Don Newtone973d342018-10-26 16:44:12 -040090 return &AddChassisReturn{DeviceID: deviceID}, nil
Author Namea594e632018-08-10 11:33:58 -040091}
92
93/*
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -040094ChangeXOSUserPassword - allows update of xos credentials
95*/
96func (s *Server) ChangeXOSUserPassword(ctx context.Context, in *ChangeXOSUserPasswordMessage) (*ChangeXOSUserPasswordReturn, error) {
97 clli := in.GetCLLI()
98 xosUser := in.GetXOSUser()
99 xosPassword := in.GetXOSPassword()
100 if xosUser == "" || xosPassword == "" {
101 return nil, errors.New("Either XOSUser or XOSPassword supplied were empty")
102 }
Don Newtone973d342018-10-26 16:44:12 -0400103 success, err := impl.ChangeXOSUserPassword(clli, xosUser, xosPassword)
104 return &ChangeXOSUserPasswordReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400105
106}
107
108/*
donNewtonAlphab9b85eb2018-08-14 14:28:22 -0400109CreateOLTChassis adds an OLT chassis/line card to the Physical chassis
Author Namea594e632018-08-10 11:33:58 -0400110*/
111func (s *Server) CreateOLTChassis(ctx context.Context, in *AddOLTChassisMessage) (*AddOLTChassisReturn, error) {
Author Namea594e632018-08-10 11:33:58 -0400112 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400113 oltType := in.GetType().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()
116 clli, err := impl.CreateOLTChassis(clli, oltType, address, hostname)
117 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/*
151DeleteOnt - deletes a previously provision ont
152*/
153func (s *Server) DeleteOnt(ctx context.Context, in *DeleteOntMessage) (*DeleteOntReturn, error) {
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400154 clli := in.GetCLLI()
Don Newtone973d342018-10-26 16:44:12 -0400155 slotNumber := int(in.GetSlotNumber())
156 portNumber := int(in.GetPortNumber())
157 ontNumber := int(in.GetOntNumber())
158 serialNumber := in.GetSerialNumber()
159 success, err := impl.DeleteOnt(clli, slotNumber, portNumber, ontNumber, serialNumber)
160 return &DeleteOntReturn{Success: success}, err
donNewtonAlphaf7cc9992018-08-29 14:23:02 -0400161}
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400162
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400163/*
164Reflow - iterates through provisioning to rebuild Seba-Pod
165*/
Don Newtone973d342018-10-26 16:44:12 -0400166func (s *Server) Reflow(ctx context.Context, in *ReflowMessage) (*ReflowReturn, error) {
167 success, err := impl.Reflow()
168 return &ReflowReturn{Success: success}, err
169
170}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400171
172/*
173Output - causes an immediate backup to be created
174*/
donNewtonAlphae7ab5b92018-09-27 15:09:14 -0400175func (s *Server) Output(ctx context.Context, in *OutputMessage) (*OutputReturn, error) {
Don Newtone973d342018-10-26 16:44:12 -0400176 success, err := impl.DoOutput()
177 return &OutputReturn{Success: success}, err
donNewtonAlpha57aa2ff2018-10-01 16:45:32 -0400178
179}
donNewtonAlpha27ad20c2018-10-30 16:18:42 -0400180
181/*
182GetFullInventory - gets a full json dump of the currently provisioned equipment
183*/
184func (s *Server) GetFullInventory(ctx context.Context, in *FullInventoryMessage) (*InventoryReturn, error) {
185 json := inventory.GatherAllInventory()
186 return &InventoryReturn{JsonDump: json}, nil
187}
188
189/*
190GetInventory - returns a json dump of a particular seba-pod
191*/
192func (s *Server) GetInventory(ctx context.Context, in *InventoryMessage) (*InventoryReturn, error) {
193 json := inventory.GatherInventory(in.GetClli())
194 return &InventoryReturn{JsonDump: json}, nil
195}