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 | package impl |
| 17 | |
| 18 | import ( |
| 19 | "errors" |
| 20 | "fmt" |
| 21 | "log" |
| 22 | "net" |
| 23 | "strings" |
| 24 | |
| 25 | "gerrit.opencord.org/abstract-olt/internal/pkg/settings" |
| 26 | "gerrit.opencord.org/abstract-olt/models" |
| 27 | "gerrit.opencord.org/abstract-olt/models/abstract" |
| 28 | "gerrit.opencord.org/abstract-olt/models/physical" |
| 29 | ) |
| 30 | |
| 31 | /* |
| 32 | CreateChassis - allocates a new Chassis struct and stores it in chassisMap |
| 33 | */ |
| 34 | func CreateChassis(clli string, xosAddress net.TCPAddr, xosUser string, xosPassword string, shelf int, rack int) (string, error) { |
| 35 | myChan := getSyncChannel() |
| 36 | <-myChan |
| 37 | defer done(myChan, true) |
| 38 | chassisMap := models.GetChassisMap() |
| 39 | |
| 40 | loginWorked := testLogin(xosUser, xosPassword, xosAddress.IP, xosAddress.Port) |
| 41 | if !loginWorked { |
| 42 | return "", errors.New("Unable to validate login not creating Abstract Chassis") |
| 43 | } |
| 44 | |
| 45 | chassisHolder := (*chassisMap)[clli] |
| 46 | if chassisHolder != nil { |
| 47 | errMsg := fmt.Sprintf("AbstractChassis %s already exists", clli) |
| 48 | return "", errors.New(errMsg) |
| 49 | } |
| 50 | |
| 51 | abstractChassis := abstract.GenerateChassis(clli, rack, shelf) |
| 52 | phyChassis := physical.Chassis{CLLI: clli, XOSUser: xosUser, XOSPassword: xosPassword, XOSAddress: xosAddress, Rack: rack, Shelf: shelf} |
| 53 | |
| 54 | chassisHolder = &models.ChassisHolder{AbstractChassis: abstractChassis, PhysicalChassis: phyChassis} |
| 55 | if settings.GetDebug() { |
| 56 | output := fmt.Sprintf("%v", abstractChassis) |
| 57 | formatted := strings.Replace(output, "{", "\n{", -1) |
| 58 | log.Printf("new chassis %s\n", formatted) |
| 59 | } |
| 60 | (*chassisMap)[clli] = chassisHolder |
| 61 | isDirty = true |
| 62 | return clli, nil |
| 63 | } |