- Timestamp:
- Aug 6, 2018 10:10:52 PM (6 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/Makefile.kmk
r73337 r73535 455 455 src-server/ClientWatcher.cpp \ 456 456 src-server/ClientToken.cpp \ 457 src-server/CloudAPI.cpp \ 457 458 src-server/CloudClientImpl.cpp \ 458 459 src-server/CloudUserProfilesImpl.cpp \ -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r73337 r73535 24875 24875 24876 24876 <enum 24877 name="Cloud Operation"24877 name="CloudCommand" 24878 24878 uuid="1c5cfa19-7754-4071-bf3e-6d21ad432655" 24879 24879 > 24880 24880 <const name="Unknown" value="0"/> 24881 24882 24881 <const name="createInstance" value="0x1"/> 24883 24882 <const name="launchInstance" value="0x2"/> … … 24886 24885 <const name="deleteInstance" value="0x5"/> 24887 24886 <const name="getInstanceProperties" value="0x6"/> 24888 <const name="listOfInstances" value="0x7"/> 24887 <const name="listInstances" value="0x7"/> 24888 <const name="importImage" value="0x8"/> 24889 24889 24890 24890 <const name="uploadFile" value="0x10"/> … … 24893 24893 <const name="getObjectProperties" value="0x13"/> 24894 24894 <const name="listObjects" value="0x14"/> 24895 24896 <const name="exportVM" value="0xf0"/> 24895 <const name="listBuckets" value="0x15"/> 24896 <const name="listNetworks" value="0x16"/> 24897 <const name="listShapes" value="0x17"/> 24898 <const name="listRegions" value="0x18"/> 24899 <const name="listAvailabilityDomains" value="0x19"/> 24900 <const name="listCompartments" value="0x20"/> 24901 <const name="getNamespace" value="0x21"/> 24897 24902 </enum> 24898 24903 24899 24904 <enum 24900 name="CloudOperationResult" 24905 name="CloudOperation" 24906 uuid="68289604-2fec-4163-b10a-eb2da7a61306" 24907 > 24908 <const name="Unknown" value="0"/> 24909 <const name="exportVM" value="0x1"/> 24910 </enum> 24911 24912 <enum 24913 name="CloudCommandResult" 24901 24914 uuid="e33af696-255a-4f5a-8dba-d65d6ee2fe9a" 24902 24915 > … … 24913 24926 > 24914 24927 24915 <method name="create Operation">24928 <method name="createCommand"> 24916 24929 <desc> 24917 24930 Creates a cloud operation object for the passed profile … … 24920 24933 returns "VERR_INVALID_PARAMETER" 24921 24934 </desc> 24922 <param name="profileName" type="wstring" dir="in"> 24923 <desc> 24924 The profile's name 24925 </desc> 24926 </param> 24927 <param name="cloudOperation" type="CloudOperation" dir="in"> 24935 <param name="cloudCommand" type="CloudCommand" dir="in"> 24928 24936 <desc> 24929 24937 The type of the supported cloud commands. 24930 24938 </desc> 24931 24939 </param> 24932 <param name=" opId" type="uuid" mod="string" dir="return">24940 <param name="Id" type="uuid" mod="string" dir="return"> 24933 24941 <desc> 24934 24942 UUID of the operation. … … 24938 24946 </method> 24939 24947 24940 <method name="run Operation">24948 <method name="runCommand"> 24941 24949 <desc> 24942 24950 Runs a cloud operation by ID 24943 24951 </desc> 24944 <param name=" opId" type="uuid" mod="string" dir="in">24952 <param name="Id" type="uuid" mod="string" dir="in"> 24945 24953 <desc> 24946 24954 UUID of the operation. … … 24952 24960 </desc> 24953 24961 </param> 24954 </method> 24955 24956 <method name="checkOperationResult" const="yes"> 24962 <param name="result" type="CloudCommandResult" dir="return"> 24963 </param> 24964 </method> 24965 24966 <method name="validateCommand"> 24967 <desc> 24968 Validates a cloud operation by ID 24969 </desc> 24970 <param name="Id" type="uuid" mod="string" dir="in"> 24971 <desc> 24972 UUID of the operation. 24973 </desc> 24974 </param> 24975 <param name="valid" type="boolean" dir="return"> 24976 <desc> 24977 if the command is valid return s true else returns false. 24978 </desc> 24979 </param> 24980 </method> 24981 24982 <method name="checkCommandResult" const="yes"> 24957 24983 <desc> 24958 24984 Check a cloud operation result by ID 24959 24985 </desc> 24960 <param name=" opId" type="uuid" mod="string" dir="in">24986 <param name="Id" type="uuid" mod="string" dir="in"> 24961 24987 <desc> 24962 24988 UUID of the operation. 24963 24989 </desc> 24964 24990 </param> 24965 <param name="start OpTime" type="long long" dir="out">24991 <param name="startTime" type="long long" dir="out"> 24966 24992 <desc> 24967 24993 Start time of operation. … … 24973 24999 </desc> 24974 25000 </param> 24975 <param name="result" type="Cloud OperationResult" dir="return">25001 <param name="result" type="CloudCommandResult" dir="return"> 24976 25002 <desc> 24977 25003 The last result of the cloud command. … … 24980 25006 </method> 24981 25007 24982 <method name="get OperationParameterNames" const="yes">25008 <method name="getCommandParameterNames" const="yes"> 24983 25009 <desc> 24984 25010 Returns the parameters names for this operation. 24985 25011 </desc> 24986 <param name="cloud Operation" type="CloudOperation" dir="in">25012 <param name="cloudCommand" type="CloudCommand" dir="in"> 24987 25013 <desc> 24988 25014 The type of the supported cloud commands. … … 24994 25020 </method> 24995 25021 24996 <method name="get OperationParameterProperties" const="yes">25022 <method name="getCommandParameterProperties" const="yes"> 24997 25023 <desc> 24998 25024 Returns the value/s for the passed parameter. 24999 25025 </desc> 25000 <param name=" opParameterName" type="wstring" dir="in">25026 <param name="parameterName" type="wstring" dir="in"> 25001 25027 <desc>Parameter name.</desc> 25002 25028 </param> 25003 <param name=" opParameterType" type="wstring" dir="out">25029 <param name="parameterType" type="wstring" dir="out"> 25004 25030 <desc>Parameter type.</desc> 25005 25031 </param> 25006 <param name=" opParameterDesc" type="wstring" dir="out">25032 <param name="parameterDesc" type="wstring" dir="out"> 25007 25033 <desc>Parameter description.</desc> 25008 25034 </param> 25009 <param name=" opParameterValues" type="wstring" safearray="yes" dir="return">25035 <param name="parameterValues" type="wstring" safearray="yes" dir="return"> 25010 25036 <desc>Possible values of the parameter.</desc> 25011 25037 </param> 25012 25038 </method> 25013 25039 25014 <method name="get OperationParameters" const="yes">25040 <method name="getCommandParameters" const="yes"> 25015 25041 <desc> 25016 25042 Returns the parameters with their values. 25017 25043 </desc> 25018 <param name="cloud Operation" type="CloudOperation" dir="in">25044 <param name="cloudCommand" type="CloudCommand" dir="in"> 25019 25045 <desc> 25020 25046 The type of the supported cloud commands. … … 25026 25052 </method> 25027 25053 25028 <method name="set ParametersForOperation">25029 <desc> 25030 Sets the parameters values for the particular operationby ID.25031 </desc> 25032 <param name=" opId" type="uuid" mod="string" dir="in">25054 <method name="setCommandParameters"> 25055 <desc> 25056 Sets the parameters values for the particular command by ID. 25057 </desc> 25058 <param name="Id" type="uuid" mod="string" dir="in"> 25033 25059 <desc> 25034 25060 UUID of the operation. 25035 25061 </desc> 25062 </param> 25063 <param name="names" type="wstring" safearray="yes" dir="in"> 25064 <desc>Names of the parameters.</desc> 25036 25065 </param> 25037 25066 <param name="values" type="wstring" safearray="yes" dir="in"> … … 25040 25069 </method> 25041 25070 25071 <method name="getCommandsForOperation" const="yes"> 25072 <desc> 25073 Returns the list of commands for particular operation. 25074 </desc> 25075 <param name="cloudOperation" type="CloudOperation" dir="in"> 25076 <desc> 25077 The type of the supported cloud operation. 25078 </desc> 25079 </param> 25080 <param name="prep" type="boolean" dir="in"> 25081 <desc> 25082 Which list to return: false - general commands, true - preparatory commands 25083 </desc> 25084 </param> 25085 <param name="cloudCommands" type="CloudCommand" safearray="yes" dir="return"> 25086 <desc> 25087 The list of cloud commands. 25088 </desc> 25089 </param> 25090 </method> 25091 25092 <method name="getOperationParameters" const="yes"> 25093 <desc> 25094 Returns the parameters with their values. 25095 </desc> 25096 <param name="cloudOperation" type="CloudOperation" dir="in"> 25097 <desc> 25098 The type of the supported cloud operation. 25099 </desc> 25100 </param> 25101 <param name="jsonString" type="wstring" dir="return"> 25102 <desc>the parameters with values in json format.</desc> 25103 </param> 25104 </method> 25105 25042 25106 </interface> 25043 25044 25045 25107 25046 25108 <!-- -
trunk/src/VBox/Main/include/CloudClientImpl.h
r73337 r73535 23 23 24 24 #include "CloudClientWrap.h" 25 #include "ProgressImpl.h" 25 26 26 27 /* VBox forward declarations */ 27 28 class CloudUserProfiles; 29 class CloudCommandCl; 30 class CloudAPI; 31 struct DataModel; 28 32 29 class CloudClient : 33 //////////////////////////////////////////////////////////////////////////////// 34 // 35 // CloudClient 36 // 37 // ///////////////////////////////////////////////////////////////////////////// 38 class CloudClient: 30 39 public CloudClientWrap 31 40 { 32 41 public: 33 42 DECLARE_EMPTY_CTOR_DTOR(CloudClient) 34 // explicit CloudClient(CloudProviderId_T aCloudProvider);35 43 36 44 HRESULT FinalConstruct(); … … 47 55 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */ 48 56 CloudProviderId_T mCloudProvider; 49 std::map <Utf8Str, Utf8Str> userProfile; 57 std::map <Utf8Str, Utf8Str> mCloudProfile; 58 std::map <com::Guid, CloudCommandCl*> mCloudCommandMap; 59 std::map <Utf8Str, CloudAPI*> mCloudAPIInstanceMap; 50 60 51 61 private: 62 HRESULT createCommand(CloudCommand_T aCloudCommand, com::Guid &aId); 63 HRESULT runCommand(const com::Guid &aId, LONG64 aTimeout, CloudCommandResult_T *aResult); 64 // HRESULT runCommand(const com::Guid &aId, LONG64 aTimeout, CloudCommandResult_T *aResult, ComPtr<IProgress> &aProgress); 65 HRESULT validateCommand(const com::Guid &aId, BOOL *aValid); 66 HRESULT checkCommandResult(const com::Guid &aId, 67 LONG64 *aStartTime, 68 LONG64 *aLastTime, 69 CloudCommandResult_T *aResult); 70 71 HRESULT getCommandParameterNames(CloudCommand_T aCloudCommand, 72 std::vector<com::Utf8Str> &aParameterNames); 73 HRESULT getCommandParameterProperties(const com::Utf8Str &aParameterName, 74 com::Utf8Str &aParameterType, 75 com::Utf8Str &aParameterDesc, 76 std::vector<com::Utf8Str> &aParameterValues); 77 HRESULT getCommandParameters(CloudCommand_T aCloudCommand, com::Utf8Str &aJsonString); 78 HRESULT setCommandParameters(const com::Guid &aId, 79 const std::vector<com::Utf8Str> &aNames, 80 const std::vector<com::Utf8Str> &aValues); 81 HRESULT getCommandsForOperation(CloudOperation_T aCloudOperation, 82 BOOL aPrep, 83 std::vector<CloudCommand_T> &aCloudCommands); 52 84 HRESULT getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString); 53 85 54 HRESULT createOperation(const com::Utf8Str &aProfileName, 55 CloudOperation_T aCloudOperation, 56 com::Guid &aOpId); 57 HRESULT runOperation(const com::Guid &aOpId, 58 LONG64 aTimeout); 59 HRESULT checkOperationResult(const com::Guid &aOpId, 60 LONG64 *aStartOpTime, 61 LONG64 *aLastTime, 62 CloudOperationResult_T *aResult); 63 HRESULT getOperationParameterNames(CloudOperation_T aCloudOperation, 64 std::vector<com::Utf8Str> &aParameterNames); 65 HRESULT getOperationParameterProperties(const com::Utf8Str &aOpParameterName, 66 com::Utf8Str &aOpParameterType, 67 com::Utf8Str &aOpParameterDesc, 68 std::vector<com::Utf8Str> &aOpParameterValues); 69 HRESULT setParametersForOperation(const com::Guid &aOpId, 70 const std::vector<com::Utf8Str> &aValues); 86 protected: 87 //Next 4 functions are wrappers for the corresponding private functions without prefix "i_" 88 int i_createCommand(CloudCommand_T aCloudCommand, com::Guid &aId); 89 int i_runCommand(CloudCommandCl &aCC); 90 // int i_runCommand(CloudCommandCl &aCC, ComObjPtr<Progress> *aProgress); 91 int i_validateCommand(CloudCommandCl &aCC, 92 const std::map<Utf8Str, Utf8Str> &aParamNameValueMap, 93 bool fWeak); 94 int i_checkCommandResult(CloudCommandCl &aCC, CloudCommandResult_T &aResult); 95 //End 4 wrappers 96 97 int i_getCommandById(const com::Guid &aId, CloudCommandCl **aCC); 98 int i_parseResponse(CloudCommandCl &aCC); 99 virtual int i_getCommandParameterNames(const CloudCommandCl &aCC, 100 std::vector<com::Utf8Str> &aParameterNames); 101 virtual int i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple); 102 // virtual int i_findCommandById(const com::Guid &aId, CloudCommandCl &res); 103 virtual int i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI **apiObj); 104 virtual HRESULT i_getSupportedAPIs(std::list<Utf8Str> &apiNames); 105 virtual HRESULT i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj); 106 virtual int i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName); 107 HRESULT i_setUpProgress(ComObjPtr<Progress> &pProgress, 108 const Utf8Str &strDescription, 109 ULONG aOperations); 71 110 }; 72 111 73 class CloudClientOCI : 74 public CloudClient 112 //////////////////////////////////////////////////////////////////////////////// 113 // 114 // CloudCLientOCI 115 // 116 // ///////////////////////////////////////////////////////////////////////////// 117 class CloudClientOCI : public CloudClient 75 118 { 76 119 public: 77 DECLARE_EMPTY_CTOR_DTOR(CloudClientOCI)78 120 CloudClientOCI(); 121 ~CloudClientOCI(); 79 122 HRESULT initCloudClient(CloudUserProfiles *aProfiles, 80 123 VirtualBox *aParent, 81 124 CloudProviderId_T aCloudProvider, 82 125 const com::Utf8Str &aProfileName); 126 private: 127 HRESULT getCommandsForOperation(CloudOperation_T aCloudOperation, 128 BOOL aPrep, 129 std::vector<CloudCommand_T> &aCloudCommands); 130 HRESULT getCommandParameters(CloudCommand_T aCommand, com::Utf8Str &aJsonString); 131 HRESULT getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString); 132 HRESULT getCommandParameterNames(CloudCommand_T aCloudCommand, std::vector<com::Utf8Str> &aParameterNames); 83 133 84 private: 85 HRESULT getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString); 134 protected: 86 135 87 HRESULT createOperation(const com::Utf8Str &aProfileName, 88 CloudOperation_T aCloudOperation, 89 com::Guid &aOpId); 90 HRESULT runOperation(const com::Guid &aOpId, 91 LONG64 aTimeout); 92 HRESULT checkOperationResult(const com::Guid &aOpId, 93 LONG64 *aStartOpTime, 94 LONG64 *aLastTime, 95 CloudOperationResult_T *aResult); 96 HRESULT getOperationParameterNames(CloudOperation_T aCloudOperation, 97 std::vector<com::Utf8Str> &aParameterNames); 98 HRESULT getOperationParameterProperties(const com::Utf8Str &aOpParameterName, 99 com::Utf8Str &aOpParameterType, 100 com::Utf8Str &aOpParameterDesc, 101 std::vector<com::Utf8Str> &aOpParameterValues); 102 HRESULT setParametersForOperation(const com::Guid &aOpId, 103 const std::vector<com::Utf8Str> &aValues); 136 int i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple); 137 int i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI **apiObj); 138 HRESULT i_getSupportedAPIs(std::list<Utf8Str> &apiNames); 139 HRESULT i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj); 140 int i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName); 141 int i_extractAskedParamsFromResponse(CloudCommandCl &aCC, std::map<Utf8Str, Utf8Str> &aParams); 104 142 }; 143 144 //////////////////////////////////////////////////////////////////////////////// 145 // 146 // CloudCLientGCP 147 // 148 // ///////////////////////////////////////////////////////////////////////////// 149 //CloudCLientGCP : public CloudClient 150 //{ 151 // CloudCLientGCP(); 152 // ~CloudCLientGCP(); 153 //}; 105 154 106 155 #endif // !____H_CLOUDCLIENTIMPL -
trunk/src/VBox/Main/src-server/CloudClientImpl.cpp
r73505 r73535 16 16 */ 17 17 18 #include <iostream> 19 #include <algorithm> 20 #include <map> 18 21 19 22 #include <iprt/path.h> 20 23 #include <iprt/cpp/utils.h> 21 24 #include <VBox/com/array.h> 22 #include <map>23 25 24 26 #include "CloudClientImpl.h" 25 27 #include "CloudUserProfileManagerImpl.h" 26 28 #include "CloudUserProfilesImpl.h" 29 #include "CloudAPI.h" 27 30 #include "VirtualBoxImpl.h" 28 31 #include "Global.h" 29 #include "ProgressImpl.h"30 32 #include "MachineImpl.h" 31 33 #include "AutoCaller.h" … … 37 39 //////////////////////////////////////////////////////////////////////////////// 38 40 // 39 // CloudClient constructor / destructor41 // CloudClient implementation 40 42 // 41 // ////////////////////////////////////////////////////////////////////////////////43 //////////////////////////////////////////////////////////////////////////////// 42 44 CloudClient::CloudClient() 43 45 : mParent(NULL) … … 72 74 73 75 unconst(mParent) = NULL; 76 77 { 78 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.begin(); 79 while (it != mCloudCommandMap.end()) 80 { 81 delete it->second; 82 ++it; 83 } 84 } 85 86 { 87 std::map <Utf8Str, CloudAPI*>::iterator it = mCloudAPIInstanceMap.begin(); 88 while (it != mCloudAPIInstanceMap.end()) 89 { 90 delete it->second; 91 ++it; 92 } 93 } 74 94 } 75 95 … … 117 137 mCloudProvider = aCloudProvider; 118 138 LogRel(("CloudProvider = %d\n", mCloudProvider)); 119 CloudUserProfiles*lProfiles = aProfiles;120 std::vector<com::Utf8Str> lNames;121 std::vector<com::Utf8Str> lValues;122 hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);123 if (FAILED(hrc))124 {125 return hrc;126 }127 128 for (size_t i=0;i<lNames.size();++i)129 {130 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";131 userProfile[lNames.at(i)] = value;132 }133 134 CloudProviderId_T aProvider;135 hrc = lProfiles->getProvider(&aProvider);136 137 switch(aProvider)138 {139 case CloudProviderId_OCI:140 default:141 LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));142 break;143 }144 }145 catch (HRESULT arc)146 {147 hrc = arc;148 LogRel(("Get cought an exception %d\n", hrc));149 }150 catch (std::bad_alloc &)151 {152 return E_OUTOFMEMORY;153 }154 155 /*156 * Confirm a successful initialization157 */158 autoInitSpan.setSucceeded();159 160 return hrc;161 }162 163 HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)164 {165 LogRel(("CloudClient::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));166 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));167 return hrc;168 }169 170 HRESULT CloudClient::createOperation(const com::Utf8Str &aProfileName,171 CloudOperation_T aCloudOperation,172 com::Guid &aOpId)173 {174 LogRel(("CloudClient::createOperation: %s, %d, %s\n", aProfileName.c_str(),175 aCloudOperation,176 aOpId.toString().c_str()));177 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));178 return hrc;179 }180 181 HRESULT CloudClient::runOperation(const com::Guid &aOpId,182 LONG64 aTimeout)183 {184 LogRel(("CloudClient::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout));185 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));186 return hrc;187 }188 189 HRESULT CloudClient::checkOperationResult(const com::Guid &aOpId,190 LONG64 *aStartOpTime,191 LONG64 *aLastTime,192 CloudOperationResult_T *aResult)193 {194 LogRel(("CloudClient::checkOperationResult: %s, %d, %d, %d\n",195 aOpId.toString().c_str(),196 *aStartOpTime,197 *aLastTime,198 *aResult));199 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));200 return hrc;201 }202 203 HRESULT CloudClient::getOperationParameterNames(CloudOperation_T aCloudOperation,204 std::vector<com::Utf8Str> &aParameterNames)205 {206 LogRel(("CloudClient::getOperationParameterNames: %d\n", aCloudOperation));207 aParameterNames.clear();208 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));209 return hrc;210 }211 212 HRESULT CloudClient::getOperationParameterProperties(const com::Utf8Str &aOpParameterName,213 com::Utf8Str &aOpParameterType,214 com::Utf8Str &aOpParameterDesc,215 std::vector<com::Utf8Str> &aOpParameterValues)216 {217 LogRel(("CloudClient::getOperationParameterProperties: %s, %s, %s\n",218 aOpParameterName.c_str(),219 aOpParameterType.c_str(),220 aOpParameterDesc.c_str()));221 aOpParameterValues.clear();222 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));223 return hrc;224 }225 226 HRESULT CloudClient::setParametersForOperation(const com::Guid &aOpId,227 const std::vector<com::Utf8Str> &aValues)228 {229 LogRel(("CloudClient::setParametersForOperation: %s\n", aOpId.toString().c_str()));230 for (size_t i=0;i<aValues.size();++i)231 {232 LogRel(("value %d: %s\n", i, aValues.at(i).c_str()));233 }234 235 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented"));236 return hrc;237 }238 239 ////////////////////////////////////////////////////////////////////////////////240 //241 // CloudClient constructor / destructor242 //243 // ////////////////////////////////////////////////////////////////////////////////244 CloudClientOCI::CloudClientOCI()245 {246 LogRel(("CloudClientOCI::CloudClientOCI()\n"));247 }248 249 CloudClientOCI::~CloudClientOCI()250 {251 LogRel(("CloudClientOCI::~CloudClientOCI()\n"));252 }253 254 HRESULT CloudClientOCI::initCloudClient(CloudUserProfiles *aProfiles,255 VirtualBox *aParent,256 CloudProviderId_T aCloudProvider,257 const com::Utf8Str &aProfileName)258 {259 LogRel(("aParent=%p\n", aParent));260 ComAssertRet(aParent, E_INVALIDARG);261 262 /* Enclose the state transition NotReady->InInit->Ready */263 AutoInitSpan autoInitSpan(this);264 AssertReturn(autoInitSpan.isOk(), E_FAIL);265 266 unconst(mParent) = aParent;267 268 HRESULT hrc = S_OK;269 270 try271 {272 mCloudProvider = aCloudProvider;273 LogRel(("CloudClientOCI = %d\n", mCloudProvider));274 139 CloudUserProfiles *lProfiles = aProfiles; 275 140 std::vector<com::Utf8Str> lNames; … … 284 149 { 285 150 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : ""; 286 userProfile[lNames.at(i)] = value;151 mCloudProfile[lNames.at(i)] = value; 287 152 } 288 153 … … 316 181 } 317 182 318 //static Utf8Str strExportParametersToOCI = "{\n" 319 // "\"Shape of instance\": {\n" 320 // "\"type\":27,\n" 321 // "\"items\": [\n" 322 // "\"VM.Standard1.1\",\n" 323 // "\"VM.Standard1.2\",\n" 324 // "\"VM.Standard1.4\",\n" 325 // "\"VM.Standard1.8\",\n" 326 // "\"VM.Standard1.16\",\n" 327 // "],\n" 328 // "},\n" 329 // "\"Availability domain\": {\n" 330 // "\"type\":28,\n" 331 // "\"items\": [\n" 332 // "\"ergw:US-ASHBURN-AD-1\",\n" 333 // "\"ergw:US-ASHBURN-AD-2\",\n" 334 // "\"ergw:US-ASHBURN-AD-3\",\n" 335 // "],\n" 336 // "},\n" 337 // "\"Disk size\": {\n" 338 // "\"type\":29,\n" 339 // "\range\":10 ... 50,\n" 340 // "\"size\":10,\n" 341 // "\"unit\":\"Gb\"\n" 342 // "},\n" 343 // "\"Bucket\": {\n" 344 // "\"type\":30,\n" 345 // "\"items\": [\n" 346 // "\"temporarly-bucket-python-ubuntu-14-x64-server\",\n" 347 // "\"temporarly-bucket-python-un-ubuntu\",\n" 348 // "\"test_cpp_bucket\",\n" 349 // "\"vbox_test_bucket_1\",\n" 350 // "],\n" 351 // "},\n" 352 // "\"Virtual Cloud Network\": {\n" 353 // "\"type\":31,\n" 354 // "\"items\": [\n" 355 // "\"vcn-scoter\",\n" 356 // "\"vcn20180510154500\",\n" 357 // "\"vcn_spider\",\n" 358 // "],\n" 359 // "},\n" 360 // "\"Public IP address\": {\n" 361 // "\"type\":32,\n" 362 // "\"set\":\"yes\n" 363 // "}\n" 364 //"}"; 183 HRESULT CloudClient::createCommand(CloudCommand_T aCloudCommand, com::Guid &aId) 184 { 185 HRESULT hrc = S_OK; 186 LogRel(("CloudClient::createCommand: %s \n", aCloudCommand)); 187 int vrc = i_createCommand(aCloudCommand, aId); 188 if (RT_FAILURE(vrc)) 189 hrc = setErrorBoth(E_FAIL, vrc, tr("Couldn't create command %d"), aCloudCommand); 190 191 return hrc; 192 } 193 194 int CloudClient::i_createCommand(CloudCommand_T aCloudCommand, com::Guid &aId) 195 { 196 LogRel(("Enter CloudClient::i_createCommand()\n")); 197 int vrc = VINF_SUCCESS; 198 199 try 200 { 201 CloudAPI* actualAPI = NULL; 202 Utf8Str apiName; 203 vrc = i_queryAPINameForCommand(aCloudCommand, apiName); 204 if (RT_SUCCESS(vrc) && mCloudAPIInstanceMap[apiName] == NULL) 205 { 206 vrc = i_queryAPIForCommand(aCloudCommand, &actualAPI); 207 if (RT_SUCCESS(vrc) && actualAPI != NULL) 208 mCloudAPIInstanceMap[apiName] = actualAPI; 209 } 210 else 211 actualAPI = mCloudAPIInstanceMap[apiName]; 212 213 if (RT_SUCCESS(vrc)) 214 { 215 com::Guid lId; 216 lId.create(); 217 CloudCommandCl *newCloudCommand = NULL; 218 219 actualAPI->createCloudCommand(aCloudCommand, mCloudProfile, lId, &newCloudCommand); 220 newCloudCommand->mAPIBaseURI = actualAPI->getBaseAPIUrl(actualAPI->getDefaultVersion(), mCloudProfile); 221 if (!newCloudCommand->mAPIBaseURI.isEmpty()) 222 { 223 LogRel(("Base API \"%s\" URI is %s \n", apiName.c_str(), newCloudCommand->mAPIBaseURI.c_str())); 224 newCloudCommand->mUsedAPI = actualAPI; 225 mCloudCommandMap.insert(make_pair(newCloudCommand->mId, newCloudCommand)); 226 aId = newCloudCommand->mId; 227 } 228 else 229 vrc = VERR_NOT_FOUND; 230 } 231 232 } 233 catch (int arc) 234 { 235 vrc = arc; 236 LogRel(("Get cought an exception %d\n", vrc)); 237 } 238 239 return vrc; 240 } 241 242 HRESULT CloudClient::runCommand(const com::Guid &aId, LONG64 aTimeout, CloudCommandResult_T *aResult) 243 { 244 LogRel(("CloudClient::runCommand: %s, %d\n", aId.toString().c_str(), aTimeout)); 245 HRESULT hrc = S_OK; 246 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.find(aId); 247 if (it !=mCloudCommandMap.end() && it->second->mfValid == true) 248 { 249 CloudCommandCl* cc = it->second; 250 cc->mTimeout = aTimeout; 251 int vrc = i_runCommand(*cc); 252 if (RT_FAILURE(vrc)) 253 { 254 hrc = setErrorBoth(E_FAIL, vrc, tr("Execution of the command with UUID \"%s\" was failed"), 255 aId.toString().c_str()); 256 *aResult = CloudCommandResult_success; 257 } 258 else 259 *aResult = CloudCommandResult_failed; 260 } 261 else 262 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found or hasn't been validated yet"), 263 aId.toString().c_str()); 264 265 return hrc; 266 } 267 268 //int CloudClient::i_runCommand(CloudCommandCl &aCC, ComObjPtr<Progress> *aProgress) 269 //{ 270 // LogRel(("Enter CloudClient::i_runCommand()\n")); 271 // int vrc = aCC.mUsedAPI->callAPICommand(aCC, aProgress); 272 // return vrc; 273 //} 274 275 int CloudClient::i_runCommand(CloudCommandCl &aCC) 276 { 277 LogRel(("Enter CloudClient::i_runCommand()\n")); 278 int vrc = aCC.mUsedAPI->callAPICommand(aCC); 279 return vrc; 280 } 281 282 HRESULT CloudClient::validateCommand(const com::Guid &aId, BOOL *aValid) 283 { 284 HRESULT hrc = S_OK; 285 //check all data in the operation and set the flag 286 //this step allows easy to control which operation may be launch 287 std::map <com::Guid, CloudCommandCl*>::const_iterator cit = mCloudCommandMap.find(aId); 288 if (cit != mCloudCommandMap.end()) 289 { 290 std::map<Utf8Str, Utf8Str> paramNameValueMap; 291 int vrc = i_validateCommand(*(cit->second), paramNameValueMap, false); 292 if (RT_SUCCESS(vrc)) 293 *aValid = true; 294 else 295 { 296 *aValid = false; 297 hrc = setErrorBoth(E_FAIL, vrc, tr("The command %d not validated"), cit->second->mCommand); 298 } 299 } 300 else 301 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found"), 302 aId.toString().c_str()); 303 return hrc; 304 } 305 306 int CloudClient::i_validateCommand(CloudCommandCl &aCC, 307 const std::map<Utf8Str, Utf8Str> &aParamNameValueMap, 308 bool fWeak) 309 { 310 LogRel(("Enter CloudClient::i_validateCommand()\n")); 311 int vrc = VINF_SUCCESS; 312 // bool isSimple = false; 313 // vrc = i_isSimpleCommand(aCC, isSimple); 314 // if (!isSimple)//parameters are needed for the command 315 { 316 std::vector<com::Utf8Str> paramNames; 317 paramNames.reserve(15); 318 std::map<Utf8Str, Utf8Str> freshParamNameValueMap; 319 320 vrc = i_getCommandParameterNames(aCC, paramNames); 321 if (RT_SUCCESS(vrc)) 322 { 323 for (size_t i=0;i<paramNames.size();++i) 324 { 325 std::map <Utf8Str, Utf8Str>::const_iterator cit = aParamNameValueMap.find(paramNames.at(i)); 326 if (cit != aParamNameValueMap.end()) 327 freshParamNameValueMap.insert(make_pair(cit->first,cit->second)); 328 else 329 { 330 if (fWeak) 331 vrc = VINF_TRY_AGAIN; 332 else 333 vrc = VERR_NOT_FOUND; 334 335 break; 336 } 337 } 338 339 if (RT_SUCCESS(vrc) && vrc != VINF_TRY_AGAIN) 340 { 341 std::map <Utf8Str, Utf8Str>::const_iterator cit = freshParamNameValueMap.begin(); 342 while (cit != freshParamNameValueMap.end()) 343 { 344 //insert new parameter/value or update old one 345 aCC.mParameters[cit->first] = cit->second; 346 ++cit; 347 } 348 349 aCC.mfValid = true; 350 } 351 else 352 aCC.mfValid = false; 353 } 354 } 355 356 return vrc; 357 } 358 359 HRESULT CloudClient::checkCommandResult(const com::Guid &aId, 360 LONG64 *aStartTime, 361 LONG64 *aLastTime, 362 CloudCommandResult_T *aResult) 363 { 364 HRESULT hrc = S_OK; 365 int vrc = VINF_SUCCESS; 366 LogRel(("CloudClient::checkCommandResult: %s, %d, %d, %d\n", 367 aId.toString().c_str(), 368 *aStartTime, 369 *aLastTime, 370 aResult)); 371 std::map <com::Guid, CloudCommandCl*>::const_iterator cit = mCloudCommandMap.find(aId); 372 if (cit != mCloudCommandMap.end()) 373 { 374 CloudCommandResult_T res; 375 CloudCommandCl *cc = cit->second; 376 vrc = i_checkCommandResult(*cc, res); 377 if (RT_FAILURE(vrc)) 378 hrc = setErrorBoth(E_FAIL, vrc, tr("Coudn't get the result for command with UUID \"%s\" "), 379 aId.toString().c_str()); 380 else 381 *aResult = res; 382 } 383 else 384 { 385 vrc = VERR_NOT_FOUND; 386 if (RT_FAILURE(vrc)) 387 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with UUID \"%s\" wasn't found"), 388 aId.toString().c_str()); 389 } 390 391 return hrc; 392 } 393 394 int CloudClient::i_checkCommandResult(CloudCommandCl &aCC, 395 CloudCommandResult_T &aResult) 396 { 397 LogRel(("Enter CloudClient::i_checkCommandResult()\n")); 398 RT_NOREF(aCC, aResult); 399 int vrc = VINF_SUCCESS;//aCC.parseResult(aResult); 400 return vrc; 401 } 402 403 int CloudClient::i_parseResponse(CloudCommandCl &aCC) 404 { 405 LogRel(("Enter CloudClient::i_parseResponse()\n")); 406 int vrc = VINF_SUCCESS; 407 //create DataModel here and fill it from the response data 408 DataParser *dp = NULL; 409 vrc = aCC.createDataParser(&dp); 410 if (RT_SUCCESS(vrc)) 411 vrc = dp->parseData(aCC); 412 //////////////////////////////// 413 //maybe partially work with data here 414 //////////////////////////////// 415 416 delete dp; 417 418 return vrc; 419 } 420 421 int CloudClient::i_getCommandById(const com::Guid &aId, CloudCommandCl **aCC) 422 { 423 int vrc = VINF_SUCCESS; 424 std::map <com::Guid, CloudCommandCl*>::iterator cit = mCloudCommandMap.find(aId); 425 if (cit != mCloudCommandMap.end()) 426 { 427 *aCC = cit->second; 428 // CloudCommandCl * lCC = cit->second->copy(); 429 // aCC = *lCC; 430 } 431 else 432 vrc = VERR_NOT_FOUND; 433 434 return vrc; 435 } 436 437 HRESULT CloudClient::getCommandParameterNames(CloudCommand_T aCloudCommand, 438 std::vector<com::Utf8Str> &aParameterNames) 439 { 440 LogRel(("CloudClient::getCommandParameterNames()\n")); 441 RT_NOREF(aCloudCommand, aParameterNames); 442 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 443 return hrc; 444 } 445 446 HRESULT CloudClient::getCommandParameterProperties(const com::Utf8Str &aParameterName, 447 com::Utf8Str &aParameterType, 448 com::Utf8Str &aParameterDesc, 449 std::vector<com::Utf8Str> &aParameterValues) 450 { 451 LogRel(("CloudClient::getCommandParameterProperties()\n")); 452 RT_NOREF(aParameterName, aParameterType, aParameterDesc, aParameterValues); 453 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 454 return hrc; 455 } 456 457 HRESULT CloudClient::getCommandParameters(CloudCommand_T aCloudCommand, com::Utf8Str &aJsonString) 458 { 459 LogRel(("CloudClient::getCommandParameters()\n")); 460 RT_NOREF(aCloudCommand, aJsonString); 461 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 462 return hrc; 463 } 464 465 HRESULT CloudClient::setCommandParameters(const com::Guid &aId, 466 const std::vector<com::Utf8Str> &aNames, 467 const std::vector<com::Utf8Str> &aValues) 468 { 469 HRESULT hrc = S_OK; 470 std::vector<com::Utf8Str> parameterNames; 471 std::map <com::Guid, CloudCommandCl*>::iterator it = mCloudCommandMap.find(aId); 472 if (it !=mCloudCommandMap.end()) 473 { 474 hrc = getCommandParameterNames(it->second->mCommand, parameterNames); 475 std::vector<com::Utf8Str>::const_iterator cit = aNames.begin(); 476 for (size_t i=0 ; i<aNames.size() && i<aValues.size(); ++i) 477 { 478 std::vector<com::Utf8Str>::iterator fit = find(parameterNames.begin(), parameterNames.end(), *cit); 479 if (fit != parameterNames.end()) 480 { 481 it->second->mParameters[aNames[i]] = aValues[i]; 482 } 483 } 484 } 485 return hrc; 486 } 487 488 HRESULT CloudClient::getCommandsForOperation(CloudOperation_T aCloudOperation, 489 BOOL aPrep, 490 std::vector<CloudCommand_T> &aCloudCommands) 491 { 492 LogRel(("CloudClient::getCommandsforOperation()\n")); 493 RT_NOREF(aCloudOperation, aPrep, aCloudCommands); 494 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 495 return hrc; 496 } 497 498 HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString) 499 { 500 LogRel(("CloudClient::getOperationParameters()\n")); 501 RT_NOREF(aCloudOperation, aJsonString); 502 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 503 return hrc; 504 } 505 506 int CloudClient::i_getCommandParameterNames(const CloudCommandCl &aCC, 507 std::vector<com::Utf8Str> &aParameterNames) 508 { 509 LogRel(("Enter CloudClient::i_getCommandParameterNames()\n")); 510 int vrc = VINF_SUCCESS; 511 std::vector<com::Utf8Str> localParameterNames; 512 localParameterNames.reserve(20); 513 vrc = aCC.getParameterNames(localParameterNames); 514 // vrc = aCC.mUsedAPI->getCommandParameterNames(&aCC, aParameterNames); 515 if (RT_FAILURE(vrc)) 516 vrc = VERR_NOT_FOUND; 517 else 518 { 519 size_t vecSize = localParameterNames.size(); 520 for (size_t i=0;i<vecSize;++i) 521 { 522 aParameterNames.push_back(localParameterNames.at(i)); 523 } 524 } 525 return vrc; 526 } 527 528 int CloudClient::i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple) 529 { 530 LogRel(("CloudClient::i_isSimpleCommand()\n")); 531 RT_NOREF(aCC, fSimple); 532 return VERR_NOT_IMPLEMENTED; 533 } 534 535 //int CloudClient::i_findCommandById(const com::Guid &aId, CloudCommandCl &res) 536 //{ 537 // HRESULT hrc = S_OK; 538 // std::map <com::Guid, CloudCommandCl*>::const_iterator it = mCloudCommandMap.find(aId); 539 // if (it !=mCloudCommandMap.end()) 540 // res = *(it->second); 541 // else 542 // hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Could not find the command object")); 543 // return hrc; 544 //} 545 546 int CloudClient::i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI** apiObj) 547 { 548 LogRel(("CloudClient::queryAPIForCommand()\n")); 549 RT_NOREF(aCommand, apiObj); 550 return VERR_NOT_IMPLEMENTED; 551 } 552 553 HRESULT CloudClient::i_getSupportedAPIs(std::list<Utf8Str> &apiNames) 554 { 555 LogRel(("CloudClient::getSupportedAPIs()\n")); 556 RT_NOREF(apiNames); 557 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 558 return hrc; 559 } 560 561 HRESULT CloudClient::i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj) 562 { 563 LogRel(("CloudClient::queryAPI()\n")); 564 RT_NOREF(apiName, apiObj); 565 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 566 return hrc; 567 } 568 569 570 int CloudClient::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName) 571 { 572 LogRel(("CloudClient::i_queryAPINameForCommand()\n")); 573 RT_NOREF(aCommand, apiName); 574 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 575 return hrc; 576 } 577 578 HRESULT CloudClient::i_setUpProgress(ComObjPtr<Progress> &pProgress, 579 const Utf8Str &strDescription, 580 ULONG aOperations) 581 { 582 HRESULT hrc; 583 584 /* Create the progress object */ 585 pProgress.createObject(); 586 587 ULONG ulTotalOperationsWeight = 100; 588 ULONG ulFirstOperationWeight = ulTotalOperationsWeight/aOperations; 589 hrc = pProgress->init(mParent, static_cast<ICloudClient*>(this), 590 Bstr(strDescription).raw(), 591 TRUE /* aCancelable */, 592 aOperations, 593 ulTotalOperationsWeight, 594 Bstr(strDescription).raw(), 595 ulFirstOperationWeight); 596 return hrc; 597 } 598 599 //////////////////////////////////////////////////////////////////////////////// 600 // 601 // CloudClientOCI implementation 602 // 603 //////////////////////////////////////////////////////////////////////////////// 604 605 CloudClientOCI::CloudClientOCI() 606 { 607 LogRel(("CloudClientOCI::CloudClientOCI()\n")); 608 } 609 610 CloudClientOCI::~CloudClientOCI() 611 { 612 LogRel(("CloudClientOCI::~CloudClientOCI()\n")); 613 } 614 615 HRESULT CloudClientOCI::initCloudClient(CloudUserProfiles *aProfiles, 616 VirtualBox *aParent, 617 CloudProviderId_T aCloudProvider, 618 const com::Utf8Str &aProfileName) 619 { 620 HRESULT hrc = S_OK; 621 try 622 { 623 hrc = CloudClient::initCloudClient(aProfiles, aParent, aCloudProvider, aProfileName); 624 if (SUCCEEDED(hrc)) 625 { 626 std::list<Utf8Str> apiNames; 627 i_getSupportedAPIs(apiNames); 628 std::list<Utf8Str>::const_iterator cit = apiNames.begin(); 629 while (cit!=apiNames.end()) 630 { 631 mCloudAPIInstanceMap[*cit] = NULL; 632 ++cit; 633 } 634 } 635 } 636 catch (HRESULT arc) 637 { 638 hrc = arc; 639 LogRel(("Get cought an exception %d\n", hrc)); 640 } 641 642 return hrc; 643 } 644 645 HRESULT CloudClientOCI::getCommandsForOperation(CloudOperation_T aCloudOperation, 646 BOOL aPrep, 647 std::vector<CloudCommand_T> &aCloudCommands) 648 { 649 HRESULT hrc = S_OK; 650 if (aCloudOperation == CloudOperation_exportVM) 651 { 652 if (aPrep) 653 { 654 aCloudCommands.push_back(CloudCommand_listAvailabilityDomains); 655 aCloudCommands.push_back(CloudCommand_listShapes); 656 aCloudCommands.push_back(CloudCommand_getNamespace); 657 aCloudCommands.push_back(CloudCommand_listBuckets); 658 aCloudCommands.push_back(CloudCommand_listNetworks); 659 } 660 else 661 { 662 aCloudCommands.push_back(CloudCommand_uploadFile); 663 aCloudCommands.push_back(CloudCommand_importImage); 664 aCloudCommands.push_back(CloudCommand_launchInstance); 665 } 666 } 667 668 return hrc; 669 } 670 671 int CloudClientOCI::i_isSimpleCommand(const CloudCommandCl &aCC, bool &fSimple) 672 { 673 int vrc = S_OK; 674 bool res = false; 675 std::vector<com::Utf8Str> paramNames; 676 HRESULT hrc = getCommandParameterNames(aCC.mCommand, paramNames); 677 if (SUCCEEDED(hrc)) 678 { 679 if (paramNames.empty()) 680 res = true; 681 } 682 else 683 vrc = VERR_NOT_FOUND; 684 685 fSimple = res; 686 687 return vrc; 688 } 689 690 int CloudClientOCI::i_queryAPIForCommand(CloudCommand_T aCommand, CloudAPI **apiObj) 691 { 692 int vrc = VINF_SUCCESS; 693 CloudAPI *newCloudAPI = NULL; 694 695 try 696 { 697 switch (aCommand) 698 { 699 case CloudCommand_createInstance: 700 case CloudCommand_launchInstance: 701 case CloudCommand_pauseInstance: 702 case CloudCommand_stopInstance: 703 case CloudCommand_deleteInstance: 704 case CloudCommand_getInstanceProperties: 705 case CloudCommand_listInstances: 706 case CloudCommand_listShapes: 707 case CloudCommand_listNetworks: 708 case CloudCommand_importImage: 709 newCloudAPI = new OCICompute(); 710 break; 711 case CloudCommand_uploadFile: 712 case CloudCommand_downloadObject: 713 case CloudCommand_deleteObject: 714 case CloudCommand_getObjectProperties: 715 case CloudCommand_listObjects: 716 case CloudCommand_listBuckets: 717 case CloudCommand_getNamespace: 718 newCloudAPI = new OCIObjectStorage(); 719 break; 720 case CloudCommand_listRegions: 721 case CloudCommand_listCompartments: 722 case CloudCommand_listAvailabilityDomains: 723 newCloudAPI = new OCIIAM(); 724 case CloudCommand_Unknown: 725 default: 726 break; 727 } 728 } 729 catch (int arc) 730 { 731 vrc = arc; 732 LogRel(("Get cought an exception %d\n", vrc)); 733 } 734 735 *apiObj = newCloudAPI; 736 return vrc; 737 } 738 739 HRESULT CloudClientOCI::i_getSupportedAPIs(std::list<Utf8Str> &apiNames) 740 { 741 HRESULT hrc = S_OK; 742 apiNames.push_back("compute"); 743 apiNames.push_back("object storage"); 744 apiNames.push_back("iam"); 745 return hrc; 746 } 747 748 HRESULT CloudClientOCI::i_queryAPI(const Utf8Str &apiName, CloudAPI **apiObj) 749 { 750 HRESULT hrc = S_OK; 751 CloudAPI *newCloudAPI = NULL; 752 try 753 { 754 if (apiName == "compute") 755 newCloudAPI = new OCICompute(); 756 else if (apiName == "object storage") 757 newCloudAPI = new OCIObjectStorage(); 758 else if (apiName == "iam") 759 newCloudAPI = new OCIIAM(); 760 } 761 catch (HRESULT arc) 762 { 763 hrc = arc; 764 LogRel(("Get cought an exception %d\n", hrc)); 765 } 766 767 *apiObj = newCloudAPI; 768 return hrc; 769 } 770 771 int CloudClientOCI::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName) 772 { 773 int vrc = VINF_SUCCESS; 774 switch (aCommand) 775 { 776 case CloudCommand_createInstance: 777 case CloudCommand_launchInstance: 778 case CloudCommand_pauseInstance: 779 case CloudCommand_stopInstance: 780 case CloudCommand_deleteInstance: 781 case CloudCommand_getInstanceProperties: 782 case CloudCommand_listInstances: 783 case CloudCommand_listShapes: 784 case CloudCommand_listNetworks: 785 case CloudCommand_importImage: 786 apiName = "compute"; 787 break; 788 case CloudCommand_uploadFile: 789 case CloudCommand_downloadObject: 790 case CloudCommand_deleteObject: 791 case CloudCommand_getObjectProperties: 792 case CloudCommand_listObjects: 793 case CloudCommand_listBuckets: 794 case CloudCommand_getNamespace: 795 apiName = "object storage"; 796 break; 797 case CloudCommand_listRegions: 798 case CloudCommand_listCompartments: 799 case CloudCommand_listAvailabilityDomains: 800 apiName = "iam"; 801 break; 802 case CloudOperation_Unknown: 803 default: 804 vrc = VERR_NOT_IMPLEMENTED; 805 break; 806 } 807 808 return vrc; 809 } 810 811 HRESULT CloudClientOCI::getCommandParameterNames(CloudCommand_T aCloudCommand, 812 std::vector<com::Utf8Str> &aParameterNames) 813 { 814 RT_NOREF(aCloudCommand, aParameterNames); 815 HRESULT hrc = S_OK; 816 // switch (aCloudCommand) 817 // { 818 // case CloudCommand_createInstance: 819 // case CloudCommand_launchInstance: 820 // aParameterNames.push_back(paramsNames[0]); 821 // aParameterNames.push_back(paramsNames[1]); 822 // aParameterNames.push_back(paramsNames[2]); 823 // aParameterNames.push_back(paramsNames[3]); 824 // aParameterNames.push_back(paramsNames[4]); 825 // aParameterNames.push_back(paramsNames[5]); 826 // aParameterNames.push_back(paramsNames[6]); 827 // break; 828 // case CloudCommand_pauseInstance: 829 // case CloudCommand_stopInstance: 830 // case CloudCommand_deleteInstance: 831 // case CloudCommand_getInstanceProperties: 832 // aParameterNames.push_back(paramsNames[7]); 833 // break; 834 // //only compartment Id is needed 835 // case CloudCommand_listInstances: 836 // case CloudCommand_listRegions: 837 // case CloudCommand_listShapes: 838 // case CloudCommand_listNetworks: 839 // case CloudCommand_listBuckets: 840 // break; 841 // case CloudCommand_importImage: 842 // aParameterNames.push_back(paramsNames[8]); 843 // break; 844 // case CloudCommand_uploadFile: 845 // aParameterNames.push_back(paramsNames[9]); 846 // aParameterNames.push_back(paramsNames[3]); 847 // break; 848 // case CloudCommand_downloadObject: 849 // case CloudCommand_deleteObject: 850 // case CloudCommand_getObjectProperties: 851 // aParameterNames.push_back(paramsNames[10]); 852 // aParameterNames.push_back(paramsNames[3]); 853 // break; 854 // case CloudCommand_listObjects: 855 // aParameterNames.push_back(paramsNames[3]); 856 // break; 857 // case CloudCommand_Unknown: 858 // default: 859 // hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Unknown cloud command %d"), aCloudCommand); 860 // break; 861 // } 862 863 return hrc; 864 } 865 866 HRESULT CloudClientOCI::getCommandParameters(CloudCommand_T aCloudCommand, com::Utf8Str &aJsonString) 867 { 868 LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudCommand)); 869 RT_NOREF(aJsonString); 870 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 871 return hrc; 872 } 365 873 366 874 static Utf8Str strExportParametersToOCI = "{\n" … … 412 920 "}"; 413 921 414 HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString) 415 { 416 LogRel(("CloudClientOCI::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str())); 922 static const char* listAvDomain = "[\n" 923 "\t{\n" 924 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 925 "\t\t\"name\": \"ergw:US-ASHBURN-AD-1\"\n" 926 "\t},\n" 927 "\t{\n" 928 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 929 "\t\t\"name\": \"ergw:US-ASHBURN-AD-2\"\n" 930 "\t},\n" 931 "\t{\n" 932 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 933 "\t\t\"name\": \"ergw:US-ASHBURN-AD-3\"\n" 934 "\t}\n" 935 "]\n"; 936 937 static Utf8Str strListAvDomain(listAvDomain); 938 939 static const char* listShape = "[\n" 940 "\t{\n" 941 "\t\t\"shape\": \"VM.Standard1.1\"\n" 942 "\t},\n" 943 "\t{\n" 944 "\t\t\"shape\": \"VM.Standard1.2\"\n" 945 "\t},\n" 946 "\t{\n" 947 "\t\t\"shape\": \"VM.Standard1.4\"\n" 948 "\t},\n" 949 "\t{\n" 950 "\t\t\"shape\": \"VM.Standard1.8\"\n" 951 "\t},\n" 952 "\t{\n" 953 "\t\t\"shape\": \"VM.Standard1.16\"\n" 954 "\t}\n" 955 "]\n"; 956 957 static Utf8Str strListShape(listShape); 958 959 static const char* namespaceName = "{\n" 960 "\t\"ovm\"\n" 961 "}\n"; 962 963 static Utf8Str strNamespaceName(namespaceName); 964 965 static const char* listBucket = "[\n" 966 "\t{\n" 967 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 968 "\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaa73t54ewmkiti4i4bmsxyjfwgiujhuf4hnhkvipgmmukkgextxujq\",\n" 969 "\t\t\"definedTags\": null,\n" 970 "\t\t\"etag\": \"06262c11-a6b3-44a1-9ccd-6d062dcf73cb\",\n" 971 "\t\t\"freeformTags\": null,\n" 972 "\t\t\"name\": \"temporarly-bucket-python-ubuntu-14-x64-server\",\n" 973 "\t\t\"namespace\": \"ovm\",\n" 974 "\t\t\"timeCreated\": \"2018-05-15T11:23:05.653000+00:00\"\n" 975 "\t},\n" 976 "\t{\n" 977 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 978 "\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaa73t54ewmkiti4i4bmsxyjfwgiujhuf4hnhkvipgmmukkgextxujq\",\n" 979 "\t\t\"definedTags\": null,\n" 980 "\t\t\"etag\": \"036be210-3021-4598-b707-c82e5c5cfa08\",\n" 981 "\t\t\"freeformTags\": null,\n" 982 "\t\t\"name\": \"temporarly-bucket-python-un-ubuntu\",\n" 983 "\t\t\"namespace\": \"ovm\",\n" 984 "\t\t\"timeCreated\": \"2018-05-10T12:30:40.376000+00:00\"\n" 985 "\t},\n" 986 "\t{\n" 987 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 988 "\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaas2vfq7jfhct4dto4uk5myhripw5cdvnz4ddgu44buv4fcxgafhhq\",\n" 989 "\t\t\"definedTags\": null,\n" 990 "\t\t\"etag\": \"b7c9f373-36be-4228-b505-0a46f07b4c41\",\n" 991 "\t\t\"freeformTags\": null,\n" 992 "\t\t\"name\": \"test_cpp_bucket\",\n" 993 "\t\t\"namespace\": \"ovm\",\n" 994 "\t\t\"timeCreated\": \"2018-07-18T15:04:31.285000+00:00\"\n" 995 "\t},\n" 996 "\t{\n" 997 "\t\t\"compartmentId\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 998 "\t\t\"createdBy\": \"ocid1.user.oc1..aaaaaaaat47uhcg5ucbznrknalr2ta2s35flxbpfwly74rzp2ivj3fd4sy3a\",\n" 999 "\t\t\"definedTags\": null,\n" 1000 "\t\t\"etag\": \"5a4477d9-8fc4-401f-994e-0e940b1dfb84\",\n" 1001 "\t\t\"freeformTags\": null,\n" 1002 "\t\t\"name\": \"vbox_test_bucket_1\",\n" 1003 "\t\t\"namespace\": \"ovm\",\n" 1004 "\t\t\"timeCreated\": \"2018-05-04T17:56:20.222000+00:00\"\n" 1005 "\t}\n" 1006 "]\n"; 1007 1008 static Utf8Str strListBucket(listBucket); 1009 1010 static const char* listVcn = "[\n" 1011 "\t{\n" 1012 "\t\t\"cidr-block\": \"192.168.0.0/24\",\n" 1013 "\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 1014 "\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaadubfpdssid2f3iewwnq2e2iudguqx4vnn5uivlvwp3uuoydxgq4q\",\n" 1015 "\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaajiksnjaqmrzqy2dfiijyxny4qnk65hyfr72cuulaeteis363w5lq\",\n" 1016 "\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaagzuwh3lxnbhmnl6wtuycynwoxoekl62fttg4tqvwh7apfbuedixq\",\n" 1017 "\t\t\"defined-tags\": {},\n" 1018 "\t\t\"display-name\": \"vcn-scoter\",\n" 1019 "\t\t\"dns-label\": \"vcnscoter\",\n" 1020 "\t\t\"freeform-tags\": {},\n" 1021 "\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaayytm3gse3cr7wqq56zjatcak2wk4prb26sh3s3egkz2azknc5d6q\",\n" 1022 "\t\t\"lifecycle-state\": \"AVAILABLE\",\n" 1023 "\t\t\"time-created\": \"2018-06-14T16:29:52.788000+00:00\",\n" 1024 "\t\t\"vcn-domain-name\": \"vcnscoter.oraclevcn.com\"\n" 1025 "\t},\n" 1026 "\t{\n" 1027 "\t\t\"cidr-block\": \"10.8.0.0/16\",\n" 1028 "\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 1029 "\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaasqjcnaqo2f7wgovvnnajgrcfinnoifqt3wc2xc5rdd76yqn3pp3q\",\n" 1030 "\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaavzwgctg35rfqr44st5d7endapdyelnndbo6nul63i4qec7ptdjna\",\n" 1031 "\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaasb5al7waxkyb4rmuky3qwym2sb4ctpphqzxbigh6e2rkfj5zgxqq\",\n" 1032 "\t\t\"defined-tags\": {},\n" 1033 "\t\t\"display-name\": \"vcn_spider\",\n" 1034 "\t\t\"dns-label\": \"vcnspider\",\n" 1035 "\t\t\"freeform-tags\": {},\n" 1036 "\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaa4mhghya6ztii7par7v2o3v2il5nbbbx32benobjv3wlcs2ekpyaq\",\n" 1037 "\t\t\"lifecycle-state\": \"AVAILABLE\",\n" 1038 "\t\t\"time-created\": \"2018-06-07T14:46:10.855000+00:00\",\n" 1039 "\t\t\"vcn-domain-name\": \"vcnspider.oraclevcn.com\"\n" 1040 "\t},\n" 1041 "\t{\n" 1042 "\t\t\"cidr-block\": \"10.0.0.0/16\",\n" 1043 "\t\t\"compartment-id\": \"ocid1.compartment.oc1..aaaaaaaap4ma65zj4xgaqpg35jrousfazylikmrsvm3lbzfvjwqbwdme3hlq\",\n" 1044 "\t\t\"default-dhcp-options-id\": \"ocid1.dhcpoptions.oc1.iad.aaaaaaaao5tkhev2vqvpyzrpvzwiqbxz6w4kolcfdoo57xxktehv3qpv6hza\",\n" 1045 "\t\t\"default-route-table-id\": \"ocid1.routetable.oc1.iad.aaaaaaaantab6kld6b2wcxgv5rs5abmg4tmd5ok274emejfnofl744pignva\",\n" 1046 "\t\t\"default-security-list-id\": \"ocid1.securitylist.oc1.iad.aaaaaaaashi4gkt35wyfwozh5vsbxi4e76leca27xkgun42n4aorgg5qtfuq\",\n" 1047 "\t\t\"defined-tags\": {},\n" 1048 "\t\t\"display-name\": \"vcn20180510154500\",\n" 1049 "\t\t\"dns-label\": \"vcn0510154459\",\n" 1050 "\t\t\"freeform-tags\": {},\n" 1051 "\t\t\"id\": \"ocid1.vcn.oc1.iad.aaaaaaaaaxetjzokkuahch46aglb4peltzto67tihc73mmako6o2ct4yk75a\",\n" 1052 "\t\t\"lifecycle-state\": \"AVAILABLE\",\n" 1053 "\t\t\"time-created\": \"2018-05-10T15:45:00.579000+00:00\",\n" 1054 "\t\t\"vcn-domain-name\": \"vcn0510154459.oraclevcn.com\"\n" 1055 "\t}\n" 1056 "]\n"; 1057 1058 static Utf8Str strListVcn(listVcn); 1059 1060 //HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString) 1061 //{ 1062 // LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudOperation)); 1063 // HRESULT hrc = S_OK; 1064 // if (aCloudOperation == CloudOperation_exportVM) 1065 // aJsonString = strExportParametersToOCI; 1066 // else 1067 // hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 1068 // return hrc; 1069 //} 1070 1071 HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, 1072 com::Utf8Str &aJsonString) 1073 // ComPtr<IProgress> &aProgress) 1074 { 1075 LogRel(("CloudClientOCI::getOperationParameters: %d\n", aCloudOperation)); 1076 RT_NOREF(aJsonString); 417 1077 HRESULT hrc = S_OK; 418 if (aCloudOperation == CloudOperation_exportVM) 419 aJsonString = strExportParametersToOCI; 420 else 421 hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 422 return hrc; 423 } 424 425 HRESULT CloudClientOCI::createOperation(const com::Utf8Str &aProfileName, 426 CloudOperation_T aCloudOperation, 427 com::Guid &aOpId) 428 { 429 LogRel(("CloudClientOCI::createOperation: %s, %d, %s\n", aProfileName.c_str(), 430 aCloudOperation, 431 aOpId.toString().c_str())); 432 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 433 return hrc; 434 } 435 436 HRESULT CloudClientOCI::runOperation(const com::Guid &aOpId, 437 LONG64 aTimeout) 438 { 439 LogRel(("CloudClientOCI::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout)); 440 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 441 return hrc; 442 } 443 444 HRESULT CloudClientOCI::checkOperationResult(const com::Guid &aOpId, 445 LONG64 *aStartOpTime, 446 LONG64 *aLastTime, 447 CloudOperationResult_T *aResult) 448 { 449 LogRel(("CloudClientOCI::checkOperationResult: %s, %d, %d, %d\n", 450 aOpId.toString().c_str(), 451 *aStartOpTime, 452 *aLastTime, 453 *aResult)); 454 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 455 return hrc; 456 } 457 458 HRESULT CloudClientOCI::getOperationParameterNames(CloudOperation_T aCloudOperation, 459 std::vector<com::Utf8Str> &aParameterNames) 460 { 461 LogRel(("CloudClientOCI::getOperationParameterNames: %d\n", aCloudOperation)); 462 aParameterNames.clear(); 463 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 464 return hrc; 465 } 466 467 HRESULT CloudClientOCI::getOperationParameterProperties(const com::Utf8Str &aOpParameterName, 468 com::Utf8Str &aOpParameterType, 469 com::Utf8Str &aOpParameterDesc, 470 std::vector<com::Utf8Str> &aOpParameterValues) 471 { 472 LogRel(("CloudClientOCI::getOperationParameterProperties: %s, %s, %s\n", 473 aOpParameterName.c_str(), 474 aOpParameterType.c_str(), 475 aOpParameterDesc.c_str())); 476 aOpParameterValues.clear(); 477 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 478 return hrc; 479 } 480 481 HRESULT CloudClientOCI::setParametersForOperation(const com::Guid &aOpId, 482 const std::vector<com::Utf8Str> &aValues) 483 { 484 LogRel(("CloudClientOCI::setParametersForOperation: %s\n", aOpId.toString().c_str())); 485 for (size_t i=0;i<aValues.size();++i) 486 { 487 LogRel(("value %d: %s\n", i, aValues.at(i).c_str())); 488 } 489 490 HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 491 return hrc; 492 } 493 1078 int vrc = VINF_SUCCESS; 1079 1080 std::vector<CloudCommand_T> commandList; 1081 hrc = getCommandsForOperation(aCloudOperation, true, commandList); 1082 if (FAILED(hrc)) 1083 return setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Commands not found")); 1084 1085 com::Guid firstCommandId; 1086 std::vector<com::Guid> commandIDs; 1087 for (size_t i=0;i<commandList.size();++i) 1088 { 1089 com::Guid cId; 1090 vrc = i_createCommand(commandList[i], cId); 1091 if (RT_SUCCESS(vrc)) 1092 { 1093 1094 //remember first command Id for getting the command description for Progress 1095 if (i==0) 1096 firstCommandId = cId; 1097 1098 commandIDs.push_back(cId); 1099 LogRel(("Command %d have got UUID %s\n", commandList[i], cId.toString().c_str())); 1100 } 1101 else 1102 { 1103 setErrorBoth(E_FAIL, vrc, tr("Creation of command %d failed."), commandList[i]); 1104 break; 1105 } 1106 } 1107 1108 if (FAILED(hrc)) 1109 return hrc; 1110 1111 std::map<Utf8Str, Utf8Str> paramNameValueMap; 1112 1113 //Setup Progress object here 1114 ComObjPtr<Progress> progress; 1115 ComPtr<IProgress> aProgress; 1116 { 1117 CloudCommandCl *cc = NULL; 1118 vrc = i_getCommandById(firstCommandId, &cc); 1119 if (RT_SUCCESS(vrc)) 1120 { 1121 paramNameValueMap = cc->mParameters; 1122 Utf8Str strDesc = cc->getDescription(); 1123 hrc = i_setUpProgress(progress, strDesc, (ULONG)commandList.size()); 1124 if (SUCCEEDED(hrc)) 1125 /* Return progress to the caller */ 1126 progress.queryInterfaceTo(aProgress.asOutParam()); 1127 } 1128 else 1129 hrc = setErrorBoth(E_FAIL, VERR_NOT_FOUND, tr("Command with Id %s not found"), firstCommandId.toString().c_str()); 1130 } 1131 1132 if (FAILED(hrc)) 1133 return hrc; 1134 1135 //stores the last command successful response 1136 std::vector<DataModel*> dm; 1137 std::map<Utf8Str, Utf8Str> summaryInfo; 1138 com::Guid lastCommandId; 1139 1140 /* 1141 * STRONG prerequisity: First command MUST BE validated always. 1142 * It means that all needed parameters must be correct or 1143 * the command hasn't any parameters. 1144 */ 1145 bool fWeakValidation = false;//validation has two tries, but for the first command there is only one try 1146 1147 for (size_t i=0;i<commandIDs.size();++i) 1148 { 1149 CloudCommandCl *cc = NULL; 1150 vrc = i_getCommandById(commandIDs.at(i), &cc); 1151 if (RT_SUCCESS(vrc) && cc!=NULL) 1152 { 1153 vrc = i_validateCommand(*cc, paramNameValueMap, fWeakValidation); 1154 if (RT_SUCCESS(vrc) && vrc != VINF_TRY_AGAIN) 1155 { 1156 // vrc = i_runCommand(*cc, progress);//<---Progress must be passed here 1157 vrc = i_runCommand(*cc); 1158 1159 CloudCommandResult_T commResult = CloudCommandResult_success; 1160 if (RT_SUCCESS(vrc)) 1161 { 1162 if (true) 1163 { 1164 switch (cc->mCommand) 1165 { 1166 case CloudCommand_getNamespace: 1167 cc->mResponse.mRaw = strNamespaceName; 1168 break; 1169 case CloudCommand_listAvailabilityDomains: 1170 cc->mResponse.mRaw = strListAvDomain; 1171 break; 1172 case CloudCommand_listNetworks: 1173 cc->mResponse.mRaw = strListVcn; 1174 break; 1175 case CloudCommand_listShapes: 1176 cc->mResponse.mRaw = strListShape; 1177 break; 1178 case CloudCommand_listBuckets: 1179 cc->mResponse.mRaw = strListBucket; 1180 break; 1181 default: 1182 break; 1183 } 1184 } 1185 // vrc = i_checkCommandResult(*cc, commResult); 1186 // if (RT_SUCCESS(vrc)) 1187 { 1188 vrc = i_parseResponse(*cc); 1189 // dm = cc->getData(); 1190 // summaryInfo = cc->getSummary(); 1191 lastCommandId = commandIDs.at(i);//remember the last command Id 1192 fWeakValidation = true;//restore weak validation for the next command 1193 } 1194 } 1195 else 1196 { 1197 hrc = setError(E_FAIL, tr("The call of command %d was unsuccessful"), cc->mCommand); 1198 } 1199 LogRel(("Command %d result is %d\n", commandList[i], commResult)); 1200 } 1201 else 1202 { 1203 if (RT_FAILURE(vrc)) 1204 { 1205 hrc = setErrorBoth(E_FAIL, vrc, tr("Command %d wasn't validated"), commandList[i]); 1206 break; 1207 } 1208 1209 if (vrc == VINF_TRY_AGAIN) 1210 { 1211 LogRel(("Command %d hasn't been validated yet.\n", commandList[i])); 1212 //try to find and extract needed parameters from the last executed command response 1213 //convert summaryInfo into paramNameValueMap (extract from summaryInfo and convert it) 1214 std::vector<com::Utf8Str> paramNames; 1215 1216 vrc = i_getCommandParameterNames(*cc, paramNames); 1217 if (RT_SUCCESS(vrc)) 1218 { 1219 CloudCommandCl *lastCC = NULL; 1220 if (lastCommandId.isValid()) 1221 { 1222 vrc = i_getCommandById(lastCommandId, &lastCC); 1223 if (RT_SUCCESS(vrc) && lastCC!=NULL) 1224 { 1225 for (size_t j=0;j<paramNames.size();++j) 1226 { 1227 Utf8Str strValue; 1228 vrc = lastCC->findParameter(paramNames.at(j), strValue); 1229 if (RT_SUCCESS(vrc)) 1230 paramNameValueMap.insert(make_pair(paramNames.at(j), strValue)); 1231 else 1232 { 1233 hrc = setErrorBoth(E_FAIL, vrc, 1234 tr("Command %d wasn't validated"), 1235 commandList[j]); 1236 break; 1237 } 1238 } 1239 } 1240 else 1241 hrc = setErrorBoth(E_FAIL, vrc, 1242 tr("Couldn't find command with Id \"%s\""), 1243 lastCommandId.toString().c_str()); 1244 } 1245 else 1246 { 1247 vrc = VERR_INVALID_UUID_FORMAT; 1248 hrc = setErrorBoth(E_FAIL, vrc, tr("Invalid UUID for the command %d "), commandList[i]); 1249 } 1250 } 1251 else 1252 hrc = setErrorBoth(E_FAIL, vrc, tr("Couldn't find command parameter names")); 1253 1254 if (RT_FAILURE(vrc)) 1255 { 1256 LogRel(("Command %d hasn't been validated twice. Can't continue.\n", commandList[i])); 1257 break; 1258 } 1259 1260 /* 1261 * Set validation to "Strong" 1262 * and try to validate the command one more time 1263 */ 1264 { 1265 fWeakValidation = false; 1266 --i; 1267 } 1268 } 1269 } 1270 } 1271 } 1272 1273 return hrc; 1274 } 1275 1276 //////////////////////////////////////////////////////////////////////////////// 1277 // 1278 // CloudClientGCP implementation 1279 // 1280 //////////////////////////////////////////////////////////////////////////////// 1281 //HRESULT CloudClientGCP::i_getSupportedAPIs(std::list<Utf8Str> &apiNames) 1282 //{ 1283 // HRESULT hrc = S_OK; 1284 // apiNames.push_back("compute"); 1285 // apiNames.push_back("storage"); 1286 // return hrc; 1287 //} 1288 // 1289 //HRESULT CloudClientGCP::i_queryAPI(const Utf8Str &apiName, CloudAPI* apiObj) 1290 //{ 1291 // HRESULT hrc = S_OK; 1292 // try 1293 // { 1294 // CloudAPI *newCloudAPI = NULL; 1295 // if (APIName == "compute") 1296 // newCloudAPI = new GCPCompute(); 1297 // else if (APIName == "storage") 1298 // newCloudAPI = new GCPStorage(); 1299 // apiObj = newCloudAPI; 1300 // } 1301 // catch (HRESULT arc) 1302 // { 1303 // hrc = arc; 1304 // LogRel(("Get cought an exception %d\n", hrc)); 1305 // } 1306 // 1307 // return hrc; 1308 //} 1309 // 1310 //HRESULT CloudClientGCP::i_queryAPINameForCommand(CloudCommand_T aCommand, Utf8Str &apiName) 1311 //{ 1312 // LogRel(("CloudClientGCP::queryAPINameForCommand: %d, %s\n", aCommand, apiName.c_str())); 1313 // HRESULT hrc = setErrorBoth(E_FAIL, VERR_NOT_IMPLEMENTED, tr("Not implemented")); 1314 // return hrc; 1315 //} 1316
Note:
See TracChangeset
for help on using the changeset viewer.