Author Name | a594e63 | 2018-08-10 11:33:58 -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 physical |
| 18 | |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 19 | import ( |
| 20 | "fmt" |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 21 | "log" |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 22 | "net" |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 23 | "net/http" |
| 24 | "strings" |
| 25 | |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 26 | "gerrit.opencord.org/abstract-olt/internal/pkg/settings" |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 27 | "gerrit.opencord.org/abstract-olt/models/tosca" |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 28 | ) |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | Chassis is a model that takes up to 16 discreet OLT chassis as if it is a 16 slot OLT chassis |
| 32 | */ |
| 33 | type Chassis struct { |
| 34 | CLLI string |
| 35 | VCoreAddress net.TCPAddr |
| 36 | Dataswitch DataSwitch |
| 37 | Linecards []OLT |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 38 | Rack int |
| 39 | Shelf int |
Author Name | a594e63 | 2018-08-10 11:33:58 -0400 | [diff] [blame] | 40 | } |
donNewtonAlpha | 8205a4d | 2018-08-16 18:27:20 -0400 | [diff] [blame] | 41 | type UnprovisionedSlotError struct { |
| 42 | CLLI string |
| 43 | SlotNumber int |
| 44 | } |
| 45 | |
| 46 | func (e *UnprovisionedSlotError) Error() string { |
| 47 | return fmt.Sprintf("SlotNumber %d in Chassis %s is currently unprovsioned", e.SlotNumber, e.CLLI) |
| 48 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | AddOLTChassis - adds a reference to a new olt chassis |
| 52 | */ |
| 53 | func (chassis *Chassis) AddOLTChassis(olt OLT) { |
| 54 | chassis.Linecards = append(chassis.Linecards, olt) |
| 55 | //TODO - api call to add olt i.e. preprovision_olt |
| 56 | fmt.Printf("chassis.AddOLTChassis(%s)\n", olt.GetHostname()) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 57 | //S>103 func NewOltProvision(name string, deviceType string, host string, port int) OltProvsion { |
| 58 | ipString := olt.GetAddress().IP.String() |
| 59 | webServerPort := olt.GetAddress().Port |
| 60 | oltStruct := tosca.NewOltProvision(chassis.CLLI, olt.GetHostname(), "openolt", ipString, webServerPort) |
| 61 | yaml, _ := oltStruct.ToYaml() |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 62 | if settings.GetDummy() { |
| 63 | log.Printf("yaml:%s\n", yaml) |
| 64 | log.Println("YAML IS NOT BEING SET TO XOS") |
| 65 | return |
| 66 | } |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 67 | client := &http.Client{} |
| 68 | requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port) |
| 69 | req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml)) |
| 70 | req.Header.Add("xos-username", "admin@opencord.org") |
| 71 | req.Header.Add("xos-password", "letmein") |
| 72 | resp, err := client.Do(req) |
| 73 | if err != nil { |
| 74 | fmt.Printf("ERROR :) %v\n", err) |
| 75 | // handle error |
| 76 | } |
| 77 | fmt.Printf("Response is %v\n", resp) |
| 78 | |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 79 | } |
| 80 | func (chassis *Chassis) provisionONT(ont Ont) { |
| 81 | //TODO - api call to provison s/c vlans and ont serial number etc |
| 82 | fmt.Printf("chassis.provisionONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan) |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 83 | ponPort := ont.Parent |
| 84 | slot := ponPort.Parent |
| 85 | |
| 86 | //func NewOntProvision(serialNumber string, oltIP net.IP, ponPortNumber int) OntProvision { |
| 87 | ontStruct := tosca.NewOntProvision(ont.SerialNumber, slot.Address.IP, ponPort.Number) |
| 88 | yaml, _ := ontStruct.ToYaml() |
| 89 | |
donNewtonAlpha | af22974 | 2018-09-19 13:22:00 -0400 | [diff] [blame] | 90 | if settings.GetDummy() { |
| 91 | log.Printf("yaml:%s\n", yaml) |
| 92 | log.Println("YAML IS NOT BEING SET TO XOS") |
| 93 | return |
| 94 | } |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 95 | client := &http.Client{} |
| 96 | requestList := fmt.Sprintf("http://%s:%d/run", chassis.VCoreAddress.IP.String(), chassis.VCoreAddress.Port) |
| 97 | req, err := http.NewRequest("POST", requestList, strings.NewReader(yaml)) |
| 98 | req.Header.Add("xos-username", "admin@opencord.org") |
| 99 | req.Header.Add("xos-password", "letmein") |
| 100 | resp, err := client.Do(req) |
| 101 | if err != nil { |
| 102 | fmt.Printf("ERROR :) %v\n", err) |
| 103 | // handle error |
| 104 | } |
| 105 | fmt.Printf("Response is %v\n", resp) |
| 106 | rgName := fmt.Sprintf("%s_%d_%d_%d_RG", chassis.CLLI, slot.Number, ponPort.Number, ont.Number) |
| 107 | subStruct := tosca.NewSubscriberProvision(rgName, ont.Cvlan, ont.Svlan, ont.SerialNumber, ont.NasPortID, ont.CircuitID, chassis.CLLI) |
| 108 | yaml, _ = subStruct.ToYaml() |
| 109 | fmt.Printf("yaml:%s\n", yaml) |
| 110 | req, err = http.NewRequest("POST", requestList, strings.NewReader(yaml)) |
| 111 | req.Header.Add("xos-username", "admin@opencord.org") |
| 112 | req.Header.Add("xos-password", "letmein") |
| 113 | resp, err = client.Do(req) |
| 114 | if err != nil { |
| 115 | fmt.Printf("ERROR :) %v\n", err) |
| 116 | // handle error |
| 117 | } |
donNewtonAlpha | 5234b13 | 2018-08-16 14:12:28 -0400 | [diff] [blame] | 118 | } |
donNewtonAlpha | f7cc999 | 2018-08-29 14:23:02 -0400 | [diff] [blame] | 119 | func (chassis *Chassis) deleteONT(ont Ont) { |
| 120 | //TODO - api call to provison s/c vlans and ont serial number etc |
| 121 | fmt.Printf("chassis.deleteONT(%s,SVlan:%d,CVlan:%d)\n", ont.SerialNumber, ont.Svlan, ont.Cvlan) |
| 122 | } |
donNewtonAlpha | 8205a4d | 2018-08-16 18:27:20 -0400 | [diff] [blame] | 123 | func (chassis *Chassis) ActivateSlot(slotNumber int) error { |
| 124 | // AT&T backend systems start at 1 and not 0 :P |
| 125 | if chassis.Linecards[slotNumber-1] == nil { |
| 126 | return &UnprovisionedSlotError{CLLI: chassis.CLLI, SlotNumber: slotNumber} |
| 127 | } |
| 128 | return chassis.Linecards[slotNumber-1].activate() |
| 129 | } |