Skip to content

Commit

Permalink
[major_change] Added parentDn to vnsRedirectDest model and client fil…
Browse files Browse the repository at this point in the history
…es (#243)
  • Loading branch information
sajagana authored Nov 9, 2022
1 parent fb289fb commit 1b7053a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 77 deletions.
57 changes: 22 additions & 35 deletions client/vnsRedirectDest_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ package client

import (
"fmt"
"log"

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

func (sm *ServiceManager) CreateDestinationofredirectedtraffic(ip string, service_redirect_policy string, tenant string, description string, vnsRedirectDestattr models.DestinationofredirectedtrafficAttributes) (*models.Destinationofredirectedtraffic, error) {
rn := fmt.Sprintf("RedirectDest_ip-[%s]", ip)
parentDn := fmt.Sprintf("uni/tn-%s/svcCont/svcRedirectPol-%s", tenant, service_redirect_policy)
vnsRedirectDest := models.NewDestinationofredirectedtraffic(rn, parentDn, description, vnsRedirectDestattr)
func (sm *ServiceManager) CreateDestinationofredirectedtraffic(ip string, parentDn string, description string, nameAlias string, vnsRedirectDestAttr models.DestinationofredirectedtrafficAttributes) (*models.Destinationofredirectedtraffic, error) {
rn := fmt.Sprintf(models.RnvnsRedirectDest, ip)
vnsRedirectDest := models.NewDestinationofredirectedtraffic(rn, parentDn, description, nameAlias, vnsRedirectDestAttr)
err := sm.Save(vnsRedirectDest)
return vnsRedirectDest, err
}

func (sm *ServiceManager) ReadDestinationofredirectedtraffic(ip string, service_redirect_policy string, tenant string) (*models.Destinationofredirectedtraffic, error) {
dn := fmt.Sprintf("uni/tn-%s/svcCont/svcRedirectPol-%s/RedirectDest_ip-[%s]", tenant, service_redirect_policy, ip)
func (sm *ServiceManager) ReadDestinationofredirectedtraffic(ip string, parentDn string) (*models.Destinationofredirectedtraffic, error) {
dn := fmt.Sprintf("%s/%s", parentDn, fmt.Sprintf(models.RnvnsRedirectDest, ip))

cont, err := sm.Get(dn)
if err != nil {
return nil, err
Expand All @@ -27,73 +26,62 @@ func (sm *ServiceManager) ReadDestinationofredirectedtraffic(ip string, service_
return vnsRedirectDest, nil
}

func (sm *ServiceManager) DeleteDestinationofredirectedtraffic(ip string, service_redirect_policy string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/svcCont/svcRedirectPol-%s/RedirectDest_ip-[%s]", tenant, service_redirect_policy, ip)
func (sm *ServiceManager) DeleteDestinationofredirectedtraffic(ip string, parentDn string) error {
dn := fmt.Sprintf("%s/%s", parentDn, fmt.Sprintf(models.RnvnsRedirectDest, ip))
return sm.DeleteByDn(dn, models.VnsredirectdestClassName)
}

func (sm *ServiceManager) UpdateDestinationofredirectedtraffic(ip string, service_redirect_policy string, tenant string, description string, vnsRedirectDestattr models.DestinationofredirectedtrafficAttributes) (*models.Destinationofredirectedtraffic, error) {
rn := fmt.Sprintf("RedirectDest_ip-[%s]", ip)
parentDn := fmt.Sprintf("uni/tn-%s/svcCont/svcRedirectPol-%s", tenant, service_redirect_policy)
vnsRedirectDest := models.NewDestinationofredirectedtraffic(rn, parentDn, description, vnsRedirectDestattr)

func (sm *ServiceManager) UpdateDestinationofredirectedtraffic(ip string, parentDn string, description string, nameAlias string, vnsRedirectDestAttr models.DestinationofredirectedtrafficAttributes) (*models.Destinationofredirectedtraffic, error) {
rn := fmt.Sprintf(models.RnvnsRedirectDest, ip)
vnsRedirectDest := models.NewDestinationofredirectedtraffic(rn, parentDn, description, nameAlias, vnsRedirectDestAttr)
vnsRedirectDest.Status = "modified"
err := sm.Save(vnsRedirectDest)
return vnsRedirectDest, err

}

func (sm *ServiceManager) ListDestinationofredirectedtraffic(service_redirect_policy string, tenant string) ([]*models.Destinationofredirectedtraffic, error) {

baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/svcCont/svcRedirectPol-%s/vnsRedirectDest.json", baseurlStr, tenant, service_redirect_policy)

func (sm *ServiceManager) ListDestinationofredirectedtraffic(parentDn string) ([]*models.Destinationofredirectedtraffic, error) {
dnUrl := fmt.Sprintf("%s/%s/vnsRedirectDest.json", models.BaseurlStr, parentDn)
cont, err := sm.GetViaURL(dnUrl)
list := models.DestinationofredirectedtrafficListFromContainer(cont)

return list, err
}

func (sm *ServiceManager) CreateRelationvnsRsRedirectHealthGroupFromDestinationofredirectedtraffic(parentDn, tnVnsRedirectHealthGroupName string) error {
func (sm *ServiceManager) CreateRelationvnsRsRedirectHealthGroup(parentDn, annotation, tDn string) error {
dn := fmt.Sprintf("%s/rsRedirectHealthGroup", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s","tDn": "%s","annotation":"orchestrator:terraform"
"dn": "%s",
"annotation": "%s",
"tDn": "%s"
}
}
}`, "vnsRsRedirectHealthGroup", dn, tnVnsRedirectHealthGroupName))
}`, "vnsRsRedirectHealthGroup", dn, annotation, tDn))

jsonPayload, err := container.ParseJSON(containerJSON)
if err != nil {
return err
}

req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true)
if err != nil {
return err
}

cont, _, err := sm.client.Do(req)
if err != nil {
return err
}
log.Printf("%+v", cont)

fmt.Printf("%+v", cont)
return nil
}

func (sm *ServiceManager) DeleteRelationvnsRsRedirectHealthGroupFromDestinationofredirectedtraffic(parentDn string) error {
func (sm *ServiceManager) DeleteRelationvnsRsRedirectHealthGroup(parentDn string) error {
dn := fmt.Sprintf("%s/rsRedirectHealthGroup", parentDn)
return sm.DeleteByDn(dn, "vnsRsRedirectHealthGroup")
}

func (sm *ServiceManager) ReadRelationvnsRsRedirectHealthGroupFromDestinationofredirectedtraffic(parentDn string) (interface{}, error) {
baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/%s/%s.json", baseurlStr, parentDn, "vnsRsRedirectHealthGroup")
func (sm *ServiceManager) ReadRelationvnsRsRedirectHealthGroup(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsRedirectHealthGroup")
cont, err := sm.GetViaURL(dnUrl)

contList := models.ListFromContainer(cont, "vnsRsRedirectHealthGroup")

if len(contList) > 0 {
Expand All @@ -102,5 +90,4 @@ func (sm *ServiceManager) ReadRelationvnsRsRedirectHealthGroupFromDestinationofr
} else {
return nil, err
}

}
77 changes: 35 additions & 42 deletions models/vns_redirect_dest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,28 @@ import (
"github.com/ciscoecosystem/aci-go-client/container"
)

const VnsredirectdestClassName = "vnsRedirectDest"
const (
RnvnsRedirectDest = "RedirectDest_ip-[%s]"
VnsredirectdestClassName = "vnsRedirectDest"
)

type Destinationofredirectedtraffic struct {
BaseAttributes
NameAliasAttribute
DestinationofredirectedtrafficAttributes
}

type DestinationofredirectedtrafficAttributes struct {
Ip string `json:",omitempty"`

Annotation string `json:",omitempty"`

DestName string `json:",omitempty"`

Ip2 string `json:",omitempty"`

Mac string `json:",omitempty"`

NameAlias string `json:",omitempty"`

PodId string `json:",omitempty"`
DestName string `json:",omitempty"`
Ip string `json:",omitempty"`
Ip2 string `json:",omitempty"`
Mac string `json:",omitempty"`
Name string `json:",omitempty"`
PodId string `json:",omitempty"`
}

func NewDestinationofredirectedtraffic(vnsRedirectDestRn, parentDn, description string, vnsRedirectDestattr DestinationofredirectedtrafficAttributes) *Destinationofredirectedtraffic {
func NewDestinationofredirectedtraffic(vnsRedirectDestRn, parentDn, description, nameAlias string, vnsRedirectDestAttr DestinationofredirectedtrafficAttributes) *Destinationofredirectedtraffic {
dn := fmt.Sprintf("%s/%s", parentDn, vnsRedirectDestRn)
return &Destinationofredirectedtraffic{
BaseAttributes: BaseAttributes{
Expand All @@ -40,8 +38,10 @@ func NewDestinationofredirectedtraffic(vnsRedirectDestRn, parentDn, description
ClassName: VnsredirectdestClassName,
Rn: vnsRedirectDestRn,
},

DestinationofredirectedtrafficAttributes: vnsRedirectDestattr,
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
DestinationofredirectedtrafficAttributes: vnsRedirectDestAttr,
}
}

Expand All @@ -51,25 +51,26 @@ func (vnsRedirectDest *Destinationofredirectedtraffic) ToMap() (map[string]strin
return nil, err
}

A(vnsRedirectDestMap, "ip", vnsRedirectDest.Ip)
alias, err := vnsRedirectDest.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}

A(vnsRedirectDestMap, "annotation", vnsRedirectDest.Annotation)
for key, value := range alias {
A(vnsRedirectDestMap, key, value)
}

A(vnsRedirectDestMap, "annotation", vnsRedirectDest.Annotation)
A(vnsRedirectDestMap, "destName", vnsRedirectDest.DestName)

A(vnsRedirectDestMap, "ip", vnsRedirectDest.Ip)
A(vnsRedirectDestMap, "ip2", vnsRedirectDest.Ip2)

A(vnsRedirectDestMap, "mac", vnsRedirectDest.Mac)

A(vnsRedirectDestMap, "nameAlias", vnsRedirectDest.NameAlias)

A(vnsRedirectDestMap, "name", vnsRedirectDest.Name)
A(vnsRedirectDestMap, "podId", vnsRedirectDest.PodId)

return vnsRedirectDestMap, err
}

func DestinationofredirectedtrafficFromContainerList(cont *container.Container, index int) *Destinationofredirectedtraffic {

DestinationofredirectedtrafficCont := cont.S("imdata").Index(index).S(VnsredirectdestClassName, "attributes")
return &Destinationofredirectedtraffic{
BaseAttributes{
Expand All @@ -79,38 +80,30 @@ func DestinationofredirectedtrafficFromContainerList(cont *container.Container,
ClassName: VnsredirectdestClassName,
Rn: G(DestinationofredirectedtrafficCont, "rn"),
},

NameAliasAttribute{
NameAlias: G(DestinationofredirectedtrafficCont, "nameAlias"),
},
DestinationofredirectedtrafficAttributes{

Ip: G(DestinationofredirectedtrafficCont, "ip"),

Annotation: G(DestinationofredirectedtrafficCont, "annotation"),

DestName: G(DestinationofredirectedtrafficCont, "destName"),

Ip2: G(DestinationofredirectedtrafficCont, "ip2"),

Mac: G(DestinationofredirectedtrafficCont, "mac"),

NameAlias: G(DestinationofredirectedtrafficCont, "nameAlias"),

PodId: G(DestinationofredirectedtrafficCont, "podId"),
DestName: G(DestinationofredirectedtrafficCont, "destName"),
Ip: G(DestinationofredirectedtrafficCont, "ip"),
Ip2: G(DestinationofredirectedtrafficCont, "ip2"),
Mac: G(DestinationofredirectedtrafficCont, "mac"),
Name: G(DestinationofredirectedtrafficCont, "name"),
PodId: G(DestinationofredirectedtrafficCont, "podId"),
},
}
}

func DestinationofredirectedtrafficFromContainer(cont *container.Container) *Destinationofredirectedtraffic {

return DestinationofredirectedtrafficFromContainerList(cont, 0)
}

func DestinationofredirectedtrafficListFromContainer(cont *container.Container) []*Destinationofredirectedtraffic {
length, _ := strconv.Atoi(G(cont, "totalCount"))

arr := make([]*Destinationofredirectedtraffic, length)

for i := 0; i < length; i++ {

arr[i] = DestinationofredirectedtrafficFromContainerList(cont, i)
}

Expand Down

0 comments on commit 1b7053a

Please sign in to comment.