/
get_xmlrpc_config
executable file
路252 lines (216 loc) 路 8.55 KB
/
get_xmlrpc_config
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2014, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'pp'
require 'digest/md5'
require 'fileutils'
###########################################
# Code to test compilation/linkning flags #
###########################################
TestCodeServer="""
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/registry.hpp>
int main(int argc, char *argv[])
{
xmlrpc_c::registry RequestManagerRegistry;
return 0;
}"""
TestCodeClient=<<-EOT
#include <cstdlib>
#include <string>
#include <iostream>
#include <xmlrpc-c/girerr.hpp>
#include <xmlrpc-c/base.hpp>
#include <xmlrpc-c/client_simple.hpp>
#include <map>
using namespace std;
int
main(int argc, char **) {
if (argc-1 > 0) {
cerr << "This program has no arguments" << endl;
exit(1);
}
try {
xmlrpc_env env;
string const serverUrl("http://localhost:8080/RPC2");
string const methodAllocate("one.vmallocate");
xmlrpc_c::clientSimple myClient;
xmlrpc_c::value resultSUBMIT;
xmlrpc_env_init(&env);
myClient.call(serverUrl, methodAllocate, "ss",
&resultSUBMIT,"SESSION-GOLA&4H9109KVFSG",
"MEMORY=345 CPU=4 DISK=[FILE=\\"img\\",TYPE=cd]"
"DISK=[FILE=\\"../f\\"]");
xmlrpc_c::value_array resultArray = xmlrpc_c::value_array(resultSUBMIT);
vector<xmlrpc_c::value> const paramArrayValue(resultArray.vectorValueValue());
//check posible Errors:
xmlrpc_c::value firstvalue;
firstvalue = static_cast<xmlrpc_c::value>(paramArrayValue[0]);
xmlrpc_c::value_boolean status = static_cast<xmlrpc_c::value_boolean>(firstvalue);
xmlrpc_c::value secondvalue;
secondvalue = static_cast<xmlrpc_c::value>(paramArrayValue[1]);
xmlrpc_c::value_string valueS = static_cast<xmlrpc_c::value_string>(secondvalue);
if(static_cast<bool>(status)) {
//Success, returns the id assigned to the VM:
cout << "vmid returned: " << static_cast<string>(valueS) << endl;
return 0;
}
else{ //Failure:
string error_value=static_cast<string>(valueS);
if (error_value.find("Error inserting",0)!=string::npos ) cout << "Error inserting VM in the database" << endl;
else if (error_value.find("Error parsing",0)!=string::npos ) cout << "Error parsing VM template" << endl;
else cout << "Unknown error " << static_cast<string>(valueS) << endl;
};
} catch (girerr::error const error) {
cerr << "Client threw error: " << error.what() << endl;
//"Client threw error:"
return 20;
} catch (std::exception const e) {
cerr << "Client threw unexpected error." << endl;
//Unexpected error:
return 999;
}
return 0;
}
EOT
TestCode={
:client => TestCodeClient,
:server => TestCodeServer
}
# Executes a command and discards stderr
def exec_command(command)
lambda {
#STDERR.puts text
text=`#{command} 2>/dev/null`
text.gsub!("\n", " ")
if $?!=0
STDERR.puts " Error calling #{command}"
nil
else
text
end
}
end
# Adds fixed flags and libraries
def flags_and_libs_array(flags, libs)
lambda {
libs_text=libs.collect {|lib| "-l"+lib }.join(' ')
text=flags+" "+libs_text
#STDERR.puts text
text
}
end
# Array with flags/libs to test
Configs=[
# Configuration using xmlrpc-c-config
{
:description => "xmlrpc-c-config",
:client => exec_command("xmlrpc-c-config c++2 client --libs --cflags"),
:server => exec_command("xmlrpc-c-config c++2 abyss-server --libs --cflags")
},
# Configuration for fedora
{
:description => "pkg-config",
:client => exec_command("pkg-config xmlrpc_client++ xmlrpc++ --libs"),
:server => exec_command("pkg-config xmlrpc_server_abyss++ --static --libs")
},
# Debian lenny
{
:description => "mixed hardcoded libraries and xmlrpc-c-config (debian lenny)",
:client => flags_and_libs_array("-I/usr/include -L/usr/lib", [
'xmlrpc_client', 'xmlrpc_client', 'xmlrpc', 'xmlrpc_util',
'xmlrpc_xmlparse', 'xmlrpc_xmltok', 'xmlrpc_client++', 'xmlrpc++'
]),
:server => exec_command("xmlrpc-c-config c++2 abyss-server --libs --cflags"),
},
# Configuration for Mac OS X and Debian
{
:description => "hardcoded libraries for Mac OS X (installed using port)",
:server => flags_and_libs_array("-I/opt/local/include -L/opt/local/lib", [
'wwwxml', 'xmltok', 'xmlparse', 'wwwzip', 'wwwinit', 'wwwapp',
'wwwtelnet', 'wwwhtml', 'wwwnews', 'wwwhttp', 'wwwmime', 'wwwgopher',
'wwwftp', 'wwwfile', 'wwwdir', 'wwwcache', 'wwwstream', 'wwwmux',
'wwwtrans', 'wwwcore', 'wwwutils', 'md5', 'dl', 'z', 'pthread',
'xmlrpc_client++', 'xmlrpc_client', 'xmlrpc++', 'xmlrpc',
'xmlrpc_util', 'xmlrpc_xmlparse', 'xmlrpc_xmltok',
'xmlrpc_server_abyss++', 'xmlrpc_server++', 'xmlrpc_server_abyss',
'xmlrpc_server', 'xmlrpc_abyss',
]),
:client => flags_and_libs_array("-I/opt/local/include -L/opt/local/lib", [
'curl', 'xmlrpc_client++', 'xmlrpc_client', 'xmlrpc++', 'xmlrpc',
'xmlrpc_util', 'xmlrpc_xmlparse', 'xmlrpc_xmltok', 'wwwxml',
'xmltok', 'xmlparse', 'wwwzip', 'wwwinit', 'wwwapp', 'wwwtelnet',
'wwwhtml', 'wwwnews', 'wwwhttp', 'wwwmime', 'wwwgopher', 'wwwftp',
'wwwfile', 'wwwdir', 'wwwcache', 'wwwstream', 'wwwmux', 'wwwtrans',
'wwwcore', 'wwwutils', 'm', 'md5'
])
},
# Example adding more custom libraries
# {
# :client => exec_command("xmlrpc-c-config client c++ --cflags --libs"),
# :server => exec_command("xmlrpc-c-config abyss-server c++ --cflags --libs | tr '\\n' ' ' ; echo -lxmlrpc_server++")
# },
]
# Compiles test code with given arguments
def compile(file, args)
logfile="#{file}.log"
command="g++ #{file} -o #{file}.out #{ENV['LDFLAGS']} -pthread #{args} 1>>#{logfile} 2>&1"
open(logfile, "a") {|f|
f.write(command+"\n")
}
STDERR.puts command
STDERR.puts ""
out=system(command)
end
def gen_test_file(kind)
dir='.xmlrpc_test'
hash=Digest::MD5.hexdigest(Time.now.to_s+kind.to_s)[0..5]
fname="xmlrpc_test."+hash+".cc"
#fname="xmlrpc_test.cc"
full_path=dir+"/"+fname
FileUtils::mkdir_p(dir)
f=open(full_path, "w")
f.write(TestCode[kind])
f.close
full_path
end
# Tests a configuration and writes build parameters if it is successful
def test_config(kind, config)
STDERR.puts "Testing recipe: "+config[:description].to_s
args=config[kind.to_sym].call
return nil if !args
args.strip!
name=gen_test_file(kind)
exit_code=compile(name, args)
#File.delete(name)
File.delete(name+".out") if File.exists?(name+".out")
return nil if !exit_code
puts args
true
end
# Test each of possible configurations and exits when it finds one working
def search_config(kind)
Configs.each {|config|
found=test_config(kind,config)
exit(0) if found
}
exit(1)
end
if !%w{client server}.include?ARGV[0]
puts "You need to specify client or server"
exit -1
end
search_config(ARGV[0].to_sym)