blob: 448569c3beb4f59ef5c34e651289bc660f62e6d6 [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 "strings"
21
22 yaml "gopkg.in/yaml.v2"
23)
24
25var subSubscriberTemplate = `tosca_definitions_version: tosca_simple_yaml_1_0
26imports:
27 - custom_types/rcordsubscriber.yaml
28
29description: Pre-provsion a subscriber
30topology_template:
31 node_templates:
32 RG_NAME:
33 type: tosca.nodes.RCORDSubscriber
34 properties:
35 name:
36 status: pre-provisioned
37 c_tag:
38 s_tag:
39 onu_device:
40 nas_port_id:
41 circuit_id:
42 remote_id:`
43
44type SubscriberProvision struct {
45 ToscaDefinitionsVersion string `yaml:"tosca_definitions_version"`
46 Imports []string `yaml:"imports"`
47 Description string `yaml:"description"`
48 TopologyTemplate struct {
49 NodeTemplates struct {
50 RgName struct {
51 Type string `yaml:"type`
52 Properties struct {
53 Name string `yaml:"name"`
54 Status string `yaml:"status"`
55 CTag int `yaml:"c_tag"`
56 STag int `yaml:"s_tag"`
57 OnuDevice string `yaml:"onu_device"`
58 NasPortID string `yaml:"nas_port_id"`
59 CircuitID string `yaml:"circuit_id"`
60 RemoteID string `yaml:"remote_id"`
61 } `yaml:"properties"`
62 } `yaml:"RG_NAME"`
63 } `yaml:"node_templates"`
64 } `yaml:"topology_template"`
65}
66
67func NewSubscriberProvision(name string, cTag int, sTag int, onuDevice string, nasPortID string, circuitID string, remoteID string) SubscriberProvision {
68 s := SubscriberProvision{}
69 err := yaml.Unmarshal([]byte(subSubscriberTemplate), &s)
70 if err != nil {
71 log.Printf("Error un-marshalling template data %v\n", err)
72 }
73 props := &s.TopologyTemplate.NodeTemplates.RgName.Properties
74 props.Name = name
75 props.CTag = cTag
76 props.STag = sTag
77 props.OnuDevice = onuDevice
78 props.NasPortID = nasPortID
79 props.CircuitID = circuitID
80 props.RemoteID = remoteID
81 return s
82}
83func (sub *SubscriberProvision) ToYaml() (string, error) {
84 b, err := yaml.Marshal(sub)
85 ret := string(b)
86 name := sub.TopologyTemplate.NodeTemplates.RgName.Properties.Name
87 ret = strings.Replace(ret, "RG_NAME", name, -1)
88 return ret, err
89}