-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new resource BFD Multihop Interface Policy (bfdMhIfPol) to suppor…
…t the relationship of bfdMhIfP object. Made the ReadRelationbfdRsMhIfPol() return tDn instead of name. (#272)
- Loading branch information
1 parent
64e486d
commit b536fc1
Showing
4 changed files
with
161 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |