Skip to content

Commit

Permalink
[minor_change] Add client and model files for snmpUserP class
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahammughal authored Jul 13, 2023
1 parent f416c83 commit 8ceaf71
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
65 changes: 65 additions & 0 deletions client/snmpUserP_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package client

import (
"fmt"

"github.com/ciscoecosystem/aci-go-client/v2/models"
)

func (sm *ServiceManager) CreateSnmpUserProfile(name string, snmp_policy string, description string, snmpUserPAttr models.SnmpUserProfileAttributes) (*models.SnmpUserProfile, error) {

rn := fmt.Sprintf(models.RnSnmpUserP, name)

parentDn := fmt.Sprintf(models.ParentDnSnmpUserP, snmp_policy)
snmpUserP := models.NewSnmpUserProfile(rn, parentDn, description, snmpUserPAttr)

err := sm.Save(snmpUserP)
return snmpUserP, err
}

func (sm *ServiceManager) ReadSnmpUserProfile(name string, snmp_policy string) (*models.SnmpUserProfile, error) {

rn := fmt.Sprintf(models.RnSnmpUserP, name)

parentDn := fmt.Sprintf(models.ParentDnSnmpUserP, snmp_policy)
dn := fmt.Sprintf("%s/%s", parentDn, rn)

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

func (sm *ServiceManager) DeleteSnmpUserProfile(name string, snmp_policy string) error {

rn := fmt.Sprintf(models.RnSnmpUserP, name)

parentDn := fmt.Sprintf(models.ParentDnSnmpUserP, snmp_policy)
dn := fmt.Sprintf("%s/%s", parentDn, rn)

return sm.DeleteByDn(dn, models.SnmpUserPClassName)
}

func (sm *ServiceManager) UpdateSnmpUserProfile(name string, snmp_policy string, description string, snmpUserPAttr models.SnmpUserProfileAttributes) (*models.SnmpUserProfile, error) {

rn := fmt.Sprintf(models.RnSnmpUserP, name)

parentDn := fmt.Sprintf(models.ParentDnSnmpUserP, snmp_policy)
snmpUserP := models.NewSnmpUserProfile(rn, parentDn, description, snmpUserPAttr)

snmpUserP.Status = "modified"
err := sm.Save(snmpUserP)
return snmpUserP, err
}

func (sm *ServiceManager) ListSnmpUserProfile(snmp_policy string) ([]*models.SnmpUserProfile, error) {

parentDn := fmt.Sprintf(models.ParentDnSnmpUserP, snmp_policy)
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, models.SnmpUserPClassName)

cont, err := sm.GetViaURL(dnUrl)
list := models.SnmpUserProfileListFromContainer(cont)
return list, err
}
97 changes: 97 additions & 0 deletions models/snmp_user_p.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package models

import (
"fmt"
"strconv"

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

const (
RnSnmpUserP = "user-%s"
DnSnmpUserP = "uni/fabric/snmppol-%s/user-%s"
ParentDnSnmpUserP = "uni/fabric/snmppol-%s"
SnmpUserPClassName = "snmpUserP"
)

type SnmpUserProfile struct {
BaseAttributes
SnmpUserProfileAttributes
}

type SnmpUserProfileAttributes struct {
Annotation string `json:",omitempty"`
AuthKey string `json:",omitempty"`
AuthType string `json:",omitempty"`
Name string `json:",omitempty"`
NameAlias string `json:",omitempty"`
PrivKey string `json:",omitempty"`
PrivType string `json:",omitempty"`
}

func NewSnmpUserProfile(snmpUserPRn, parentDn, description string, snmpUserPAttr SnmpUserProfileAttributes) *SnmpUserProfile {
dn := fmt.Sprintf("%s/%s", parentDn, snmpUserPRn)
return &SnmpUserProfile{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: SnmpUserPClassName,
Rn: snmpUserPRn,
},
SnmpUserProfileAttributes: snmpUserPAttr,
}
}

func (snmpUserP *SnmpUserProfile) ToMap() (map[string]string, error) {
snmpUserPMap, err := snmpUserP.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

A(snmpUserPMap, "annotation", snmpUserP.Annotation)
A(snmpUserPMap, "authKey", snmpUserP.AuthKey)
A(snmpUserPMap, "authType", snmpUserP.AuthType)
A(snmpUserPMap, "name", snmpUserP.Name)
A(snmpUserPMap, "nameAlias", snmpUserP.NameAlias)
A(snmpUserPMap, "privKey", snmpUserP.PrivKey)
A(snmpUserPMap, "privType", snmpUserP.PrivType)
return snmpUserPMap, err
}

func SnmpUserProfileFromContainerList(cont *container.Container, index int) *SnmpUserProfile {
SnmpUserProfileCont := cont.S("imdata").Index(index).S(SnmpUserPClassName, "attributes")
return &SnmpUserProfile{
BaseAttributes{
DistinguishedName: G(SnmpUserProfileCont, "dn"),
Description: G(SnmpUserProfileCont, "descr"),
Status: G(SnmpUserProfileCont, "status"),
ClassName: SnmpUserPClassName,
Rn: G(SnmpUserProfileCont, "rn"),
},
SnmpUserProfileAttributes{
Annotation: G(SnmpUserProfileCont, "annotation"),
AuthKey: G(SnmpUserProfileCont, "authKey"),
AuthType: G(SnmpUserProfileCont, "authType"),
Name: G(SnmpUserProfileCont, "name"),
NameAlias: G(SnmpUserProfileCont, "nameAlias"),
PrivKey: G(SnmpUserProfileCont, "privKey"),
PrivType: G(SnmpUserProfileCont, "privType"),
},
}
}

func SnmpUserProfileFromContainer(cont *container.Container) *SnmpUserProfile {
return SnmpUserProfileFromContainerList(cont, 0)
}

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

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

return arr
}

0 comments on commit 8ceaf71

Please sign in to comment.