-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v2.31.0
- v2.30.1
- v2.30.0
- v2.29.0
- v2.28.2
- v2.28.1
- v2.28.0
- v2.27.0
- v2.26.0
- v2.25.2
- v2.25.1
- v2.25.0
- v2.24.0
- v2.23.0
- v2.22.1
- v2.22.0
- v2.21.0
- v2.20.0
- v2.19.0
- v2.18.0
- v2.17.0
- v2.16.0
- v2.15.0
- v2.14.0
- v2.13.0
- v2.12.0
- v2.11.1
- v2.11.0
- v2.10.0
- v2.9.0
- v2.8.0
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.0
- v2.2.0
- v2.1.0
- v2.0.2
- v2.0.1
- v2.0.0
- v1.54.0
- v1.53.2
- v1.53.1
- v1.53.0
- v1.52.0
- v1.51.0
- v1.50.0
- v1.49.0
- v1.48.0
- v1.47.0
- v1.46.0
- v1.45.3
- v1.45.2
- v1.45.1
- v1.45.0
- v1.44.0
- v1.43.0
- v1.42.0
- v1.41.0
- v1.40.0
- v1.39.1
- v1.39.0
- v1.38.1
- v1.38.0
- v1.37.0
- v1.36.1
- v1.36.0
- v1.35.2
- v1.35.1
- v1.35.0
- v1.34.1
- v1.34.0
- v1.33.0
- v1.32.0
- v1.31.0
- v1.30.0
- v1.29.1
- v1.29.0
- v1.28.0
- v1.27.0
- v1.26.2
- v1.26.1
- v1.26.0
- v1.25.1
- v1.25.0
- v1.24.1
- v1.24.0
- v1.23.2
- v1.23.1
- v1.23.0
- v1.22.0
- v1.21.1
- v1.21.0
- v1.20.4
- v1.20.3
- v1.20.2
- v1.20.1
- v1.20.0
- v1.19.2
- v1.19.1
- v1.19.0
Showing
2 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreateTag(key string, parentDn string, tagTagAttr models.TagAttributes) (*models.Tag, error) { | ||
rn := fmt.Sprintf(models.RnTagTag, key) | ||
tagTag := models.NewTag(rn, parentDn, tagTagAttr) | ||
err := sm.Save(tagTag) | ||
return tagTag, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadTag(key string, parentDn string) (*models.Tag, error) { | ||
dn := fmt.Sprintf(models.DnTagTag, parentDn, key) | ||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tagTag := models.TagFromContainer(cont) | ||
return tagTag, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteTag(key string, parentDn string) error { | ||
dn := fmt.Sprintf(models.DnTagTag, parentDn, key) | ||
return sm.DeleteByDn(dn, models.TagTagClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdateTag(key string, parentDn string, tagTagAttr models.TagAttributes) (*models.Tag, error) { | ||
rn := fmt.Sprintf(models.RnTagTag, key) | ||
tagTag := models.NewTag(rn, parentDn, tagTagAttr) | ||
tagTag.Status = "modified" | ||
err := sm.Save(tagTag) | ||
return tagTag, err | ||
} | ||
|
||
func (sm *ServiceManager) ListTag() ([]*models.Tag, error) { | ||
dnUrl := fmt.Sprintf("%s/tagTag.json", models.BaseurlStr) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.TagListFromContainer(cont) | ||
return list, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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, 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 | ||
} |