VirtualBox

source: vbox/trunk/src/VBox/Main/src-server/CloudClientImpl.cpp@ 73321

Last change on this file since 73321 was 73321, checked in by vboxsync, 7 years ago

Main: bugref:9152: A bit of fixes for hardcoded json string to improve NLS translation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.1 KB
Line 
1/* $Id: CloudClientImpl.cpp 73321 2018-07-23 13:49:09Z vboxsync $*/
2/** @file
3 * ICloudClient COM class implementations.
4 */
5
6/*
7 * Copyright (C) 2008-2018 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19#include <iprt/path.h>
20#include <iprt/cpp/utils.h>
21#include <VBox/com/array.h>
22#include <map>
23
24#include "CloudClientImpl.h"
25#include "CloudUserProfileManagerImpl.h"
26#include "CloudUserProfileListImpl.h"
27#include "VirtualBoxImpl.h"
28#include "Global.h"
29#include "ProgressImpl.h"
30#include "MachineImpl.h"
31#include "AutoCaller.h"
32#include "Logging.h"
33
34using namespace std;
35
36
37////////////////////////////////////////////////////////////////////////////////
38//
39// CloudClient constructor / destructor
40//
41// ////////////////////////////////////////////////////////////////////////////////
42CloudClient::CloudClient()
43 : mParent(NULL)
44{
45 LogRel(("CloudClient::CloudClient()\n"));
46}
47
48CloudClient::~CloudClient()
49{
50 LogRel(("CloudClient::~CloudClient()\n"));
51}
52
53HRESULT CloudClient::FinalConstruct()
54{
55 return BaseFinalConstruct();
56}
57
58void CloudClient::FinalRelease()
59{
60 uninit();
61
62 BaseFinalRelease();
63}
64
65void CloudClient::uninit()
66{
67 LogRel(("CloudClient::uninit()\n"));
68 /* Enclose the state transition Ready->InUninit->NotReady */
69 AutoUninitSpan autoUninitSpan(this);
70 if (autoUninitSpan.uninitDone())
71 return;
72
73 unconst(mParent) = NULL;
74}
75
76HRESULT CloudClient::init(VirtualBox *aParent)
77{
78 LogRel(("aParent=%p\n", aParent));
79 ComAssertRet(aParent, E_INVALIDARG);
80
81 /* Enclose the state transition NotReady->InInit->Ready */
82 AutoInitSpan autoInitSpan(this);
83 AssertReturn(autoInitSpan.isOk(), E_FAIL);
84
85 unconst(mParent) = aParent;
86
87 mCloudProvider = CloudProviderId_OCI;
88
89 LogRel(("aParent=%p\n", aParent));
90
91 /*
92 * Confirm a successful initialization
93 */
94 autoInitSpan.setSucceeded();
95
96 return S_OK;
97}
98
99HRESULT CloudClient::initCloudClient(CloudUserProfileList *aProfiles,
100 VirtualBox *aParent,
101 CloudProviderId_T aCloudProvider,
102 const com::Utf8Str &aProfileName)
103{
104 LogRel(("aParent=%p\n", aParent));
105 ComAssertRet(aParent, E_INVALIDARG);
106
107 /* Enclose the state transition NotReady->InInit->Ready */
108 AutoInitSpan autoInitSpan(this);
109 AssertReturn(autoInitSpan.isOk(), E_FAIL);
110
111 unconst(mParent) = aParent;
112
113 HRESULT hrc = S_OK;
114
115 try
116 {
117 mCloudProvider = aCloudProvider;
118 LogRel(("CloudProvider = %d\n", mCloudProvider));
119 CloudUserProfileList *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 initialization
157 */
158 autoInitSpan.setSucceeded();
159
160 return hrc;
161}
162
163HRESULT 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
170HRESULT 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
181HRESULT 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
189HRESULT 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
203HRESULT 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
212HRESULT 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
226HRESULT 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 / destructor
242//
243// ////////////////////////////////////////////////////////////////////////////////
244CloudClientOCI::CloudClientOCI()
245{
246 LogRel(("CloudClientOCI::CloudClientOCI()\n"));
247}
248
249CloudClientOCI::~CloudClientOCI()
250{
251 LogRel(("CloudClientOCI::~CloudClientOCI()\n"));
252}
253
254HRESULT CloudClientOCI::initCloudClient(CloudUserProfileList *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 try
271 {
272 mCloudProvider = aCloudProvider;
273 LogRel(("CloudClientOCI = %d\n", mCloudProvider));
274 CloudUserProfileList *lProfiles = aProfiles;
275 std::vector<com::Utf8Str> lNames;
276 std::vector<com::Utf8Str> lValues;
277 hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
278 if (FAILED(hrc))
279 {
280 return hrc;
281 }
282
283 for (size_t i=0;i<lNames.size();++i)
284 {
285 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
286 userProfile[lNames.at(i)] = value;
287 }
288
289 CloudProviderId_T aProvider;
290 hrc = lProfiles->getProvider(&aProvider);
291
292 switch(aProvider)
293 {
294 case CloudProviderId_OCI:
295 default:
296 LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
297 break;
298 }
299 }
300 catch (HRESULT arc)
301 {
302 hrc = arc;
303 LogRel(("Get cought an exception %d\n", hrc));
304 }
305 catch (std::bad_alloc)
306 {
307 return E_OUTOFMEMORY;
308 }
309
310 /*
311 * Confirm a successful initialization
312 */
313 autoInitSpan.setSucceeded();
314
315 return hrc;
316}
317
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//"}";
365
366static Utf8Str strExportParametersToOCI = "{\n"
367"\t""\"Shape of instance\": {\n"
368"\t""\t""\"type\": 27,\n"
369"\t""\t""\"items\": [\n"
370"\t""\t""\t""\"VM.Standard1.1\",\n"
371"\t""\t""\t""\"VM.Standard1.2\",\n"
372"\t""\t""\t""\"VM.Standard1.4\",\n"
373"\t""\t""\t""\"VM.Standard1.8\",\n"
374"\t""\t""\t""\"VM.Standard1.16\"\n"
375"\t""\t""]\n"
376"\t""},\n"
377"\t""\"Availability domain\": {\n"
378"\t""\t""\"type\": 28,\n"
379"\t""\t""\"items\": [\n"
380"\t""\t""\t""\"ergw:US-ASHBURN-AD-1\",\n"
381"\t""\t""\t""\"ergw:US-ASHBURN-AD-2\",\n"
382"\t""\t""\t""\"ergw:US-ASHBURN-AD-3\"\n"
383"\t""\t""]\n"
384"\t""},\n"
385"\t""\"Disk size\": {\n"
386"\t""\t""\"type\": 29,\n"
387"\t""\t""\"min\": 10,\n"
388"\t""\t""\"max\": 50,\n"
389"\t""\t""\"unit\": \"GB\"\n"
390"\t""},\n"
391"\t""\"Bucket\": {\n"
392"\t""\t""\"type\": 30,\n"
393"\t""\t""\"items\": [\n"
394"\t""\t""\t""\"temporarly-bucket-python-ubuntu-14-x64-server\",\n"
395"\t""\t""\t""\"temporarly-bucket-python-un-ubuntu\",\n"
396"\t""\t""\t""\"test_cpp_bucket\",\n"
397"\t""\t""\t""\"vbox_test_bucket_1\"\n"
398"\t""\t""]\n"
399"\t""},\n"
400"\t""\"Virtual Cloud Network\": {\n"
401"\t""\t""\"type\": 31,\n"
402"\t""\t""\"items\": [\n"
403"\t""\t""\t""\"vcn-scoter\",\n"
404"\t""\t""\t""\"vcn20180510154500\",\n"
405"\t""\t""\t""\"vcn_spider\"\n"
406"\t""\t""]\n"
407"\t""},\n"
408"\t""\"Public IP address\": {\n"
409"\t""\t""\"type\": 32,\n"
410"\t""\t""\"bool\": true\n"
411"\t""}\n"
412"}";
413
414HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
415{
416 LogRel(("CloudClientOCI::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));
417 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
425HRESULT 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
436HRESULT 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
444HRESULT 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
458HRESULT 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
467HRESULT 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
481HRESULT 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
Note: See TracBrowser for help on using the repository browser.

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