-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutilities.cpp
69 lines (58 loc) · 2.48 KB
/
utilities.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* This file is part of CernVM Web API Plugin.
*
* CVMWebAPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CVMWebAPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CVMWebAPI. If not, see <http://www.gnu.org/licenses/>.
*
* Developed by Ioannis Charalampidis 2013
* Contact: <ioannis.charalampidis[at]cern.ch>
*/
#include "utilities.h"
/**
* Compile and return a Json::Value with all the state information
* for the given session
*/
Json::Value sessionStateInfoToJSON( HVSessionPtr hvSession ) {
CRASH_REPORT_BEGIN;
Json::Value data, properties, config;
// --- Populate properties field ---
std::vector<std::string> propKeys = hvSession->properties->enumKeys();
for ( std::vector<std::string>::iterator it = propKeys.begin(); it != propKeys.end(); ++it ) {
std::string k = *it;
properties[k] = hvSession->properties->get(k, "");
}
// --- Populate config field ---
// Calculate api URL
std::string apiHost = hvSession->local->get("apiHost", "127.0.0.1");
std::string apiPort = hvSession->local->get("apiPort", "80");
std::string apiURL = "http://" + apiHost + ":" + apiPort;
config["apiURL"] = apiURL;
// Calculate RDP URl
std::string resolution = hvSession->getExtraInfo(EXIF_VIDEO_MODE);
config["rdpURL"] = hvSession->getRDPAddress() + "@" + resolution;
// Return only particular configuration variables
config["ip"] = hvSession->parameters->get("ip", "");
config["cpus"] = hvSession->parameters->getNum<int>("cpus", 1);
config["disk"] = hvSession->parameters->getNum<int>("disk", 1024);
config["memory"] = hvSession->parameters->getNum<int>("memory", 512);
config["cernvmVersion"] = hvSession->parameters->get("cernvmVersion", "1.17-11");
config["cernvmFlavor"] = hvSession->parameters->get("cernvmFlavor", "prod");
config["executionCap"] = hvSession->parameters->getNum<int>("executionCap", 100);
config["flags"] = hvSession->parameters->getNum<int>("flags", 0);
// Update data field
data.append(config);
data.append(properties);
// Return data
return data;
CRASH_REPORT_END;
}