Skip to content

Commit

Permalink
[minor_change] Addition of model and client files for vnsRedirectHeal…
Browse files Browse the repository at this point in the history
…thGroup (#216)
  • Loading branch information
shrsr authored Jun 1, 2022
1 parent cadec7e commit 66a5ef8
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
48 changes: 48 additions & 0 deletions client/vnsRedirectHealthGroup_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package client

import (
"fmt"

"github.com/ciscoecosystem/aci-go-client/models"
)

func (sm *ServiceManager) CreateL4L7RedirectHealthGroup(name string, tenant string, description string, nameAlias string, vnsRedirectHealthGroupAttr models.L4L7RedirectHealthGroupAttributes) (*models.L4L7RedirectHealthGroup, error) {
rn := fmt.Sprintf(models.RnvnsRedirectHealthGroup, name)
parentDn := fmt.Sprintf(models.ParentDnvnsRedirectHealthGroup, tenant)
vnsRedirectHealthGroup := models.NewL4L7RedirectHealthGroup(rn, parentDn, description, nameAlias, vnsRedirectHealthGroupAttr)
err := sm.Save(vnsRedirectHealthGroup)
return vnsRedirectHealthGroup, err
}

func (sm *ServiceManager) ReadL4L7RedirectHealthGroup(name string, tenant string) (*models.L4L7RedirectHealthGroup, error) {
dn := fmt.Sprintf(models.DnvnsRedirectHealthGroup, tenant, name)

cont, err := sm.Get(dn)
if err != nil {
return nil, err
}

vnsRedirectHealthGroup := models.L4L7RedirectHealthGroupFromContainer(cont)
return vnsRedirectHealthGroup, nil
}

func (sm *ServiceManager) DeleteL4L7RedirectHealthGroup(name string, tenant string) error {
dn := fmt.Sprintf(models.DnvnsRedirectHealthGroup, tenant, name)
return sm.DeleteByDn(dn, models.VnsredirecthealthgroupClassName)
}

func (sm *ServiceManager) UpdateL4L7RedirectHealthGroup(name string, tenant string, description string, nameAlias string, vnsRedirectHealthGroupAttr models.L4L7RedirectHealthGroupAttributes) (*models.L4L7RedirectHealthGroup, error) {
rn := fmt.Sprintf(models.RnvnsRedirectHealthGroup, name)
parentDn := fmt.Sprintf(models.ParentDnvnsRedirectHealthGroup, tenant)
vnsRedirectHealthGroup := models.NewL4L7RedirectHealthGroup(rn, parentDn, description, nameAlias, vnsRedirectHealthGroupAttr)
vnsRedirectHealthGroup.Status = "modified"
err := sm.Save(vnsRedirectHealthGroup)
return vnsRedirectHealthGroup, err
}

func (sm *ServiceManager) ListL4L7RedirectHealthGroup(tenant string) ([]*models.L4L7RedirectHealthGroup, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/svcCont/vnsRedirectHealthGroup.json", models.BaseurlStr, tenant)
cont, err := sm.GetViaURL(dnUrl)
list := models.L4L7RedirectHealthGroupListFromContainer(cont)
return list, err
}
98 changes: 98 additions & 0 deletions models/vns_redirect_health_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package models

import (
"fmt"
"strconv"

"github.com/ciscoecosystem/aci-go-client/container"
)

const (
DnvnsRedirectHealthGroup = "uni/tn-%s/svcCont/redirectHealthGroup-%s"
RnvnsRedirectHealthGroup = "redirectHealthGroup-%s"
ParentDnvnsRedirectHealthGroup = "uni/tn-%s/svcCont"
VnsredirecthealthgroupClassName = "vnsRedirectHealthGroup"
)

type L4L7RedirectHealthGroup struct {
BaseAttributes
NameAliasAttribute
L4L7RedirectHealthGroupAttributes
}

type L4L7RedirectHealthGroupAttributes struct {
Annotation string `json:",omitempty"`
Name string `json:",omitempty"`
}

func NewL4L7RedirectHealthGroup(vnsRedirectHealthGroupRn, parentDn, description, nameAlias string, vnsRedirectHealthGroupAttr L4L7RedirectHealthGroupAttributes) *L4L7RedirectHealthGroup {
dn := fmt.Sprintf("%s/%s", parentDn, vnsRedirectHealthGroupRn)
return &L4L7RedirectHealthGroup{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: VnsredirecthealthgroupClassName,
Rn: vnsRedirectHealthGroupRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
L4L7RedirectHealthGroupAttributes: vnsRedirectHealthGroupAttr,
}
}

func (vnsRedirectHealthGroup *L4L7RedirectHealthGroup) ToMap() (map[string]string, error) {
vnsRedirectHealthGroupMap, err := vnsRedirectHealthGroup.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

alias, err := vnsRedirectHealthGroup.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}

for key, value := range alias {
A(vnsRedirectHealthGroupMap, key, value)
}

A(vnsRedirectHealthGroupMap, "annotation", vnsRedirectHealthGroup.Annotation)
A(vnsRedirectHealthGroupMap, "name", vnsRedirectHealthGroup.Name)
return vnsRedirectHealthGroupMap, err
}

func L4L7RedirectHealthGroupFromContainerList(cont *container.Container, index int) *L4L7RedirectHealthGroup {
L4L7RedirectHealthGroupCont := cont.S("imdata").Index(index).S(VnsredirecthealthgroupClassName, "attributes")
return &L4L7RedirectHealthGroup{
BaseAttributes{
DistinguishedName: G(L4L7RedirectHealthGroupCont, "dn"),
Description: G(L4L7RedirectHealthGroupCont, "descr"),
Status: G(L4L7RedirectHealthGroupCont, "status"),
ClassName: VnsredirecthealthgroupClassName,
Rn: G(L4L7RedirectHealthGroupCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(L4L7RedirectHealthGroupCont, "nameAlias"),
},
L4L7RedirectHealthGroupAttributes{
Annotation: G(L4L7RedirectHealthGroupCont, "annotation"),
Name: G(L4L7RedirectHealthGroupCont, "name"),
},
}
}

func L4L7RedirectHealthGroupFromContainer(cont *container.Container) *L4L7RedirectHealthGroup {
return L4L7RedirectHealthGroupFromContainerList(cont, 0)
}

func L4L7RedirectHealthGroupListFromContainer(cont *container.Container) []*L4L7RedirectHealthGroup {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*L4L7RedirectHealthGroup, length)

for i := 0; i < length; i++ {
arr[i] = L4L7RedirectHealthGroupFromContainerList(cont, i)
}

return arr
}

0 comments on commit 66a5ef8

Please sign in to comment.