-
Notifications
You must be signed in to change notification settings - Fork 30
/
tag_tag.go
76 lines (66 loc) · 1.66 KB
/
tag_tag.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
package models
import (
"fmt"
"strconv"
"github.com/ciscoecosystem/aci-go-client/container"
)
const (
DnTagTag = "%s/tagKey-%s"
RnTagTag = "tagKey-%s"
TagTagClassName = "tagTag"
)
type Tag struct {
BaseAttributes
TagAttributes
}
type TagAttributes struct {
Key string `json:",omitempty"`
Value string `json:",omitempty"`
}
func NewTag(tagTagRn, parentDn string, tagTagAttr TagAttributes) *Tag {
dn := fmt.Sprintf("%s/%s", parentDn, tagTagRn)
return &Tag{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Status: "created, modified",
ClassName: TagTagClassName,
Rn: tagTagRn,
},
TagAttributes: tagTagAttr,
}
}
func (tagTag *Tag) ToMap() (map[string]string, error) {
tagTagMap, err := tagTag.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
A(tagTagMap, "key", tagTag.Key)
A(tagTagMap, "value", tagTag.Value)
return tagTagMap, err
}
func TagFromContainerList(cont *container.Container, index int) *Tag {
TagCont := cont.S("imdata").Index(index).S(TagTagClassName, "attributes")
return &Tag{
BaseAttributes{
DistinguishedName: G(TagCont, "dn"),
Status: G(TagCont, "status"),
ClassName: TagTagClassName,
Rn: G(TagCont, "rn"),
},
TagAttributes{
Key: G(TagCont, "key"),
Value: G(TagCont, "value"),
},
}
}
func TagFromContainer(cont *container.Container) *Tag {
return TagFromContainerList(cont, 0)
}
func TagListFromContainer(cont *container.Container) []*Tag {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*Tag, length)
for i := 0; i < length; i++ {
arr[i] = TagFromContainerList(cont, i)
}
return arr
}