VirtualBox

Changeset 73929 in vbox for trunk/src/VBox/Main/src-server


Ignore:
Timestamp:
Aug 28, 2018 6:00:59 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124655
Message:

OCI: commit OCI code as-is. Doesn't yet compile in extpack but should
not break the normal build.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/ApplianceImplExport.cpp

    r73903 r73929  
    3131#include "MachineImpl.h"
    3232#include "MediumImpl.h"
     33#include "Global.h"
    3334#include "MediumFormatImpl.h"
    34 #include "Global.h"
    3535#include "SystemPropertiesImpl.h"
    3636
     
    3939
    4040#include "ApplianceImplPrivate.h"
     41
     42//#include "OCIProvider.h"
     43//#include "CloudClientImpl.h"
     44//#include "OCIProfile.h"
     45//#include "CloudAPI.h"
     46//#include "VBoxOCIApi.h"
     47//#include "VBoxOCIRest.h"
    4148
    4249using namespace std;
     
    867874            skipped = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
    868875            itSkipped = skipped.begin();
     876
     877            ComObjPtr<Medium> ptrSourceDisk;
    869878            while (itSkipped != skipped.end())
    870879            {
     
    872881                // Locate the Medium object for this entry (by location/path).
    873882                Log(("Finding source disk \"%s\"\n", path.c_str()));
    874                 ComObjPtr<Medium> ptrSourceDisk;
    875883                rc = mVirtualBox->i_findHardDiskByLocation(path, true , &ptrSourceDisk);
     884                if (SUCCEEDED(rc))
     885                    break;
     886                else
     887                    ++itSkipped;
     888            }
     889
     890            ComPtr<IMedium> pBootableBaseMedium;
     891            // returns pBootableMedium if there are no diff images
     892            rc = ptrSourceDisk->COMGETTER(Base)(pBootableBaseMedium.asOutParam());
     893            if (FAILED(rc))
     894                throw rc;
     895
     896            //Get base bootable disk location
     897            Bstr bstrBootLocation;
     898            rc = pBootableBaseMedium->COMGETTER(Location)(bstrBootLocation.asOutParam());
     899            if (FAILED(rc)) throw rc;
     900            Utf8Str strBootLocation = bstrBootLocation;
     901
     902            skipped = vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage);
     903            itSkipped = skipped.begin();
     904            while (itSkipped != skipped.end())
     905            {
     906                Utf8Str path = (*itSkipped)->strVBoxCurrent;
     907                // Locate the Medium object for this entry (by location/path).
     908                Log(("Finding disk \"%s\"\n", path.c_str()));
     909                rc = mVirtualBox->i_findHardDiskByLocation(path, true , &ptrSourceDisk);
     910                if (FAILED(rc))
     911                    throw rc;
     912
     913                if (!path.equalsIgnoreCase(strBootLocation))
     914                    (*itSkipped)->skipIt = true;
     915
    876916                ++itSkipped;
    877917            }
     918
     919            //just in case
     920            if (vsdescThis->i_findByType(VirtualSystemDescriptionType_HardDiskImage).empty())
     921            {
     922                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     923                                    tr("Strange, but nothing to export to OCI after preparation steps"));
     924            }
     925
     926            /*
     927             * Fills out the OCI settings
     928            */
     929            std::list<VirtualSystemDescriptionEntry*> machineName =
     930                vsdescThis->i_findByType(VirtualSystemDescriptionType_Name);
     931            if (machineName.empty())
     932                throw setError(VBOX_E_FILE_ERROR, tr("OCI: VM name wasn't found"));
     933            m->m_OciExportData.strDisplayMachineName = machineName.front()->strVBoxCurrent;
     934            LogRel(("Exported machine name: %s\n", m->m_OciExportData.strDisplayMachineName.c_str()));
     935
     936            m->m_OciExportData.strBootImageName = strBootLocation;
     937            LogRel(("Exported image: %s\n", m->m_OciExportData.strBootImageName.c_str()));
     938
     939            if (aLocInfo.strPath.isEmpty())
     940                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     941                                    tr("OCI: Cloud user profile wasn't found"));
     942
     943            m->m_OciExportData.strProfileName = aLocInfo.strPath;
     944            LogRel(("OCI profile name: %s\n", m->m_OciExportData.strProfileName.c_str()));
     945
     946            Utf8Str strInstanceShapeId;
     947            std::list<VirtualSystemDescriptionEntry*> shapeId =
     948                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIInstanceShape);
     949            if (shapeId.empty())
     950                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     951                                    tr("OCI: Shape of instance wasn't found"));
     952
     953            m->m_OciExportData.strInstanceShapeId = shapeId.front()->strVBoxCurrent;
     954            LogRel(("OCI shape: %s\n", m->m_OciExportData.strInstanceShapeId.c_str()));
     955
     956            std::list<VirtualSystemDescriptionEntry*> domainName =
     957                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIDomain);
     958            if (domainName.empty())
     959                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     960                                    tr("OCI: Available domain wasn't found"));
     961
     962            m->m_OciExportData.strDomainName = domainName.front()->strVBoxCurrent;
     963            LogRel(("OCI available domain name: %s\n", m->m_OciExportData.strDomainName.c_str()));
     964
     965            std::list<VirtualSystemDescriptionEntry*> bootDiskSize =
     966                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIBootDiskSize);
     967            if (bootDiskSize.empty())
     968                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     969                                    tr("OCI: Boot disk size wasn't found"));
     970
     971            m->m_OciExportData.strBootDiskSize = bootDiskSize.front()->strVBoxCurrent;
     972            LogRel(("OCI boot disk size: %s\n", m->m_OciExportData.strBootDiskSize.c_str()));
     973
     974            std::list<VirtualSystemDescriptionEntry*> bucketId =
     975                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIBucket);
     976            if (bucketId.empty())
     977                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     978                                    tr("OCI: Bucket wasn't found"));
     979
     980            m->m_OciExportData.strBucketId = bucketId.front()->strVBoxCurrent;
     981            LogRel(("OCI bucket name: %s\n", m->m_OciExportData.strBucketId.c_str()));
     982
     983            std::list<VirtualSystemDescriptionEntry*> vcn =
     984                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIVCN);
     985            if (vcn.empty())
     986                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     987                                    tr("OCI: VCN wasn't found"));
     988
     989            m->m_OciExportData.strVCN = vcn.front()->strVBoxCurrent;
     990            LogRel(("OCI VCN name: %s\n", m->m_OciExportData.strVCN.c_str()));
     991
     992            std::list<VirtualSystemDescriptionEntry*> publicIP =
     993                vsdescThis->i_findByType(VirtualSystemDescriptionType_CloudOCIPublicIP);
     994            if (publicIP.empty())
     995                throw rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     996                                    tr("OCI: Public IP setting wasn't found"));
     997
     998            m->m_OciExportData.fPublicIP = (publicIP.front()->strVBoxCurrent == "true") ? true : false;
     999            LogRel(("OCI public IP: %s\n", m->m_OciExportData.fPublicIP ? "yes" : "no"));
    8781000        }
    8791001
     
    22482370HRESULT Appliance::i_writeFSOCI(TaskOCI *pTask)
    22492371{
     2372    RT_NOREF(pTask); // XXX
    22502373    LogFlowFuncEnter();
    2251     RT_NOREF(pTask);
    22522374    HRESULT hrc = S_OK;
    2253 
     2375    //int vrc = VINF_SUCCESS;
     2376    ComPtr<ICloudProviderManager> cpm;
     2377    hrc = mVirtualBox->COMGETTER(CloudProviderManager)(cpm.asOutParam());
     2378
     2379    Utf8Str strProviderName("OCI");
     2380    ComPtr<ICloudProvider> ociProfile;
     2381    hrc = cpm->GetProviderByShortName(Bstr(strProviderName.c_str()).raw(), ociProfile.asOutParam());
     2382//  initNew(VirtualBox *aVirtualBox,
     2383//                          OCIProvider *aParent,
     2384//                          const com::Utf8Str &aProfileName,
     2385//                          const std::vector<com::Utf8Str> &aNames,
     2386//                          const std::vector<com::Utf8Str> &aValues)
     2387
     2388//  hrc = cpm.i_getProfilesByProvider("OCI", ociProfiles);
     2389//  if (FAILED(hrc) || ociProfiles.isNull())
     2390//      return hrc;
     2391
     2392    //fills by values from m->m_OciExportData
     2393    //mostly all names(keys) come from official OCI API documentation (see LaunchInstance description)
     2394    std::map<Utf8Str, Utf8Str> paramNameValueMap;
     2395    paramNameValueMap.insert(make_pair("displayName", m->m_OciExportData.strDisplayMachineName));
     2396    paramNameValueMap.insert(make_pair("objectName", m->m_OciExportData.strBootImageName));
     2397    paramNameValueMap.insert(make_pair("vcnId", m->m_OciExportData.strVCN));
     2398    paramNameValueMap.insert(make_pair("bucketName", m->m_OciExportData.strBucketId));
     2399    paramNameValueMap.insert(make_pair("bootVolumeSizeInGBs", m->m_OciExportData.strBootDiskSize));
     2400    paramNameValueMap.insert(make_pair("availabilityDomain", m->m_OciExportData.strDomainName));
     2401    paramNameValueMap.insert(make_pair("shape", m->m_OciExportData.strInstanceShapeId));
     2402    paramNameValueMap.insert(make_pair("profileName", m->m_OciExportData.strProfileName));
     2403    paramNameValueMap.insert(make_pair("assignPublicIp", (m->m_OciExportData.fPublicIP == true) ? "true" : "false"));
     2404
     2405    com::SafeArray<CloudCommand_T> commandList;
     2406/*
     2407    ComObjPtr<ICloudClient> aCloudClient;
     2408    hrc = ociProfiles->CreateCloudClient(Bstr(m->m_OciExportData.strProfileName).raw(), aCloudClient.asOutParam());
     2409
     2410    if (SUCCEEDED(hrc))
     2411    {
     2412        try
     2413        {
     2414            CloudClient *client = static_cast<CloudClient*>(aCloudClient.operator->());
     2415
     2416            hrc = aCloudClient->GetCommandsForOperation(CloudOperation_exportVM, false,
     2417                                                        ComSafeArrayAsOutParam(commandList));
     2418            if (SUCCEEDED(hrc))
     2419            {
     2420                std::vector<com::Guid> commandIdList;
     2421
     2422                for (ULONG i = 0; i < commandList.size(); i++)
     2423                {
     2424                    CloudCommand_T cmd = commandList[i];
     2425                    Bstr bStrId;
     2426                    hrc = aCloudClient->CreateCommand(cmd, bStrId.asOutParam());
     2427
     2428                    if (SUCCEEDED(hrc))
     2429                    {
     2430                        com::Guid cId(bStrId);
     2431                        //set conditions
     2432                        {
     2433                            CloudCommandCl *cc = NULL;
     2434                            vrc = client->i_getCommandById(cId, &cc);
     2435                            if (RT_SUCCESS(vrc))
     2436                            {
     2437                                switch(cmd)
     2438                                {
     2439                                    case CloudCommand_getImage:
     2440                                    case CloudCommand_getSubnet:
     2441                                        vrc = cc->setCondition(new oci::LifecycleStateCondition(Utf8Str("AVAILABLE")));
     2442                                        break;
     2443                                    case CloudCommand_getInstance:
     2444                                        vrc = cc->setCondition(new oci::LifecycleStateCondition(Utf8Str("RUNNING")));
     2445                                        break;
     2446                                    default:
     2447                                        break;
     2448                                }
     2449                                if (RT_FAILURE(vrc))
     2450                                {
     2451                                    hrc = E_FAIL;
     2452                                    break;
     2453                                }
     2454
     2455                            }
     2456                            else
     2457                            {
     2458                                hrc = E_FAIL;
     2459                                break;
     2460                            }
     2461                        }
     2462
     2463                        commandIdList.push_back(cId);//fills the Id list
     2464                    }
     2465                }
     2466
     2467                if (SUCCEEDED(hrc))
     2468                    vrc = client->i_runSeveralCommands(commandIdList, paramNameValueMap);
     2469            }
     2470        }
     2471        catch (HRESULT arc)
     2472        {
     2473            hrc = arc;
     2474        }
     2475        catch (...)
     2476        {
     2477            LogRel(("Appliance::i_writeFSOCI(): get cought unknown exception\n"));
     2478        }
     2479
     2480        aCloudClient.setNull();
     2481    }
     2482    */
     2483    LogFlowFuncLeave();
    22542484    return hrc;
    22552485}
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