From 66a5ef83879a60fbf44db5ba1ad9a6f5f1670577 Mon Sep 17 00:00:00 2001 From: Shreyas Date: Tue, 31 May 2022 19:05:37 -0700 Subject: [PATCH] [minor_change] Addition of model and client files for vnsRedirectHealthGroup (#216) --- client/vnsRedirectHealthGroup_service.go | 48 ++++++++++++ models/vns_redirect_health_group.go | 98 ++++++++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 client/vnsRedirectHealthGroup_service.go create mode 100644 models/vns_redirect_health_group.go diff --git a/client/vnsRedirectHealthGroup_service.go b/client/vnsRedirectHealthGroup_service.go new file mode 100644 index 00000000..8039c01a --- /dev/null +++ b/client/vnsRedirectHealthGroup_service.go @@ -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 +} diff --git a/models/vns_redirect_health_group.go b/models/vns_redirect_health_group.go new file mode 100644 index 00000000..d07b7256 --- /dev/null +++ b/models/vns_redirect_health_group.go @@ -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 +}