Skip to content

Commit

Permalink
Added new class object rtctrlMatchCommRegexTerm
Browse files Browse the repository at this point in the history
  • Loading branch information
anvitha-jain authored and lhercot committed Mar 25, 2022
1 parent be66af5 commit 3362cf4
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
48 changes: 48 additions & 0 deletions client/rtctrlMatchCommRegexTerm_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/models"
)

func (sm *ServiceManager) CreateMatchRuleBasedonCommunityRegularExpression(commType string, match_rule string, tenant string, description string, nameAlias string, rtctrlMatchCommRegexTermAttr models.MatchRuleBasedonCommunityRegularExpressionAttributes) (*models.MatchRuleBasedonCommunityRegularExpression, error) {
rn := fmt.Sprintf(models.RnrtctrlMatchCommRegexTerm, commType)
parentDn := fmt.Sprintf(models.ParentDnrtctrlMatchCommRegexTerm, tenant, match_rule)
rtctrlMatchCommRegexTerm := models.NewMatchRuleBasedonCommunityRegularExpression(rn, parentDn, description, nameAlias, rtctrlMatchCommRegexTermAttr)
err := sm.Save(rtctrlMatchCommRegexTerm)
return rtctrlMatchCommRegexTerm, err
}

func (sm *ServiceManager) ReadMatchRuleBasedonCommunityRegularExpression(commType string, match_rule string, tenant string) (*models.MatchRuleBasedonCommunityRegularExpression, error) {
dn := fmt.Sprintf(models.DnrtctrlMatchCommRegexTerm, tenant, match_rule, commType)

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

rtctrlMatchCommRegexTerm := models.MatchRuleBasedonCommunityRegularExpressionFromContainer(cont)
return rtctrlMatchCommRegexTerm, nil
}

func (sm *ServiceManager) DeleteMatchRuleBasedonCommunityRegularExpression(commType string, match_rule string, tenant string) error {
dn := fmt.Sprintf(models.DnrtctrlMatchCommRegexTerm, tenant, match_rule, commType)
return sm.DeleteByDn(dn, models.RtctrlmatchcommregextermClassName)
}

func (sm *ServiceManager) UpdateMatchRuleBasedonCommunityRegularExpression(commType string, match_rule string, tenant string, description string, nameAlias string, rtctrlMatchCommRegexTermAttr models.MatchRuleBasedonCommunityRegularExpressionAttributes) (*models.MatchRuleBasedonCommunityRegularExpression, error) {
rn := fmt.Sprintf(models.RnrtctrlMatchCommRegexTerm, commType)
parentDn := fmt.Sprintf(models.ParentDnrtctrlMatchCommRegexTerm, tenant, match_rule)
rtctrlMatchCommRegexTerm := models.NewMatchRuleBasedonCommunityRegularExpression(rn, parentDn, description, nameAlias, rtctrlMatchCommRegexTermAttr)
rtctrlMatchCommRegexTerm.Status = "modified"
err := sm.Save(rtctrlMatchCommRegexTerm)
return rtctrlMatchCommRegexTerm, err
}

func (sm *ServiceManager) ListMatchRuleBasedonCommunityRegularExpression(match_rule string, tenant string) ([]*models.MatchRuleBasedonCommunityRegularExpression, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/subj-%s/rtctrlMatchCommRegexTerm.json", models.BaseurlStr, tenant, match_rule)
cont, err := sm.GetViaURL(dnUrl)
list := models.MatchRuleBasedonCommunityRegularExpressionListFromContainer(cont)
return list, err
}
104 changes: 104 additions & 0 deletions models/rtctrl_match_comm_regex_term.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package models

import (
"fmt"
"strconv"

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

const (
DnrtctrlMatchCommRegexTerm = "uni/tn-%s/subj-%s/commrxtrm-%s"
RnrtctrlMatchCommRegexTerm = "commrxtrm-%s"
ParentDnrtctrlMatchCommRegexTerm = "uni/tn-%s/subj-%s"
RtctrlmatchcommregextermClassName = "rtctrlMatchCommRegexTerm"
)

type MatchRuleBasedonCommunityRegularExpression struct {
BaseAttributes
NameAliasAttribute
MatchRuleBasedonCommunityRegularExpressionAttributes
}

type MatchRuleBasedonCommunityRegularExpressionAttributes struct {
Annotation string `json:",omitempty"`
CommType string `json:",omitempty"`
Name string `json:",omitempty"`
Regex string `json:",omitempty"`
}

func NewMatchRuleBasedonCommunityRegularExpression(rtctrlMatchCommRegexTermRn, parentDn, description, nameAlias string, rtctrlMatchCommRegexTermAttr MatchRuleBasedonCommunityRegularExpressionAttributes) *MatchRuleBasedonCommunityRegularExpression {
dn := fmt.Sprintf("%s/%s", parentDn, rtctrlMatchCommRegexTermRn)
return &MatchRuleBasedonCommunityRegularExpression{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: RtctrlmatchcommregextermClassName,
Rn: rtctrlMatchCommRegexTermRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
MatchRuleBasedonCommunityRegularExpressionAttributes: rtctrlMatchCommRegexTermAttr,
}
}

func (rtctrlMatchCommRegexTerm *MatchRuleBasedonCommunityRegularExpression) ToMap() (map[string]string, error) {
rtctrlMatchCommRegexTermMap, err := rtctrlMatchCommRegexTerm.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

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

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

A(rtctrlMatchCommRegexTermMap, "annotation", rtctrlMatchCommRegexTerm.Annotation)
A(rtctrlMatchCommRegexTermMap, "commType", rtctrlMatchCommRegexTerm.CommType)
A(rtctrlMatchCommRegexTermMap, "name", rtctrlMatchCommRegexTerm.Name)
A(rtctrlMatchCommRegexTermMap, "regex", rtctrlMatchCommRegexTerm.Regex)
return rtctrlMatchCommRegexTermMap, err
}

func MatchRuleBasedonCommunityRegularExpressionFromContainerList(cont *container.Container, index int) *MatchRuleBasedonCommunityRegularExpression {
MatchRuleBasedonCommunityRegularExpressionCont := cont.S("imdata").Index(index).S(RtctrlmatchcommregextermClassName, "attributes")
return &MatchRuleBasedonCommunityRegularExpression{
BaseAttributes{
DistinguishedName: G(MatchRuleBasedonCommunityRegularExpressionCont, "dn"),
Description: G(MatchRuleBasedonCommunityRegularExpressionCont, "descr"),
Status: G(MatchRuleBasedonCommunityRegularExpressionCont, "status"),
ClassName: RtctrlmatchcommregextermClassName,
Rn: G(MatchRuleBasedonCommunityRegularExpressionCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(MatchRuleBasedonCommunityRegularExpressionCont, "nameAlias"),
},
MatchRuleBasedonCommunityRegularExpressionAttributes{
Annotation: G(MatchRuleBasedonCommunityRegularExpressionCont, "annotation"),
CommType: G(MatchRuleBasedonCommunityRegularExpressionCont, "commType"),
Name: G(MatchRuleBasedonCommunityRegularExpressionCont, "name"),
Regex: G(MatchRuleBasedonCommunityRegularExpressionCont, "regex"),
},
}
}

func MatchRuleBasedonCommunityRegularExpressionFromContainer(cont *container.Container) *MatchRuleBasedonCommunityRegularExpression {
return MatchRuleBasedonCommunityRegularExpressionFromContainerList(cont, 0)
}

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

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

return arr
}

0 comments on commit 3362cf4

Please sign in to comment.