Skip to content

Commit

Permalink
Added fix InfraRsDomP class (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana authored Mar 17, 2022
1 parent fea3265 commit d2cb4a0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 62 deletions.
41 changes: 14 additions & 27 deletions client/infraRsDomP_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,35 @@ import (
"github.com/ciscoecosystem/aci-go-client/models"
)

func (sm *ServiceManager) CreateDomain(tDn string, attachable_access_entity_profile string, description string, infraRsDomPattr models.DomainAttributes) (*models.Domain, error) {
rn := fmt.Sprintf("rsdomP-[%s]", tDn)
parentDn := fmt.Sprintf("uni/infra/attentp-%s", attachable_access_entity_profile)
infraRsDomP := models.NewDomain(rn, parentDn, description, infraRsDomPattr)
func (sm *ServiceManager) CreateInfraRsDomP(tDn string, attachable_access_entity_profile string, infraRsDomPAttr models.InfraRsDomPAttributes) (*models.InfraRsDomP, error) {
rn := fmt.Sprintf(models.RninfraRsDomP, tDn)
parentDn := fmt.Sprintf(models.ParentDninfraRsDomP, attachable_access_entity_profile)
infraRsDomP := models.NewInfraRsDomP(rn, parentDn, infraRsDomPAttr)
err := sm.Save(infraRsDomP)
return infraRsDomP, err
}

func (sm *ServiceManager) ReadDomain(tDn string, attachable_access_entity_profile string) (*models.Domain, error) {
dn := fmt.Sprintf("uni/infra/attentp-%s/rsdomP-[%s]", attachable_access_entity_profile, tDn)
func (sm *ServiceManager) ReadInfraRsDomP(tDn string, attachable_access_entity_profile string) (*models.InfraRsDomP, error) {
dn := fmt.Sprintf(models.DninfraRsDomP, attachable_access_entity_profile, tDn)

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

infraRsDomP := models.DomainFromContainer(cont)
infraRsDomP := models.InfraRsDomPFromContainer(cont)
return infraRsDomP, nil
}

func (sm *ServiceManager) DeleteDomain(tDn string, attachable_access_entity_profile string) error {
dn := fmt.Sprintf("uni/infra/attentp-%s/rsdomP-[%s]", attachable_access_entity_profile, tDn)
func (sm *ServiceManager) DeleteInfraRsDomP(tDn string, attachable_access_entity_profile string) error {
dn := fmt.Sprintf(models.DninfraRsDomP, attachable_access_entity_profile, tDn)
return sm.DeleteByDn(dn, models.InfrarsdompClassName)
}

func (sm *ServiceManager) UpdateDomain(tDn string, attachable_access_entity_profile string, description string, infraRsDomPattr models.DomainAttributes) (*models.Domain, error) {
rn := fmt.Sprintf("rsdomP-[%s]", tDn)
parentDn := fmt.Sprintf("uni/infra/attentp-%s", attachable_access_entity_profile)
infraRsDomP := models.NewDomain(rn, parentDn, description, infraRsDomPattr)

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

}

func (sm *ServiceManager) ListDomain(attachable_access_entity_profile string) ([]*models.Domain, error) {

baseurlStr := "/api/node/class"
dnUrl := fmt.Sprintf("%s/uni/infra/attentp-%s/infraRsDomP.json", baseurlStr, attachable_access_entity_profile)

func (sm *ServiceManager) ListInfraRsDomP(attachable_access_entity_profile string) ([]*models.InfraRsDomP, error) {
parentDn := fmt.Sprintf(models.ParentDninfraRsDomP, attachable_access_entity_profile)
dnUrl := fmt.Sprintf("%s/%s/infraRsDomP.json", models.BaseurlStr, parentDn)
cont, err := sm.GetViaURL(dnUrl)
list := models.DomainListFromContainer(cont)

list := models.InfraRsDomPListFromContainer(cont)
return list, err
}
64 changes: 29 additions & 35 deletions models/infra_rs_dom_p.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,75 @@ import (
"github.com/ciscoecosystem/aci-go-client/container"
)

const InfrarsdompClassName = "infraRsDomP"
const (
DninfraRsDomP = "%s/%s"
RninfraRsDomP = "rsdomP-[%s]"
ParentDninfraRsDomP = "uni/infra/attentp-%s"
InfrarsdompClassName = "infraRsDomP"
)

type Domain struct {
type InfraRsDomP struct {
BaseAttributes
DomainAttributes
InfraRsDomPAttributes
}

type DomainAttributes struct {
TDn string `json:",omitempty"`

type InfraRsDomPAttributes struct {
Annotation string `json:",omitempty"`
TDn string `json:",omitempty"`
}

func NewDomain(infraRsDomPRn, parentDn, description string, infraRsDomPattr DomainAttributes) *Domain {
func NewInfraRsDomP(infraRsDomPRn string, parentDn string, infraRsDomPAttr InfraRsDomPAttributes) *InfraRsDomP {
dn := fmt.Sprintf("%s/%s", parentDn, infraRsDomPRn)
return &Domain{
return &InfraRsDomP{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: InfrarsdompClassName,
Rn: infraRsDomPRn,
},

DomainAttributes: infraRsDomPattr,
InfraRsDomPAttributes: infraRsDomPAttr,
}
}

func (infraRsDomP *Domain) ToMap() (map[string]string, error) {
func (infraRsDomP *InfraRsDomP) ToMap() (map[string]string, error) {
infraRsDomPMap, err := infraRsDomP.BaseAttributes.ToMap()
if err != nil {
return nil, err
}

A(infraRsDomPMap, "tDn", infraRsDomP.TDn)

A(infraRsDomPMap, "annotation", infraRsDomP.Annotation)

A(infraRsDomPMap, "tDn", infraRsDomP.TDn)
return infraRsDomPMap, err
}

func DomainFromContainerList(cont *container.Container, index int) *Domain {

DomainCont := cont.S("imdata").Index(index).S(InfrarsdompClassName, "attributes")
return &Domain{
func InfraRsDomPFromContainerList(cont *container.Container, index int) *InfraRsDomP {
InfraRsDomPCont := cont.S("imdata").Index(index).S(InfrarsdompClassName, "attributes")
return &InfraRsDomP{
BaseAttributes{
DistinguishedName: G(DomainCont, "dn"),
Description: G(DomainCont, "descr"),
Status: G(DomainCont, "status"),
DistinguishedName: G(InfraRsDomPCont, "dn"),
Status: G(InfraRsDomPCont, "status"),
ClassName: InfrarsdompClassName,
Rn: G(DomainCont, "rn"),
Rn: G(InfraRsDomPCont, "rn"),
},

DomainAttributes{

TDn: G(DomainCont, "tDn"),

Annotation: G(DomainCont, "annotation"),
InfraRsDomPAttributes{
Annotation: G(InfraRsDomPCont, "annotation"),
TDn: G(InfraRsDomPCont, "tDn"),
},
}
}

func DomainFromContainer(cont *container.Container) *Domain {

return DomainFromContainerList(cont, 0)
func InfraRsDomPFromContainer(cont *container.Container) *InfraRsDomP {
return InfraRsDomPFromContainerList(cont, 0)
}

func DomainListFromContainer(cont *container.Container) []*Domain {
func InfraRsDomPListFromContainer(cont *container.Container) []*InfraRsDomP {
length, _ := strconv.Atoi(G(cont, "totalCount"))

arr := make([]*Domain, length)
arr := make([]*InfraRsDomP, length)

for i := 0; i < length; i++ {

arr[i] = DomainFromContainerList(cont, i)
arr[i] = InfraRsDomPFromContainerList(cont, i)
}

return arr
Expand Down

0 comments on commit d2cb4a0

Please sign in to comment.