VirtualBox

Changeset 91319 in vbox


Ignore:
Timestamp:
Sep 20, 2021 6:07:20 PM (3 years ago)
Author:
vboxsync
Message:

VBoxManageCloudMachine: cloud machine start and shutdown, but
primarily more refactoring of the argument parsing code to avoid
copy-pasting boilerplate. bugref:10065.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloudMachine.cpp

    r91188 r91319  
    7070                                         const ComPtr<ICloudClient> &pClient);
    7171
     72static RTEXITCODE handleCloudMachineStart(HandlerArg *a, int iFirst,
     73                                          const ComPtr<ICloudClient> &pClient);
     74static RTEXITCODE handleCloudMachineShutdown(HandlerArg *a, int iFirst,
     75                                             const ComPtr<ICloudClient> &pClient);
     76
    7277static RTEXITCODE handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
    7378                                                   const ComPtr<ICloudClient> &pClient);
     79
    7480static RTEXITCODE listCloudMachinesImpl(HandlerArg *a, int iFirst,
    7581                                        const ComPtr<ICloudClient> &pClient);
     
    607613        kMachine_Info,
    608614        kMachine_List,
     615        kMachine_Shutdown,
     616        kMachine_Start,
    609617    };
    610618
     
    616624        { "info",               kMachine_Info,              RTGETOPT_REQ_NOTHING },
    617625        { "list",               kMachine_List,              RTGETOPT_REQ_NOTHING },
     626        { "shutdown",           kMachine_Shutdown,          RTGETOPT_REQ_NOTHING },
     627        { "start",              kMachine_Start,             RTGETOPT_REQ_NOTHING },
    618628        CLOUD_MACHINE_RTGETOPTDEF_HELP
    619629    };
     
    640650            case kMachine_List:
    641651                return listCloudMachinesImpl(a, OptState.iNext, pClient);
     652
     653            case kMachine_Shutdown:
     654                return handleCloudMachineShutdown(a, OptState.iNext, pClient);
     655
     656            case kMachine_Start:
     657                return handleCloudMachineStart(a, OptState.iNext, pClient);
    642658
    643659
     
    909925        return RTEXITCODE_FAILURE;
    910926
     927    /* end of boilerplate */
     928
    911929
    912930    hrc = printMachineInfo(pMachine);
     
    11481166
    11491167/*
    1150  * cloud machine console-history "id"
     1168 * Boilerplate code to get machine by name/id from the arguments.
     1169 * Shared by action subcommands b/c they currently don't have any
     1170 * extra options (but we can't use this for e.g. "info" that has
     1171 * --details).
    11511172 */
    11521173static RTEXITCODE
    1153 handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
    1154                                  const ComPtr<ICloudClient> &pClient)
     1174getMachineFromArgs(ComPtr<ICloudMachine> &pMachine,
     1175                   uint64_t fCurSubcommandScope,
     1176                   HandlerArg *a, int iFirst,
     1177                   const ComPtr<ICloudClient> &pClient)
    11551178{
    11561179    MachineSpec machineSpec;
    1157     ComPtr<ICloudMachine> pMachine;
    11581180    HRESULT hrc;
    11591181    int rc;
    11601182
    1161     // setCurrentSubcommand(HELP_SCOPE_CLOUD_MACHINE_CONSOLEHISTORY);
     1183    RT_NOREF(fCurSubcommandScope); /// @todo scopes not in the manual yet
     1184    // setCurrentSubcommand(fCurSubcommandScope);
    11621185    static const RTGETOPTDEF s_aOptions[] =
    11631186    {
     
    11981221        return RTEXITCODE_FAILURE;
    11991222
     1223    return RTEXITCODE_SUCCESS;
     1224}
     1225
     1226
     1227/*
     1228 * cloud machine start "id"
     1229 */
     1230static RTEXITCODE
     1231handleCloudMachineStart(HandlerArg *a, int iFirst,
     1232                        const ComPtr<ICloudClient> &pClient)
     1233{
     1234    ComPtr<ICloudMachine> pMachine;
     1235    HRESULT hrc;
     1236
     1237    RTEXITCODE status
     1238        = getMachineFromArgs(pMachine,
     1239              /* HELP_SCOPE_CLOUD_MACHINE_START */ 0,
     1240              a, iFirst, pClient);
     1241    if (status != RTEXITCODE_SUCCESS)
     1242        return status;
     1243
     1244
     1245    ComPtr<IProgress> pProgress;
     1246    CHECK_ERROR2_RET(hrc, pMachine,
     1247        PowerUp(pProgress.asOutParam()),
     1248            RTEXITCODE_FAILURE);
     1249
     1250    hrc = showProgress(pProgress, SHOW_PROGRESS_NONE);
     1251    return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     1252}
     1253
     1254
     1255/*
     1256 * cloud machine shutdown "id"
     1257 */
     1258static RTEXITCODE
     1259handleCloudMachineShutdown(HandlerArg *a, int iFirst,
     1260                           const ComPtr<ICloudClient> &pClient)
     1261{
     1262    ComPtr<ICloudMachine> pMachine;
     1263    HRESULT hrc;
     1264
     1265    RTEXITCODE status
     1266        = getMachineFromArgs(pMachine,
     1267              /* HELP_SCOPE_CLOUD_MACHINE_SHUTDOWN */ 0,
     1268              a, iFirst, pClient);
     1269    if (status != RTEXITCODE_SUCCESS)
     1270        return status;
     1271
     1272
     1273    ComPtr<IProgress> pProgress;
     1274    CHECK_ERROR2_RET(hrc, pMachine,
     1275        Shutdown(pProgress.asOutParam()),
     1276            RTEXITCODE_FAILURE);
     1277
     1278    hrc = showProgress(pProgress, SHOW_PROGRESS_NONE);
     1279    return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     1280}
     1281
     1282
     1283/*
     1284 * cloud machine console-history "id"
     1285 */
     1286static RTEXITCODE
     1287handleCloudMachineConsoleHistory(HandlerArg *a, int iFirst,
     1288                                 const ComPtr<ICloudClient> &pClient)
     1289{
     1290    ComPtr<ICloudMachine> pMachine;
     1291    HRESULT hrc;
     1292
     1293    RTEXITCODE status
     1294        = getMachineFromArgs(pMachine,
     1295              /* HELP_SCOPE_CLOUD_MACHINE_CONSOLEHISTORY */ 0,
     1296              a, iFirst, pClient);
     1297    if (status != RTEXITCODE_SUCCESS)
     1298        return status;
     1299
    12001300
    12011301    ComPtr<IDataStream> pHistoryStream;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette