(cmd *cobra.Command, args []string)
| 414 | var imageName string |
| 415 | |
| 416 | func upgadeAgent(cmd *cobra.Command, args []string) { |
| 417 | if len(args) == 0 { |
| 418 | fmt.Fprintf(os.Stderr, "must specify name and package. Examples: \n%s", cmd.Example) |
| 419 | return |
| 420 | } |
| 421 | vtapName := args[0] |
| 422 | |
| 423 | server := common.GetServerInfo(cmd) |
| 424 | serverURL := fmt.Sprintf("http://%s:%d/v1/controllers/", server.IP, server.Port) |
| 425 | response, err := common.CURLPerform("GET", serverURL, nil, "", |
| 426 | []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...) |
| 427 | if err != nil { |
| 428 | fmt.Fprintln(os.Stderr, err) |
| 429 | return |
| 430 | } |
| 431 | hosts := map[string]struct{}{ |
| 432 | server.IP: struct{}{}, |
| 433 | } |
| 434 | controllerArray := response.Get("DATA").MustArray() |
| 435 | if len(controllerArray) == 0 { |
| 436 | fmt.Printf("get controller info failed, url: %s\n", serverURL) |
| 437 | return |
| 438 | } |
| 439 | for index := range controllerArray { |
| 440 | controller := response.Get("DATA").GetIndex(index) |
| 441 | ip := controller.Get("IP").MustString() |
| 442 | if controller.Get("NODE_TYPE").MustInt() != 1 || ip == "" { |
| 443 | continue |
| 444 | } |
| 445 | hosts[ip] = struct{}{} |
| 446 | } |
| 447 | |
| 448 | vtapURL := fmt.Sprintf("http://%s:%d/v1/vtaps/?name=%s", server.IP, server.Port, vtapName) |
| 449 | response, err = common.CURLPerform("GET", vtapURL, nil, "", |
| 450 | []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...) |
| 451 | if err != nil { |
| 452 | fmt.Fprintln(os.Stderr, err) |
| 453 | return |
| 454 | } |
| 455 | |
| 456 | if len(response.Get("DATA").MustArray()) == 0 { |
| 457 | fmt.Printf("get agent (%s) info failed, url: %s\n", vtapName, vtapURL) |
| 458 | return |
| 459 | } |
| 460 | vtapLcuuid := response.Get("DATA").GetIndex(0).Get("LCUUID").MustString() |
| 461 | vtapController := response.Get("DATA").GetIndex(0).Get("CONTROLLER_IP").MustString() |
| 462 | if vtapController == "" || vtapLcuuid == "" { |
| 463 | fmt.Printf("get agent(%s) controller ip failed, url: %s\n", vtapName, vtapURL) |
| 464 | return |
| 465 | } |
| 466 | hosts[vtapController] = struct{}{} |
| 467 | vtapCurrentController := response.Get("DATA").GetIndex(0).Get("CUR_CONTROLLER_IP").MustString() |
| 468 | if vtapCurrentController != "" { |
| 469 | hosts[vtapCurrentController] = struct{}{} |
| 470 | } |
| 471 | url_format := "http://%s:%d/v1/upgrade/vtap/%s/" |
| 472 | body := map[string]interface{}{ |
| 473 | "image_name": imageName, |
no test coverage detected