VirtualBox

Changeset 98852 in vbox for trunk


Ignore:
Timestamp:
Mar 7, 2023 10:53:12 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156176
Message:

bugref:10380. Added the function listCloudVnicAttachments() and the command 'VBoxManage cloud list vnicattachments' into VBoxManage CLI.

File:
1 edited

Legend:

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

    r98785 r98852  
    441441
    442442/**
     443 * List all available cloud vnic attachments for the specified cloud provider.
     444 *
     445 * @returns RTEXITCODE
     446 * @param a is the list of passed arguments
     447 * @param iFirst is the position of the first unparsed argument in the arguments list
     448 * @param pCommonOpts is a pointer to the structure CLOUDCOMMONOPT with some common
     449 * arguments which have been already parsed before
     450 */
     451static RTEXITCODE listCloudVnicAttachments(HandlerArg *a, int iFirst, PCLOUDCOMMONOPT pCommonOpts)
     452{
     453    static const RTGETOPTDEF s_aOptions[] =
     454    {
     455        { "--compartment-id", 'c', RTGETOPT_REQ_STRING },
     456        { "--filter",         'f', RTGETOPT_REQ_STRING },/*instanceId=<id>, vnicId=<id>, domainName=<name>*/
     457        { "help",             'h', RTGETOPT_REQ_NOTHING },
     458        { "--help",           'h', RTGETOPT_REQ_NOTHING }
     459    };
     460    RTGETOPTSTATE GetState;
     461    RTGETOPTUNION ValueUnion;
     462    int vrc = RTGetOptInit(&GetState, a->argc, a->argv, s_aOptions, RT_ELEMENTS(s_aOptions), iFirst, 0);
     463    AssertRCReturn(vrc, RTEXITCODE_FAILURE);
     464
     465    com::SafeArray<BSTR> parameters;
     466    Utf8Str strCompartmentId;
     467    Utf8Str filterList;
     468    HRESULT hrc = S_OK;
     469
     470    int c;
     471    while ((c = RTGetOpt(&GetState, &ValueUnion)) != 0)
     472    {
     473        switch (c)
     474        {
     475            case 'c':
     476                strCompartmentId = ValueUnion.psz;
     477                Bstr(Utf8Str("compartmentId=").append(ValueUnion.psz)).detachTo(parameters.appendedRaw());
     478                break;
     479
     480            case 'f':
     481                filterList.append(ValueUnion.psz).append(",");
     482                Bstr(Utf8Str(ValueUnion.psz)).detachTo(parameters.appendedRaw());
     483                break;
     484            case 'h':
     485                printHelp(g_pStdOut);
     486                return RTEXITCODE_SUCCESS;
     487            case VINF_GETOPT_NOT_OPTION:
     488                return errorUnknownSubcommand(ValueUnion.psz);
     489
     490            default:
     491                return errorGetOpt(c, &ValueUnion);
     492        }
     493    }
     494
     495    RTPrintf(Cloud::tr("Filters: \'%s\' \n"), filterList.c_str());
     496
     497    /* Delayed check. It allows us to print help information.*/
     498    hrc = checkAndSetCommonOptions(a, pCommonOpts);
     499    if (FAILED(hrc))
     500        return RTEXITCODE_FAILURE;
     501
     502    ComPtr<IVirtualBox> pVirtualBox = a->virtualBox;
     503
     504    ComPtr<ICloudProviderManager> pCloudProviderManager;
     505    CHECK_ERROR2_RET(hrc, pVirtualBox,
     506                     COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()),
     507                     RTEXITCODE_FAILURE);
     508
     509    ComPtr<ICloudProvider> pCloudProvider;
     510    CHECK_ERROR2_RET(hrc, pCloudProviderManager,
     511                     GetProviderByShortName(Bstr(pCommonOpts->provider.pszProviderName).raw(), pCloudProvider.asOutParam()),
     512                     RTEXITCODE_FAILURE);
     513
     514    ComPtr<ICloudProfile> pCloudProfile;
     515    CHECK_ERROR2_RET(hrc, pCloudProvider,
     516                     GetProfileByName(Bstr(pCommonOpts->profile.pszProfileName).raw(), pCloudProfile.asOutParam()),
     517                     RTEXITCODE_FAILURE);
     518
     519    if (strCompartmentId.isNotEmpty())
     520    {
     521        CHECK_ERROR2_RET(hrc, pCloudProfile,
     522                         SetProperty(Bstr("compartment").raw(), Bstr(strCompartmentId).raw()),\
     523                         RTEXITCODE_FAILURE);
     524    }
     525    else
     526    {
     527        RTPrintf(Cloud::tr("Parameter \'compartment\' is empty or absent.\n"
     528                 "Trying to get the compartment from the passed cloud profile \'%s\'\n"), pCommonOpts->profile.pszProfileName);
     529        Bstr bStrCompartmentId;
     530        CHECK_ERROR2_RET(hrc, pCloudProfile,
     531                         GetProperty(Bstr("compartment").raw(), bStrCompartmentId.asOutParam()),
     532                         RTEXITCODE_FAILURE);
     533        strCompartmentId = bStrCompartmentId;
     534        if (strCompartmentId.isNotEmpty())
     535            RTPrintf(Cloud::tr("Found the compartment \'%s\':\n"), strCompartmentId.c_str());
     536        else
     537            return errorArgument(Cloud::tr("Parameter --compartment-id is required."));
     538    }
     539
     540    Bstr bstrProfileName;
     541    pCloudProfile->COMGETTER(Name)(bstrProfileName.asOutParam());
     542
     543    ComObjPtr<ICloudClient> oCloudClient;
     544    CHECK_ERROR2_RET(hrc, pCloudProfile,
     545                     CreateCloudClient(oCloudClient.asOutParam()),
     546                     RTEXITCODE_FAILURE);
     547
     548    ComPtr<IStringArray> pVnicAttachmentIdsHolder;
     549    ComPtr<IStringArray> pVnicIdsHolder;
     550    com::SafeArray<BSTR> arrayVnicAttachmentIds;
     551    com::SafeArray<BSTR> arrayVnicIds;
     552    ComPtr<IProgress> pProgress;
     553
     554    RTPrintf(Cloud::tr("Reply is in the form \'Vnic attachment <id>\': \n\t \'Vnic <id>\'\n"));
     555    CHECK_ERROR2_RET(hrc, oCloudClient,
     556                     ListVnicAttachments(ComSafeArrayAsInParam(parameters),
     557                                         pVnicAttachmentIdsHolder.asOutParam(),
     558                                         pVnicIdsHolder.asOutParam(),
     559                                         pProgress.asOutParam()),
     560                     RTEXITCODE_FAILURE);
     561    showProgress(pProgress);
     562    CHECK_PROGRESS_ERROR_RET(pProgress, (Cloud::tr("Failed to list Vnic attachments")), RTEXITCODE_FAILURE);
     563
     564    CHECK_ERROR2_RET(hrc,
     565        pVnicAttachmentIdsHolder, COMGETTER(Values)(ComSafeArrayAsOutParam(arrayVnicAttachmentIds)),
     566            RTEXITCODE_FAILURE);
     567    CHECK_ERROR2_RET(hrc,
     568        pVnicIdsHolder, COMGETTER(Values)(ComSafeArrayAsOutParam(arrayVnicIds)),
     569            RTEXITCODE_FAILURE);
     570
     571    RTPrintf(Cloud::tr("The list of the Vnic attachments:\n"));
     572    size_t cVnicAttchIds = arrayVnicAttachmentIds.size();
     573    size_t cVnicIds = arrayVnicIds.size();
     574
     575    if (cVnicAttchIds == 0)
     576        RTPrintf(Cloud::tr("\tEmpty\n"));
     577    else
     578    {
     579        Bstr value;
     580        for (size_t k = 0; k < cVnicAttchIds; k++)
     581        {
     582            if (k < cVnicIds)
     583                value = arrayVnicIds[k];
     584            RTPrintf(Cloud::tr("Vnic attachment id [%ls]:\n\t Vnic id - %ls\n"), arrayVnicAttachmentIds[k], value.raw());
     585        }
     586    }
     587
     588    return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     589}
     590
     591
     592/**
    443593 * General function which handles the "list" commands
    444594 *
     
    461611        kCloudList_Subnets,
    462612        kCloudList_Vcns,
     613        kCloudList_VnicAttachments,
    463614    };
    464615
     
    473624        { "vcns",                kCloudList_Vcns,      RTGETOPT_REQ_NOTHING },
    474625        { "vms",                 kCloudList_Machines,  RTGETOPT_REQ_NOTHING },
     626        { "vnicattachments",     kCloudList_VnicAttachments, RTGETOPT_REQ_NOTHING },
    475627
    476628        { "help",                'h',                  RTGETOPT_REQ_NOTHING },
     
    509661                                         pCommonOpts->profile.pszProfileName);
    510662
     663            case kCloudList_VnicAttachments:
     664                setCurrentSubcommand(HELP_SCOPE_CLOUDLIST_VNICATTACHMENTS);
     665                return listCloudVnicAttachments(a, GetState.iNext, pCommonOpts);
     666
    511667            case 'h':
    512668                printHelp(g_pStdOut);
     
    523679    return errorNoSubcommand();
    524680}
     681
    525682
    526683static RTEXITCODE createCloudInstance(HandlerArg *a, int iFirst, PCLOUDCOMMONOPT pCommonOpts)
Note: See TracChangeset for help on using the changeset viewer.

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