Skip to content

Commit

Permalink
[bugfix] Add condition to associate cloudRsZoneAttach child when zone…
Browse files Browse the repository at this point in the history
…Dn is defined (#239)
  • Loading branch information
shrsr authored Oct 19, 2022
1 parent 7f1b400 commit 11f9110
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions client/cloudSubnet_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package client

import (
"fmt"
"log"

"github.com/ciscoecosystem/aci-go-client/container"
"github.com/ciscoecosystem/aci-go-client/models"
Expand All @@ -15,26 +14,26 @@ func (sm *ServiceManager) CreateCloudSubnet(ip string, cloud_cidr_pool_dn string
cloudSubnet := models.NewCloudSubnet(rn, parentDn, description, cloudSubnetattr)
jsonPayload, _, err := sm.PrepareModel(cloudSubnet)

rsZoneAttachJSON := []byte(fmt.Sprintf(`
{
"cloudRsZoneAttach": {
"attributes": {
"annotation": "orchestrator:terraform",
"dn": "%s/%s/rszoneAttach",
"tDn": "%s"
if zoneDn != "" {
rsZoneAttachJSON := []byte(fmt.Sprintf(`
{
"cloudRsZoneAttach": {
"attributes": {
"annotation": "orchestrator:terraform",
"dn": "%s/%s/rszoneAttach",
"tDn": "%s"
}
}
}
}
`, parentDn, rn, zoneDn))
zoneCon, err := container.ParseJSON(rsZoneAttachJSON)
if err != nil {
return nil, err
}
`, parentDn, rn, zoneDn))
zoneCon, err := container.ParseJSON(rsZoneAttachJSON)
if err != nil {
return nil, err
}

log.Printf("\n[DEBUG]asas %v", zoneCon.Data())
jsonPayload.Array(cloudSubnet.ClassName, "children")
jsonPayload.ArrayAppend(zoneCon.Data(), cloudSubnet.ClassName, "children")
log.Printf("\n\n[DEBUG]asas %s\n\n", jsonPayload.String())
jsonPayload.Array(cloudSubnet.ClassName, "children")
jsonPayload.ArrayAppend(zoneCon.Data(), cloudSubnet.ClassName, "children")
}
jsonPayload.Set(ip, cloudSubnet.ClassName, "attributes", "ip")

req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("/api/node/mo/%s/%s.json", parentDn, rn), jsonPayload, true)
Expand Down Expand Up @@ -90,10 +89,8 @@ func (sm *ServiceManager) UpdateCloudSubnet(ip string, cloud_cidr_pool_dn string
return nil, err
}

log.Printf("\n[DEBUG]asas %v", zoneCon.Data())
jsonPayload.Array(cloudSubnet.ClassName, "children")
jsonPayload.ArrayAppend(zoneCon.Data(), cloudSubnet.ClassName, "children")
log.Printf("\n\n[DEBUG]asas %s\n\n", jsonPayload.String())
jsonPayload.Set(ip, cloudSubnet.ClassName, "attributes", "ip")

req, err := sm.client.MakeRestRequest("POST", fmt.Sprintf("/api/node/mo/%s/%s.json", parentDn, rn), jsonPayload, true)
Expand Down

0 comments on commit 11f9110

Please sign in to comment.