-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |