Skip to content

Commit

Permalink
Add new resource BFD Multihop Interface Policy (bfdMhIfPol) to suppor…
Browse files Browse the repository at this point in the history
…t the relationship of bfdMhIfP object. Made the ReadRelationbfdRsMhIfPol() return tDn instead of name. (#272)
  • Loading branch information
anvitha-jain authored Jul 12, 2023
1 parent 64e486d commit b536fc1
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/bfdMhIfP_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (sm *ServiceManager) ReadRelationbfdRsMhIfPol(parentDn string) (interface{}
contList := models.ListFromContainer(cont, "bfdRsMhIfPol")

if len(contList) > 0 {
dat := models.G(contList[0], "tnBfdMhIfPolName")
dat := models.G(contList[0], "tDn")
return dat, err
} else {
return nil, err
Expand Down
48 changes: 48 additions & 0 deletions client/bfdMhIfPol_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/v2/models"
)

func (sm *ServiceManager) CreateAciBfdMultihopInterfacePolicy(name string, tenant string, description string, nameAlias string, bfdMhIfPolAttr models.AciBfdMultihopInterfacePolicyAttributes) (*models.AciBfdMultihopInterfacePolicy, error) {
rn := fmt.Sprintf(models.RnbfdMhIfPol, name)
parentDn := fmt.Sprintf(models.ParentDnbfdMhIfPol, tenant)
bfdMhIfPol := models.NewAciBfdMultihopInterfacePolicy(rn, parentDn, description, nameAlias, bfdMhIfPolAttr)
err := sm.Save(bfdMhIfPol)
return bfdMhIfPol, err
}

func (sm *ServiceManager) ReadAciBfdMultihopInterfacePolicy(name string, tenant string) (*models.AciBfdMultihopInterfacePolicy, error) {
dn := fmt.Sprintf(models.DnbfdMhIfPol, tenant, name)

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

bfdMhIfPol := models.AciBfdMultihopInterfacePolicyFromContainer(cont)
return bfdMhIfPol, nil
}

func (sm *ServiceManager) DeleteAciBfdMultihopInterfacePolicy(name string, tenant string) error {
dn := fmt.Sprintf(models.DnbfdMhIfPol, tenant, name)
return sm.DeleteByDn(dn, models.BfdmhifpolClassName)
}

func (sm *ServiceManager) UpdateAciBfdMultihopInterfacePolicy(name string, tenant string, description string, nameAlias string, bfdMhIfPolAttr models.AciBfdMultihopInterfacePolicyAttributes) (*models.AciBfdMultihopInterfacePolicy, error) {
rn := fmt.Sprintf(models.RnbfdMhIfPol, name)
parentDn := fmt.Sprintf(models.ParentDnbfdMhIfPol, tenant)
bfdMhIfPol := models.NewAciBfdMultihopInterfacePolicy(rn, parentDn, description, nameAlias, bfdMhIfPolAttr)
bfdMhIfPol.Status = "modified"
err := sm.Save(bfdMhIfPol)
return bfdMhIfPol, err
}

func (sm *ServiceManager) ListAciBfdMultihopInterfacePolicy(tenant string) ([]*models.AciBfdMultihopInterfacePolicy, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/bfdMhIfPol.json", models.BaseurlStr, tenant)
cont, err := sm.GetViaURL(dnUrl)
list := models.AciBfdMultihopInterfacePolicyListFromContainer(cont)
return list, err
}
4 changes: 2 additions & 2 deletions models/bfd_mh_if_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (bfdMhIfP *AciBfdMultihopInterfaceProfile) ToMap() (map[string]string, erro
A(bfdMhIfPMap, "key", bfdMhIfP.Key)
A(bfdMhIfPMap, "keyId", bfdMhIfP.KeyId)
A(bfdMhIfPMap, "name", bfdMhIfP.Name)
A(bfdMhIfPMap, "InterfaceProfile_type", bfdMhIfP.InterfaceProfile_type)
A(bfdMhIfPMap, "type", bfdMhIfP.InterfaceProfile_type)
return bfdMhIfPMap, err
}

Expand All @@ -86,7 +86,7 @@ func AciBfdMultihopInterfaceProfileFromContainerList(cont *container.Container,
Key: G(AciBfdMultihopInterfaceProfileCont, "key"),
KeyId: G(AciBfdMultihopInterfaceProfileCont, "keyId"),
Name: G(AciBfdMultihopInterfaceProfileCont, "name"),
InterfaceProfile_type: G(AciBfdMultihopInterfaceProfileCont, "InterfaceProfile_type"),
InterfaceProfile_type: G(AciBfdMultihopInterfaceProfileCont, "type"),
},
}
}
Expand Down
110 changes: 110 additions & 0 deletions models/bfd_mh_if_pol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package models

