From fb4cdbf0d49d9e511afeef46c057cb4fc71050f6 Mon Sep 17 00:00:00 2001 From: Mateusz F <61707914+mfr-6@users.noreply.github.com> Date: Fri, 23 Jun 2023 02:25:44 +0200 Subject: [PATCH] [minor_change] Add client and model files for l3extConsLbl --- client/l3extConsLbl_service.go | 41 +++++++++++++++ models/l3ext_cons_lbl.go | 93 ++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 client/l3extConsLbl_service.go create mode 100644 models/l3ext_cons_lbl.go diff --git a/client/l3extConsLbl_service.go b/client/l3extConsLbl_service.go new file mode 100644 index 0000000..08285e9 --- /dev/null +++ b/client/l3extConsLbl_service.go @@ -0,0 +1,41 @@ +package client + +import ( + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/models" +) + +func (sm *ServiceManager) CreateL3ExtConsLbl(name string, l3_outside string, tenant string, description string, consLblAttr models.L3ExtConsLblAttributes) (*models.L3ExtConsLbl, error) { + rn := fmt.Sprintf(models.RnL3extConsLbl, name) + parentDn := fmt.Sprintf(models.ParentDnL3ExtConsLbl, tenant, l3_outside) + consLbl := models.NewL3ExtConsLbl(rn, parentDn, description, consLblAttr) + err := sm.Save(consLbl) + return consLbl, err +} + +func (sm *ServiceManager) ReadL3ExtConsLbl(name string, l3_outside string, tenant string) (*models.L3ExtConsLbl, error) { + dn := fmt.Sprintf(models.DnL3extConsLbl, tenant, l3_outside, name) + cont, err := sm.Get(dn) + if err != nil { + return nil, err + } + + consLbl := models.L3ExtConsLblFromContainer(cont) + return consLbl, nil +} + +func (sm *ServiceManager) DeleteL3ExtConsLbl(name string, l3_outside string, tenant string) error { + dn := fmt.Sprintf(models.DnL3extConsLbl, tenant, l3_outside, name) + return sm.DeleteByDn(dn, models.L3extConsLblClassName) +} + +func (sm *ServiceManager) UpdateL3ExtConsLbl(name string, l3_outside string, tenant string, description string, consLblAttr models.L3ExtConsLblAttributes) (*models.L3ExtConsLbl, error) { + rn := fmt.Sprintf(models.RnL3extConsLbl, name) + parentDn := fmt.Sprintf(models.ParentDnL3ExtConsLbl, tenant, l3_outside) + consLbl := models.NewL3ExtConsLbl(rn, parentDn, description, consLblAttr) + + consLbl.Status = "modified" + err := sm.Save(consLbl) + return consLbl, err +} diff --git a/models/l3ext_cons_lbl.go b/models/l3ext_cons_lbl.go new file mode 100644 index 0000000..9642827 --- /dev/null +++ b/models/l3ext_cons_lbl.go @@ -0,0 +1,93 @@ +package models + +import ( + "fmt" + "strconv" + + "github.com/ciscoecosystem/aci-go-client/v2/container" +) + +const ( + DnL3extConsLbl = "uni/tn-%s/out-%s/conslbl-%s" + RnL3extConsLbl = "conslbl-%s" + ParentDnL3ExtConsLbl = "uni/tn-%s/out-%s" + L3extConsLblClassName = "l3extConsLbl" +) + +type L3ExtConsLbl struct { + BaseAttributes + L3ExtConsLblAttributes +} + +type L3ExtConsLblAttributes struct { + Name string `json:",omitempty"` + Annotation string `json:",omitempty"` + NameAlias string `json:",omitempty"` + Owner string `json:",omitempty"` + Tag string `json:",omitempty"` +} + +func NewL3ExtConsLbl(consLblRn, parentDn, description string, consLblAttr L3ExtConsLblAttributes) *L3ExtConsLbl { + dn := fmt.Sprintf("%s/%s", parentDn, consLblRn) + return &L3ExtConsLbl{ + BaseAttributes: BaseAttributes{ + DistinguishedName: dn, + Description: description, + Status: "created, modified", + ClassName: L3extConsLblClassName, + Rn: consLblRn, + }, + + L3ExtConsLblAttributes: consLblAttr, + } +} + +func (consLbl *L3ExtConsLbl) ToMap() (map[string]string, error) { + consLblMap, err := consLbl.BaseAttributes.ToMap() + if err != nil { + return nil, err + } + + A(consLblMap, "name", consLbl.Name) + A(consLblMap, "annotation", consLbl.Annotation) + A(consLblMap, "nameAlias", consLbl.NameAlias) + A(consLblMap, "owner", consLbl.Owner) + A(consLblMap, "tag", consLbl.Tag) + return consLblMap, err +} + +func L3ExtConsLblFromContainerList(cont *container.Container, index int) *L3ExtConsLbl { + L3ExtConsLblCont := cont.S("imdata").Index(index).S(L3extConsLblClassName, "attributes") + return &L3ExtConsLbl{ + BaseAttributes{ + DistinguishedName: G(L3ExtConsLblCont, "dn"), + Description: G(L3ExtConsLblCont, "descr"), + Status: G(L3ExtConsLblCont, "status"), + ClassName: L3extConsLblClassName, + Rn: G(L3ExtConsLblCont, "rn"), + }, + + L3ExtConsLblAttributes{ + Name: G(L3ExtConsLblCont, "name"), + Annotation: G(L3ExtConsLblCont, "annotation"), + NameAlias: G(L3ExtConsLblCont, "nameAlias"), + Owner: G(L3ExtConsLblCont, "owner"), + Tag: G(L3ExtConsLblCont, "tag"), + }, + } +} + +func L3ExtConsLblFromContainer(cont *container.Container) *L3ExtConsLbl { + return L3ExtConsLblFromContainerList(cont, 0) +} + +func L3ExtConsLblListFromContainer(cont *container.Container) []*L3ExtConsLbl { + length, _ := strconv.Atoi(G(cont, "totalCount")) + + arr := make([]*L3ExtConsLbl, length) + for i := 0; i < length; i++ { + arr[i] = L3ExtConsLblFromContainerList(cont, i) + } + + return arr +}