@@ -195,16 +195,22 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
195
195
}
196
196
197
197
// Find the component with type "SERVER"
198
- var clonedComponent map [string ]interface {}
198
+ var serverComponent map [string ]interface {}
199
199
200
200
for _ , comp := range components {
201
201
comp := comp .(map [string ]interface {})
202
202
if comp ["type" ].(string ) == "SERVER" {
203
- clonedComponent = comp
203
+ serverComponent = comp
204
204
break
205
205
}
206
206
}
207
207
208
+ // Deep copy the component
209
+ clonedComponent := make (map [string ]interface {})
210
+ for key , value := range serverComponent {
211
+ clonedComponent [key ] = value
212
+ }
213
+
208
214
// Modify ID and GUID of the cloned component
209
215
clonedComponent ["id" ] = uuid
210
216
clonedComponent ["name" ] = uuid
@@ -216,12 +222,24 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
216
222
clonedComponent ["osPuppetCertName" ] = nil
217
223
clonedComponent ["managementIpAddress" ] = nil
218
224
225
+ // Deep copy resources
219
226
resources , ok := clonedComponent ["resources" ].([]interface {})
220
227
if ! ok {
221
- fmt .Println ("Error: components field not found or not a []interface{}" )
228
+ fmt .Println ("Error: resources field not found or not a []interface{}" )
222
229
return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
223
230
}
224
231
232
+ clonedResources := make ([]interface {}, len (resources ))
233
+ for i , res := range resources {
234
+ resCopy := make (map [string ]interface {})
235
+ for k , v := range res .(map [string ]interface {}) {
236
+ resCopy [k ] = v
237
+ }
238
+ clonedResources [i ] = resCopy
239
+ }
240
+ clonedComponent ["resources" ] = clonedResources
241
+
242
+ // Exclude list of parameters to skip
225
243
excludeList := map [string ]bool {
226
244
"razor_image" : true ,
227
245
"scaleio_enabled" : true ,
@@ -230,36 +248,62 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
230
248
"replication_enabled" : true ,
231
249
}
232
250
233
- for _ , comp := range resources {
251
+ // Iterate over resources to modify parameters
252
+ for _ , comp := range clonedResources {
234
253
comp := comp .(map [string ]interface {})
235
254
if comp ["id" ].(string ) == "asm::server" {
236
255
256
+ comp ["guid" ] = nil
257
+
237
258
parameters , ok := comp ["parameters" ].([]interface {})
238
259
if ! ok {
239
260
fmt .Println ("Error: components field not found or not a []interface{}" )
240
261
return nil , fmt .Errorf ("Error While Parsing Response Data For Deployment: %s" , ok )
241
262
}
242
263
243
- for _ , parameter := range parameters {
264
+ clonedParams := make ([]interface {}, len (parameters ))
265
+ for i , param := range parameters {
266
+ paramCopy := make (map [string ]interface {})
267
+ for k , v := range param .(map [string ]interface {}) {
268
+ paramCopy [k ] = v
269
+ }
270
+ clonedParams [i ] = paramCopy
271
+ }
272
+
273
+ for _ , parameter := range clonedParams {
244
274
parameter := parameter .(map [string ]interface {})
245
275
if ! excludeList [parameter ["id" ].(string )] {
246
- parameter ["guid" ] = nil
247
- parameter ["value" ] = nil
276
+
277
+ if parameter ["id" ].(string ) == "scaleio_mdm_role" {
278
+ parameter ["guid" ] = nil
279
+ parameter ["value" ] = "standby_mdm"
280
+ } else {
281
+ parameter ["guid" ] = nil
282
+ parameter ["value" ] = nil
283
+ }
284
+
248
285
}
249
286
}
287
+
288
+ // Update parameters in the component
289
+ comp ["parameters" ] = clonedParams
250
290
}
251
291
}
252
292
253
- clonedComponent ["resources" ] = resources
254
-
255
293
// Append the cloned component back to the components array
256
294
components = append (components , clonedComponent )
257
295
296
+ // Update serviceTemplate with modified components
258
297
serviceTemplate ["components" ] = components
259
298
299
+ // Update deploymentData with modified serviceTemplate
300
+ deploymentData ["serviceTemplate" ] = serviceTemplate
301
+
302
+ // Update other fields as needed
260
303
deploymentData ["scaleUp" ] = true
261
304
deploymentData ["retry" ] = true
262
305
306
+ // Marshal deploymentData to JSON
263
307
deploymentPayloadJson , _ = json .Marshal (deploymentData )
264
308
265
309
} else {
@@ -276,6 +320,10 @@ func (gc *GatewayClient) UpdateService(deploymentID, deploymentName, deploymentD
276
320
deploymentPayloadJson , _ = json .Marshal (deploymentResponse )
277
321
}
278
322
323
+ fmt .Println ("==================================" )
324
+
325
+ fmt .Println (string (deploymentPayloadJson ))
326
+
279
327
req , httpError := http .NewRequest ("PUT" , gc .host + "/Api/V1/Deployment/" + deploymentID , bytes .NewBuffer (deploymentPayloadJson ))
280
328
if httpError != nil {
281
329
return nil , httpError
0 commit comments