donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -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 tosca |
| 17 | |
| 18 | import ( |
| 19 | "log" |
| 20 | |
| 21 | yaml "gopkg.in/yaml.v2" |
| 22 | ) |
| 23 | |
| 24 | var templateData = ` |
| 25 | tosca_definitions_version: tosca_simple_yaml_1_0 |
| 26 | imports: |
| 27 | - custom_types/oltdevice.yaml |
| 28 | - custom_types/onudevice.yaml |
| 29 | - custom_types/ponport.yaml |
| 30 | - custom_types/voltservice.yaml |
| 31 | description: Create a simulated OLT Device in VOLTHA |
| 32 | topology_template: |
| 33 | node_templates: |
| 34 | service#volt: |
| 35 | type: tosca.nodes.VOLTService |
| 36 | properties: |
| 37 | name: volt |
| 38 | must-exist: true |
| 39 | olt_device: |
| 40 | type: tosca.nodes.OLTDevice |
| 41 | properties: |
| 42 | name: test |
| 43 | type: test |
| 44 | host: test |
| 45 | port: 32 |
| 46 | outer_tpid: "0x8100" |
| 47 | uplink: "65536" |
| 48 | nas_id: |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 49 | switch_datapath_id: of:0000000000000001 |
| 50 | switch_port: "1" |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 51 | requirements: |
| 52 | - volt_service: |
| 53 | node: service#volt |
| 54 | relationship: tosca.relationships.BelongsToOne |
| 55 | ` |
| 56 | |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 57 | /* |
| 58 | OltProvision struct that serves as model for yaml to provsion OLT in XOS |
| 59 | */ |
| 60 | |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 61 | type OltProvsion struct { |
| 62 | ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"` |
| 63 | Imports []string `yaml:"imports"` |
| 64 | Description string `yaml:"description"` |
| 65 | TopologyTemplate struct { |
| 66 | NodeTemplates struct { |
| 67 | ServiceVolt struct { |
| 68 | Type string `yaml:"type"` |
| 69 | Properties struct { |
| 70 | Name string `yaml:"name"` |
| 71 | MustExist bool `yaml:"must-exist"` |
| 72 | } `yaml:"properties"` |
| 73 | } `yaml:"service#volt"` |
| 74 | OltDevice struct { |
| 75 | DeviceType string `yaml:"type"` |
| 76 | Properties struct { |
donNewtonAlpha | e7ab5b9 | 2018-09-27 15:09:14 -0400 | [diff] [blame] | 77 | Name string `yaml:"name"` |
| 78 | Type string `yaml:"device_type"` |
| 79 | Host string `yaml:"host"` |
| 80 | Port int `yaml:"port"` |
| 81 | OuterTpid string `yaml:"outer_tpid"` |
| 82 | Uplink string `yaml:"uplink"` |
| 83 | NasID string `yaml:"nas_id"` |
| 84 | SwitchDataPathID string `yaml:"switch_datapath_id"` |
| 85 | SwitchPort string `yaml:"switch_port"` |
donNewtonAlpha | 1d2d681 | 2018-09-14 16:00:02 -0400 | [diff] [blame] | 86 | } `yaml:"properties"` |
| 87 | Requirements []struct { |
| 88 | VoltService struct { |
| 89 | Node string `yaml:"node"` |
| 90 | Relationship string `yaml:"relationship"` |
| 91 | } `yaml:"volt_service"` |
| 92 | } `yaml:"requirements"` |
| 93 | } `yaml:"olt_device"` |
| 94 | } `yaml:"node_templates"` |
| 95 | } `yaml:"topology_template"` |
| 96 | } |
| 97 | |
| 98 | /*var templateData = ` |
| 99 | tosca_definitions_version: tosca_simple_yaml_1_0 |
| 100 | imports: |
| 101 | - custom_types/oltdevice.yaml |
| 102 | - custom_types/onudevice.yaml |
| 103 | - custom_types/ponport.yaml |
| 104 | - custom_types/voltservice.yaml |
| 105 | ` |
| 106 | |
| 107 | type OltProvsion struct { |
| 108 | Tosca_Definitions_Version string |
| 109 | Imports []string |
| 110 | } |
| 111 | */ |
| 112 | |
| 113 | func NewOltProvision(clli string, name string, deviceType string, host string, port int) OltProvsion { |
| 114 | o := OltProvsion{} |
| 115 | err := yaml.Unmarshal([]byte(templateData), &o) |
| 116 | if err != nil { |
| 117 | log.Printf("Error un-marshalling template data %v\n", err) |
| 118 | } |
| 119 | |
| 120 | props := &o.TopologyTemplate.NodeTemplates.OltDevice.Properties |
| 121 | props.Name = name |
| 122 | props.Type = deviceType |
| 123 | props.Host = host |
| 124 | props.Port = port |
| 125 | props.NasID = clli |
| 126 | return o |
| 127 | } |
| 128 | |
| 129 | func (olt *OltProvsion) ToYaml() (string, error) { |
| 130 | b, err := yaml.Marshal(olt) |
| 131 | return string(b), err |
| 132 | } |