import (
"fmt"
"strconv"

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

const (
DnbfdMhIfPol = "uni/tn-%s/bfdMhIfPol-%s"
RnbfdMhIfPol = "bfdMhIfPol-%s"
ParentDnbfdMhIfPol = "uni/tn-%s"
BfdmhifpolClassName = "bfdMhIfPol"
)

type AciBfdMultihopInterfacePolicy struct {
BaseAttributes
NameAliasAttribute
AciBfdMultihopInterfacePolicyAttributes
}

type AciBfdMultihopInterfacePolicyAttributes struct {
Annotation string `json:",omitempty"`
AdminSt string `json:",omitempty"`
DetectMult string `json:",omitempty"`
MinRxIntvl string `json:",omitempty"`
MinTxIntvl string `json:",omitempty"`
Name string `json:",omitempty"`
}

func NewAciBfdMultihopInterfacePolicy(bfdMhIfPolRn, parentDn, description, nameAlias string, bfdMhIfPolAttr AciBfdMultihopInterfacePolicyAttributes) *AciBfdMultihopInterfacePolicy {
dn := fmt.Sprintf("%s/%s", parentDn, bfdMhIfPolRn)
return &AciBfdMultihopInterfacePolicy{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: BfdmhifpolClassName,
Rn: bfdMhIfPolRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
AciBfdMultihopInterfacePolicyAttributes: bfdMhIfPolAttr,
}
}

func (bfdMhIfPol *AciBfdMultihopInterfacePolicy) ToMap() (map[string]string, error) {
bfdMhIfPolMap, err := bfdMhIfPol.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

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

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

A(bfdMhIfPolMap, "adminSt", bfdMhIfPol.AdminSt)
A(bfdMhIfPolMap, "annotation", bfdMhIfPol.Annotation)
A(bfdMhIfPolMap, "detectMult", bfdMhIfPol.DetectMult)
A(bfdMhIfPolMap, "minRxIntvl", bfdMhIfPol.MinRxIntvl)
A(bfdMhIfPolMap, "minTxIntvl", bfdMhIfPol.MinTxIntvl)
A(bfdMhIfPolMap, "name", bfdMhIfPol.Name)
return bfdMhIfPolMap, err
}

func AciBfdMultihopInterfacePolicyFromContainerList(cont *container.Container, index int) *AciBfdMultihopInterfacePolicy {
AciBfdMultihopInterfacePolicyCont := cont.S("imdata").Index(index).S(BfdmhifpolClassName, "attributes")
return &AciBfdMultihopInterfacePolicy{
BaseAttributes{
DistinguishedName: G(AciBfdMultihopInterfacePolicyCont, "dn"),
Description: G(AciBfdMultihopInterfacePolicyCont, "descr"),
Status: G(AciBfdMultihopInterfacePolicyCont, "status"),
ClassName: BfdmhifpolClassName,
Rn: G(AciBfdMultihopInterfacePolicyCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(AciBfdMultihopInterfacePolicyCont, "nameAlias"),
},
AciBfdMultihopInterfacePolicyAttributes{
AdminSt: G(AciBfdMultihopInterfacePolicyCont, "adminSt"),
Annotation: G(AciBfdMultihopInterfacePolicyCont, "annotation"),
DetectMult: G(AciBfdMultihopInterfacePolicyCont, "detectMult"),
MinRxIntvl: G(AciBfdMultihopInterfacePolicyCont, "minRxIntvl"),
MinTxIntvl: G(AciBfdMultihopInterfacePolicyCont, "minTxIntvl"),
Name: G(AciBfdMultihopInterfacePolicyCont, "name"),
},
}
}

func AciBfdMultihopInterfacePolicyFromContainer(cont *container.Container) *AciBfdMultihopInterfacePolicy {
return AciBfdMultihopInterfacePolicyFromContainerList(cont, 0)
}

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

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

return arr
}

0 comments on commit b536fc1

Please sign in to comment.