-
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] Add vnsBackupPol and vnsL1L2RedirectDest models and cl…
…ient files (#244)
- Loading branch information
Showing
4 changed files
with
391 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,48 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreatePBRBackupPolicy(name string, tenant string, description string, nameAlias string, vnsBackupPolAttr models.PBRBackupPolicyAttributes) (*models.PBRBackupPolicy, error) { | ||
rn := fmt.Sprintf(models.RnvnsBackupPol, name) | ||
parentDn := fmt.Sprintf(models.ParentDnvnsBackupPol, tenant) | ||
vnsBackupPol := models.NewPBRBackupPolicy(rn, parentDn, description, nameAlias, vnsBackupPolAttr) | ||
err := sm.Save(vnsBackupPol) | ||
return vnsBackupPol, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadPBRBackupPolicy(name string, tenant string) (*models.PBRBackupPolicy, error) { | ||
dn := fmt.Sprintf(models.DnvnsBackupPol, tenant, name) | ||
|
||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vnsBackupPol := models.PBRBackupPolicyFromContainer(cont) | ||
return vnsBackupPol, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeletePBRBackupPolicy(name string, tenant string) error { | ||
dn := fmt.Sprintf(models.DnvnsBackupPol, tenant, name) | ||
return sm.DeleteByDn(dn, models.VnsbackuppolClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdatePBRBackupPolicy(name string, tenant string, description string, nameAlias string, vnsBackupPolAttr models.PBRBackupPolicyAttributes) (*models.PBRBackupPolicy, error) { | ||
rn := fmt.Sprintf(models.RnvnsBackupPol, name) | ||
parentDn := fmt.Sprintf(models.ParentDnvnsBackupPol, tenant) | ||
vnsBackupPol := models.NewPBRBackupPolicy(rn, parentDn, description, nameAlias, vnsBackupPolAttr) | ||
vnsBackupPol.Status = "modified" | ||
err := sm.Save(vnsBackupPol) | ||
return vnsBackupPol, err | ||
} | ||
|
||
func (sm *ServiceManager) ListPBRBackupPolicy(tenant string) ([]*models.PBRBackupPolicy, error) { | ||
dnUrl := fmt.Sprintf("%s/uni/tn-%s/svcCont/vnsBackupPol.json", models.BaseurlStr, tenant) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.PBRBackupPolicyListFromContainer(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,138 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/container" | ||
"github.com/ciscoecosystem/aci-go-client/v2/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreateL1L2RedirectDestTraffic(destName string, parentDn string, description string, nameAlias string, vnsL1L2RedirectDestAttr models.L1L2RedirectDestTrafficAttributes) (*models.L1L2RedirectDestTraffic, error) { | ||
rn := fmt.Sprintf(models.RnvnsL1L2RedirectDest, destName) | ||
vnsL1L2RedirectDest := models.NewL1L2RedirectDestTraffic(rn, parentDn, description, nameAlias, vnsL1L2RedirectDestAttr) | ||
err := sm.Save(vnsL1L2RedirectDest) | ||
return vnsL1L2RedirectDest, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadL1L2RedirectDestTraffic(destName string, parentDn string) (*models.L1L2RedirectDestTraffic, error) { | ||
dn := fmt.Sprintf("%s/%s", parentDn, fmt.Sprintf(models.RnvnsL1L2RedirectDest, destName)) | ||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vnsL1L2RedirectDest := models.L1L2RedirectDestTrafficFromContainer(cont) | ||
return vnsL1L2RedirectDest, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteL1L2RedirectDestTraffic(destName string, parentDn string) error { | ||
dn := fmt.Sprintf("%s/%s", parentDn, fmt.Sprintf(models.RnvnsL1L2RedirectDest, destName)) | ||
return sm.DeleteByDn(dn, models.Vnsl1l2redirectdestClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdateL1L2RedirectDestTraffic(destName string, parentDn string, description string, nameAlias string, vnsL1L2RedirectDestAttr models.L1L2RedirectDestTrafficAttributes) (*models.L1L2RedirectDestTraffic, error) { | ||
rn := fmt.Sprintf(models.RnvnsL1L2RedirectDest, destName) | ||
vnsL1L2RedirectDest := models.NewL1L2RedirectDestTraffic(rn, parentDn, description, nameAlias, vnsL1L2RedirectDestAttr) | ||
vnsL1L2RedirectDest.Status = "modified" | ||
err := sm.Save(vnsL1L2RedirectDest) | ||
return vnsL1L2RedirectDest, err | ||
} | ||
|
||
func (sm *ServiceManager) ListL1L2RedirectDestTraffic(parentDn string) ([]*models.L1L2RedirectDestTraffic, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/vnsL1L2RedirectDest.json", models.BaseurlStr, parentDn) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.L1L2RedirectDestTrafficListFromContainer(cont) | ||
return list, err | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsL1L2RedirectHealthGroup(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rsL1L2RedirectHealthGroup", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsL1L2RedirectHealthGroup", 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) DeleteRelationvnsRsL1L2RedirectHealthGroup(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rsL1L2RedirectHealthGroup", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsL1L2RedirectHealthGroup") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsL1L2RedirectHealthGroup(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsL1L2RedirectHealthGroup") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsL1L2RedirectHealthGroup") | ||
|
||
if len(contList) > 0 { | ||
dat := models.G(contList[0], "tDn") | ||
return dat, err | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsToCIf(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rstoCIf", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsToCIf", 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) DeleteRelationvnsRsToCIf(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rstoCIf", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsToCIf") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsToCIf(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsToCIf") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsToCIf") | ||
|
||
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,100 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/container" | ||
) | ||
|
||
const ( | ||
DnvnsBackupPol = "uni/tn-%s/svcCont/backupPol-%s" | ||
RnvnsBackupPol = "backupPol-%s" | ||
ParentDnvnsBackupPol = "uni/tn-%s/svcCont" | ||
VnsbackuppolClassName = "vnsBackupPol" // PBR Backup Policy ClassName | ||
RnvnsSvcCont = "svcCont" // Service Container RN | ||
VnsSvcContClassName = "vnsSvcCont" // Service Container ClassName | ||
) | ||
|
||
type PBRBackupPolicy struct { | ||
BaseAttributes | ||
NameAliasAttribute | ||
PBRBackupPolicyAttributes | ||
} | ||
|
||
type PBRBackupPolicyAttributes struct { | ||
Annotation string `json:",omitempty"` | ||
Name string `json:",omitempty"` | ||
} | ||
|
||
func NewPBRBackupPolicy(vnsBackupPolRn, parentDn, description, nameAlias string, vnsBackupPolAttr PBRBackupPolicyAttributes) *PBRBackupPolicy { | ||
dn := fmt.Sprintf("%s/%s", parentDn, vnsBackupPolRn) | ||
return &PBRBackupPolicy{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Description: description, | ||
Status: "created, modified", | ||
ClassName: VnsbackuppolClassName, | ||
Rn: vnsBackupPolRn, | ||
}, | ||
NameAliasAttribute: NameAliasAttribute{ | ||
NameAlias: nameAlias, | ||
}, | ||
PBRBackupPolicyAttributes: vnsBackupPolAttr, | ||
} | ||
} | ||
|
||
func (vnsBackupPol *PBRBackupPolicy) ToMap() (map[string]string, error) { | ||
vnsBackupPolMap, err := vnsBackupPol.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
alias, err := vnsBackupPol.NameAliasAttribute.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range alias { | ||
A(vnsBackupPolMap, key, value) | ||
} | ||
|
||
A(vnsBackupPolMap, "annotation", vnsBackupPol.Annotation) | ||
A(vnsBackupPolMap, "name", vnsBackupPol.Name) | ||
return vnsBackupPolMap, err | ||
} | ||
|
||
func PBRBackupPolicyFromContainerList(cont *container.Container, index int) *PBRBackupPolicy { | ||
PBRBackupPolicyCont := cont.S("imdata").Index(index).S(VnsbackuppolClassName, "attributes") | ||
return &PBRBackupPolicy{ | ||
BaseAttributes{ | ||
DistinguishedName: G(PBRBackupPolicyCont, "dn"), | ||
Description: G(PBRBackupPolicyCont, "descr"), | ||
Status: G(PBRBackupPolicyCont, "status"), | ||
ClassName: VnsbackuppolClassName, | ||
Rn: G(PBRBackupPolicyCont, "rn"), | ||
}, | ||
NameAliasAttribute{ | ||
NameAlias: G(PBRBackupPolicyCont, "nameAlias"), | ||
}, | ||
PBRBackupPolicyAttributes{ | ||
Annotation: G(PBRBackupPolicyCont, "annotation"), | ||
Name: G(PBRBackupPolicyCont, "name"), | ||
}, | ||
} | ||
} | ||
|
||
func PBRBackupPolicyFromContainer(cont *container.Container) *PBRBackupPolicy { | ||
return PBRBackupPolicyFromContainerList(cont, 0) | ||
} | ||
|
||
func PBRBackupPolicyListFromContainer(cont *container.Container) []*PBRBackupPolicy { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*PBRBackupPolicy, length) | ||
|
||
for i := 0; i < length; i++ { | ||
arr[i] = PBRBackupPolicyFromContainerList(cont, i) | ||
} | ||
|
||
return arr | ||
} |
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,105 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/container" | ||
) | ||
|
||
const ( | ||
RnvnsL1L2RedirectDest = "L1L2RedirectDest-%s" | ||
Vnsl1l2redirectdestClassName = "vnsL1L2RedirectDest" | ||
) | ||
|
||
type L1L2RedirectDestTraffic struct { | ||
BaseAttributes | ||
NameAliasAttribute | ||
L1L2RedirectDestTrafficAttributes | ||
} | ||
|
||
type L1L2RedirectDestTrafficAttributes struct { | ||
Annotation string `json:",omitempty"` | ||
DestName string `json:",omitempty"` | ||
Mac string `json:",omitempty"` | ||
Name string `json:",omitempty"` | ||
PodId string `json:",omitempty"` | ||
} | ||
|
||
func NewL1L2RedirectDestTraffic(vnsL1L2RedirectDestRn, parentDn, description, nameAlias string, vnsL1L2RedirectDestAttr L1L2RedirectDestTrafficAttributes) *L1L2RedirectDestTraffic { | ||
dn := fmt.Sprintf("%s/%s", parentDn, vnsL1L2RedirectDestRn) | ||
return &L1L2RedirectDestTraffic{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Description: description, | ||
Status: "created, modified", | ||
ClassName: Vnsl1l2redirectdestClassName, | ||
Rn: vnsL1L2RedirectDestRn, | ||
}, | ||
NameAliasAttribute: NameAliasAttribute{ | ||
NameAlias: nameAlias, | ||
}, | ||
L1L2RedirectDestTrafficAttributes: vnsL1L2RedirectDestAttr, | ||
} | ||
} | ||
|
||
func (vnsL1L2RedirectDest *L1L2RedirectDestTraffic) ToMap() (map[string]string, error) { | ||
vnsL1L2RedirectDestMap, err := vnsL1L2RedirectDest.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
alias, err := vnsL1L2RedirectDest.NameAliasAttribute.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range alias { | ||
A(vnsL1L2RedirectDestMap, key, value) | ||
} | ||
|
||
A(vnsL1L2RedirectDestMap, "annotation", vnsL1L2RedirectDest.Annotation) | ||
A(vnsL1L2RedirectDestMap, "destName", vnsL1L2RedirectDest.DestName) | ||
A(vnsL1L2RedirectDestMap, "mac", vnsL1L2RedirectDest.Mac) | ||
A(vnsL1L2RedirectDestMap, "name", vnsL1L2RedirectDest.Name) | ||
A(vnsL1L2RedirectDestMap, "podId", vnsL1L2RedirectDest.PodId) | ||
return vnsL1L2RedirectDestMap, err | ||
} | ||
|
||
func L1L2RedirectDestTrafficFromContainerList(cont *container.Container, index int) *L1L2RedirectDestTraffic { | ||
L1L2RedirectDestTrafficCont := cont.S("imdata").Index(index).S(Vnsl1l2redirectdestClassName, "attributes") | ||
return &L1L2RedirectDestTraffic{ | ||
BaseAttributes{ | ||
DistinguishedName: G(L1L2RedirectDestTrafficCont, "dn"), | ||
Description: G(L1L2RedirectDestTrafficCont, "descr"), | ||
Status: G(L1L2RedirectDestTrafficCont, "status"), | ||
ClassName: Vnsl1l2redirectdestClassName, | ||
Rn: G(L1L2RedirectDestTrafficCont, "rn"), | ||
}, | ||
NameAliasAttribute{ | ||
NameAlias: G(L1L2RedirectDestTrafficCont, "nameAlias"), | ||
}, | ||
L1L2RedirectDestTrafficAttributes{ | ||
Annotation: G(L1L2RedirectDestTrafficCont, "annotation"), | ||
DestName: G(L1L2RedirectDestTrafficCont, "destName"), | ||
Mac: G(L1L2RedirectDestTrafficCont, "mac"), | ||
Name: G(L1L2RedirectDestTrafficCont, "name"), | ||
PodId: G(L1L2RedirectDestTrafficCont, "podId"), | ||
}, | ||
} | ||
} | ||
|
||
func L1L2RedirectDestTrafficFromContainer(cont *container.Container) *L1L2RedirectDestTraffic { | ||
return L1L2RedirectDestTrafficFromContainerList(cont, 0) | ||
} | ||
|
||
func L1L2RedirectDestTrafficListFromContainer(cont *container.Container) []*L1L2RedirectDestTraffic { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*L1L2RedirectDestTraffic, length) | ||
|
||
for i := 0; i < length; i++ { | ||
arr[i] = L1L2RedirectDestTrafficFromContainerList(cont, i) | ||
} | ||
|
||
return arr | ||
} |