blob: 07bd997134539fa78796851d5cb6b05f36b033ae [file] [log] [blame]
donNewtonAlpha1d2d6812018-09-14 16:00:02 -04001/*
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*/
16package tosca
17
18import (
19 "log"
20
21 yaml "gopkg.in/yaml.v2"
22)
23
24var templateData = `
25tosca_definitions_version: tosca_simple_yaml_1_0
26imports:
27 - custom_types/oltdevice.yaml
28 - custom_types/onudevice.yaml
29 - custom_types/ponport.yaml
30 - custom_types/voltservice.yaml
31description: Create a simulated OLT Device in VOLTHA
32topology_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"
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040047 nas_id:
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040048 switch_datapath_id: of:0000000000000001
49 switch_port: "1"
Don Newton276cd1f2019-02-06 17:14:03 -050050 uplink: "65536"
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040051 requirements:
52 - volt_service:
53 node: service#volt
54 relationship: tosca.relationships.BelongsToOne
55`
56
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040057/*
58OltProvision struct that serves as model for yaml to provsion OLT in XOS
59*/
60
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040061type 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 {
donNewtonAlphae7ab5b92018-09-27 15:09:14 -040077 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"`
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040086 } `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 = `
99tosca_definitions_version: tosca_simple_yaml_1_0
100imports:
101 - custom_types/oltdevice.yaml
102 - custom_types/onudevice.yaml
103 - custom_types/ponport.yaml
104 - custom_types/voltservice.yaml
105`
106
107type OltProvsion struct {
108 Tosca_Definitions_Version string
109 Imports []string
110}
111*/
112
113func 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
129func (olt *OltProvsion) ToYaml() (string, error) {
130 b, err := yaml.Marshal(olt)
131 return string(b), err
132}