79
int main (int argc, char * argv[] )
83
// find value of the given param in the eucalyptus.conf (e.g., /usr/bin/euca-bundle-upload for NC_BUNDLE_UPLOAD_PATH)
84
// return NULL if the param is commented out
85
static char* find_conf_value(const char* eucahome, const char* param)
81
virConnectPtr conn = NULL;
82
int dom_ids [MAXDOMS];
84
char *hypervisor, hypervisorURL[32], cmd[1024];
87
logfile (NULL, EUCAFATAL); /* suppress all messages */
90
fprintf (stderr, "error: test_nc expects one parameter (name of hypervisor)\n");
95
if (!strcmp(hypervisor, "kvm")) {
96
snprintf(hypervisorURL, 32, "qemu:///system");
97
} else if (!strcmp(hypervisor, "xen")) {
98
snprintf(hypervisorURL, 32, "xen:///");
99
} else if (!strcmp(hypervisor, "not_configured")) {
100
fprintf (stderr, "error: HYPERVISOR variable is not set in eucalyptus.conf\n");
103
fprintf (stderr, "error: hypervisor type (%s) is not recognized\n", hypervisor);
107
/* check that commands that NC needs are there */
109
if ( system("perl --version") ) {
110
fprintf (stderr, "error: could not run perl\n");
114
eucahome = getenv (EUCALYPTUS_ENV_VAR_NAME);
116
eucahome = strdup (""); /* root by default */
118
eucahome = strdup(eucahome);
121
if (!strcmp(hypervisor, "kvm")) {
122
snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_sys_info", eucahome, eucahome);
124
snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_xen_info", eucahome, eucahome);
128
fprintf (stderr, "error: could not run '%s'\n", cmd);
132
/* check that libvirt can query the hypervisor */
133
conn = virConnectOpen (hypervisorURL); /* NULL means local hypervisor */
135
print_libvirt_error ();
136
fprintf (stderr, "error: failed to connect to hypervisor\n");
140
num_doms = virConnectListDomains (conn, dom_ids, MAXDOMS);
142
print_libvirt_error ();
143
fprintf (stderr, "error: failed to query running domains\n");
93
if (!eucahome || !param)
96
snprintf (conf_path, 1024, "%s/etc/eucalyptus/eucalyptus.conf", eucahome);
97
f_conf = fopen (conf_path, "r");
102
while (fgets (line, 1024, f_conf)!=NULL) {
103
if (strstr(line, param)!=NULL) { // found the param in the line
104
if (strchr(line, '#')!= NULL) { // the line is commented out (assume # can't appear in the middle)
107
char* pch = strtok(line, "="); // again assume '=' can't appear in the middle of value
108
pch = strtok(NULL, "=");
109
if (pch && strlen(pch)>0) {
110
value = calloc(strlen(pch)+1, 1);
115
snprintf(value, strlen(pch)+1, "%s", pch);
123
// remove "" from the value
126
for (int i=0; i<strlen(value); i++) {
130
value[i-quote] = value[i];
132
value[strlen(value)-quote] = 0x00;
136
while (value[i]==' ' || value[i]=='\t')
138
for(int j=i; j<strlen(value); j++)
139
value[j-i] = value[j];
140
value[strlen(value)-i] = 0x00;
142
if(value[strlen(value)-1] == '\n')
143
value[strlen(value)-1] = 0x00;
150
int main (int argc, char * argv[])
152
virConnectPtr conn = NULL;
153
int dom_ids [MAXDOMS];
155
char *hypervisor, hypervisorURL[32], cmd[1024];
158
// logfile (NULL, EUCAFATAL); // suppress all messages
161
fprintf (stderr, "error: test_nc expects one parameter (name of hypervisor)\n");
165
hypervisor = argv[1];
166
if (!strcmp(hypervisor, "kvm")) {
167
snprintf(hypervisorURL, 32, "qemu:///system");
168
} else if (!strcmp(hypervisor, "xen")) {
169
snprintf(hypervisorURL, 32, "xen:///");
170
} else if (!strcmp(hypervisor, "not_configured")) {
171
fprintf (stderr, "error: HYPERVISOR variable is not set in eucalyptus.conf\n");
174
fprintf (stderr, "error: hypervisor type (%s) is not recognized\n", hypervisor);
178
// check that commands that NC needs are there
180
if (system("perl --version")) {
181
fprintf (stderr, "error: could not run perl\n");
185
eucahome = getenv (EUCALYPTUS_ENV_VAR_NAME);
187
eucahome = strdup (""); // root by default
189
eucahome = strdup(eucahome);
192
add_euca_to_path (eucahome);
194
fprintf (stderr, "looking for system utilities...\n");
198
// check if euca2ools commands for bundle-instance are available
199
fprintf (stderr, "ok\n\nlooking for euca2ools...\n");
200
static char * helpers_name [3] = {
201
"euca-bundle-upload",
206
char * helpers_path [3]; // load paths from eucalyptus.conf or set to NULL
207
helpers_path [0] = find_conf_value (eucahome, "NC_BUNDLE_UPLOAD_PATH");
208
helpers_path [1] = find_conf_value (eucahome, "NC_CHECK_BUCKET_PATH");
209
helpers_path [2] = find_conf_value (eucahome, "NC_DELETE_BUNDLE_PATH");
211
if (verify_helpers (helpers_name, helpers_path, 3) > 0) {
212
if (verify_helpers (helpers_name, NULL, 3) > 0) {
213
fprintf (stderr, "error: failed to find required euca2ools\n");
218
// ensure hypervisor information is available
219
fprintf (stderr, "ok\n\nchecking the hypervisor...\n");
220
if (!strcmp(hypervisor, "kvm")) {
221
snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_sys_info", eucahome, eucahome);
223
snprintf(cmd, 1024, "%s/usr/lib/eucalyptus/euca_rootwrap %s/usr/share/eucalyptus/get_xen_info", eucahome, eucahome);
226
fprintf (stderr, "error: could not run '%s'\n", cmd);
230
// check that libvirt can query the hypervisor
231
conn = virConnectOpen (hypervisorURL); // NULL means local hypervisor
233
print_libvirt_error ();
234
fprintf (stderr, "error: failed to connect to hypervisor\n");
238
num_doms = virConnectListDomains (conn, dom_ids, MAXDOMS);
240
print_libvirt_error ();
241
fprintf (stderr, "error: failed to query running domains\n");