MCPcopy Create free account
hub / github.com/deepflowio/deepflow / updateAgent

Function updateAgent

cli/ctl/agent.go:301–402  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, updateFilename string)

Source from the content-addressed store, hash-verified

299}
300
301func updateAgent(cmd *cobra.Command, args []string, updateFilename string) {
302 yamlFile, err := os.ReadFile(updateFilename)
303 if err != nil {
304 fmt.Fprintln(os.Stderr, err)
305 return
306 }
307
308 updateMap := make(map[string]interface{})
309 err = yaml.Unmarshal(yamlFile, &updateMap)
310 if err != nil {
311 fmt.Fprintln(os.Stderr, err)
312 return
313 }
314
315 vtapName, ok := updateMap["name"]
316 if !ok {
317 fmt.Fprintln(os.Stderr, "must specify agent name")
318 return
319 }
320
321 server := common.GetServerInfo(cmd)
322 url := fmt.Sprintf("http://%s:%d/v1/vtaps/?name=%s", server.IP, server.Port, vtapName)
323 // call vtap api, get lcuuid
324 response, err := common.CURLPerform("GET", url, nil, "",
325 []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...)
326 if err != nil {
327 fmt.Fprintln(os.Stderr, err)
328 return
329 }
330
331 if len(response.Get("DATA").MustArray()) == 0 {
332 fmt.Fprintln(os.Stderr, "agent (%s) not exist\n")
333 }
334 vtap := response.Get("DATA").GetIndex(0)
335 lcuuid := vtap.Get("LCUUID").MustString()
336
337 // modify tap_mode
338 if tapMode, ok := updateMap["tap_mode"]; ok {
339 url = fmt.Sprintf("http://%s:%d/v1/vtaps-tap-mode/", server.IP, server.Port)
340 updateBody := make(map[string]interface{})
341 updateBody["VTAP_LCUUIDS"] = []string{lcuuid}
342 updateBody["TAP_MODE"] = common.GetVtapTapModeByName(tapMode.(string))
343
344 updateJson, _ := json.Marshal(updateBody)
345 _, err := common.CURLPerform("PATCH", url, nil, string(updateJson),
346 []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...)
347 if err != nil {
348 fmt.Fprintln(os.Stderr, err)
349 return
350 }
351 delete(updateMap, "tap_mode")
352 }
353
354 // return if only update tap_mode
355 if len(updateMap) == 0 {
356 return
357 }
358

Callers 1

RegisterAgentCommandFunction · 0.85

Calls 4

UnmarshalMethod · 0.65
GetMethod · 0.65
GetORGIDMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected