Skip to content

Commit

Permalink
[minor_changes] Added new resource for BFD multihop under L3out Logic…
Browse files Browse the repository at this point in the history
…al Interface Profiles
  • Loading branch information
anvitha-jain authored and lhercot committed Jun 28, 2023
1 parent fb4cdbf commit f69ec3b
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 0 deletions.
95 changes: 95 additions & 0 deletions client/bfdMhIfP_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package client

import (
"fmt"

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

func (sm *ServiceManager) CreateAciBfdMultihopInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, nameAlias string, bfdMhIfPAttr models.AciBfdMultihopInterfaceProfileAttributes) (*models.AciBfdMultihopInterfaceProfile, error) {
rn := fmt.Sprintf(models.RnbfdMhIfP)
parentDn := fmt.Sprintf(models.ParentDnbfdMhIfP, tenant, l3_outside, logical_node_profile, logical_interface_profile)
bfdMhIfP := models.NewAciBfdMultihopInterfaceProfile(rn, parentDn, description, nameAlias, bfdMhIfPAttr)
err := sm.Save(bfdMhIfP)
return bfdMhIfP, err
}

func (sm *ServiceManager) ReadAciBfdMultihopInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) (*models.AciBfdMultihopInterfaceProfile, error) {
dn := fmt.Sprintf(models.DnbfdMhIfP, tenant, l3_outside, logical_node_profile, logical_interface_profile)

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

bfdMhIfP := models.AciBfdMultihopInterfaceProfileFromContainer(cont)
return bfdMhIfP, nil
}

func (sm *ServiceManager) DeleteAciBfdMultihopInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) error {
dn := fmt.Sprintf(models.DnbfdMhIfP, tenant, l3_outside, logical_node_profile, logical_interface_profile)
return sm.DeleteByDn(dn, models.BfdmhifpClassName)
}

func (sm *ServiceManager) UpdateAciBfdMultihopInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string, description string, nameAlias string, bfdMhIfPAttr models.AciBfdMultihopInterfaceProfileAttributes) (*models.AciBfdMultihopInterfaceProfile, error) {
rn := fmt.Sprintf(models.RnbfdMhIfP)
parentDn := fmt.Sprintf(models.ParentDnbfdMhIfP, tenant, l3_outside, logical_node_profile, logical_interface_profile)
bfdMhIfP := models.NewAciBfdMultihopInterfaceProfile(rn, parentDn, description, nameAlias, bfdMhIfPAttr)
bfdMhIfP.Status = "modified"
err := sm.Save(bfdMhIfP)
return bfdMhIfP, err
}

func (sm *ServiceManager) ListAciBfdMultihopInterfaceProfile(logical_interface_profile string, logical_node_profile string, l3_outside string, tenant string) ([]*models.AciBfdMultihopInterfaceProfile, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/out-%s/lnodep-%s/lifp-%s/bfdMhIfP.json", models.BaseurlStr, tenant, l3_outside, logical_node_profile, logical_interface_profile)
cont, err := sm.GetViaURL(dnUrl)
list := models.AciBfdMultihopInterfaceProfileListFromContainer(cont)
return list, err
}

func (sm *ServiceManager) CreateRelationbfdRsMhIfPol(parentDn, annotation, tnBfdMhIfPolName string) error {
dn := fmt.Sprintf("%s/rsMhIfPol", parentDn)
containerJSON := []byte(fmt.Sprintf(`{
"%s": {
"attributes": {
"dn": "%s",
"annotation": "%s",
"tnBfdMhIfPolName": "%s"
}
}
}`, "bfdRsMhIfPol", dn, annotation, tnBfdMhIfPolName))

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
}
fmt.Printf("%+v", cont)
return nil
}

func (sm *ServiceManager) DeleteRelationbfdRsMhIfPol(parentDn string) error {
dn := fmt.Sprintf("%s/rsMhIfPol", parentDn)
return sm.DeleteByDn(dn, "bfdRsMhIfPol")
}

