-
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.
[minor_change] Addition of models and service files for vnsEpgDef (#218)
- Loading branch information
Showing
2 changed files
with
343 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,231 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
"github.com/ciscoecosystem/aci-go-client/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreateEPgDef(name string, parent_dn string, description string, nameAlias string, vnsEPgDefAttr models.EPgDefAttributes) (*models.EPgDef, error) { | ||
rn := fmt.Sprintf(models.RnvnsEPgDef, name) | ||
vnsEPgDef := models.NewEPgDef(rn, parent_dn, description, nameAlias, vnsEPgDefAttr) | ||
err := sm.Save(vnsEPgDef) | ||
return vnsEPgDef, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadEPgDef(name string, parent_dn string) (*models.EPgDef, error) { | ||
dn := fmt.Sprintf(models.DnvnsEPgDef, parent_dn, name) | ||
|
||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vnsEPgDef := models.EPgDefFromContainer(cont) | ||
return vnsEPgDef, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteEPgDef(name string, parent_dn string) error { | ||
dn := fmt.Sprintf(models.DnvnsEPgDef, parent_dn, name) | ||
return sm.DeleteByDn(dn, models.VnsepgdefClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdateEPgDef(name string, parent_dn string, description string, nameAlias string, vnsEPgDefAttr models.EPgDefAttributes) (*models.EPgDef, error) { | ||
rn := fmt.Sprintf(models.RnvnsEPgDef, name) | ||
vnsEPgDef := models.NewEPgDef(rn, parent_dn, description, nameAlias, vnsEPgDefAttr) | ||
vnsEPgDef.Status = "modified" | ||
err := sm.Save(vnsEPgDef) | ||
return vnsEPgDef, err | ||
} | ||
|
||
func (sm *ServiceManager) ListEPgDef(parent_dn string) ([]*models.EPgDef, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/vnsEPgDef.json", models.BaseurlStr, parent_dn) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.EPgDefListFromContainer(cont) | ||
return list, err | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsEPgDefToConn(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsEPgDefToConn", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsEPgDefToConn", dn, annotation, tDn)) | ||
|
||
jsonPayload, err := container.ParseJSON(containerJSON) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true) | ||
if err != nil { | ||
return err | ||
} | ||
cont, _, err := sm.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%+v", cont) | ||
return nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteRelationvnsRsEPgDefToConn(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsEPgDefToConn", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsEPgDefToConn") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsEPgDefToConn(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsEPgDefToConn") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsEPgDefToConn") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsEPgDefToLIf(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsEPgDefToLIf", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsEPgDefToLIf", dn, annotation, tDn)) | ||
|
||
jsonPayload, err := container.ParseJSON(containerJSON) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true) | ||
if err != nil { | ||
return err | ||
} | ||
cont, _, err := sm.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%+v", cont) | ||
return nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteRelationvnsRsEPgDefToLIf(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsEPgDefToLIf", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsEPgDefToLIf") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsEPgDefToLIf(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsEPgDefToLIf") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsEPgDefToLIf") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsEPpInfoAtt(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsePpInfoAtt", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsEPpInfoAtt", dn, annotation, tDn)) | ||
|
||
jsonPayload, err := container.ParseJSON(containerJSON) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true) | ||
if err != nil { | ||
return err | ||
} | ||
cont, _, err := sm.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%+v", cont) | ||
return nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteRelationvnsRsEPpInfoAtt(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsePpInfoAtt", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsEPpInfoAtt") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsEPpInfoAtt(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsEPpInfoAtt") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsEPpInfoAtt") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsSEPpInfoAtt(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsSEPpInfoAtt", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsSEPpInfoAtt", dn, annotation, tDn)) | ||
|
||
jsonPayload, err := container.ParseJSON(containerJSON) | ||
if err != nil { | ||
return err | ||
} | ||
req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("%s.json", sm.MOURL), jsonPayload, true) | ||
if err != nil { | ||
return err | ||
} | ||
cont, _, err := sm.client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Printf("%+v", cont) | ||
return nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteRelationvnsRsSEPpInfoAtt(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsSEPpInfoAtt", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsSEPpInfoAtt") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsSEPpInfoAtt(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsSEPpInfoAtt") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsSEPpInfoAtt") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, 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,112 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
) | ||
|
||
const ( | ||
DnvnsEPgDef = "%s/EPgDef-%s" | ||
RnvnsEPgDef = "EPgDef-%s" | ||
VnsepgdefClassName = "vnsEPgDef" | ||
) | ||
|
||
type EPgDef struct { | ||
BaseAttributes | ||
NameAliasAttribute | ||
EPgDefAttributes | ||
} | ||
|
||
type EPgDefAttributes struct { | ||
Name string `json:",omitempty"` | ||
Encap string `json:",omitempty"` | ||
FabricEncap string `json:",omitempty"` | ||
IsDelPbr string `json:",omitempty"` | ||
LIfCtxDn string `json:",omitempty"` | ||
MemberType string `json:",omitempty"` | ||
RtrId string `json:",omitempty"` | ||
} | ||
|
||
func NewEPgDef(vnsEPgDefRn, parentDn, description, nameAlias string, vnsEPgDefAttr EPgDefAttributes) *EPgDef { | ||
dn := fmt.Sprintf("%s/%s", parentDn, vnsEPgDefRn) | ||
return &EPgDef{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Description: description, | ||
Status: "created, modified", | ||
ClassName: VnsepgdefClassName, | ||
Rn: vnsEPgDefRn, | ||
}, | ||
NameAliasAttribute: NameAliasAttribute{ | ||
NameAlias: nameAlias, | ||
}, | ||
EPgDefAttributes: vnsEPgDefAttr, | ||
} | ||
} | ||
|
||
func (vnsEPgDef *EPgDef) ToMap() (map[string]string, error) { | ||
vnsEPgDefMap, err := vnsEPgDef.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
alias, err := vnsEPgDef.NameAliasAttribute.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range alias { | ||
A(vnsEPgDefMap, key, value) | ||
} | ||
|
||
A(vnsEPgDefMap, "name", vnsEPgDef.Name) | ||
A(vnsEPgDefMap, "encap", vnsEPgDef.Encap) | ||
A(vnsEPgDefMap, "fabEncap", vnsEPgDef.FabricEncap) | ||
A(vnsEPgDefMap, "isDelPbr", vnsEPgDef.IsDelPbr) | ||
A(vnsEPgDefMap, "membType", vnsEPgDef.MemberType) | ||
A(vnsEPgDefMap, "lIfCtxDn", vnsEPgDef.LIfCtxDn) | ||
A(vnsEPgDefMap, "rtrId", vnsEPgDef.RtrId) | ||
return vnsEPgDefMap, err | ||
} | ||
|
||
func EPgDefFromContainerList(cont *container.Container, index int) *EPgDef { | ||
EPgDefCont := cont.S("imdata").Index(index).S(VnsepgdefClassName, "attributes") | ||
return &EPgDef{ | ||
BaseAttributes{ | ||
DistinguishedName: G(EPgDefCont, "dn"), | ||
Description: G(EPgDefCont, "descr"), | ||
Status: G(EPgDefCont, "status"), | ||
ClassName: VnsepgdefClassName, | ||
Rn: G(EPgDefCont, "rn"), | ||
}, | ||
NameAliasAttribute{ | ||
NameAlias: G(EPgDefCont, "nameAlias"), | ||
}, | ||
EPgDefAttributes{ | ||
Name: G(EPgDefCont, "name"), | ||
Encap: G(EPgDefCont, "encap"), | ||
FabricEncap: G(EPgDefCont, "fabEncap"), | ||
IsDelPbr: G(EPgDefCont, "isDelPbr"), | ||
MemberType: G(EPgDefCont, "membType"), | ||
LIfCtxDn: G(EPgDefCont, "lIfCtxDn"), | ||
RtrId: G(EPgDefCont, "rtrId"), | ||
}, | ||
} | ||
} | ||
|
||
func EPgDefFromContainer(cont *container.Container) *EPgDef { | ||
return EPgDefFromContainerList(cont, 0) | ||
} | ||
|
||
func EPgDefListFromContainer(cont *container.Container) []*EPgDef { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*EPgDef, length) | ||
|
||
for i := 0; i < length; i++ { | ||
arr[i] = EPgDefFromContainerList(cont, i) | ||
} | ||
|
||
return arr | ||
} |