From ee338a0cf45c981a42ee4384325c8d2b9129163a Mon Sep 17 00:00:00 2001 From: Gaspard Micol <129436116+gmicol@users.noreply.github.com> Date: Thu, 24 Aug 2023 13:42:47 -0400 Subject: [PATCH] [minor_change] Add models and clients for cloudServiceEPg, cloudPrivateLinkLabel and cloudSvcEpSelector (#281) --- client/cloudPrivateLinkLabel_service.go | 56 ++ client/cloudSvcEPSelector_service.go | 65 +++ client/cloudSvcEPg_service.go | 647 ++++++++++++++++++++++++ models/cloud_private_link_label.go | 83 +++ models/cloud_svc_epg.go | 115 +++++ models/cloud_svc_epselector.go | 88 ++++ 6 files changed, 1054 insertions(+) create mode 100644 client/cloudPrivateLinkLabel_service.go create mode 100644 client/cloudSvcEPSelector_service.go create mode 100644 client/cloudSvcEPg_service.go create mode 100644 models/cloud_private_link_label.go create mode 100644 models/cloud_svc_epg.go create mode 100644 models/cloud_svc_epselector.go diff --git a/client/cloudPrivateLinkLabel_service.go b/client/cloudPrivateLinkLabel_service.go new file mode 100644 index 0000000..faa2758 --- /dev/null +++ b/client/cloudPrivateLinkLabel_service.go @@ -0,0 +1,56 @@ +package client + +import ( + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/models" +) + +func (sm *ServiceManager) CreateCloudPrivateLinkLabel(name string, parentDn string, description string, cloudPrivateLinkLabelAttr models.CloudPrivateLinkLabelAttributes) (*models.CloudPrivateLinkLabel, error) { + + rn := fmt.Sprintf(models.RnCloudPrivateLinkLabel, name) + cloudPrivateLinkLabel := models.NewCloudPrivateLinkLabel(rn, parentDn, description, cloudPrivateLinkLabelAttr) + + err := sm.Save(cloudPrivateLinkLabel) + return cloudPrivateLinkLabel, err +} + +func (sm *ServiceManager) ReadCloudPrivateLinkLabel(name string, parentDn string) (*models.CloudPrivateLinkLabel, error) { + + rn := fmt.Sprintf(models.RnCloudPrivateLinkLabel, name) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + cont, err := sm.Get(dn) + if err != nil { + return nil, err + } + cloudPrivateLinkLabel := models.CloudPrivateLinkLabelFromContainer(cont) + return cloudPrivateLinkLabel, nil +} + +func (sm *ServiceManager) DeleteCloudPrivateLinkLabel(name string, parentDn string) error { + + rn := fmt.Sprintf(models.RnCloudPrivateLinkLabel, name) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + return sm.DeleteByDn(dn, models.CloudPrivateLinkLabelClassName) +} + +func (sm *ServiceManager) UpdateCloudPrivateLinkLabel(name string, parentDn string, description string, cloudPrivateLinkLabelAttr models.CloudPrivateLinkLabelAttributes) (*models.CloudPrivateLinkLabel, error) { + + rn := fmt.Sprintf(models.RnCloudPrivateLinkLabel, name) + cloudPrivateLinkLabel := models.NewCloudPrivateLinkLabel(rn, parentDn, description, cloudPrivateLinkLabelAttr) + + cloudPrivateLinkLabel.Status = "modified" + err := sm.Save(cloudPrivateLinkLabel) + return cloudPrivateLinkLabel, err +} + +func (sm *ServiceManager) ListCloudPrivateLinkLabel(parentDn string) ([]*models.CloudPrivateLinkLabel, error) { + + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, models.CloudPrivateLinkLabelClassName) + + cont, err := sm.GetViaURL(dnUrl) + list := models.CloudPrivateLinkLabelListFromContainer(cont) + return list, err +} diff --git a/client/cloudSvcEPSelector_service.go b/client/cloudSvcEPSelector_service.go new file mode 100644 index 0000000..0a6db1a --- /dev/null +++ b/client/cloudSvcEPSelector_service.go @@ -0,0 +1,65 @@ +package client + +import ( + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/models" +) + +func (sm *ServiceManager) CreateCloudServiceEndpointSelector(name string, cloud_service_epg string, cloud_application_container string, tenant string, description string, cloudSvcEPSelectorAttr models.CloudServiceEndpointSelectorAttributes) (*models.CloudServiceEndpointSelector, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPSelector, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPSelector, tenant, cloud_application_container, cloud_service_epg) + cloudSvcEPSelector := models.NewCloudServiceEndpointSelector(rn, parentDn, description, cloudSvcEPSelectorAttr) + + err := sm.Save(cloudSvcEPSelector) + return cloudSvcEPSelector, err +} + +func (sm *ServiceManager) ReadCloudServiceEndpointSelector(name string, cloud_service_epg string, cloud_application_container string, tenant string) (*models.CloudServiceEndpointSelector, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPSelector, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPSelector, tenant, cloud_application_container, cloud_service_epg) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + cont, err := sm.Get(dn) + if err != nil { + return nil, err + } + cloudSvcEPSelector := models.CloudServiceEndpointSelectorFromContainer(cont) + return cloudSvcEPSelector, nil +} + +func (sm *ServiceManager) DeleteCloudServiceEndpointSelector(name string, cloud_service_epg string, cloud_application_container string, tenant string) error { + + rn := fmt.Sprintf(models.RnCloudSvcEPSelector, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPSelector, tenant, cloud_application_container, cloud_service_epg) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + return sm.DeleteByDn(dn, models.CloudSvcEPSelectorClassName) +} + +func (sm *ServiceManager) UpdateCloudServiceEndpointSelector(name string, cloud_service_epg string, cloud_application_container string, tenant string, description string, cloudSvcEPSelectorAttr models.CloudServiceEndpointSelectorAttributes) (*models.CloudServiceEndpointSelector, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPSelector, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPSelector, tenant, cloud_application_container, cloud_service_epg) + cloudSvcEPSelector := models.NewCloudServiceEndpointSelector(rn, parentDn, description, cloudSvcEPSelectorAttr) + + cloudSvcEPSelector.Status = "modified" + err := sm.Save(cloudSvcEPSelector) + return cloudSvcEPSelector, err +} + +func (sm *ServiceManager) ListCloudServiceEndpointSelector(cloud_service_epg string, cloud_application_container string, tenant string) ([]*models.CloudServiceEndpointSelector, error) { + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPSelector, tenant, cloud_application_container, cloud_service_epg) + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, models.CloudSvcEPSelectorClassName) + + cont, err := sm.GetViaURL(dnUrl) + list := models.CloudServiceEndpointSelectorListFromContainer(cont) + return list, err +} diff --git a/client/cloudSvcEPg_service.go b/client/cloudSvcEPg_service.go new file mode 100644 index 0000000..d7ebd09 --- /dev/null +++ b/client/cloudSvcEPg_service.go @@ -0,0 +1,647 @@ +package client + +import ( + "encoding/json" + "fmt" + + "github.com/ciscoecosystem/aci-go-client/v2/container" + "github.com/ciscoecosystem/aci-go-client/v2/models" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +func (sm *ServiceManager) CreateCloudServiceEPg(name string, cloud_application_container string, tenant string, description string, cloudSvcEPgAttr models.CloudServiceEPgAttributes) (*models.CloudServiceEPg, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPg, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPg, tenant, cloud_application_container) + cloudSvcEPg := models.NewCloudServiceEPg(rn, parentDn, description, cloudSvcEPgAttr) + + err := sm.Save(cloudSvcEPg) + return cloudSvcEPg, err +} + +func (sm *ServiceManager) ReadCloudServiceEPg(name string, cloud_application_container string, tenant string) (*models.CloudServiceEPg, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPg, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPg, tenant, cloud_application_container) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + cont, err := sm.Get(dn) + if err != nil { + return nil, err + } + cloudSvcEPg := models.CloudServiceEPgFromContainer(cont) + return cloudSvcEPg, nil +} + +func (sm *ServiceManager) DeleteCloudServiceEPg(name string, cloud_application_container string, tenant string) error { + + rn := fmt.Sprintf(models.RnCloudSvcEPg, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPg, tenant, cloud_application_container) + dn := fmt.Sprintf("%s/%s", parentDn, rn) + + return sm.DeleteByDn(dn, models.CloudSvcEPgClassName) +} + +func (sm *ServiceManager) UpdateCloudServiceEPg(name string, cloud_application_container string, tenant string, description string, cloudSvcEPgAttr models.CloudServiceEPgAttributes) (*models.CloudServiceEPg, error) { + + rn := fmt.Sprintf(models.RnCloudSvcEPg, name) + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPg, tenant, cloud_application_container) + cloudSvcEPg := models.NewCloudServiceEPg(rn, parentDn, description, cloudSvcEPgAttr) + + cloudSvcEPg.Status = "modified" + err := sm.Save(cloudSvcEPg) + return cloudSvcEPg, err +} + +func (sm *ServiceManager) ListCloudServiceEPg(cloud_application_container string, tenant string) ([]*models.CloudServiceEPg, error) { + + parentDn := fmt.Sprintf(models.ParentDnCloudSvcEPg, tenant, cloud_application_container) + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, models.CloudSvcEPgClassName) + + cont, err := sm.GetViaURL(dnUrl) + list := models.CloudServiceEPgListFromContainer(cont) + return list, err +} + +func (sm *ServiceManager) CreateRelationcloudRsCloudEPgCtxFromCloudServiceEpg(parentDn, annotation, tnFvCtxName string) error { + dn := fmt.Sprintf("%s/rsCloudEPgCtx", parentDn) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnFvCtxName": "%s" + } + } + }`, "cloudRsCloudEPgCtx", dn, annotation, tnFvCtxName)) + + 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) DeleteRelationcloudRsCloudEPgCtxFromCloudServiceEpg(parentDn string) error { + dn := fmt.Sprintf("%s/rsCloudEPgCtx", parentDn) + return sm.DeleteByDn(dn, "cloudRsCloudEPgCtx") +} + +func (sm *ServiceManager) ReadRelationcloudRsCloudEPgCtxFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "cloudRsCloudEPgCtx") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "cloudRsCloudEPgCtx") + + if len(contList) > 0 { + paramMap := make(map[string]string) + paramMap["tnFvCtxName"] = models.G(contList[0], "tnFvCtxName") + paramMap["tDn"] = models.G(contList[0], "tDn") + return paramMap, err + } else { + return nil, err + } +} + +func (sm *ServiceManager) CreateRelationfvRsConsFromCloudServiceEpg(parentDn, annotation, prio string, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rscons-%s", parentDn, tnVzBrCPName) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnVzBrCPName": "%s" + } + } + }`, "fvRsCons", dn, annotation, tnVzBrCPName)) + + attributes := map[string]interface{}{ + "prio": prio, + } + var output map[string]interface{} + err_output := json.Unmarshal([]byte(containerJSON), &output) + if err_output != nil { + return err_output + } + for _, mo := range output { + if mo_map, ok := mo.(map[string]interface{}); ok { + for _, mo_attributes := range mo_map { + if mo_attributes_map, ok := mo_attributes.(map[string]interface{}); ok { + for key, value := range attributes { + if value != "" { + mo_attributes_map[key] = value + } + } + } + } + } + + } + input, out_err := json.Marshal(output) + if out_err != nil { + return out_err + } + jsonPayload, err := container.ParseJSON(input) + 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) DeleteRelationfvRsConsFromCloudServiceEpg(parentDn, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rscons-%s", parentDn, tnVzBrCPName) + return sm.DeleteByDn(dn, "fvRsCons") +} + +func (sm *ServiceManager) ReadRelationfvRsConsFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsCons") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsCons") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tnVzBrCPName"] = models.G(contItem, "tnVzBrCPName") + paramMap["tDn"] = models.G(contList[0], "tDn") + paramMap["prio"] = models.G(contList[0], "prio") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsConsIfFromCloudServiceEpg(parentDn, annotation, prio string, tnVzCPIfName string) error { + dn := fmt.Sprintf("%s/rsconsIf-%s", parentDn, tnVzCPIfName) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnVzCPIfName": "%s" + } + } + }`, "fvRsConsIf", dn, annotation, tnVzCPIfName)) + + attributes := map[string]interface{}{ + "prio": prio, + } + var output map[string]interface{} + err_output := json.Unmarshal([]byte(containerJSON), &output) + if err_output != nil { + return err_output + } + for _, mo := range output { + if mo_map, ok := mo.(map[string]interface{}); ok { + for _, mo_attributes := range mo_map { + if mo_attributes_map, ok := mo_attributes.(map[string]interface{}); ok { + for key, value := range attributes { + if value != "" { + mo_attributes_map[key] = value + } + } + } + } + } + + } + input, out_err := json.Marshal(output) + if out_err != nil { + return out_err + } + jsonPayload, err := container.ParseJSON(input) + 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) DeleteRelationfvRsConsIfFromCloudServiceEpg(parentDn, tnVzCPIfName string) error { + dn := fmt.Sprintf("%s/rsconsIf-%s", parentDn, tnVzCPIfName) + return sm.DeleteByDn(dn, "fvRsConsIf") +} + +func (sm *ServiceManager) ReadRelationfvRsConsIfFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsConsIf") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsConsIf") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tnVzCPIfName"] = models.G(contItem, "tnVzCPIfName") + paramMap["tDn"] = models.G(contList[0], "tDn") + paramMap["prio"] = models.G(contList[0], "prio") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsCustQosPolFromCloudServiceEpg(parentDn, annotation, tnQosCustomPolName string) error { + dn := fmt.Sprintf("%s/rscustQosPol", parentDn) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnQosCustomPolName": "%s" + } + } + }`, "fvRsCustQosPol", dn, annotation, tnQosCustomPolName)) + + 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) DeleteRelationfvRsCustQosPolFromCloudServiceEpg(parentDn string) error { + dn := fmt.Sprintf("%s/rscustQosPol", parentDn) + return sm.DeleteByDn(dn, "fvRsCustQosPol") +} + +func (sm *ServiceManager) ReadRelationfvRsCustQosPolFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsCustQosPol") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsCustQosPol") + + if len(contList) > 0 { + paramMap := make(map[string]string) + paramMap["tnQosCustomPolName"] = models.G(contList[0], "tnQosCustomPolName") + paramMap["tDn"] = models.G(contList[0], "tDn") + return paramMap, err + } else { + return nil, err + } +} + +func (sm *ServiceManager) CreateRelationfvRsGraphDefFromCloudServiceEpg(parentDn, annotation, tDn string) error { + dn := fmt.Sprintf("%s/rsgraphDef-[%s]", parentDn, tDn) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tDn": "%s" + } + } + }`, "fvRsGraphDef", 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) DeleteRelationfvRsGraphDefFromCloudServiceEpg(parentDn, tDn string) error { + dn := fmt.Sprintf("%s/rsgraphDef-[%s]", parentDn, tDn) + return sm.DeleteByDn(dn, "fvRsGraphDef") +} + +func (sm *ServiceManager) ReadRelationfvRsGraphDefFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsGraphDef") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsGraphDef") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tDn"] = models.G(contItem, "tDn") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsIntraEpgFromCloudServiceEpg(parentDn, annotation, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rsintraEpg-%s", parentDn, tnVzBrCPName) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnVzBrCPName": "%s" + } + } + }`, "fvRsIntraEpg", dn, annotation, tnVzBrCPName)) + + 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) DeleteRelationfvRsIntraEpgFromCloudServiceEpg(parentDn, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rsintraEpg-%s", parentDn, tnVzBrCPName) + return sm.DeleteByDn(dn, "fvRsIntraEpg") +} + +func (sm *ServiceManager) ReadRelationfvRsIntraEpgFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsIntraEpg") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsIntraEpg") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tnVzBrCPName"] = models.G(contItem, "tnVzBrCPName") + paramMap["tDn"] = models.G(contList[0], "tDn") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsProtByFromCloudServiceEpg(parentDn, annotation, tnVzTabooName string) error { + dn := fmt.Sprintf("%s/rsprotBy-%s", parentDn, tnVzTabooName) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnVzTabooName": "%s" + } + } + }`, "fvRsProtBy", dn, annotation, tnVzTabooName)) + + 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) DeleteRelationfvRsProtByFromCloudServiceEpg(parentDn, tnVzTabooName string) error { + dn := fmt.Sprintf("%s/rsprotBy-%s", parentDn, tnVzTabooName) + return sm.DeleteByDn(dn, "fvRsProtBy") +} + +func (sm *ServiceManager) ReadRelationfvRsProtByFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsProtBy") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsProtBy") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tnVzTabooName"] = models.G(contItem, "tnVzTabooName") + paramMap["tDn"] = models.G(contList[0], "tDn") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsProvFromCloudServiceEpg(parentDn, annotation, matchT string, prio string, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rsprov-%s", parentDn, tnVzBrCPName) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tnVzBrCPName": "%s" + } + } + }`, "fvRsProv", dn, annotation, tnVzBrCPName)) + + attributes := map[string]interface{}{ + "matchT": matchT, + "prio": prio, + } + var output map[string]interface{} + err_output := json.Unmarshal([]byte(containerJSON), &output) + if err_output != nil { + return err_output + } + for _, mo := range output { + if mo_map, ok := mo.(map[string]interface{}); ok { + for _, mo_attributes := range mo_map { + if mo_attributes_map, ok := mo_attributes.(map[string]interface{}); ok { + for key, value := range attributes { + if value != "" { + mo_attributes_map[key] = value + } + } + } + } + } + + } + input, out_err := json.Marshal(output) + if out_err != nil { + return out_err + } + jsonPayload, err := container.ParseJSON(input) + 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) DeleteRelationfvRsProvFromCloudServiceEpg(parentDn, tnVzBrCPName string) error { + dn := fmt.Sprintf("%s/rsprov-%s", parentDn, tnVzBrCPName) + return sm.DeleteByDn(dn, "fvRsProv") +} + +func (sm *ServiceManager) ReadRelationfvRsProvFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsProv") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsProv") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tnVzBrCPName"] = models.G(contItem, "tnVzBrCPName") + paramMap["tDn"] = models.G(contList[0], "tDn") + paramMap["matchT"] = models.G(contList[0], "matchT") + paramMap["prio"] = models.G(contList[0], "prio") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsProvDefFromCloudServiceEpg(parentDn, annotation, tDn string) error { + dn := fmt.Sprintf("%s/rsprovDef-[%s]", parentDn, tDn) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tDn": "%s" + } + } + }`, "fvRsProvDef", 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) DeleteRelationfvRsProvDefFromCloudServiceEpg(parentDn, tDn string) error { + dn := fmt.Sprintf("%s/rsprovDef-[%s]", parentDn, tDn) + return sm.DeleteByDn(dn, "fvRsProvDef") +} + +func (sm *ServiceManager) ReadRelationfvRsProvDefFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsProvDef") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsProvDef") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tDn"] = models.G(contItem, "tDn") + st.Add(paramMap) + } + return st, err +} + +func (sm *ServiceManager) CreateRelationfvRsSecInheritedFromCloudServiceEpg(parentDn, annotation, tDn string) error { + dn := fmt.Sprintf("%s/rssecInherited-[%s]", parentDn, tDn) + containerJSON := []byte(fmt.Sprintf(`{ + "%s": { + "attributes": { + "dn": "%s", + "annotation": "%s", + "tDn": "%s" + } + } + }`, "fvRsSecInherited", 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) DeleteRelationfvRsSecInheritedFromCloudServiceEpg(parentDn, tDn string) error { + dn := fmt.Sprintf("%s/rssecInherited-[%s]", parentDn, tDn) + return sm.DeleteByDn(dn, "fvRsSecInherited") +} + +func (sm *ServiceManager) ReadRelationfvRsSecInheritedFromCloudServiceEpg(parentDn string) (interface{}, error) { + dnUrl := fmt.Sprintf("%s/%s/%s.json", models.BaseurlStr, parentDn, "fvRsSecInherited") + cont, err := sm.GetViaURL(dnUrl) + contList := models.ListFromContainer(cont, "fvRsSecInherited") + + st := &schema.Set{ + F: schema.HashString, + } + for _, contItem := range contList { + paramMap := make(map[string]string) + paramMap["tDn"] = models.G(contItem, "tDn") + st.Add(paramMap) + } + return st, err +} diff --git a/models/cloud_private_link_label.go b/models/cloud_private_link_label.go new file mode 100644 index 0000000..645adae --- /dev/null +++ b/models/cloud_private_link_label.go @@ -0,0 +1,83 @@ +package models + +import ( + "fmt" + "strconv" + + "github.com/ciscoecosystem/aci-go-client/v2/container" +) + +const ( + RnCloudPrivateLinkLabel = "privatelinklabel-%s" + CloudPrivateLinkLabelClassName = "cloudPrivateLinkLabel" +) + +type CloudPrivateLinkLabel struct { + BaseAttributes + CloudPrivateLinkLabelAttributes +} + +type CloudPrivateLinkLabelAttributes struct { + Annotation string `json:",omitempty"` + Name string `json:",omitempty"` + NameAlias string `json:",omitempty"` +} + +func NewCloudPrivateLinkLabel(cloudPrivateLinkLabelRn, parentDn, description string, cloudPrivateLinkLabelAttr CloudPrivateLinkLabelAttributes) *CloudPrivateLinkLabel { + dn := fmt.Sprintf("%s/%s", parentDn, cloudPrivateLinkLabelRn) + return &CloudPrivateLinkLabel{ + BaseAttributes: BaseAttributes{ + DistinguishedName: dn, + Description: description, + Status: "created, modified", + ClassName: CloudPrivateLinkLabelClassName, + Rn: cloudPrivateLinkLabelRn, + }, + CloudPrivateLinkLabelAttributes: cloudPrivateLinkLabelAttr, + } +} + +func (cloudPrivateLinkLabel *CloudPrivateLinkLabel) ToMap() (map[string]string, error) { + cloudPrivateLinkLabelMap, err := cloudPrivateLinkLabel.BaseAttributes.ToMap() + if err != nil { + return nil, err + } + + A(cloudPrivateLinkLabelMap, "annotation", cloudPrivateLinkLabel.Annotation) + A(cloudPrivateLinkLabelMap, "name", cloudPrivateLinkLabel.Name) + A(cloudPrivateLinkLabelMap, "nameAlias", cloudPrivateLinkLabel.NameAlias) + return cloudPrivateLinkLabelMap, err +} + +func CloudPrivateLinkLabelFromContainerList(cont *container.Container, index int) *CloudPrivateLinkLabel { + CloudPrivateLinkLabelCont := cont.S("imdata").Index(index).S(CloudPrivateLinkLabelClassName, "attributes") + return &CloudPrivateLinkLabel{ + BaseAttributes{ + DistinguishedName: G(CloudPrivateLinkLabelCont, "dn"), + Description: G(CloudPrivateLinkLabelCont, "descr"), + Status: G(CloudPrivateLinkLabelCont, "status"), + ClassName: CloudPrivateLinkLabelClassName, + Rn: G(CloudPrivateLinkLabelCont, "rn"), + }, + CloudPrivateLinkLabelAttributes{ + Annotation: G(CloudPrivateLinkLabelCont, "annotation"), + Name: G(CloudPrivateLinkLabelCont, "name"), + NameAlias: G(CloudPrivateLinkLabelCont, "nameAlias"), + }, + } +} + +func CloudPrivateLinkLabelFromContainer(cont *container.Container) *CloudPrivateLinkLabel { + return CloudPrivateLinkLabelFromContainerList(cont, 0) +} + +func CloudPrivateLinkLabelListFromContainer(cont *container.Container) []*CloudPrivateLinkLabel { + length, _ := strconv.Atoi(G(cont, "totalCount")) + arr := make([]*CloudPrivateLinkLabel, length) + + for i := 0; i < length; i++ { + arr[i] = CloudPrivateLinkLabelFromContainerList(cont, i) + } + + return arr +} diff --git a/models/cloud_svc_epg.go b/models/cloud_svc_epg.go new file mode 100644 index 0000000..91b3a98 --- /dev/null +++ b/models/cloud_svc_epg.go @@ -0,0 +1,115 @@ +package models + +import ( + "fmt" + "strconv" + + "github.com/ciscoecosystem/aci-go-client/v2/container" +) + +const ( + RnCloudSvcEPg = "cloudsvcepg-%s" + DnCloudSvcEPg = "uni/tn-%s/cloudapp-%s/cloudsvcepg-%s" + ParentDnCloudSvcEPg = "uni/tn-%s/cloudapp-%s" + CloudSvcEPgClassName = "cloudSvcEPg" +) + +type CloudServiceEPg struct { + BaseAttributes + CloudServiceEPgAttributes +} + +type CloudServiceEPgAttributes struct { + AccessType string `json:",omitempty"` + Annotation string `json:",omitempty"` + AzPrivateEndpoint string `json:",omitempty"` + CustomSvcType string `json:",omitempty"` + DeploymentType string `json:",omitempty"` + ExceptionTag string `json:",omitempty"` + FloodOnEncap string `json:",omitempty"` + MatchT string `json:",omitempty"` + Name string `json:",omitempty"` + NameAlias string `json:",omitempty"` + PrefGrMemb string `json:",omitempty"` + Prio string `json:",omitempty"` + CloudServiceEPg_type string `json:",omitempty"` +} + +func NewCloudServiceEPg(cloudSvcEPgRn, parentDn, description string, cloudSvcEPgAttr CloudServiceEPgAttributes) *CloudServiceEPg { + dn := fmt.Sprintf("%s/%s", parentDn, cloudSvcEPgRn) + return &CloudServiceEPg{ + BaseAttributes: BaseAttributes{ + DistinguishedName: dn, + Description: description, + Status: "created, modified", + ClassName: CloudSvcEPgClassName, + Rn: cloudSvcEPgRn, + }, + CloudServiceEPgAttributes: cloudSvcEPgAttr, + } +} + +func (cloudSvcEPg *CloudServiceEPg) ToMap() (map[string]string, error) { + cloudSvcEPgMap, err := cloudSvcEPg.BaseAttributes.ToMap() + if err != nil { + return nil, err + } + + A(cloudSvcEPgMap, "accessType", cloudSvcEPg.AccessType) + A(cloudSvcEPgMap, "annotation", cloudSvcEPg.Annotation) + A(cloudSvcEPgMap, "azPrivateEndpoint", cloudSvcEPg.AzPrivateEndpoint) + A(cloudSvcEPgMap, "customSvcType", cloudSvcEPg.CustomSvcType) + A(cloudSvcEPgMap, "deploymentType", cloudSvcEPg.DeploymentType) + A(cloudSvcEPgMap, "exceptionTag", cloudSvcEPg.ExceptionTag) + A(cloudSvcEPgMap, "floodOnEncap", cloudSvcEPg.FloodOnEncap) + A(cloudSvcEPgMap, "matchT", cloudSvcEPg.MatchT) + A(cloudSvcEPgMap, "name", cloudSvcEPg.Name) + A(cloudSvcEPgMap, "nameAlias", cloudSvcEPg.NameAlias) + A(cloudSvcEPgMap, "prefGrMemb", cloudSvcEPg.PrefGrMemb) + A(cloudSvcEPgMap, "prio", cloudSvcEPg.Prio) + A(cloudSvcEPgMap, "type", cloudSvcEPg.CloudServiceEPg_type) + return cloudSvcEPgMap, err +} + +func CloudServiceEPgFromContainerList(cont *container.Container, index int) *CloudServiceEPg { + CloudServiceEPgCont := cont.S("imdata").Index(index).S(CloudSvcEPgClassName, "attributes") + return &CloudServiceEPg{ + BaseAttributes{ + DistinguishedName: G(CloudServiceEPgCont, "dn"), + Description: G(CloudServiceEPgCont, "descr"), + Status: G(CloudServiceEPgCont, "status"), + ClassName: CloudSvcEPgClassName, + Rn: G(CloudServiceEPgCont, "rn"), + }, + CloudServiceEPgAttributes{ + AccessType: G(CloudServiceEPgCont, "accessType"), + Annotation: G(CloudServiceEPgCont, "annotation"), + AzPrivateEndpoint: G(CloudServiceEPgCont, "azPrivateEndpoint"), + CustomSvcType: G(CloudServiceEPgCont, "customSvcType"), + DeploymentType: G(CloudServiceEPgCont, "deploymentType"), + ExceptionTag: G(CloudServiceEPgCont, "exceptionTag"), + FloodOnEncap: G(CloudServiceEPgCont, "floodOnEncap"), + MatchT: G(CloudServiceEPgCont, "matchT"), + Name: G(CloudServiceEPgCont, "name"), + NameAlias: G(CloudServiceEPgCont, "nameAlias"), + PrefGrMemb: G(CloudServiceEPgCont, "prefGrMemb"), + Prio: G(CloudServiceEPgCont, "prio"), + CloudServiceEPg_type: G(CloudServiceEPgCont, "type"), + }, + } +} + +func CloudServiceEPgFromContainer(cont *container.Container) *CloudServiceEPg { + return CloudServiceEPgFromContainerList(cont, 0) +} + +func CloudServiceEPgListFromContainer(cont *container.Container) []*CloudServiceEPg { + length, _ := strconv.Atoi(G(cont, "totalCount")) + arr := make([]*CloudServiceEPg, length) + + for i := 0; i < length; i++ { + arr[i] = CloudServiceEPgFromContainerList(cont, i) + } + + return arr +} diff --git a/models/cloud_svc_epselector.go b/models/cloud_svc_epselector.go new file mode 100644 index 0000000..3c5a16e --- /dev/null +++ b/models/cloud_svc_epselector.go @@ -0,0 +1,88 @@ +package models + +import ( + "fmt" + "strconv" + + "github.com/ciscoecosystem/aci-go-client/v2/container" +) + +const ( + RnCloudSvcEPSelector = "svcepselector-%s" + DnCloudSvcEPSelector = "uni/tn-%s/cloudapp-%s/cloudsvcepg-%s/svcepselector-%s" + ParentDnCloudSvcEPSelector = "uni/tn-%s/cloudapp-%s/cloudsvcepg-%s" + CloudSvcEPSelectorClassName = "cloudSvcEPSelector" +) + +type CloudServiceEndpointSelector struct { + BaseAttributes + CloudServiceEndpointSelectorAttributes +} + +type CloudServiceEndpointSelectorAttributes struct { + Annotation string `json:",omitempty"` + MatchExpression string `json:",omitempty"` + Name string `json:",omitempty"` + NameAlias string `json:",omitempty"` +} + +func NewCloudServiceEndpointSelector(cloudSvcEPSelectorRn, parentDn, description string, cloudSvcEPSelectorAttr CloudServiceEndpointSelectorAttributes) *CloudServiceEndpointSelector { + dn := fmt.Sprintf("%s/%s", parentDn, cloudSvcEPSelectorRn) + return &CloudServiceEndpointSelector{ + BaseAttributes: BaseAttributes{ + DistinguishedName: dn, + Description: description, + Status: "created, modified", + ClassName: CloudSvcEPSelectorClassName, + Rn: cloudSvcEPSelectorRn, + }, + CloudServiceEndpointSelectorAttributes: cloudSvcEPSelectorAttr, + } +} + +func (cloudSvcEPSelector *CloudServiceEndpointSelector) ToMap() (map[string]string, error) { + cloudSvcEPSelectorMap, err := cloudSvcEPSelector.BaseAttributes.ToMap() + if err != nil { + return nil, err + } + + A(cloudSvcEPSelectorMap, "annotation", cloudSvcEPSelector.Annotation) + A(cloudSvcEPSelectorMap, "matchExpression", cloudSvcEPSelector.MatchExpression) + A(cloudSvcEPSelectorMap, "name", cloudSvcEPSelector.Name) + A(cloudSvcEPSelectorMap, "nameAlias", cloudSvcEPSelector.NameAlias) + return cloudSvcEPSelectorMap, err +} + +func CloudServiceEndpointSelectorFromContainerList(cont *container.Container, index int) *CloudServiceEndpointSelector { + CloudServiceEndpointSelectorCont := cont.S("imdata").Index(index).S(CloudSvcEPSelectorClassName, "attributes") + return &CloudServiceEndpointSelector{ + BaseAttributes{ + DistinguishedName: G(CloudServiceEndpointSelectorCont, "dn"), + Description: G(CloudServiceEndpointSelectorCont, "descr"), + Status: G(CloudServiceEndpointSelectorCont, "status"), + ClassName: CloudSvcEPSelectorClassName, + Rn: G(CloudServiceEndpointSelectorCont, "rn"), + }, + CloudServiceEndpointSelectorAttributes{ + Annotation: G(CloudServiceEndpointSelectorCont, "annotation"), + MatchExpression: G(CloudServiceEndpointSelectorCont, "matchExpression"), + Name: G(CloudServiceEndpointSelectorCont, "name"), + NameAlias: G(CloudServiceEndpointSelectorCont, "nameAlias"), + }, + } +} + +func CloudServiceEndpointSelectorFromContainer(cont *container.Container) *CloudServiceEndpointSelector { + return CloudServiceEndpointSelectorFromContainerList(cont, 0) +} + +func CloudServiceEndpointSelectorListFromContainer(cont *container.Container) []*CloudServiceEndpointSelector { + length, _ := strconv.Atoi(G(cont, "totalCount")) + arr := make([]*CloudServiceEndpointSelector, length) + + for i := 0; i < length; i++ { + arr[i] = CloudServiceEndpointSelectorFromContainerList(cont, i) + } + + return arr +}