func (sm *ServiceManager) ReadRelationbfdRsMhIfPol(parentDn string) (interface{}, error) {
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "bfdRsMhIfPol")
cont, err := sm.GetViaURL(dnUrl)
contList := models.ListFromContainer(cont, "bfdRsMhIfPol")

if len(contList) > 0 {
dat := models.G(contList[0], "tnBfdMhIfPolName")
return dat, err
} else {
return nil, err
}
}
107 changes: 107 additions & 0 deletions models/bfd_mh_if_p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package models

import (
"fmt"
"strconv"

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

const (
DnbfdMhIfP = "uni/tn-%s/out-%s/lnodep-%s/lifp-%s/bfdMhIfP"
RnbfdMhIfP = "bfdMhIfP"
ParentDnbfdMhIfP = "uni/tn-%s/out-%s/lnodep-%s/lifp-%s"
BfdmhifpClassName = "bfdMhIfP"
)

type AciBfdMultihopInterfaceProfile struct {
BaseAttributes
NameAliasAttribute
AciBfdMultihopInterfaceProfileAttributes
}

type AciBfdMultihopInterfaceProfileAttributes struct {
Annotation string `json:",omitempty"`
Key string `json:",omitempty"`
KeyId string `json:",omitempty"`
Name string `json:",omitempty"`
InterfaceProfile_type string `json:",omitempty"`
}

func NewAciBfdMultihopInterfaceProfile(bfdMhIfPRn, parentDn, description, nameAlias string, bfdMhIfPAttr AciBfdMultihopInterfaceProfileAttributes) *AciBfdMultihopInterfaceProfile {
dn := fmt.Sprintf("%s/%s", parentDn, bfdMhIfPRn)
return &AciBfdMultihopInterfaceProfile{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: BfdmhifpClassName,
Rn: bfdMhIfPRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
AciBfdMultihopInterfaceProfileAttributes: bfdMhIfPAttr,
}
}

func (bfdMhIfP *AciBfdMultihopInterfaceProfile) ToMap() (map[string]string, error) {
bfdMhIfPMap, err := bfdMhIfP.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

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

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

A(bfdMhIfPMap, "annotation", bfdMhIfP.Annotation)
A(bfdMhIfPMap, "key", bfdMhIfP.Key)
A(bfdMhIfPMap, "keyId", bfdMhIfP.KeyId)
A(bfdMhIfPMap, "name", bfdMhIfP.Name)
A(bfdMhIfPMap, "InterfaceProfile_type", bfdMhIfP.InterfaceProfile_type)
return bfdMhIfPMap, err
}

func AciBfdMultihopInterfaceProfileFromContainerList(cont *container.Container, index int) *AciBfdMultihopInterfaceProfile {
AciBfdMultihopInterfaceProfileCont := cont.S("imdata").Index(index).S(BfdmhifpClassName, "attributes")
return &AciBfdMultihopInterfaceProfile{
BaseAttributes{
DistinguishedName: G(AciBfdMultihopInterfaceProfileCont, "dn"),
Description: G(AciBfdMultihopInterfaceProfileCont, "descr"),
Status: G(AciBfdMultihopInterfaceProfileCont, "status"),
ClassName: BfdmhifpClassName,
Rn: G(AciBfdMultihopInterfaceProfileCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(AciBfdMultihopInterfaceProfileCont, "nameAlias"),
},
AciBfdMultihopInterfaceProfileAttributes{
Annotation: G(AciBfdMultihopInterfaceProfileCont, "annotation"),
Key: G(AciBfdMultihopInterfaceProfileCont, "key"),
KeyId: G(AciBfdMultihopInterfaceProfileCont, "keyId"),
Name: G(AciBfdMultihopInterfaceProfileCont, "name"),
InterfaceProfile_type: G(AciBfdMultihopInterfaceProfileCont, "InterfaceProfile_type"),
},
}
}

func AciBfdMultihopInterfaceProfileFromContainer(cont *container.Container) *AciBfdMultihopInterfaceProfile {
return AciBfdMultihopInterfaceProfileFromContainerList(cont, 0)
}

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

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

return arr
}

0 comments on commit f69ec3b

Please sign in to comment.