diff --git a/client/bfdMhIfP_service.go b/client/bfdMhIfP_service.go index d4bbf6a..5bf6f4c 100644 --- a/client/bfdMhIfP_service.go +++ b/client/bfdMhIfP_service.go @@ -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 diff --git a/client/bfdMhIfPol_service.go b/client/bfdMhIfPol_service.go new file mode 100644 index 0000000..60baa47 --- /dev/null +++ b/client/bfdMhIfPol_service.go @@ -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 +} diff --git a/models/bfd_mh_if_p.go b/models/bfd_mh_if_p.go index 9578245..1252712 100644 --- a/models/bfd_mh_if_p.go +++ b/models/bfd_mh_if_p.go @@ -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 } @@ -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"), }, } } diff --git a/models/bfd_mh_if_pol.go b/models/bfd_mh_if_pol.go new file mode 100644 index 0000000..80a5ec7 --- /dev/null +++ b/models/bfd_mh_if_pol.go @@ -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 +}