From 3362cf4f04d72d077c345524cb9693fa8f5ddf14 Mon Sep 17 00:00:00 2001 From: anvitha jain Date: Fri, 25 Mar 2022 10:35:19 -0700 Subject: [PATCH] Added new class object rtctrlMatchCommRegexTerm --- client/rtctrlMatchCommRegexTerm_service.go | 48 ++++++++++ models/rtctrl_match_comm_regex_term.go | 104 +++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 client/rtctrlMatchCommRegexTerm_service.go create mode 100644 models/rtctrl_match_comm_regex_term.go diff --git a/client/rtctrlMatchCommRegexTerm_service.go b/client/rtctrlMatchCommRegexTerm_service.go new file mode 100644 index 00000000..d4cefc11 --- /dev/null +++ b/client/rtctrlMatchCommRegexTerm_service.go @@ -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 +} diff --git a/models/rtctrl_match_comm_regex_term.go b/models/rtctrl_match_comm_regex_term.go new file mode 100644 index 00000000..5b9c0ca3 --- /dev/null +++ b/models/rtctrl_match_comm_regex_term.go @@ -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 +}