Skip to content

Commit

Permalink
Updated rtctrlAttrP model with current coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana authored and lhercot committed Mar 23, 2022
1 parent db86e85 commit 426dcaf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
23 changes: 11 additions & 12 deletions client/rtctrlAttrP_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"github.com/ciscoecosystem/aci-go-client/models"
)

func (sm *ServiceManager) CreateActionRuleProfile(name string, tenant string, description string, rtctrlAttrPattr models.ActionRuleProfileAttributes) (*models.ActionRuleProfile, error) {
rn := fmt.Sprintf("attr-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s", tenant)
rtctrlAttrP := models.NewActionRuleProfile(rn, parentDn, description, rtctrlAttrPattr)
func (sm *ServiceManager) CreateActionRuleProfile(name string, tenant string, description string, nameAlias string, rtctrlAttrPAttr models.ActionRuleProfileAttributes) (*models.ActionRuleProfile, error) {
rn := fmt.Sprintf(models.RnrtctrlAttrP, name)
parentDn := fmt.Sprintf(models.ParentDnrtctrlAttrP, tenant)
rtctrlAttrP := models.NewActionRuleProfile(rn, parentDn, description, nameAlias, rtctrlAttrPAttr)
err := sm.Save(rtctrlAttrP)
return rtctrlAttrP, err
}

func (sm *ServiceManager) ReadActionRuleProfile(name string, tenant string) (*models.ActionRuleProfile, error) {
dn := fmt.Sprintf("uni/tn-%s/attr-%s", tenant, name)
dn := fmt.Sprintf(models.DnrtctrlAttrP, tenant, name)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
Expand All @@ -26,14 +26,14 @@ func (sm *ServiceManager) ReadActionRuleProfile(name string, tenant string) (*mo
}

func (sm *ServiceManager) DeleteActionRuleProfile(name string, tenant string) error {
dn := fmt.Sprintf("uni/tn-%s/attr-%s", tenant, name)
dn := fmt.Sprintf(models.DnrtctrlAttrP, tenant, name)
return sm.DeleteByDn(dn, models.RtctrlattrpClassName)
}

func (sm *ServiceManager) UpdateActionRuleProfile(name string, tenant string, description string, rtctrlAttrPattr models.ActionRuleProfileAttributes) (*models.ActionRuleProfile, error) {
rn := fmt.Sprintf("attr-%s", name)
parentDn := fmt.Sprintf("uni/tn-%s", tenant)
rtctrlAttrP := models.NewActionRuleProfile(rn, parentDn, description, rtctrlAttrPattr)
func (sm *ServiceManager) UpdateActionRuleProfile(name string, tenant string, description string, nameAlias string, rtctrlAttrPAttr models.ActionRuleProfileAttributes) (*models.ActionRuleProfile, error) {
rn := fmt.Sprintf(models.RnrtctrlAttrP, name)
parentDn := fmt.Sprintf(models.ParentDnrtctrlAttrP, tenant)
rtctrlAttrP := models.NewActionRuleProfile(rn, parentDn, description, nameAlias, rtctrlAttrPAttr)

rtctrlAttrP.Status = "modified"
err := sm.Save(rtctrlAttrP)
Expand All @@ -43,8 +43,7 @@ func (sm *ServiceManager) UpdateActionRuleProfile(name string, tenant string, de

func (sm *ServiceManager) ListActionRuleProfile(tenant string) ([]*models.ActionRuleProfile, error) {

baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/tn-%s/rtctrlAttrP.json", baseurlStr, tenant)
dnUrl := fmt.Sprintf("%s/uni/tn-%s/rtctrlAttrP.json", models.BaseurlStr, tenant)

cont, err := sm.GetViaURL(dnUrl)
list := models.ActionRuleProfileListFromContainer(cont)
Expand Down
36 changes: 24 additions & 12 deletions models/rtctrl_attr_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import (
"github.com/ciscoecosystem/aci-go-client/container"
)

const RtctrlattrpClassName = "rtctrlAttrP"
const (
DnrtctrlAttrP = "uni/tn-%s/attr-%s"
RnrtctrlAttrP = "attr-%s"
ParentDnrtctrlAttrP = "uni/tn-%s"
RtctrlattrpClassName = "rtctrlAttrP"
)

type ActionRuleProfile struct {
BaseAttributes
NameAliasAttribute
ActionRuleProfileAttributes
}

Expand All @@ -22,7 +28,7 @@ type ActionRuleProfileAttributes struct {
NameAlias string `json:",omitempty"`
}

func NewActionRuleProfile(rtctrlAttrPRn, parentDn, description string, rtctrlAttrPattr ActionRuleProfileAttributes) *ActionRuleProfile {
func NewActionRuleProfile(rtctrlAttrPRn, parentDn, description, nameAlias string, rtctrlAttrPAttr ActionRuleProfileAttributes) *ActionRuleProfile {
dn := fmt.Sprintf("%s/%s", parentDn, rtctrlAttrPRn)
return &ActionRuleProfile{
BaseAttributes: BaseAttributes{
Expand All @@ -32,8 +38,10 @@ func NewActionRuleProfile(rtctrlAttrPRn, parentDn, description string, rtctrlAtt
ClassName: RtctrlattrpClassName,
Rn: rtctrlAttrPRn,
},

ActionRuleProfileAttributes: rtctrlAttrPattr,
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
ActionRuleProfileAttributes: rtctrlAttrPAttr,
}
}

Expand All @@ -43,17 +51,21 @@ func (rtctrlAttrP *ActionRuleProfile) ToMap() (map[string]string, error) {
return nil, err
}

A(rtctrlAttrPMap, "name", rtctrlAttrP.Name)

A(rtctrlAttrPMap, "annotation", rtctrlAttrP.Annotation)
alias, err := rtctrlAttrP.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}

A(rtctrlAttrPMap, "nameAlias", rtctrlAttrP.NameAlias)
for key, value := range alias {
A(rtctrlAttrPMap, key, value)
}

A(rtctrlAttrPMap, "annotation", rtctrlAttrP.Annotation)
A(rtctrlAttrPMap, "name", rtctrlAttrP.Name)
return rtctrlAttrPMap, err
}

func ActionRuleProfileFromContainerList(cont *container.Container, index int) *ActionRuleProfile {

ActionRuleProfileCont := cont.S("imdata").Index(index).S(RtctrlattrpClassName, "attributes")
return &ActionRuleProfile{
BaseAttributes{
Expand All @@ -63,14 +75,14 @@ func ActionRuleProfileFromContainerList(cont *container.Container, index int) *A
ClassName: RtctrlattrpClassName,
Rn: G(ActionRuleProfileCont, "rn"),
},

NameAliasAttribute{
NameAlias: G(ActionRuleProfileCont, "nameAlias"),
},
ActionRuleProfileAttributes{

Name: G(ActionRuleProfileCont, "name"),

Annotation: G(ActionRuleProfileCont, "annotation"),

NameAlias: G(ActionRuleProfileCont, "nameAlias"),
},
}
}
Expand Down

0 comments on commit 426dcaf

Please sign in to comment.