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