Changeset 91171 in vbox
- Timestamp:
- Sep 9, 2021 1:17:57 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp
r91163 r91171 43 43 static HRESULT getMachineById(ComPtr<ICloudMachine> &pMachineOut, 44 44 const ComPtr<ICloudClient> &pClient, 45 const char *pcszStrId); 45 const char *pcszId); 46 static HRESULT getMachineByName(ComPtr<ICloudMachine> &pMachineOut, 47 const ComPtr<ICloudClient> &pClient, 48 const char *pcszName); 49 static HRESULT getMachine(ComPtr<ICloudMachine> &pMachineOut, 50 const ComPtr<ICloudClient> &pClient, 51 const char *pcszWhatever); 46 52 47 53 … … 278 284 getMachineById(ComPtr<ICloudMachine> &pMachineOut, 279 285 const ComPtr<ICloudClient> &pClient, 280 const char *pcsz StrId)286 const char *pcszId) 281 287 { 282 288 HRESULT hrc; … … 284 290 ComPtr<ICloudMachine> pMachine; 285 291 CHECK_ERROR2_RET(hrc, pClient, 286 GetCloudMachine(com::Bstr(pcsz StrId).raw(),292 GetCloudMachine(com::Bstr(pcszId).raw(), 287 293 pMachine.asOutParam()), hrc); 288 294 … … 298 304 return S_OK; 299 305 } 306 307 308 static HRESULT 309 getMachineByName(ComPtr<ICloudMachine> &pMachineOut, 310 const ComPtr<ICloudClient> &pClient, 311 const char *pcszName) 312 { 313 HRESULT hrc; 314 315 com::SafeIfaceArray<ICloudMachine> aMachines; 316 hrc = getMachineList(aMachines, pClient); 317 if (FAILED(hrc)) 318 return hrc; 319 320 const size_t cMachines = aMachines.size(); 321 if (cMachines == 0) 322 return VBOX_E_OBJECT_NOT_FOUND; 323 324 ComPtr<ICloudMachine> pMachineFound; 325 for (size_t i = 0; i < cMachines; ++i) 326 { 327 const ComPtr<ICloudMachine> pMachine = aMachines[i]; 328 329 com::Bstr bstrName; 330 CHECK_ERROR2_RET(hrc, pMachine, 331 COMGETTER(Name)(bstrName.asOutParam()), 332 hrc); 333 334 if (!bstrName.equals(pcszName)) 335 continue; 336 337 if (pMachineFound.isNull()) 338 { 339 pMachineFound = pMachine; 340 } 341 else 342 { 343 com::Bstr bstrId1, bstrId2; 344 CHECK_ERROR2_RET(hrc, pMachineFound, 345 COMGETTER(Id)(bstrId1.asOutParam()), 346 hrc); 347 CHECK_ERROR2_RET(hrc, pMachine, 348 COMGETTER(Id)(bstrId2.asOutParam()), 349 hrc); 350 351 RTMsgError("ambiguous name: %ls and %ls", bstrId1, bstrId2); 352 return VBOX_E_OBJECT_NOT_FOUND; 353 } 354 } 355 356 if (pMachineFound.isNull()) 357 return VBOX_E_OBJECT_NOT_FOUND; 358 359 pMachineOut = pMachineFound; 360 return S_OK; 361 } 362 363 364 /* 365 * Try to find the machine refered by pcszWhatever. If the look up by 366 * id fails we might want to fallback to look up by name, b/c someone 367 * might want to use a uuid as a display name of a machine. But cloud 368 * lookups are not fast, so that would be incurring performance 369 * penalty for typos or for machines that are gone. Should provide 370 * explicit --id/--name options instead. 371 */ 372 static HRESULT 373 getMachine(ComPtr<ICloudMachine> &pMachineOut, 374 const ComPtr<ICloudClient> &pClient, 375 const char *pcszWhatever) 376 { 377 ComPtr<ICloudMachine> pMachine; 378 379 HRESULT hrc; 380 381 RTUUID Uuid; 382 int rc = RTUuidFromStr(&Uuid, pcszWhatever); 383 if (RT_SUCCESS(rc)) 384 hrc = getMachineById(pMachine, pClient, pcszWhatever); 385 else 386 hrc = getMachineByName(pMachine, pClient, pcszWhatever); 387 388 if (FAILED(hrc)) 389 return hrc; 390 391 pMachineOut = pMachine; 392 return S_OK; 393 } 394 300 395 301 396 … … 603 698 { 604 699 ComPtr<ICloudMachine> pMachine; 605 hrc = getMachineById(pMachine, pClient, a->argv[i]); 606 if (FAILED(hrc)) 700 hrc = getMachine(pMachine, pClient, a->argv[i]); 701 if (hrc == VBOX_E_OBJECT_NOT_FOUND) 702 return RTMsgErrorExit(RTEXITCODE_FAILURE, 703 "%s: not found", a->argv[i]); 704 else if (FAILED(hrc)) 607 705 return RTEXITCODE_FAILURE; 608 706 … … 871 969 872 970 ComPtr<ICloudMachine> pMachine; 873 hrc = getMachine ById(pMachine, pClient, a->argv[iFirst]);971 hrc = getMachine(pMachine, pClient, a->argv[iFirst]); 874 972 if (FAILED(hrc)) 875 973 return RTEXITCODE_FAILURE;
Note:
See TracChangeset
for help on using the changeset viewer.

