-
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 model and client files for psuInstPol (#270)
- Loading branch information
Showing
2 changed files
with
132 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,44 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreatePowerSupplyRedundancyPolicy(name string, description string, psuInstPolAttr models.PsuInstPolAttributes) (*models.PsuInstPol, error) { | ||
rn := fmt.Sprintf(models.RnPsuInstPol, name) | ||
psuInstPol := models.NewPowerSupplyRedundancyPolicy(rn, description, psuInstPolAttr) | ||
err := sm.Save(psuInstPol) | ||
return psuInstPol, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadPowerSupplyRedundancyPolicy(name string) (*models.PsuInstPol, error) { | ||
dn := fmt.Sprintf(models.DnPsuInstPol, name) | ||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
psuInstPol := models.PsuInstPolFromContainer(cont) | ||
return psuInstPol, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeletePowerSupplyRedundancyPolicy(name string) error { | ||
dn := fmt.Sprintf(models.DnPsuInstPol, name) | ||
return sm.DeleteByDn(dn, models.PsuInstPolClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdatePowerSupplyRedundancyPolicy(name string, description string, psuInstPolAttr models.PsuInstPolAttributes) (*models.PsuInstPol, error) { | ||
rn := fmt.Sprintf(models.RnPsuInstPol, name) | ||
psuInstPol := models.NewPowerSupplyRedundancyPolicy(rn, description, psuInstPolAttr) | ||
psuInstPol.Status = "modified" | ||
err := sm.Save(psuInstPol) | ||
return psuInstPol, err | ||
} | ||
|
||
func (sm *ServiceManager) ListPowerSupplyRedundancyPolicy() ([]*models.PsuInstPol, error) { | ||
dnUrl := fmt.Sprintf("%s/uni/fabric/psuInstPol.json", models.BaseurlStr) | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.PsuInstPolListFromContainer(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,88 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/v2/container" | ||
) | ||
|
||
const ( | ||
DnPsuInstPol = "uni/fabric/psuInstP-%s" | ||
RnPsuInstPol = "psuInstP-%s" | ||
ParentDnPsuInstPol = "uni/fabric" | ||
PsuInstPolClassName = "psuInstPol" | ||
) | ||
|
||
type PsuInstPol struct { | ||
BaseAttributes | ||
PsuInstPolAttributes | ||
} | ||
|
||
type PsuInstPolAttributes struct { | ||
AdminRdnM string `json:",omitempty"` | ||
Name string `json:",omitempty"` | ||
Annotation string `json:",omitempty"` | ||
NameAlias string `json:",omitempty"` | ||
} | ||
|
||
func NewPowerSupplyRedundancyPolicy(psuInstPolRn, description string, psuInstPolAttr PsuInstPolAttributes) *PsuInstPol { | ||
dn := fmt.Sprintf("%s/%s", ParentDnPsuInstPol, psuInstPolRn) | ||
return &PsuInstPol{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Description: description, | ||
Status: "created, modified", | ||
ClassName: PsuInstPolClassName, | ||
Rn: psuInstPolRn, | ||
}, | ||
|
||
PsuInstPolAttributes: psuInstPolAttr, | ||
} | ||
} | ||
|
||
func (psuInstPol *PsuInstPol) ToMap() (map[string]string, error) { | ||
psuInstPolMap, err := psuInstPol.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
A(psuInstPolMap, "adminRdnM", psuInstPol.AdminRdnM) | ||
A(psuInstPolMap, "name", psuInstPol.Name) | ||
A(psuInstPolMap, "annotation", psuInstPol.Annotation) | ||
A(psuInstPolMap, "nameAlias", psuInstPol.NameAlias) | ||
|
||
return psuInstPolMap, err | ||
} | ||
|
||
func PsuInstPolFromContainerList(cont *container.Container, index int) *PsuInstPol { | ||
PsuInstPolCont := cont.S("imdata").Index(index).S(PsuInstPolClassName, "attributes") | ||
return &PsuInstPol{ | ||
BaseAttributes{ | ||
DistinguishedName: G(PsuInstPolCont, "dn"), | ||
Description: G(PsuInstPolCont, "descr"), | ||
Status: G(PsuInstPolCont, "status"), | ||
ClassName: PsuInstPolClassName, | ||
Rn: G(PsuInstPolCont, "rn"), | ||
}, | ||
PsuInstPolAttributes{ | ||
AdminRdnM: G(PsuInstPolCont, "adminRdnM"), | ||
Name: G(PsuInstPolCont, "name"), | ||
Annotation: G(PsuInstPolCont, "annotation"), | ||
NameAlias: G(PsuInstPolCont, "nameAlias"), | ||
}, | ||
} | ||
} | ||
|
||
func PsuInstPolFromContainer(cont *container.Container) *PsuInstPol { | ||
return PsuInstPolFromContainerList(cont, 0) | ||
} | ||
|
||
func PsuInstPolListFromContainer(cont *container.Container) []*PsuInstPol { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*PsuInstPol, length) | ||
for i := 0; i < length; i++ { | ||
arr[i] = PsuInstPolFromContainerList(cont, i) | ||
} | ||
return arr | ||
} |