blob: 680dd5ee8bdc28b17d86572394bc4c2a4c586d3a [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"`
Don Newton281e0252018-10-22 14:38:50 -040055 CTag uint32 `yaml:"c_tag"`
56 STag uint32 `yaml:"s_tag"`
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040057 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
Don Newton281e0252018-10-22 14:38:50 -040067func NewSubscriberProvision(name string, cTag uint32, sTag uint32, onuDevice string, nasPortID string, circuitID string, remoteID string) SubscriberProvision {
donNewtonAlpha1d2d6812018-09-14 16:00:02 -040068 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}