Changeset 18754 in vbox for trunk/src/VBox
- Timestamp:
- Apr 6, 2009 1:18:51 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageImport.cpp
r18623 r18754 53 53 /////////////////////////////////////////////////////////////////////////////// 54 54 55 typedef std::map<Utf8Str, Utf8Str> ArgsMap; // pairs of strings like " -vmname" => "newvmname"55 typedef std::map<Utf8Str, Utf8Str> ArgsMap; // pairs of strings like "vmname" => "newvmname" 56 56 typedef std::map<uint32_t, ArgsMap> ArgsMapsMap; // map of maps, one for each virtual system, sorted by index 57 57 … … 78 78 } 79 79 80 static const RTGETOPTDEF g_aImportApplianceOptions[] = 81 { 82 { "--dry-run", 'n', RTGETOPT_REQ_NOTHING }, 83 { "-dry-run", 'n', RTGETOPT_REQ_NOTHING }, // deprecated 84 { "--dryrun", 'n', RTGETOPT_REQ_NOTHING }, 85 { "-dryrun", 'n', RTGETOPT_REQ_NOTHING }, // deprecated 86 { "--detailed-progress", 'P', RTGETOPT_REQ_NOTHING }, 87 { "-detailed-progress", 'P', RTGETOPT_REQ_NOTHING }, // deprecated 88 { "--vsys", 's', RTGETOPT_REQ_UINT32 }, 89 { "-vsys", 's', RTGETOPT_REQ_UINT32 }, // deprecated 90 { "--ostype", 'o', RTGETOPT_REQ_STRING }, 91 { "-ostype", 'o', RTGETOPT_REQ_STRING }, // deprecated 92 { "--vmname", 'V', RTGETOPT_REQ_STRING }, 93 { "-vmname", 'V', RTGETOPT_REQ_STRING }, // deprecated 94 { "--eula", 'L', RTGETOPT_REQ_STRING }, 95 { "-eula", 'L', RTGETOPT_REQ_STRING }, // deprecated 96 { "--unit", 'u', RTGETOPT_REQ_UINT32 }, 97 { "-unit", 'u', RTGETOPT_REQ_UINT32 }, // deprecated 98 { "--ignore", 'x', RTGETOPT_REQ_NOTHING }, 99 { "-ignore", 'x', RTGETOPT_REQ_NOTHING }, // deprecated 100 { "--scsitype", 'T', RTGETOPT_REQ_UINT32 }, 101 { "-scsitype", 'T', RTGETOPT_REQ_UINT32 }, // deprecated 102 { "--type", 'T', RTGETOPT_REQ_UINT32 }, // deprecated 103 { "-type", 'T', RTGETOPT_REQ_UINT32 }, // deprecated 104 }; 105 80 106 int handleImportAppliance(HandlerArg *a) 81 107 { … … 84 110 Utf8Str strOvfFilename; 85 111 bool fExecute = true; // if true, then we actually do the import 86 87 112 uint32_t ulCurVsys = (uint32_t)-1; 88 89 // for each - vsys X command, maintain a map of command line items113 uint32_t ulCurUnit = (uint32_t)-1; 114 // for each --vsys X command, maintain a map of command line items 90 115 // (we'll parse them later after interpreting the OVF, when we can 91 116 // actually check whether they make sense semantically) … … 93 118 IgnoresMapsMap mapIgnoresMapsPerVsys; 94 119 95 for (int i = 0; 96 i < a->argc; 97 ++i) 120 int c; 121 RTGETOPTUNION ValueUnion; 122 RTGETOPTSTATE GetState; 123 // start at 0 because main() has hacked both the argc and argv given to us 124 RTGetOptInit(&GetState, a->argc, a->argv, g_aImportApplianceOptions, RT_ELEMENTS(g_aImportApplianceOptions), 0, 0 /* fFlags */); 125 while ((c = RTGetOpt(&GetState, &ValueUnion))) 98 126 { 99 bool fIsIgnore = false; 100 Utf8Str strThisArg(a->argv[i]); 101 if ( (strThisArg == "--dry-run") 102 || (strThisArg == "-dry-run") 103 || (strThisArg == "-n") 104 ) 105 fExecute = false; 106 else if (strThisArg == "--detailed-progress") 107 g_fDetailedProgress = true; 108 else if (strThisArg == "-vsys") 109 { 110 if (++i < a->argc) 111 { 112 uint32_t ulVsys; 113 if (VINF_SUCCESS != (rc = Utf8Str(a->argv[i]).toInt(ulVsys))) // don't use SUCCESS() macro, fail even on warnings 114 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Argument to -vsys option must be a non-negative number."); 115 116 ulCurVsys = ulVsys; 117 } 118 else 119 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Missing argument to -vsys option."); 120 } 121 else if ( (strThisArg == "-ostype") 122 || (strThisArg == "-vmname") 123 || (strThisArg == "-memory") 124 || (strThisArg == "-eula") 125 || (fIsIgnore = (strThisArg == "-ignore")) 126 || (strThisArg.substr(0, 5) == "-type") 127 || (strThisArg.substr(0, 11) == "-controller") 128 ) 129 { 130 if (ulCurVsys == (uint32_t)-1) 131 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding -vsys argument.", strThisArg.c_str()); 132 133 if (++i < a->argc) 134 if (fIsIgnore) 127 switch (c) 128 { 129 case 'n': // --dry-run 130 fExecute = false; 131 break; 132 133 case 'P': // --detailed-progress 134 g_fDetailedProgress = true; 135 break; 136 137 case 's': // --vsys 138 ulCurVsys = ValueUnion.u32; 139 ulCurUnit = (uint32_t)-1; 140 break; 141 142 case 'o': // --ostype 143 if (ulCurVsys == (uint32_t)-1) 144 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 145 mapArgsMapsPerVsys[ulCurVsys]["ostype"] = ValueUnion.psz; 146 break; 147 148 case 'V': // --vmname 149 if (ulCurVsys == (uint32_t)-1) 150 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 151 mapArgsMapsPerVsys[ulCurVsys]["vmname"] = ValueUnion.psz; 152 break; 153 154 case 'm': // --memory 155 if (ulCurVsys == (uint32_t)-1) 156 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 157 mapArgsMapsPerVsys[ulCurVsys]["memory"] = ValueUnion.psz; 158 break; 159 160 case 'u': // --unit 161 ulCurUnit = ValueUnion.u32; 162 break; 163 164 case 'x': // --ignore 165 if (ulCurVsys == (uint32_t)-1) 166 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 167 if (ulCurUnit == (uint32_t)-1) 168 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong); 169 mapIgnoresMapsPerVsys[ulCurVsys][ulCurUnit] = true; 170 break; 171 172 case 'T': // --scsitype 173 if (ulCurVsys == (uint32_t)-1) 174 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 175 if (ulCurUnit == (uint32_t)-1) 176 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong); 177 mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("scsitype%u", ulCurUnit)] = ValueUnion.psz; 178 break; 179 180 case 'C': // --controller 181 if (ulCurVsys == (uint32_t)-1) 182 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --vsys argument.", GetState.pDef->pszLong); 183 if (ulCurUnit == (uint32_t)-1) 184 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Option \"%s\" requires preceding --unit argument.", GetState.pDef->pszLong); 185 mapArgsMapsPerVsys[ulCurVsys][Utf8StrFmt("controller%u", ulCurUnit)] = ValueUnion.psz; 186 break; 187 188 case VINF_GETOPT_NOT_OPTION: 189 if (!strOvfFilename) 190 strOvfFilename = ValueUnion.psz; 191 else 192 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid parameter '%s'", ValueUnion.psz); 193 break; 194 195 default: 196 if (c > 0) 135 197 { 136 uint32_t ulItem; 137 if (VINF_SUCCESS != Utf8Str(a->argv[i]).toInt(ulItem)) 138 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Argument to -vsys option must be a non-negative number."); 139 140 mapIgnoresMapsPerVsys[ulCurVsys][ulItem] = true; 198 if (RT_C_IS_PRINT(c)) 199 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid option -%c", c); 200 else 201 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Invalid option case %i", c); 141 202 } 203 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 204 return errorSyntax(USAGE_IMPORTAPPLIANCE, "unknown option: %s\n", ValueUnion.psz); 205 else if (ValueUnion.pDef) 206 return errorSyntax(USAGE_IMPORTAPPLIANCE, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 142 207 else 143 { 144 // store both this arg and the next one in the strings map for later parsing 145 mapArgsMapsPerVsys[ulCurVsys][strThisArg] = Utf8Str(a->argv[i]); 146 } 147 else 148 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Missing argument to \"%s\" option.", strThisArg.c_str()); 149 } 150 else if (strThisArg[0] == '-') 151 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Unknown option \"%s\".", strThisArg.c_str()); 152 else if (!strOvfFilename) 153 strOvfFilename = strThisArg; 154 else 155 return errorSyntax(USAGE_IMPORTAPPLIANCE, "Too many arguments for \"import\" command."); 208 return errorSyntax(USAGE_IMPORTAPPLIANCE, "error: %Rrs", c); 209 } 156 210 } 157 211 … … 245 299 ComSafeArrayAsOutParam(aExtraConfigValues))); 246 300 247 RTPrintf("Virtual system % i:\n", i);301 RTPrintf("Virtual system %u:\n", i); 248 302 249 303 // look up the corresponding command line options, if any … … 272 326 { 273 327 case VirtualSystemDescriptionType_Name: 274 if (findArgValue(strOverride, pmapArgs, " -vmname"))328 if (findArgValue(strOverride, pmapArgs, "vmname")) 275 329 { 276 330 bstrFinalValue = strOverride; 277 RTPrintf("%2 d: VM name specified with-vmname: \"%ls\"\n",331 RTPrintf("%2u: VM name specified with --vmname: \"%ls\"\n", 278 332 a, bstrFinalValue.raw()); 279 333 } 280 334 else 281 RTPrintf("%2 d: Suggested VM name \"%ls\""282 "\n (change with \"- vsys %d-vmname <name>\")\n",335 RTPrintf("%2u: Suggested VM name \"%ls\"" 336 "\n (change with \"--vsys %u --vmname <name>\")\n", 283 337 a, bstrFinalValue.raw(), i); 284 338 break; 285 339 286 340 case VirtualSystemDescriptionType_OS: 287 if (findArgValue(strOverride, pmapArgs, " -ostype"))341 if (findArgValue(strOverride, pmapArgs, "ostype")) 288 342 { 289 343 bstrFinalValue = strOverride; 290 RTPrintf("%2 d: OS type specified with-ostype: \"%ls\"\n",344 RTPrintf("%2u: OS type specified with --ostype: \"%ls\"\n", 291 345 a, bstrFinalValue.raw()); 292 346 } 293 347 else 294 RTPrintf("%2 d: Suggested OS type: \"%ls\""295 "\n (change with \"- vsys %d-ostype <type>\"; use \"list ostypes\" to list all)\n",348 RTPrintf("%2u: Suggested OS type: \"%ls\"" 349 "\n (change with \"--vsys %u --ostype <type>\"; use \"list ostypes\" to list all)\n", 296 350 a, bstrFinalValue.raw(), i); 297 351 break; 298 352 299 353 case VirtualSystemDescriptionType_Description: 300 RTPrintf("%2 d: Description: \"%ls\"\n",354 RTPrintf("%2u: Description: \"%ls\"\n", 301 355 a, bstrFinalValue.raw()); 302 356 break; … … 304 358 case VirtualSystemDescriptionType_License: 305 359 ++cLicensesInTheWay; 306 if (findArgValue(strOverride, pmapArgs, " -eula"))360 if (findArgValue(strOverride, pmapArgs, "eula")) 307 361 { 308 362 if (strOverride == "show") 309 363 { 310 RTPrintf("%2 d: End-user license agreement"311 "\n (accept with \"- vsys %d-eula accept\"):"364 RTPrintf("%2u: End-user license agreement" 365 "\n (accept with \"--vsys %u --eula accept\"):" 312 366 "\n\n%ls\n\n", 313 367 a, i, bstrFinalValue.raw()); … … 315 369 else if (strOverride == "accept") 316 370 { 317 RTPrintf("%2 d: End-user license agreement (accepted)\n",371 RTPrintf("%2u: End-user license agreement (accepted)\n", 318 372 a); 319 373 --cLicensesInTheWay; … … 321 375 else 322 376 return errorSyntax(USAGE_IMPORTAPPLIANCE, 323 "Argument to - eula must be either \"show\" or \"accept\".");324 } 325 else 326 RTPrintf("%2 d: End-user license agreement"327 "\n (display with \"- vsys %d-eula show\";"328 "\n accept with \"- vsys %d-eula accept\")\n",377 "Argument to --eula must be either \"show\" or \"accept\"."); 378 } 379 else 380 RTPrintf("%2u: End-user license agreement" 381 "\n (display with \"--vsys %u -eula show\";" 382 "\n accept with \"--vsys %u -eula accept\")\n", 329 383 a, i, i); 330 384 break; 331 385 332 386 case VirtualSystemDescriptionType_CPU: 333 RTPrintf("%2 d: Number of CPUs (ignored): %ls\n",387 RTPrintf("%2u: Number of CPUs (ignored): %ls\n", 334 388 a, aVboxValues[a]); 335 389 break; … … 337 391 case VirtualSystemDescriptionType_Memory: 338 392 { 339 if (findArgValue(strOverride, pmapArgs, " -memory"))393 if (findArgValue(strOverride, pmapArgs, "memory")) 340 394 { 341 395 uint32_t ulMemMB; … … 343 397 { 344 398 bstrFinalValue = strOverride; 345 RTPrintf("%2 d: Guest memory specified with-memory: %ls MB\n",399 RTPrintf("%2u: Guest memory specified with --memory: %ls MB\n", 346 400 a, bstrFinalValue.raw()); 347 401 } 348 402 else 349 403 return errorSyntax(USAGE_IMPORTAPPLIANCE, 350 "Argument to - memory option must be a non-negative number.");351 } 352 else 353 RTPrintf("%2 d: Guest memory: %ls MB\n (change with \"-vsys %d-memory <MB>\")\n",404 "Argument to --memory option must be a non-negative number."); 405 } 406 else 407 RTPrintf("%2u: Guest memory: %ls MB\n (change with \"--vsys %u --memory <MB>\")\n", 354 408 a, bstrFinalValue.raw(), i); 355 409 } … … 359 413 if (fIgnoreThis) 360 414 { 361 RTPrintf("%2 d: IDE controller, type %ls -- disabled\n",415 RTPrintf("%2u: IDE controller, type %ls -- disabled\n", 362 416 a, 363 417 aVboxValues[a]); … … 365 419 } 366 420 else 367 RTPrintf("%2 d: IDE controller, type %ls"368 "\n (disable with \"- vsys %d -ignore %d\")\n",421 RTPrintf("%2u: IDE controller, type %ls" 422 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 369 423 a, 370 424 aVboxValues[a], … … 375 429 if (fIgnoreThis) 376 430 { 377 RTPrintf("%2 d: SATA controller, type %ls -- disabled\n",431 RTPrintf("%2u: SATA controller, type %ls -- disabled\n", 378 432 a, 379 433 aVboxValues[a]); … … 381 435 } 382 436 else 383 RTPrintf("%2 d: SATA controller, type %ls"384 "\n (disable with \"- vsys %d -ignore %d\")\n",437 RTPrintf("%2u: SATA controller, type %ls" 438 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 385 439 a, 386 440 aVboxValues[a], … … 391 445 if (fIgnoreThis) 392 446 { 393 RTPrintf("%2 d: SCSI controller, type %ls -- disabled\n",447 RTPrintf("%2u: SCSI controller, type %ls -- disabled\n", 394 448 a, 395 449 aVboxValues[a]); … … 398 452 else 399 453 { 400 Utf8StrFmt strTypeArg(" -type%RI16", a);454 Utf8StrFmt strTypeArg("scsitype%u", a); 401 455 if (findArgValue(strOverride, pmapArgs, strTypeArg)) 402 456 { 403 457 bstrFinalValue = strOverride; 404 RTPrintf("%2 d: SCSI controller, type set with -type%d: %ls\n",458 RTPrintf("%2u: SCSI controller, type set with --unit %u --scsitype: \"%ls\"\n", 405 459 a, 406 460 a, … … 408 462 } 409 463 else 410 RTPrintf("%2 d: SCSI controller, type %ls"411 "\n (change with \"- vsys %d -type%d{BusLogic|LsiLogic}\";"412 "\n disable with \"- vsys %d -ignore %d\")\n",464 RTPrintf("%2u: SCSI controller, type %ls" 465 "\n (change with \"--vsys %u --unit %u --scsitype {BusLogic|LsiLogic}\";" 466 "\n disable with \"--vsys %u --unit %u --ignore\")\n", 413 467 a, 414 468 aVboxValues[a], … … 420 474 if (fIgnoreThis) 421 475 { 422 RTPrintf("%2 d: Hard disk image: source image=%ls -- disabled\n",476 RTPrintf("%2u: Hard disk image: source image=%ls -- disabled\n", 423 477 a, 424 478 aOvfValues[a]); … … 427 481 else 428 482 { 429 Utf8StrFmt strTypeArg(" -controller%RI16", a);483 Utf8StrFmt strTypeArg("controller%u", a); 430 484 if (findArgValue(strOverride, pmapArgs, strTypeArg)) 431 485 { … … 435 489 Bstr bstrExtraConfigValue = strOverride; 436 490 bstrExtraConfigValue.detachTo(&aExtraConfigValues[a]); 437 RTPrintf("%2 d: Hard disk image: source image=%ls, target path=%ls, %ls\n",491 RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls\n", 438 492 a, 439 493 aOvfValues[a], … … 442 496 } 443 497 else 444 RTPrintf("%2 d: Hard disk image: source image=%ls, target path=%ls, %ls"445 "\n (change controller with \"- vsys %d -controller%d<id>\";"446 "\n disable with \"- vsys %d -ignore %d\")\n",498 RTPrintf("%2u: Hard disk image: source image=%ls, target path=%ls, %ls" 499 "\n (change controller with \"--vsys %u --unit %u --controller <id>\";" 500 "\n disable with \"--vsys %u --unit %u --ignore\")\n", 447 501 a, 448 502 aOvfValues[a], … … 456 510 if (fIgnoreThis) 457 511 { 458 RTPrintf("%2 d: CD-ROM -- disabled\n",512 RTPrintf("%2u: CD-ROM -- disabled\n", 459 513 a); 460 514 aEnabled[a] = false; 461 515 } 462 516 else 463 RTPrintf("%2 d: CD-ROM"464 "\n (disable with \"- vsys %d -ignore %d\")\n",517 RTPrintf("%2u: CD-ROM" 518 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 465 519 a, i, a); 466 520 break; … … 469 523 if (fIgnoreThis) 470 524 { 471 RTPrintf("%2 d: Floppy -- disabled\n",525 RTPrintf("%2u: Floppy -- disabled\n", 472 526 a); 473 527 aEnabled[a] = false; 474 528 } 475 529 else 476 RTPrintf("%2 d: Floppy"477 "\n (disable with \"- vsys %d -ignore %d\")\n",530 RTPrintf("%2u: Floppy" 531 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 478 532 a, i, a); 479 533 break; 480 534 481 535 case VirtualSystemDescriptionType_NetworkAdapter: 482 RTPrintf("%2 d: Network adapter: orig %ls, config %ls, extra %ls\n", // @todo implement once we have a plan for the back-end536 RTPrintf("%2u: Network adapter: orig %ls, config %ls, extra %ls\n", // @todo implement once we have a plan for the back-end 483 537 a, 484 538 aOvfValues[a], … … 490 544 if (fIgnoreThis) 491 545 { 492 RTPrintf("%2 d: USB controller -- disabled\n",546 RTPrintf("%2u: USB controller -- disabled\n", 493 547 a); 494 548 aEnabled[a] = false; 495 549 } 496 550 else 497 RTPrintf("%2 d: USB controller"498 "\n (disable with \"- vsys %d -ignore %d\")\n",551 RTPrintf("%2u: USB controller" 552 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 499 553 a, i, a); 500 554 break; … … 503 557 if (fIgnoreThis) 504 558 { 505 RTPrintf("%2 d: Sound card \"%ls\" -- disabled\n",559 RTPrintf("%2u: Sound card \"%ls\" -- disabled\n", 506 560 a, 507 561 aOvfValues[a]); … … 509 563 } 510 564 else 511 RTPrintf("%2 d: Sound card (appliance expects \"%ls\", can change on import)"512 "\n (disable with \"- vsys %d -ignore %d\")\n",565 RTPrintf("%2u: Sound card (appliance expects \"%ls\", can change on import)" 566 "\n (disable with \"--vsys %u --unit %u --ignore\")\n", 513 567 a, 514 568 aOvfValues[a],
Note:
See TracChangeset
for help on using the changeset viewer.