Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package impl |
| 18 | |
| 19 | import ( |
| 20 | "errors" |
| 21 | "fmt" |
| 22 | "net" |
| 23 | |
| 24 | "gerrit.opencord.org/abstract-olt/models" |
| 25 | "gerrit.opencord.org/abstract-olt/models/physical" |
| 26 | ) |
| 27 | |
| 28 | /* |
| 29 | CreateOLTChassis adds an OLT chassis/line card to the Physical chassis |
| 30 | */ |
Don Newton | 5154fff | 2018-11-06 17:40:58 -0500 | [diff] [blame] | 31 | func CreateOLTChassis(clli string, oltType string, driver string, address net.TCPAddr, hostname string) (string, error) { |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 32 | myChan := getSyncChannel() |
| 33 | <-myChan |
| 34 | defer done(myChan, true) |
| 35 | chassisMap := models.GetChassisMap() |
| 36 | chassisHolder := (*chassisMap)[clli] |
| 37 | if chassisHolder == nil { |
| 38 | errString := fmt.Sprintf("There is no chassis with CLLI of %s", clli) |
| 39 | return "", errors.New(errString) |
| 40 | } |
| 41 | physicalChassis := &chassisHolder.PhysicalChassis |
Don Newton | 5154fff | 2018-11-06 17:40:58 -0500 | [diff] [blame] | 42 | sOlt := physical.SimpleOLT{CLLI: clli, Hostname: hostname, Driver: driver, Address: address, Parent: physicalChassis} |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 43 | switch oltType { |
| 44 | case "edgecore": |
| 45 | sOlt.CreateEdgecore() |
| 46 | case "adtran": |
| 47 | case "tibit": |
| 48 | } |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 49 | ports := sOlt.GetPorts() |
| 50 | for i := 0; i < len(ports); i++ { |
Don Newton | 5154fff | 2018-11-06 17:40:58 -0500 | [diff] [blame] | 51 | absPort, err := chassisHolder.AbstractChassis.NextPort() |
| 52 | if err != nil { |
| 53 | fmt.Println(err) |
| 54 | return "", err |
| 55 | } |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 56 | absPort.PhysPort = &ports[i] |
| 57 | //AssignTraits(&ports[i], absPort) |
| 58 | } |
Don Newton | 5154fff | 2018-11-06 17:40:58 -0500 | [diff] [blame] | 59 | physicalChassis.AddOLTChassis(sOlt) |
Don Newton | e973d34 | 2018-10-26 16:44:12 -0400 | [diff] [blame] | 60 | isDirty = true |
| 61 | return clli, nil |
| 62 | |
| 63 | } |