Skip to content

Commit

Permalink
fvEPSelector files (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrsr authored Apr 24, 2021
1 parent a47adf0 commit c366ebd
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
46 changes: 46 additions & 0 deletions client/fvEPSelector_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package client

import (
"fmt"

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

func (sm *ServiceManager) CreateEndpointSecurityGroupSelector(matchExpression string, endpoint_security_group string, application_profile string, tenant string, description string, nameAlias string, fvEPSelectorAttr models.EndpointSecurityGroupSelectorAttributes) (*models.EndpointSecurityGroupSelector, error) {
rn := fmt.Sprintf(models.RnfvEPSelector, matchExpression)
parentDn := fmt.Sprintf(models.ParentDnfvEPSelector, tenant, application_profile, endpoint_security_group)
fvEPSelector := models.NewEndpointSecurityGroupSelector(rn, parentDn, description, nameAlias, fvEPSelectorAttr)
err := sm.Save(fvEPSelector)
return fvEPSelector, err
}

func (sm *ServiceManager) ReadEndpointSecurityGroupSelector(matchExpression string, endpoint_security_group string, application_profile string, tenant string) (*models.EndpointSecurityGroupSelector, error) {
dn := fmt.Sprintf(models.DnfvEPSelector, tenant, application_profile, endpoint_security_group, matchExpression)
cont, err := sm.Get(dn)
if err != nil {
return nil, err
}
fvEPSelector := models.EndpointSecurityGroupSelectorFromContainer(cont)
return fvEPSelector, nil
}

func (sm *ServiceManager) DeleteEndpointSecurityGroupSelector(matchExpression string, endpoint_security_group string, application_profile string, tenant string) error {
dn := fmt.Sprintf(models.DnfvEPSelector, tenant, application_profile, endpoint_security_group, matchExpression)
return sm.DeleteByDn(dn, models.FvepselectorClassName)
}

func (sm *ServiceManager) UpdateEndpointSecurityGroupSelector(matchExpression string, endpoint_security_group string, application_profile string, tenant string, description string, nameAlias string, fvEPSelectorAttr models.EndpointSecurityGroupSelectorAttributes) (*models.EndpointSecurityGroupSelector, error) {
rn := fmt.Sprintf(models.RnfvEPSelector, matchExpression)
parentDn := fmt.Sprintf(models.ParentDnfvEPSelector, tenant, application_profile, endpoint_security_group)
fvEPSelector := models.NewEndpointSecurityGroupSelector(rn, parentDn, description, nameAlias, fvEPSelectorAttr)
fvEPSelector.Status = "modified"
err := sm.Save(fvEPSelector)
return fvEPSelector, err
}

func (sm *ServiceManager) ListEndpointSecurityGroupSelector(endpoint_security_group string, application_profile string, tenant string) ([]*models.EndpointSecurityGroupSelector, error) {
dnUrl := fmt.Sprintf("%s/uni/tn-%s/ap-%s/esg-%s/fvEPSelector.json", models.BaseurlStr, tenant, application_profile, endpoint_security_group)
cont, err := sm.GetViaURL(dnUrl)
list := models.EndpointSecurityGroupSelectorListFromContainer(cont)
return list, err
}
96 changes: 96 additions & 0 deletions models/fv_ep_selector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package models

import (
"fmt"
"strconv"

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

const (
DnfvEPSelector = "uni/tn-%s/ap-%s/esg-%s/epselector-[%s]"
RnfvEPSelector = "epselector-[%s]"
ParentDnfvEPSelector = "uni/tn-%s/ap-%s/esg-%s"
FvepselectorClassName = "fvEPSelector"
)

type EndpointSecurityGroupSelector struct {
BaseAttributes
NameAliasAttribute
EndpointSecurityGroupSelectorAttributes
}

type EndpointSecurityGroupSelectorAttributes struct {
Annotation string `json:",omitempty"`
MatchExpression string `json:",omitempty"`
Name string `json:",omitempty"`
}

func NewEndpointSecurityGroupSelector(fvEPSelectorRn, parentDn, description, nameAlias string, fvEPSelectorAttr EndpointSecurityGroupSelectorAttributes) *EndpointSecurityGroupSelector {
dn := fmt.Sprintf("%s/%s", parentDn, fvEPSelectorRn)
return &EndpointSecurityGroupSelector{
BaseAttributes: BaseAttributes{
DistinguishedName: dn,
Description: description,
Status: "created, modified",
ClassName: FvepselectorClassName,
Rn: fvEPSelectorRn,
},
NameAliasAttribute: NameAliasAttribute{
NameAlias: nameAlias,
},
EndpointSecurityGroupSelectorAttributes: fvEPSelectorAttr,
}
}

func (fvEPSelector *EndpointSecurityGroupSelector) ToMap() (map[string]string, error) {
fvEPSelectorMap, err := fvEPSelector.BaseAttributes.ToMap()
if err != nil {
return nil, err
}
alias, err := fvEPSelector.NameAliasAttribute.ToMap()
if err != nil {
return nil, err
}
for key, value := range alias {
A(fvEPSelectorMap, key, value)
}
A(fvEPSelectorMap, "annotation", fvEPSelector.Annotation)
A(fvEPSelectorMap, "matchExpression", fvEPSelector.MatchExpression)
A(fvEPSelectorMap, "name", fvEPSelector.Name)
return fvEPSelectorMap, err
}

func EndpointSecurityGroupSelectorFromContainerList(cont *container.Container, index int) *EndpointSecurityGroupSelector {
EndpointSecurityGroupSelectorCont := cont.S("imdata").Index(index).S(FvepselectorClassName, "attributes")
return &EndpointSecurityGroupSelector{
BaseAttributes{
DistinguishedName: G(EndpointSecurityGroupSelectorCont, "dn"),
Description: G(EndpointSecurityGroupSelectorCont, "descr"),
Status: G(EndpointSecurityGroupSelectorCont, "status"),
ClassName: FvepselectorClassName,
Rn: G(EndpointSecurityGroupSelectorCont, "rn"),
},
NameAliasAttribute{
NameAlias: G(EndpointSecurityGroupSelectorCont, "nameAlias"),
},
EndpointSecurityGroupSelectorAttributes{
Annotation: G(EndpointSecurityGroupSelectorCont, "annotation"),
MatchExpression: G(EndpointSecurityGroupSelectorCont, "matchExpression"),
Name: G(EndpointSecurityGroupSelectorCont, "name"),
},
}
}

func EndpointSecurityGroupSelectorFromContainer(cont *container.Container) *EndpointSecurityGroupSelector {
return EndpointSecurityGroupSelectorFromContainerList(cont, 0)
}

func EndpointSecurityGroupSelectorListFromContainer(cont *container.Container) []*EndpointSecurityGroupSelector {
length, _ := strconv.Atoi(G(cont, "totalCount"))
arr := make([]*EndpointSecurityGroupSelector, length)
for i := 0; i < length; i++ {
arr[i] = EndpointSecurityGroupSelectorFromContainerList(cont, i)
}
return arr
}

0 comments on commit c366ebd

Please sign in to comment.