-
Notifications
You must be signed in to change notification settings - Fork 20
/
interface-mapping.go
91 lines (75 loc) · 2.19 KB
/
interface-mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package tosca_v2_0
import (
"reflect"
"github.com/tliron/kutil/ard"
"github.com/tliron/puccini/tosca"
)
//
// InterfaceMapping
//
// [TOSCA-v2.0] @ ?
// [TOSCA-Simple-Profile-YAML-v1.3] @ 3.8.12
// [TOSCA-Simple-Profile-YAML-v1.2] @ 3.8.11
//
type InterfaceMapping struct {
*Entity `name:"interface mapping"`
Name string
NodeTemplateName *string
InterfaceName *string
NodeTemplate *NodeTemplate `traverse:"ignore" json:"-" yaml:"-"`
Interface *InterfaceAssignment `traverse:"ignore" json:"-" yaml:"-"`
}
func NewInterfaceMapping(context *tosca.Context) *InterfaceMapping {
return &InterfaceMapping{
Entity: NewEntity(context),
Name: context.Name,
}
}
// tosca.Reader signature
func ReadInterfaceMapping(context *tosca.Context) tosca.EntityPtr {
self := NewInterfaceMapping(context)
if context.ValidateType(ard.TypeList) {
strings := context.ReadStringListFixed(2)
if strings != nil {
self.NodeTemplateName = &(*strings)[0]
self.InterfaceName = &(*strings)[1]
}
}
return self
}
// tosca.Mappable interface
func (self *InterfaceMapping) GetKey() string {
return self.Name
}
func (self *InterfaceMapping) GetInterfaceDefinition() (*InterfaceDefinition, bool) {
if (self.Interface != nil) && (self.NodeTemplate != nil) {
return self.Interface.GetDefinitionForNodeTemplate(self.NodeTemplate)
} else {
return nil, false
}
}
// parser.Renderable interface
func (self *InterfaceMapping) Render() {
logRender.Debug("interface mapping")
if (self.NodeTemplateName == nil) || (self.InterfaceName == nil) {
return
}
nodeTemplateName := *self.NodeTemplateName
var nodeTemplateType *NodeTemplate
if nodeTemplate, ok := self.Context.Namespace.LookupForType(nodeTemplateName, reflect.TypeOf(nodeTemplateType)); ok {
self.NodeTemplate = nodeTemplate.(*NodeTemplate)
self.NodeTemplate.Render()
} else {
self.Context.ListChild(0, nodeTemplateName).ReportUnknown("node template")
return
}
name := *self.InterfaceName
var ok bool
if self.Interface, ok = self.NodeTemplate.Interfaces[name]; !ok {
self.Context.ListChild(1, name).ReportReferenceNotFound("interface", self.NodeTemplate)
}
}
//
// InterfaceMappings
//
type InterfaceMappings map[string]*InterfaceMapping