-
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 new client and model files for vncCDev (#210)
- Loading branch information
Showing
3 changed files
with
209 additions
and
2 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,92 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
"github.com/ciscoecosystem/aci-go-client/models" | ||
) | ||
|
||
func (sm *ServiceManager) CreateConcreteDevice(name string, parent_dn string, nameAlias string, vnsCDevAttr models.ConcreteDeviceAttributes) (*models.ConcreteDevice, error) { | ||
rn := fmt.Sprintf(models.RnvnsCDev, name) | ||
vnsCDev := models.NewConcreteDevice(rn, parent_dn, nameAlias, vnsCDevAttr) | ||
err := sm.Save(vnsCDev) | ||
return vnsCDev, err | ||
} | ||
|
||
func (sm *ServiceManager) ReadConcreteDevice(name string, parent_dn string) (*models.ConcreteDevice, error) { | ||
dn := fmt.Sprintf(parent_dn+"/"+models.RnvnsCDev, name) | ||
cont, err := sm.Get(dn) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
vnsCDev := models.ConcreteDeviceFromContainer(cont) | ||
return vnsCDev, nil | ||
} | ||
|
||
func (sm *ServiceManager) DeleteConcreteDevice(name string, parent_dn string) error { | ||
dn := fmt.Sprintf(parent_dn+"/"+models.RnvnsCDev, name) | ||
return sm.DeleteByDn(dn, models.VnscdevClassName) | ||
} | ||
|
||
func (sm *ServiceManager) UpdateConcreteDevice(name string, parent_dn string, nameAlias string, vnsCDevAttr models.ConcreteDeviceAttributes) (*models.ConcreteDevice, error) { | ||
rn := fmt.Sprintf(models.RnvnsCDev, name) | ||
vnsCDev := models.NewConcreteDevice(rn, parent_dn, nameAlias, vnsCDevAttr) | ||
vnsCDev.Status = "modified" | ||
err := sm.Save(vnsCDev) | ||
return vnsCDev, err | ||
} | ||
|
||
func (sm *ServiceManager) ListConcreteDevice(parent_dn string) ([]*models.ConcreteDevice, error) { | ||
dnUrl := fmt.Sprintf(models.BaseurlStr + "/" + parent_dn + "/vnsCDev.json") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
list := models.ConcreteDeviceListFromContainer(cont) | ||
return list, err | ||
} | ||
|
||
func (sm *ServiceManager) CreateRelationvnsRsCDevToCtrlrP(parentDn, annotation, tDn string) error { | ||
dn := fmt.Sprintf("%s/rscDevToCtrlrP", parentDn) | ||
containerJSON := []byte(fmt.Sprintf(`{ | ||
"%s": { | ||
"attributes": { | ||
"dn": "%s", | ||
"annotation": "%s", | ||
"tDn": "%s" | ||
} | ||
} | ||
}`, "vnsRsCDevToCtrlrP", 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) DeleteRelationvnsRsCDevToCtrlrP(parentDn string) error { | ||
dn := fmt.Sprintf("%s/rscDevToCtrlrP", parentDn) | ||
return sm.DeleteByDn(dn, "vnsRsCDevToCtrlrP") | ||
} | ||
|
||
func (sm *ServiceManager) ReadRelationvnsRsCDevToCtrlrP(parentDn string) (interface{}, error) { | ||
dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "vnsRsCDevToCtrlrP") | ||
cont, err := sm.GetViaURL(dnUrl) | ||
contList := models.ListFromContainer(cont, "vnsRsCDevToCtrlrP") | ||
|
||
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,116 @@ | ||
package models | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/ciscoecosystem/aci-go-client/container" | ||
) | ||
|
||
const ( | ||
DnvnsCDev = "%s/cDev-%s" | ||
RnvnsCDev = "cDev-%s" | ||
VnscdevClassName = "vnsCDev" | ||
) | ||
|
||
type ConcreteDevice struct { | ||
BaseAttributes | ||
NameAliasAttribute | ||
ConcreteDeviceAttributes | ||
} | ||
|
||
type ConcreteDeviceAttributes struct { | ||
CloneCount string `json:",omitempty"` | ||
DevCtxLbl string `json:",omitempty"` | ||
Host string `json:",omitempty"` | ||
IsCloneOperation string `json:",omitempty"` | ||
IsTemplate string `json:",omitempty"` | ||
Name string `json:",omitempty"` | ||
VcenterName string `json:",omitempty"` | ||
VmName string `json:",omitempty"` | ||
Annotation string `json:",omitempty"` | ||
} | ||
|
||
func NewConcreteDevice(vnsCDevRn, parentDn, nameAlias string, vnsCDevAttr ConcreteDeviceAttributes) *ConcreteDevice { | ||
dn := fmt.Sprintf("%s/%s", parentDn, vnsCDevRn) | ||
return &ConcreteDevice{ | ||
BaseAttributes: BaseAttributes{ | ||
DistinguishedName: dn, | ||
Status: "created, modified", | ||
ClassName: VnscdevClassName, | ||
Rn: vnsCDevRn, | ||
}, | ||
NameAliasAttribute: NameAliasAttribute{ | ||
NameAlias: nameAlias, | ||
}, | ||
ConcreteDeviceAttributes: vnsCDevAttr, | ||
} | ||
} | ||
|
||
func (vnsCDev *ConcreteDevice) ToMap() (map[string]string, error) { | ||
vnsCDevMap, err := vnsCDev.BaseAttributes.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
alias, err := vnsCDev.NameAliasAttribute.ToMap() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
for key, value := range alias { | ||
A(vnsCDevMap, key, value) | ||
} | ||
|
||
A(vnsCDevMap, "cloneCount", vnsCDev.CloneCount) | ||
A(vnsCDevMap, "annotation", vnsCDev.Annotation) | ||
A(vnsCDevMap, "devCtxLbl", vnsCDev.DevCtxLbl) | ||
A(vnsCDevMap, "host", vnsCDev.Host) | ||
A(vnsCDevMap, "isCloneOperation", vnsCDev.IsCloneOperation) | ||
A(vnsCDevMap, "isTemplate", vnsCDev.IsTemplate) | ||
A(vnsCDevMap, "name", vnsCDev.Name) | ||
A(vnsCDevMap, "vcenterName", vnsCDev.VcenterName) | ||
A(vnsCDevMap, "vmName", vnsCDev.VmName) | ||
return vnsCDevMap, err | ||
} | ||
|
||
func ConcreteDeviceFromContainerList(cont *container.Container, index int) *ConcreteDevice { | ||
ConcreteDeviceCont := cont.S("imdata").Index(index).S(VnscdevClassName, "attributes") | ||
return &ConcreteDevice{ | ||
BaseAttributes{ | ||
DistinguishedName: G(ConcreteDeviceCont, "dn"), | ||
Status: G(ConcreteDeviceCont, "status"), | ||
ClassName: VnscdevClassName, | ||
Rn: G(ConcreteDeviceCont, "rn"), | ||
}, | ||
NameAliasAttribute{ | ||
NameAlias: G(ConcreteDeviceCont, "nameAlias"), | ||
}, | ||
ConcreteDeviceAttributes{ | ||
CloneCount: G(ConcreteDeviceCont, "cloneCount"), | ||
Annotation: G(ConcreteDeviceCont, "annotation"), | ||
DevCtxLbl: G(ConcreteDeviceCont, "devCtxLbl"), | ||
Host: G(ConcreteDeviceCont, "host"), | ||
IsCloneOperation: G(ConcreteDeviceCont, "isCloneOperation"), | ||
IsTemplate: G(ConcreteDeviceCont, "isTemplate"), | ||
Name: G(ConcreteDeviceCont, "name"), | ||
VcenterName: G(ConcreteDeviceCont, "vcenterName"), | ||
VmName: G(ConcreteDeviceCont, "vmName"), | ||
}, | ||
} | ||
} | ||
|
||
func ConcreteDeviceFromContainer(cont *container.Container) *ConcreteDevice { | ||
return ConcreteDeviceFromContainerList(cont, 0) | ||
} | ||
|
||
func ConcreteDeviceListFromContainer(cont *container.Container) []*ConcreteDevice { | ||
length, _ := strconv.Atoi(G(cont, "totalCount")) | ||
arr := make([]*ConcreteDevice, length) | ||
|
||
for i := 0; i < length; i++ { | ||
arr[i] = ConcreteDeviceFromContainerList(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