MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / runGuestsMigrate

Function runGuestsMigrate

internal/cli/guests.go:1213–1311  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

1211}
1212
1213func runGuestsMigrate(cmd *cobra.Command, args []string) error {
1214 vmid, err := parseVMID(args[0])
1215 if err != nil {
1216 return printError(err)
1217 }
1218 targetNode := args[1]
1219
1220 session, err := initCLISession(cmd)
1221 if err != nil {
1222 return printError(err)
1223 }
1224 if session == nil {
1225 return nil
1226 }
1227
1228 ctx := context.Background()
1229
1230 vm, err := session.findVM(ctx, vmid)
1231 if err != nil {
1232 return printError(err)
1233 }
1234
1235 // Validate target node exists and is online.
1236 target, err := session.findNodeByName(ctx, targetNode)
1237 if err != nil {
1238 return printError(err)
1239 }
1240 if !target.Online {
1241 return printError(fmt.Errorf("target node %q is offline", targetNode))
1242 }
1243 if target.Name == vm.Node {
1244 return printError(fmt.Errorf("guest %d is already on node %q", vmid, targetNode))
1245 }
1246
1247 forceOnline, _ := cmd.Flags().GetBool("online")
1248 forceOffline, _ := cmd.Flags().GetBool("offline")
1249
1250 if vm.Type == api.VMTypeLXC && (forceOnline || forceOffline) {
1251 return printError(fmt.Errorf("--online/--offline are not applicable to LXC containers"))
1252 }
1253 if forceOnline && forceOffline {
1254 return printError(fmt.Errorf("--online and --offline are mutually exclusive"))
1255 }
1256
1257 // Build migration options with auto mode selection.
1258 options := &api.MigrationOptions{Target: targetNode}
1259 mode := "offline"
1260 switch vm.Type {
1261 case api.VMTypeLXC:
1262 mode = "restart"
1263 case api.VMTypeQemu:
1264 online := vm.Status == api.VMStatusRunning
1265 if forceOnline {
1266 online = true
1267 }
1268 if forceOffline {
1269 online = false
1270 }

Callers

nothing calls this directly

Calls 10

parseVMIDFunction · 0.85
printErrorFunction · 0.85
initCLISessionFunction · 0.85
getNoWaitFunction · 0.85
printJSONFunction · 0.85
waitForTaskFunction · 0.85
findVMMethod · 0.80
findNodeByNameMethod · 0.80
clientForVMMethod · 0.80
MigrateVMMethod · 0.80

Tested by

no test coverage detected