blob: 00058001c8c49389be1c81a080e7ca9d024c060d [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"
47 uplink: "65536"
48 nas_id:
49 requirements:
50 - volt_service:
51 node: service#volt
52 relationship: tosca.relationships.BelongsToOne
53`
54
55type OltProvsion struct {
56 ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"`
57 Imports []string `yaml:"imports"`
58 Description string `yaml:"description"`
59 TopologyTemplate struct {
60 NodeTemplates struct {
61 ServiceVolt struct {
62 Type string `yaml:"type"`
63 Properties struct {
64 Name string `yaml:"name"`
65 MustExist bool `yaml:"must-exist"`
66 } `yaml:"properties"`
67 } `yaml:"service#volt"`
68 OltDevice struct {
69 DeviceType string `yaml:"type"`
70 Properties struct {
71 Name string `yaml:"name"`
72 Type string `yaml:"device_type"`
73 Host string `yaml:"host"`
74 Port int `yaml:"port"`
75 OuterTpid string `yaml:"outer_tpid"`
76 Uplink string `yaml:"uplink"`
77 NasID string `yaml:"nas_id"`
78 } `yaml:"properties"`
79 Requirements []struct {
80 VoltService struct {
81 Node string `yaml:"node"`
82 Relationship string `yaml:"relationship"`
83 } `yaml:"volt_service"`
84 } `yaml:"requirements"`
85 } `yaml:"olt_device"`
86 } `yaml:"node_templates"`
87 } `yaml:"topology_template"`
88}
89
90/*var templateData = `
91tosca_definitions_version: tosca_simple_yaml_1_0
92imports:
93 - custom_types/oltdevice.yaml
94 - custom_types/onudevice.yaml
95 - custom_types/ponport.yaml
96 - custom_types/voltservice.yaml
97`
98
99type OltProvsion struct {
100 Tosca_Definitions_Version string
101 Imports []string
102}
103*/
104
105func NewOltProvision(clli string, name string, deviceType string, host string, port int) OltProvsion {
106 o := OltProvsion{}
107 err := yaml.Unmarshal([]byte(templateData), &o)
108 if err != nil {
109 log.Printf("Error un-marshalling template data %v\n", err)
110 }
111
112 props := &o.TopologyTemplate.NodeTemplates.OltDevice.Properties
113 props.Name = name
114 props.Type = deviceType
115 props.Host = host
116 props.Port = port
117 props.NasID = clli
118 return o
119}
120
121func (olt *OltProvsion) ToYaml() (string, error) {
122 b, err := yaml.Marshal(olt)
123 return string(b), err
124}