VirtualBox

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

Last change on this file since 73216 was 73216, checked in by vboxsync, 6 years ago

bugref:9152. Added 6 new values into VirtualSystemDescriptionType. Added CloudClientOCI class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.7 KB
Line 
1/* $Id: CloudClientImpl.cpp 73216 2018-07-18 16:01:16Z 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
53//CloudClient::CloudClient(CloudProviderId_T aCloudProvider)
54// : mParent(NULL)
55//{
56// LogRel(("CloudClient::CloudClient(CloudProviderId_T %d)\n", mCloudProvider));
57// mCloudProvider = aCloudProvider;
58//}
59
60HRESULT CloudClient::FinalConstruct()
61{
62 return BaseFinalConstruct();
63}
64
65void CloudClient::FinalRelease()
66{
67 uninit();
68
69 BaseFinalRelease();
70}
71
72void CloudClient::uninit()
73{
74 LogRel(("CloudClient::uninit()\n"));
75 /* Enclose the state transition Ready->InUninit->NotReady */
76 AutoUninitSpan autoUninitSpan(this);
77 if (autoUninitSpan.uninitDone())
78 return;
79
80 unconst(mParent) = NULL;
81}
82
83HRESULT CloudClient::init(VirtualBox *aParent)
84{
85 LogRel(("aParent=%p\n", aParent));
86 ComAssertRet(aParent, E_INVALIDARG);
87
88 /* Enclose the state transition NotReady->InInit->Ready */
89 AutoInitSpan autoInitSpan(this);
90 AssertReturn(autoInitSpan.isOk(), E_FAIL);
91
92 unconst(mParent) = aParent;
93
94 mCloudProvider = CloudProviderId_OCI;
95
96 LogRel(("aParent=%p\n", aParent));
97
98 /*
99 * Confirm a successful initialization
100 */
101 autoInitSpan.setSucceeded();
102
103 return S_OK;
104}
105
106HRESULT CloudClient::initCloudClient(CloudUserProfileList *aProfiles,
107 VirtualBox *aParent,
108 CloudProviderId_T aCloudProvider,
109 const com::Utf8Str &aProfileName)
110{
111 LogRel(("aParent=%p\n", aParent));
112 ComAssertRet(aParent, E_INVALIDARG);
113
114 /* Enclose the state transition NotReady->InInit->Ready */
115 AutoInitSpan autoInitSpan(this);
116 AssertReturn(autoInitSpan.isOk(), E_FAIL);
117
118 unconst(mParent) = aParent;
119
120 HRESULT hrc = S_OK;
121
122 try
123 {
124 mCloudProvider = aCloudProvider;
125 LogRel(("CloudProvider = %d\n", mCloudProvider));
126 CloudUserProfileList *lProfiles = aProfiles;
127 std::vector<com::Utf8Str> lNames;
128 std::vector<com::Utf8Str> lValues;
129 hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
130 if (FAILED(hrc))
131 {
132 throw hrc;
133 }
134
135 for (size_t i=0;i<lNames.size();++i)
136 {
137 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
138 userProfile[lNames.at(i)] = value;
139 }
140
141 CloudProviderId_T aProvider;
142 hrc = lProfiles->getProvider(&aProvider);
143
144 switch(aProvider)
145 {
146 case CloudProviderId_OCI:
147 default:
148 LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
149 break;
150 }
151 }
152 catch (HRESULT arc)
153 {
154 hrc = arc;
155 LogRel(("Get cought an exception %d\n", hrc));
156 }
157 catch (std::bad_alloc)
158 {
159 return E_OUTOFMEMORY;
160 }
161
162 /*
163 * Confirm a successful initialization
164 */
165 autoInitSpan.setSucceeded();
166
167 return hrc;
168}
169
170HRESULT CloudClient::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
171{
172 LogRel(("CloudClient::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));
173 HRESULT hrc = VERR_NOT_IMPLEMENTED;
174
175 return hrc;
176}
177
178HRESULT CloudClient::createOperation(const com::Utf8Str &aProfileName,
179 CloudOperation_T aCloudOperation,
180 com::Guid &aOpId)
181{
182 LogRel(("CloudClient::createOperation: %s, %d, %s\n", aProfileName.c_str(),
183 aCloudOperation,
184 aOpId.toString().c_str()));
185 HRESULT hrc = VERR_NOT_IMPLEMENTED;
186 return hrc;
187}
188
189HRESULT CloudClient::runOperation(const com::Guid &aOpId,
190 LONG64 aTimeout)
191{
192 LogRel(("CloudClient::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout));
193 HRESULT hrc = VERR_NOT_IMPLEMENTED;
194 return hrc;
195}
196
197HRESULT CloudClient::checkOperationResult(const com::Guid &aOpId,
198 LONG64 *aStartOpTime,
199 LONG64 *aLastTime,
200 CloudOperationResult_T *aResult)
201{
202 LogRel(("CloudClient::checkOperationResult: %s, %d, %d, %d\n",
203 aOpId.toString().c_str(),
204 *aStartOpTime,
205 *aLastTime,
206 *aResult));
207 HRESULT hrc = VERR_NOT_IMPLEMENTED;
208 return hrc;
209}
210
211HRESULT CloudClient::getOperationParameterNames(CloudOperation_T aCloudOperation,
212 std::vector<com::Utf8Str> &aParameterNames)
213{
214 LogRel(("CloudClient::getOperationParameterNames: %d\n", aCloudOperation));
215 aParameterNames.clear();
216 HRESULT hrc = VERR_NOT_IMPLEMENTED;
217 return hrc;
218}
219
220HRESULT CloudClient::getOperationParameterProperties(const com::Utf8Str &aOpParameterName,
221 com::Utf8Str &aOpParameterType,
222 com::Utf8Str &aOpParameterDesc,
223 std::vector<com::Utf8Str> &aOpParameterValues)
224{
225 LogRel(("CloudClient::getOperationParameterProperties: %s, %s, %s\n",
226 aOpParameterName.c_str(),
227 aOpParameterType.c_str(),
228 aOpParameterDesc.c_str()));
229 aOpParameterValues.clear();
230 HRESULT hrc = VERR_NOT_IMPLEMENTED;
231 return hrc;
232}
233
234HRESULT CloudClient::setParametersForOperation(const com::Guid &aOpId,
235 const std::vector<com::Utf8Str> &aValues)
236{
237 LogRel(("CloudClient::setParametersForOperation: %s\n", aOpId.toString().c_str()));
238 for (size_t i=0;i<aValues.size();++i)
239 {
240 LogRel(("value %d: %s\n", i, aValues.at(i).c_str()));
241 }
242
243 HRESULT hrc = VERR_NOT_IMPLEMENTED;
244 return hrc;
245}
246
247////////////////////////////////////////////////////////////////////////////////
248//
249// CloudClient constructor / destructor
250//
251// ////////////////////////////////////////////////////////////////////////////////
252CloudClientOCI::CloudClientOCI()
253{
254 LogRel(("CloudClientOCI::CloudClientOCI()\n"));
255}
256
257CloudClientOCI::~CloudClientOCI()
258{
259 LogRel(("CloudClientOCI::~CloudClientOCI()\n"));
260}
261
262HRESULT CloudClientOCI::initCloudClient(CloudUserProfileList *aProfiles,
263 VirtualBox *aParent,
264 CloudProviderId_T aCloudProvider,
265 const com::Utf8Str &aProfileName)
266{
267 LogRel(("aParent=%p\n", aParent));
268 ComAssertRet(aParent, E_INVALIDARG);
269
270 /* Enclose the state transition NotReady->InInit->Ready */
271 AutoInitSpan autoInitSpan(this);
272 AssertReturn(autoInitSpan.isOk(), E_FAIL);
273
274 unconst(mParent) = aParent;
275
276 HRESULT hrc = S_OK;
277
278 try
279 {
280 mCloudProvider = aCloudProvider;
281 LogRel(("CloudClientOCI = %d\n", mCloudProvider));
282 CloudUserProfileList *lProfiles = aProfiles;
283 std::vector<com::Utf8Str> lNames;
284 std::vector<com::Utf8Str> lValues;
285 hrc = lProfiles->getProfileProperties(aProfileName, lNames, lValues);
286 if (FAILED(hrc))
287 {
288 throw hrc;
289 }
290
291 for (size_t i=0;i<lNames.size();++i)
292 {
293 com::Utf8Str value = (i<lValues.size()) ? lValues.at(i) : "";
294 userProfile[lNames.at(i)] = value;
295 }
296
297 CloudProviderId_T aProvider;
298 hrc = lProfiles->getProvider(&aProvider);
299
300 switch(aProvider)
301 {
302 case CloudProviderId_OCI:
303 default:
304 LogRel(("Reading profile %s has been done\n", aProfileName.c_str()));
305 break;
306 }
307 }
308 catch (HRESULT arc)
309 {
310 hrc = arc;
311 LogRel(("Get cought an exception %d\n", hrc));
312 }
313 catch (std::bad_alloc)
314 {
315 return E_OUTOFMEMORY;
316 }
317
318 /*
319 * Confirm a successful initialization
320 */
321 autoInitSpan.setSucceeded();
322
323 return hrc;
324}
325
326//static Utf8Str strExportParametersToOCI = "{\n"
327// "\"Shape of instance\": {\n"
328// "\"type\":27,\n"
329// "\"items\": [\n"
330// "\"VM.Standard1.1\",\n"
331// "\"VM.Standard1.2\",\n"
332// "\"VM.Standard1.4\",\n"
333// "\"VM.Standard1.8\",\n"
334// "\"VM.Standard1.16\",\n"
335// "],\n"
336// "},\n"
337// "\"Availability domain\": {\n"
338// "\"type\":28,\n"
339// "\"items\": [\n"
340// "\"ergw:US-ASHBURN-AD-1\",\n"
341// "\"ergw:US-ASHBURN-AD-2\",\n"
342// "\"ergw:US-ASHBURN-AD-3\",\n"
343// "],\n"
344// "},\n"
345// "\"Disk size\": {\n"
346// "\"type\":29,\n"
347// "\range\":10 ... 50,\n"
348// "\"size\":10,\n"
349// "\"unit\":\"Gb\"\n"
350// "},\n"
351// "\"Bucket\": {\n"
352// "\"type\":30,\n"
353// "\"items\": [\n"
354// "\"temporarly-bucket-python-ubuntu-14-x64-server\",\n"
355// "\"temporarly-bucket-python-un-ubuntu\",\n"
356// "\"test_cpp_bucket\",\n"
357// "\"vbox_test_bucket_1\",\n"
358// "],\n"
359// "},\n"
360// "\"Virtual Cloud Network\": {\n"
361// "\"type\":31,\n"
362// "\"items\": [\n"
363// "\"vcn-scoter\",\n"
364// "\"vcn20180510154500\",\n"
365// "\"vcn_spider\",\n"
366// "],\n"
367// "},\n"
368// "\"Public IP address\": {\n"
369// "\"type\":32,\n"
370// "\"set\":\"yes\n"
371// "}\n"
372//"}";
373
374static Utf8Str strExportParametersToOCI = "{\n"
375"\t""\"Shape of instance\": {\n"
376"\t""\t""\"type\":27,\n"
377"\t""\t""\"items\": [\n"
378"\t""\t""\t""\"VM.Standard1.1\",\n"
379"\t""\t""\t""\"VM.Standard1.2\",\n"
380"\t""\t""\t""\"VM.Standard1.4\",\n"
381"\t""\t""\t""\"VM.Standard1.8\",\n"
382"\t""\t""\t""\"VM.Standard1.16\",\n"
383"\t""\t""],\n"
384"\t""},\n"
385"\t""\"Availability domain\": {\n"
386"\t""\t""\"type\":28,\n"
387"\t""\t""\"items\": [\n"
388"\t""\t""\t""\"ergw:US-ASHBURN-AD-1\",\n"
389"\t""\t""\t""\"ergw:US-ASHBURN-AD-2\",\n"
390"\t""\t""\t""\"ergw:US-ASHBURN-AD-3\",\n"
391"\t""\t""],\n"
392"\t""},\n"
393"\t""\"Disk size\": {\n"
394"\t""\t""\"type\":29,\n"
395"\t""\t""\"range\":10 ... 50,\n"
396"\t""\t""\"size\":10,\n"
397"\t""\t""\"unit\":\"Gb\"\n"
398"\t""},\n"
399"\t""\"Bucket\": {\n"
400"\t""\t""\"type\":30,\n"
401"\t""\t""\"items\": [\n"
402"\t""\t""\t""\"temporarly-bucket-python-ubuntu-14-x64-server\",\n"
403"\t""\t""\t""\"temporarly-bucket-python-un-ubuntu\",\n"
404"\t""\t""\t""\"test_cpp_bucket\",\n"
405"\t""\t""\t""\"vbox_test_bucket_1\",\n"
406"\t""\t""],\n"
407"\t""},\n"
408"\t""\"Virtual Cloud Network\": {\n"
409"\t""\t""\"type\":31,\n"
410"\t""\t""\"items\": [\n"
411"\t""\t""\t""\"vcn-scoter\",\n"
412"\t""\t""\t""\"vcn20180510154500\",\n"
413"\t""\t""\t""\"vcn_spider\",\n"
414"\t""\t""],\n"
415"\t""},\n"
416"\t""\"Public IP address\": {\n"
417"\t""\t""\"type\":32,\n"
418"\t""\t""\"set\":\"yes\n"
419"\t""}\n"
420"}";
421
422HRESULT CloudClientOCI::getOperationParameters(CloudOperation_T aCloudOperation, com::Utf8Str &aJsonString)
423{
424 LogRel(("CloudClientOCI::getOperationParameters: %d, %s\n", aCloudOperation, aJsonString.c_str()));
425 HRESULT hrc = S_OK;
426 if (aCloudOperation == CloudOperation_exportVM)
427 aJsonString = strExportParametersToOCI;
428 else
429 hrc = VERR_NOT_IMPLEMENTED;
430 return hrc;
431}
432
433HRESULT CloudClientOCI::createOperation(const com::Utf8Str &aProfileName,
434 CloudOperation_T aCloudOperation,
435 com::Guid &aOpId)
436{
437 LogRel(("CloudClientOCI::createOperation: %s, %d, %s\n", aProfileName.c_str(),
438 aCloudOperation,
439 aOpId.toString().c_str()));
440 HRESULT hrc = VERR_NOT_IMPLEMENTED;
441 return hrc;
442}
443
444HRESULT CloudClientOCI::runOperation(const com::Guid &aOpId,
445 LONG64 aTimeout)
446{
447 LogRel(("CloudClientOCI::runOperation: %s, %d\n", aOpId.toString().c_str(), aTimeout));
448 HRESULT hrc = VERR_NOT_IMPLEMENTED;
449 return hrc;
450}
451
452HRESULT CloudClientOCI::checkOperationResult(const com::Guid &aOpId,
453 LONG64 *aStartOpTime,
454 LONG64 *aLastTime,
455 CloudOperationResult_T *aResult)
456{
457 LogRel(("CloudClientOCI::checkOperationResult: %s, %d, %d, %d\n",
458 aOpId.toString().c_str(),
459 *aStartOpTime,
460 *aLastTime,
461 *aResult));
462 HRESULT hrc = VERR_NOT_IMPLEMENTED;
463 return hrc;
464}
465
466HRESULT CloudClientOCI::getOperationParameterNames(CloudOperation_T aCloudOperation,
467 std::vector<com::Utf8Str> &aParameterNames)
468{
469 LogRel(("CloudClientOCI::getOperationParameterNames: %d\n", aCloudOperation));
470 aParameterNames.clear();
471 HRESULT hrc = VERR_NOT_IMPLEMENTED;
472 return hrc;
473}
474
475HRESULT CloudClientOCI::getOperationParameterProperties(const com::Utf8Str &aOpParameterName,
476 com::Utf8Str &aOpParameterType,
477 com::Utf8Str &aOpParameterDesc,
478 std::vector<com::Utf8Str> &aOpParameterValues)
479{
480 LogRel(("CloudClientOCI::getOperationParameterProperties: %s, %s, %s\n",
481 aOpParameterName.c_str(),
482 aOpParameterType.c_str(),
483 aOpParameterDesc.c_str()));
484 aOpParameterValues.clear();
485 HRESULT hrc = VERR_NOT_IMPLEMENTED;
486 return hrc;
487}
488
489HRESULT CloudClientOCI::setParametersForOperation(const com::Guid &aOpId,
490 const std::vector<com::Utf8Str> &aValues)
491{
492 LogRel(("CloudClientOCI::setParametersForOperation: %s\n", aOpId.toString().c_str()));
493 for (size_t i=0;i<aValues.size();++i)
494 {
495 LogRel(("value %d: %s\n", i, aValues.at(i).c_str()));
496 }
497
498 HRESULT hrc = VERR_NOT_IMPLEMENTED;
499 return hrc;
500}
501
Note: See TracBrowser for help on using the repository browser.

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