Revision 5b9fed52
SConstruct | ||
---|---|---|
63 | 63 |
cwd+'/src/pool', |
64 | 64 |
cwd+'/src/template', |
65 | 65 |
cwd+'/src/vm', |
66 |
cwd+'/src/vm_template', |
|
66 | 67 |
cwd+'/src/vmm', |
67 | 68 |
cwd+'/src/lcm', |
68 | 69 |
cwd+'/src/tm', |
... | ... | |
178 | 179 |
'src/nebula/SConstruct', |
179 | 180 |
'src/pool/SConstruct', |
180 | 181 |
'src/vm/SConstruct', |
182 |
'src/vm_template/SConstruct', |
|
181 | 183 |
'src/vmm/SConstruct', |
182 | 184 |
'src/lcm/SConstruct', |
183 | 185 |
'src/rm/SConstruct', |
include/AuthManager.h | ||
---|---|---|
293 | 293 |
NET, |
294 | 294 |
IMAGE, |
295 | 295 |
USER, |
296 |
CLUSTER |
|
296 |
CLUSTER, |
|
297 |
TEMPLATE |
|
297 | 298 |
}; |
298 | 299 |
|
299 | 300 |
/** |
include/Nebula.h | ||
---|---|---|
25 | 25 |
#include "VirtualNetworkPool.h" |
26 | 26 |
#include "HostPool.h" |
27 | 27 |
#include "UserPool.h" |
28 |
#include "VMTemplatePool.h" |
|
28 | 29 |
|
29 | 30 |
#include "VirtualMachineManager.h" |
30 | 31 |
#include "LifeCycleManager.h" |
... | ... | |
80 | 81 |
return cpool; |
81 | 82 |
}; |
82 | 83 |
|
84 |
VMTemplatePool * get_tpool() |
|
85 |
{ |
|
86 |
return tpool; |
|
87 |
}; |
|
88 |
|
|
83 | 89 |
// -------------------------------------------------------------- |
84 | 90 |
// Manager Accessors |
85 | 91 |
// -------------------------------------------------------------- |
... | ... | |
228 | 234 |
//Constructors and = are private to only access the class through instance |
229 | 235 |
// ----------------------------------------------------------------------- |
230 | 236 |
|
231 |
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),upool(0), |
|
232 |
ipool(0),cpool(0),lcm(0),vmm(0),im(0),tm(0),dm(0),rm(0),hm(0),authm(0) |
|
237 |
Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0), |
|
238 |
upool(0),ipool(0),cpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),dm(0), |
|
239 |
rm(0),hm(0),authm(0) |
|
233 | 240 |
{ |
234 | 241 |
const char * nl = getenv("ONE_LOCATION"); |
235 | 242 |
|
... | ... | |
294 | 301 |
delete cpool; |
295 | 302 |
} |
296 | 303 |
|
304 |
if ( tpool != 0) |
|
305 |
{ |
|
306 |
delete tpool; |
|
307 |
} |
|
308 |
|
|
297 | 309 |
if ( vmm != 0) |
298 | 310 |
{ |
299 | 311 |
delete vmm; |
... | ... | |
381 | 393 |
UserPool * upool; |
382 | 394 |
ImagePool * ipool; |
383 | 395 |
ClusterPool * cpool; |
396 |
VMTemplatePool * tpool; |
|
384 | 397 |
|
385 | 398 |
// --------------------------------------------------------------- |
386 | 399 |
// Nebula Managers |
include/RequestManager.h | ||
---|---|---|
24 | 24 |
#include "VirtualNetworkPool.h" |
25 | 25 |
#include "ImagePool.h" |
26 | 26 |
#include "ClusterPool.h" |
27 |
#include "VMTemplatePool.h" |
|
27 | 28 |
|
28 | 29 |
#include <xmlrpc-c/base.hpp> |
29 | 30 |
#include <xmlrpc-c/registry.hpp> |
... | ... | |
46 | 47 |
UserPool * _upool, |
47 | 48 |
ImagePool * _ipool, |
48 | 49 |
ClusterPool * _cpool, |
50 |
VMTemplatePool * _tpool, |
|
49 | 51 |
int _port, |
50 | 52 |
string _xml_log_file) |
51 | 53 |
:vmpool(_vmpool),hpool(_hpool),vnpool(_vnpool),upool(_upool), |
52 |
ipool(_ipool),cpool(_cpool),port(_port),socket_fd(-1), |
|
54 |
ipool(_ipool),cpool(_cpool),tpool(_tpool),port(_port),socket_fd(-1),
|
|
53 | 55 |
xml_log_file(_xml_log_file) |
54 | 56 |
{ |
55 | 57 |
am.addListener(this); |
... | ... | |
130 | 132 |
ImagePool * ipool; |
131 | 133 |
|
132 | 134 |
/** |
133 |
* Pointer to the Image Pool, to access images
|
|
135 |
* Pointer to the Cluster Pool, to access clusters
|
|
134 | 136 |
*/ |
135 | 137 |
ClusterPool * cpool; |
136 | 138 |
|
137 | 139 |
/** |
140 |
* Pointer to the Template Pool, to access templates |
|
141 |
*/ |
|
142 |
VMTemplatePool * tpool; |
|
143 |
|
|
144 |
/** |
|
138 | 145 |
* Port number where the connection will be open |
139 | 146 |
*/ |
140 | 147 |
int port; |
... | ... | |
502 | 509 |
}; |
503 | 510 |
|
504 | 511 |
/* ---------------------------------------------------------------------- */ |
512 |
/* Template Interface */ |
|
513 |
/* ---------------------------------------------------------------------- */ |
|
514 |
|
|
515 |
class TemplateAllocate: public xmlrpc_c::method |
|
516 |
{ |
|
517 |
public: |
|
518 |
TemplateAllocate( |
|
519 |
VMTemplatePool * _tpool, |
|
520 |
UserPool * _upool): |
|
521 |
tpool(_tpool), |
|
522 |
upool(_upool) |
|
523 |
{ |
|
524 |
_signature="A:ss"; |
|
525 |
_help="Allocates a template in the pool"; |
|
526 |
}; |
|
527 |
|
|
528 |
~TemplateAllocate(){}; |
|
529 |
|
|
530 |
void execute( |
|
531 |
xmlrpc_c::paramList const& paramList, |
|
532 |
xmlrpc_c::value * const retvalP); |
|
533 |
|
|
534 |
private: |
|
535 |
VMTemplatePool * tpool; |
|
536 |
UserPool * upool; |
|
537 |
}; |
|
538 |
|
|
539 |
/* ---------------------------------------------------------------------- */ |
|
540 |
|
|
541 |
class TemplateDelete: public xmlrpc_c::method |
|
542 |
{ |
|
543 |
public: |
|
544 |
TemplateDelete(VMTemplatePool * _tpool, |
|
545 |
UserPool * _upool): |
|
546 |
tpool(_tpool), |
|
547 |
upool(_upool) |
|
548 |
{ |
|
549 |
_signature="A:si"; |
|
550 |
_help="Deletes a Template"; |
|
551 |
}; |
|
552 |
|
|
553 |
~TemplateDelete(){}; |
|
554 |
|
|
555 |
void execute( |
|
556 |
xmlrpc_c::paramList const& paramList, |
|
557 |
xmlrpc_c::value * const retvalP); |
|
558 |
|
|
559 |
private: |
|
560 |
VMTemplatePool * tpool; |
|
561 |
UserPool * upool; |
|
562 |
}; |
|
563 |
|
|
564 |
/* ---------------------------------------------------------------------- */ |
|
565 |
|
|
566 |
class TemplateInfo: public xmlrpc_c::method |
|
567 |
{ |
|
568 |
public: |
|
569 |
TemplateInfo(VMTemplatePool * _tpool, |
|
570 |
UserPool * _upool): |
|
571 |
tpool(_tpool), |
|
572 |
upool(_upool) |
|
573 |
{ |
|
574 |
_signature="A:si"; |
|
575 |
_help="Returns information for a Template"; |
|
576 |
}; |
|
577 |
|
|
578 |
~TemplateInfo(){}; |
|
579 |
|
|
580 |
void execute( |
|
581 |
xmlrpc_c::paramList const& paramList, |
|
582 |
xmlrpc_c::value * const retvalP); |
|
583 |
|
|
584 |
private: |
|
585 |
VMTemplatePool * tpool; |
|
586 |
UserPool * upool; |
|
587 |
}; |
|
588 |
|
|
589 |
/* ---------------------------------------------------------------------- */ |
|
590 |
|
|
591 |
class TemplateUpdate: public xmlrpc_c::method |
|
592 |
{ |
|
593 |
public: |
|
594 |
TemplateUpdate(VMTemplatePool * _tpool, |
|
595 |
UserPool * _upool): |
|
596 |
tpool(_tpool), |
|
597 |
upool(_upool) |
|
598 |
{ |
|
599 |
_signature="A:siss"; |
|
600 |
_help="Modifies Template attribute"; |
|
601 |
}; |
|
602 |
|
|
603 |
~TemplateUpdate(){}; |
|
604 |
|
|
605 |
void execute( |
|
606 |
xmlrpc_c::paramList const& paramList, |
|
607 |
xmlrpc_c::value * const retvalP); |
|
608 |
|
|
609 |
private: |
|
610 |
VMTemplatePool * tpool; |
|
611 |
UserPool * upool; |
|
612 |
}; |
|
613 |
|
|
614 |
/* ---------------------------------------------------------------------- */ |
|
615 |
|
|
616 |
class TemplateRemoveAttribute: public xmlrpc_c::method |
|
617 |
{ |
|
618 |
public: |
|
619 |
TemplateRemoveAttribute(VMTemplatePool * _tpool, |
|
620 |
UserPool * _upool): |
|
621 |
tpool(_tpool), |
|
622 |
upool(_upool) |
|
623 |
{ |
|
624 |
_signature="A:sis"; |
|
625 |
_help="Removes Template attribute"; |
|
626 |
}; |
|
627 |
|
|
628 |
~TemplateRemoveAttribute(){}; |
|
629 |
|
|
630 |
void execute( |
|
631 |
xmlrpc_c::paramList const& paramList, |
|
632 |
xmlrpc_c::value * const retvalP); |
|
633 |
|
|
634 |
private: |
|
635 |
VMTemplatePool * tpool; |
|
636 |
UserPool * upool; |
|
637 |
}; |
|
638 |
|
|
639 |
/* ---------------------------------------------------------------------- */ |
|
640 |
|
|
641 |
class TemplatePublish: public xmlrpc_c::method |
|
642 |
{ |
|
643 |
public: |
|
644 |
TemplatePublish(VMTemplatePool * _tpool, |
|
645 |
UserPool * _upool): |
|
646 |
tpool(_tpool), |
|
647 |
upool(_upool) |
|
648 |
{ |
|
649 |
_signature="A:sib"; |
|
650 |
_help="Publish/Unpublish the Template"; |
|
651 |
}; |
|
652 |
|
|
653 |
~TemplatePublish(){}; |
|
654 |
|
|
655 |
void execute( |
|
656 |
xmlrpc_c::paramList const& paramList, |
|
657 |
xmlrpc_c::value * const retvalP); |
|
658 |
|
|
659 |
private: |
|
660 |
VMTemplatePool * tpool; |
|
661 |
UserPool * upool; |
|
662 |
}; |
|
663 |
|
|
664 |
/* ---------------------------------------------------------------------- */ |
|
665 |
|
|
666 |
class TemplatePoolInfo: public xmlrpc_c::method |
|
667 |
{ |
|
668 |
public: |
|
669 |
TemplatePoolInfo( |
|
670 |
VMTemplatePool * _tpool, |
|
671 |
UserPool * _upool): |
|
672 |
tpool(_tpool), |
|
673 |
upool(_upool) |
|
674 |
{ |
|
675 |
_signature="A:sii"; |
|
676 |
_help="Returns the template pool"; |
|
677 |
}; |
|
678 |
|
|
679 |
~TemplatePoolInfo(){}; |
|
680 |
|
|
681 |
void execute( |
|
682 |
xmlrpc_c::paramList const& paramList, |
|
683 |
xmlrpc_c::value * const retvalP); |
|
684 |
|
|
685 |
private: |
|
686 |
VMTemplatePool * tpool; |
|
687 |
UserPool * upool; |
|
688 |
}; |
|
689 |
|
|
690 |
/* ---------------------------------------------------------------------- */ |
|
505 | 691 |
/* Host Interface */ |
506 | 692 |
/* ---------------------------------------------------------------------- */ |
507 | 693 |
|
include/User.h | ||
---|---|---|
141 | 141 |
* @param vaues the column values |
142 | 142 |
* @return 0 on success |
143 | 143 |
*/ |
144 |
int select_cb(void *nil, int num, char **values, char **names); |
|
144 |
// int select_cb(void *nil, int num, char **values, char **names);
|
|
145 | 145 |
|
146 | 146 |
/** |
147 | 147 |
* Bootstraps the database table(s) associated to the User |
include/VMTemplate.h | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#ifndef VMTEMPLATE_H_ |
|
18 |
#define VMTEMPLATE_H_ |
|
19 |
|
|
20 |
#include "PoolObjectSQL.h" |
|
21 |
#include "VirtualMachineTemplate.h" |
|
22 |
|
|
23 |
/* -------------------------------------------------------------------------- */ |
|
24 |
/* -------------------------------------------------------------------------- */ |
|
25 |
|
|
26 |
/** |
|
27 |
* The VMTemplate class. |
|
28 |
*/ |
|
29 |
class VMTemplate : public PoolObjectSQL |
|
30 |
{ |
|
31 |
public: |
|
32 |
|
|
33 |
/** |
|
34 |
* Function to write a VMTemplate on an output stream |
|
35 |
*/ |
|
36 |
friend ostream& operator<<(ostream& os, VMTemplate& u); |
|
37 |
|
|
38 |
/** |
|
39 |
* Function to print the VMTemplate object into a string in XML format |
|
40 |
* @param xml the resulting XML string |
|
41 |
* @return a reference to the generated string |
|
42 |
*/ |
|
43 |
string& to_xml(string& xml) const; |
|
44 |
|
|
45 |
/** |
|
46 |
* Returns true if the object is public |
|
47 |
* @return true if the Virtual Network is public |
|
48 |
*/ |
|
49 |
bool isPublic() |
|
50 |
{ |
|
51 |
return (public_template == 1); |
|
52 |
}; |
|
53 |
|
|
54 |
/** |
|
55 |
* Publish or unpublish an object |
|
56 |
* @param pub true to publish the object |
|
57 |
* @return 0 on success |
|
58 |
*/ |
|
59 |
bool publish(bool pub) |
|
60 |
{ |
|
61 |
if (pub == true) |
|
62 |
{ |
|
63 |
public_template = 1; |
|
64 |
} |
|
65 |
else |
|
66 |
{ |
|
67 |
public_template = 0; |
|
68 |
} |
|
69 |
|
|
70 |
return true; |
|
71 |
}; |
|
72 |
|
|
73 |
// ------------------------------------------------------------------------ |
|
74 |
// Template Contents |
|
75 |
// ------------------------------------------------------------------------ |
|
76 |
|
|
77 |
/** |
|
78 |
* Gets the values of a template attribute |
|
79 |
* @param name of the attribute |
|
80 |
* @param values of the attribute |
|
81 |
* @return the number of values |
|
82 |
*/ |
|
83 |
int get_template_attribute( |
|
84 |
string& name, |
|
85 |
vector<const Attribute*>& values) const |
|
86 |
{ |
|
87 |
return template_contents->get(name,values); |
|
88 |
}; |
|
89 |
|
|
90 |
/** |
|
91 |
* Gets the values of a template attribute |
|
92 |
* @param name of the attribute |
|
93 |
* @param values of the attribute |
|
94 |
* @return the number of values |
|
95 |
*/ |
|
96 |
int get_template_attribute( |
|
97 |
const char *name, |
|
98 |
vector<const Attribute*>& values) const |
|
99 |
{ |
|
100 |
string str=name; |
|
101 |
return template_contents->get(str,values); |
|
102 |
}; |
|
103 |
|
|
104 |
/** |
|
105 |
* Gets a string based attribute |
|
106 |
* @param name of the attribute |
|
107 |
* @param value of the attribute (a string), will be "" if not defined |
|
108 |
*/ |
|
109 |
void get_template_attribute( |
|
110 |
const char * name, |
|
111 |
string& value) const |
|
112 |
{ |
|
113 |
string str=name; |
|
114 |
template_contents->get(str,value); |
|
115 |
}; |
|
116 |
|
|
117 |
/** |
|
118 |
* Gets a string based attribute |
|
119 |
* @param name of the attribute |
|
120 |
* @param value of the attribute (an int), will be 0 if not defined |
|
121 |
*/ |
|
122 |
void get_template_attribute( |
|
123 |
const char * name, |
|
124 |
int& value) const |
|
125 |
{ |
|
126 |
string str=name; |
|
127 |
template_contents->get(str,value); |
|
128 |
}; |
|
129 |
|
|
130 |
/** |
|
131 |
* Removes an attribute |
|
132 |
* @param name of the attribute |
|
133 |
*/ |
|
134 |
int remove_template_attribute(const string& name) |
|
135 |
{ |
|
136 |
return template_contents->erase(name); |
|
137 |
}; |
|
138 |
|
|
139 |
/** |
|
140 |
* Adds a new attribute to the template (replacing it if |
|
141 |
* already defined), the object's mutex SHOULD be locked |
|
142 |
* @param name of the new attribute |
|
143 |
* @param value of the new attribute |
|
144 |
* @return 0 on success |
|
145 |
*/ |
|
146 |
int replace_template_attribute( |
|
147 |
const string& name, |
|
148 |
const string& value) |
|
149 |
{ |
|
150 |
SingleAttribute * sattr; |
|
151 |
|
|
152 |
template_contents->erase(name); |
|
153 |
|
|
154 |
sattr = new SingleAttribute(name,value); |
|
155 |
template_contents->set(sattr); |
|
156 |
|
|
157 |
return 0; |
|
158 |
}; |
|
159 |
|
|
160 |
private: |
|
161 |
// ------------------------------------------------------------------------- |
|
162 |
// Friends |
|
163 |
// ------------------------------------------------------------------------- |
|
164 |
|
|
165 |
friend class VMTemplatePool; |
|
166 |
|
|
167 |
// ------------------------------------------------------------------------- |
|
168 |
// VMTemplate Attributes |
|
169 |
// ------------------------------------------------------------------------- |
|
170 |
|
|
171 |
/** |
|
172 |
* Owner's name |
|
173 |
*/ |
|
174 |
string user_name; |
|
175 |
|
|
176 |
/** |
|
177 |
* The Virtual Machine template, holds the VM attributes. |
|
178 |
*/ |
|
179 |
VirtualMachineTemplate* template_contents; |
|
180 |
|
|
181 |
|
|
182 |
/** |
|
183 |
* Public scope of the VMTemplate |
|
184 |
*/ |
|
185 |
int public_template; |
|
186 |
|
|
187 |
// ************************************************************************* |
|
188 |
// DataBase implementation (Private) |
|
189 |
// ************************************************************************* |
|
190 |
|
|
191 |
/** |
|
192 |
* Execute an INSERT or REPLACE Sql query. |
|
193 |
* @param db The SQL DB |
|
194 |
* @param replace Execute an INSERT or a REPLACE |
|
195 |
* @return 0 one success |
|
196 |
*/ |
|
197 |
int insert_replace(SqlDB *db, bool replace); |
|
198 |
|
|
199 |
/** |
|
200 |
* Bootstraps the database table(s) associated to the VMTemplate |
|
201 |
*/ |
|
202 |
static void bootstrap(SqlDB * db) |
|
203 |
{ |
|
204 |
ostringstream oss(VMTemplate::db_bootstrap); |
|
205 |
|
|
206 |
db->exec(oss); |
|
207 |
}; |
|
208 |
|
|
209 |
/** |
|
210 |
* Rebuilds the object from an xml formatted string |
|
211 |
* @param xml_str The xml-formatted string |
|
212 |
* |
|
213 |
* @return 0 on success, -1 otherwise |
|
214 |
*/ |
|
215 |
int from_xml(const string &xml_str); |
|
216 |
|
|
217 |
protected: |
|
218 |
|
|
219 |
// ************************************************************************* |
|
220 |
// Constructor |
|
221 |
// ************************************************************************* |
|
222 |
VMTemplate(int id, int uid, string _user_name, |
|
223 |
VirtualMachineTemplate * _template_contents); |
|
224 |
|
|
225 |
~VMTemplate(); |
|
226 |
|
|
227 |
// ************************************************************************* |
|
228 |
// DataBase implementation |
|
229 |
// ************************************************************************* |
|
230 |
|
|
231 |
static const char * db_names; |
|
232 |
|
|
233 |
static const char * db_bootstrap; |
|
234 |
|
|
235 |
static const char * table; |
|
236 |
|
|
237 |
/** |
|
238 |
* Writes the VMTemplate in the database. |
|
239 |
* @param db pointer to the db |
|
240 |
* @return 0 on success |
|
241 |
*/ |
|
242 |
int insert(SqlDB *db, string& error_str); |
|
243 |
|
|
244 |
/** |
|
245 |
* Writes/updates the VMTemplate data fields in the database. |
|
246 |
* @param db pointer to the db |
|
247 |
* @return 0 on success |
|
248 |
*/ |
|
249 |
int update(SqlDB *db) |
|
250 |
{ |
|
251 |
return insert_replace(db, true); |
|
252 |
}; |
|
253 |
}; |
|
254 |
|
|
255 |
#endif /*VMTEMPLATE_H_*/ |
include/VMTemplatePool.h | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#ifndef VMTEMPLATE_POOL_H_ |
|
18 |
#define VMTEMPLATE_POOL_H_ |
|
19 |
|
|
20 |
#include "PoolSQL.h" |
|
21 |
#include "VMTemplate.h" |
|
22 |
|
|
23 |
/** |
|
24 |
* The VMTemplate Pool class. |
|
25 |
*/ |
|
26 |
class VMTemplatePool : public PoolSQL |
|
27 |
{ |
|
28 |
public: |
|
29 |
|
|
30 |
VMTemplatePool(SqlDB * db) : PoolSQL(db, VMTemplate::table){}; |
|
31 |
|
|
32 |
~VMTemplatePool(){}; |
|
33 |
|
|
34 |
/** |
|
35 |
* Allocates a new object, writting it in the pool database. No memory is |
|
36 |
* allocated for the object. |
|
37 |
* @param uid user id (the owner of the Template) |
|
38 |
* @param user_name Owner's user name |
|
39 |
* @param template_contents a VM Template object |
|
40 |
* @param oid the id assigned to the Template |
|
41 |
* @param error_str Returns the error reason, if any |
|
42 |
* |
|
43 |
* @return the oid assigned to the object, -1 in case of failure |
|
44 |
*/ |
|
45 |
int allocate(int uid, |
|
46 |
string user_name, |
|
47 |
VirtualMachineTemplate * template_contents, |
|
48 |
int * oid, |
|
49 |
string& error_str); |
|
50 |
|
|
51 |
/** |
|
52 |
* Gets an object from the pool (if needed the object is loaded from the |
|
53 |
* database). |
|
54 |
* @param oid the object unique identifier |
|
55 |
* @param lock locks the object if true |
|
56 |
* |
|
57 |
* @return a pointer to the object, 0 in case of failure |
|
58 |
*/ |
|
59 |
VMTemplate * get(int oid, bool lock) |
|
60 |
{ |
|
61 |
return static_cast<VMTemplate *>(PoolSQL::get(oid,lock)); |
|
62 |
}; |
|
63 |
|
|
64 |
/** |
|
65 |
* Gets an object from the pool (if needed the object is loaded from the |
|
66 |
* database). |
|
67 |
* @param name of the object |
|
68 |
* @param uid id of owner |
|
69 |
* @param lock locks the object if true |
|
70 |
* |
|
71 |
* @return a pointer to the object, 0 in case of failure |
|
72 |
*/ |
|
73 |
VMTemplate * get(const string& name, int uid, bool lock) |
|
74 |
{ |
|
75 |
return static_cast<VMTemplate *>(PoolSQL::get(name,uid,lock)); |
|
76 |
}; |
|
77 |
|
|
78 |
/** |
|
79 |
* Updates the object's data in the data base. The object mutex SHOULD be |
|
80 |
* locked. |
|
81 |
* @param objsql a pointer to the object |
|
82 |
* |
|
83 |
* @return 0 on success. |
|
84 |
*/ |
|
85 |
int update(VMTemplate * vm_template) |
|
86 |
{ |
|
87 |
return vm_template->update(db); |
|
88 |
}; |
|
89 |
|
|
90 |
/** |
|
91 |
* Drops the object's data in the data base. The object mutex SHOULD be |
|
92 |
* locked. |
|
93 |
* @param objsql a pointer to the object |
|
94 |
* @return 0 on success. |
|
95 |
*/ |
|
96 |
int drop(VMTemplate * vm_template) |
|
97 |
{ |
|
98 |
return PoolSQL::drop(vm_template); |
|
99 |
}; |
|
100 |
|
|
101 |
/** |
|
102 |
* Dumps the pool in XML format. A filter can be also added to the |
|
103 |
* query |
|
104 |
* @param oss the output stream to dump the pool contents |
|
105 |
* @param where filter for the objects, defaults to all |
|
106 |
* |
|
107 |
* @return 0 on success |
|
108 |
*/ |
|
109 |
int dump(ostringstream& oss, const string& where) |
|
110 |
{ |
|
111 |
return PoolSQL::dump(oss, "TEMPLATE_POOL",VMTemplate::table,where); |
|
112 |
}; |
|
113 |
|
|
114 |
/** |
|
115 |
* Bootstraps the database table(s) associated to the pool |
|
116 |
*/ |
|
117 |
static void bootstrap(SqlDB *_db) |
|
118 |
{ |
|
119 |
VMTemplate::bootstrap(_db); |
|
120 |
}; |
|
121 |
|
|
122 |
private: |
|
123 |
//-------------------------------------------------------------------------- |
|
124 |
// Configuration Attributes for Images |
|
125 |
// ------------------------------------------------------------------------- |
|
126 |
|
|
127 |
// TODO |
|
128 |
|
|
129 |
//-------------------------------------------------------------------------- |
|
130 |
// Pool Attributes |
|
131 |
// ------------------------------------------------------------------------- |
|
132 |
|
|
133 |
// TODO |
|
134 |
|
|
135 |
|
|
136 |
/** |
|
137 |
* Factory method to produce Image objects |
|
138 |
* @return a pointer to the new Image |
|
139 |
*/ |
|
140 |
PoolObjectSQL * create() |
|
141 |
{ |
|
142 |
return new VMTemplate(-1,-1,"", 0); |
|
143 |
}; |
|
144 |
}; |
|
145 |
|
|
146 |
#endif /*VMTEMPLATE_POOL_H_*/ |
include/VirtualMachinePool.h | ||
---|---|---|
41 | 41 |
/** |
42 | 42 |
* Function to allocate a new VM object |
43 | 43 |
* @param uid user id (the owner of the VM) |
44 |
* @param user_name Owner's user name |
|
44 | 45 |
* @param vm_template a VM Template object describing the VM |
45 | 46 |
* @param oid the id assigned to the VM (output) |
47 |
* @param error_str Returns the error reason, if any |
|
46 | 48 |
* @param on_hold flag to submit on hold |
47 | 49 |
* @return oid on success, -1 error inserting in DB or -2 error parsing |
48 | 50 |
* the template |
src/authm/AuthManager.cc | ||
---|---|---|
86 | 86 |
case IMAGE: oss << "IMAGE:" ; break; |
87 | 87 |
case USER: oss << "USER:" ; break; |
88 | 88 |
case CLUSTER: oss << "CLUSTER:" ; break; |
89 |
case TEMPLATE: oss << "TEMPLATE:" ; break; |
|
89 | 90 |
} |
90 | 91 |
|
91 | 92 |
if (op == CREATE) //encode the ob_id, it is a template |
src/nebula/Nebula.cc | ||
---|---|---|
235 | 235 |
UserPool::bootstrap(db); |
236 | 236 |
ImagePool::bootstrap(db); |
237 | 237 |
ClusterPool::bootstrap(db); |
238 |
VMTemplatePool::bootstrap(db); |
|
238 | 239 |
} |
239 | 240 |
catch (exception&) |
240 | 241 |
{ |
... | ... | |
276 | 277 |
default_device_prefix); |
277 | 278 |
|
278 | 279 |
cpool = new ClusterPool(db); |
280 |
|
|
281 |
tpool = new VMTemplatePool(db); |
|
279 | 282 |
} |
280 | 283 |
catch (exception&) |
281 | 284 |
{ |
... | ... | |
442 | 445 |
upool, |
443 | 446 |
ipool, |
444 | 447 |
cpool, |
448 |
tpool, |
|
445 | 449 |
rm_port, |
446 | 450 |
log_location + "one_xmlrpc.log"); |
447 | 451 |
} |
src/nebula/SConstruct | ||
---|---|---|
50 | 50 |
'nebula_host', |
51 | 51 |
'nebula_vnm', |
52 | 52 |
'nebula_vm', |
53 |
'nebula_vmtemplate', |
|
53 | 54 |
'nebula_common', |
54 | 55 |
'nebula_sql', |
55 | 56 |
'nebula_log', |
src/rm/RequestManager.cc | ||
---|---|---|
233 | 233 |
|
234 | 234 |
xmlrpc_c::methodPtr vm_pool_info(new |
235 | 235 |
RequestManager::VirtualMachinePoolInfo(vmpool,upool)); |
236 |
|
|
236 |
|
|
237 |
xmlrpc_c::methodPtr template_allocate(new |
|
238 |
RequestManager::TemplateAllocate(tpool,upool)); |
|
239 |
|
|
240 |
xmlrpc_c::methodPtr template_delete(new |
|
241 |
RequestManager::TemplateDelete(tpool, upool)); |
|
242 |
|
|
243 |
xmlrpc_c::methodPtr template_info(new |
|
244 |
RequestManager::TemplateInfo(tpool, upool)); |
|
245 |
|
|
246 |
xmlrpc_c::methodPtr template_update(new |
|
247 |
RequestManager::TemplateUpdate(tpool, upool)); |
|
248 |
|
|
249 |
xmlrpc_c::methodPtr template_rm_attribute(new |
|
250 |
RequestManager::TemplateRemoveAttribute(tpool, upool)); |
|
251 |
|
|
252 |
xmlrpc_c::methodPtr template_publish(new |
|
253 |
RequestManager::TemplatePublish(tpool, upool)); |
|
254 |
|
|
255 |
xmlrpc_c::methodPtr template_pool_info(new |
|
256 |
RequestManager::TemplatePoolInfo(tpool,upool)); |
|
257 |
|
|
237 | 258 |
xmlrpc_c::methodPtr host_allocate(new |
238 | 259 |
RequestManager::HostAllocate(hpool,upool)); |
239 | 260 |
|
... | ... | |
340 | 361 |
RequestManagerRegistry.addMethod("one.vm.savedisk", vm_savedisk); |
341 | 362 |
|
342 | 363 |
RequestManagerRegistry.addMethod("one.vmpool.info", vm_pool_info); |
343 |
|
|
364 |
|
|
365 |
/* VM Template related methods*/ |
|
366 |
|
|
367 |
RequestManagerRegistry.addMethod("one.template.allocate",template_allocate); |
|
368 |
RequestManagerRegistry.addMethod("one.templatepool.info",template_pool_info); |
|
369 |
|
|
344 | 370 |
/* Host related methods*/ |
345 | 371 |
|
346 | 372 |
RequestManagerRegistry.addMethod("one.host.allocate", host_allocate); |
src/rm/RequestManagerImagePoolInfo.cc | ||
---|---|---|
65 | 65 |
switch(filter_flag) |
66 | 66 |
{ |
67 | 67 |
case -2: |
68 |
// TODO define authentication bug #278 |
|
69 | 68 |
break; |
70 | 69 |
case -1: |
71 | 70 |
where_string << "UID=" << rc << " OR PUBLIC=1"; |
src/rm/RequestManagerTemplateAllocate.cc | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#include "RequestManager.h" |
|
18 |
#include "NebulaLog.h" |
|
19 |
|
|
20 |
#include "Nebula.h" |
|
21 |
|
|
22 |
/* -------------------------------------------------------------------------- */ |
|
23 |
/* -------------------------------------------------------------------------- */ |
|
24 |
|
|
25 |
void RequestManager::TemplateAllocate::execute( |
|
26 |
xmlrpc_c::paramList const& paramList, |
|
27 |
xmlrpc_c::value * const retval) |
|
28 |
{ |
|
29 |
string session; |
|
30 |
string str_template; |
|
31 |
string error_str; |
|
32 |
string user_name; |
|
33 |
|
|
34 |
const string method_name = "TemplateAllocate"; |
|
35 |
|
|
36 |
int oid, uid; |
|
37 |
int rc; |
|
38 |
|
|
39 |
ostringstream oss; |
|
40 |
|
|
41 |
vector<xmlrpc_c::value> arrayData; |
|
42 |
xmlrpc_c::value_array * arrayresult; |
|
43 |
|
|
44 |
VirtualMachineTemplate * template_contents; |
|
45 |
User * user; |
|
46 |
char * error_msg = 0; |
|
47 |
|
|
48 |
|
|
49 |
NebulaLog::log("ReM",Log::DEBUG,"TemplateAllocate invoked"); |
|
50 |
|
|
51 |
session = xmlrpc_c::value_string(paramList.getString(0)); |
|
52 |
str_template = xmlrpc_c::value_string(paramList.getString(1)); |
|
53 |
str_template += "\n"; |
|
54 |
|
|
55 |
//-------------------------------------------------------------------------- |
|
56 |
// Authenticate the user |
|
57 |
//-------------------------------------------------------------------------- |
|
58 |
uid = TemplateAllocate::upool->authenticate(session); |
|
59 |
|
|
60 |
if (uid == -1) |
|
61 |
{ |
|
62 |
goto error_authenticate; |
|
63 |
} |
|
64 |
|
|
65 |
//-------------------------------------------------------------------------- |
|
66 |
// Check the template syntax |
|
67 |
//-------------------------------------------------------------------------- |
|
68 |
template_contents = new VirtualMachineTemplate; |
|
69 |
|
|
70 |
rc = template_contents->parse(str_template,&error_msg); |
|
71 |
|
|
72 |
if ( rc != 0 ) |
|
73 |
{ |
|
74 |
goto error_parse; |
|
75 |
} |
|
76 |
|
|
77 |
//-------------------------------------------------------------------------- |
|
78 |
// Authorize this request |
|
79 |
//-------------------------------------------------------------------------- |
|
80 |
if ( uid != 0 ) |
|
81 |
{ |
|
82 |
AuthRequest ar(uid); |
|
83 |
string t64; |
|
84 |
|
|
85 |
ar.add_auth(AuthRequest::TEMPLATE, |
|
86 |
template_contents->to_xml(t64), |
|
87 |
AuthRequest::CREATE, |
|
88 |
uid, |
|
89 |
false); |
|
90 |
|
|
91 |
if (UserPool::authorize(ar) == -1) |
|
92 |
{ |
|
93 |
goto error_authorize; |
|
94 |
} |
|
95 |
} |
|
96 |
|
|
97 |
//-------------------------------------------------------------------------- |
|
98 |
// Get the User Name |
|
99 |
//-------------------------------------------------------------------------- |
|
100 |
|
|
101 |
user = TemplateAllocate::upool->get(uid,true); |
|
102 |
|
|
103 |
if ( user == 0 ) |
|
104 |
{ |
|
105 |
goto error_user_get; |
|
106 |
} |
|
107 |
|
|
108 |
user_name = user->get_name(); |
|
109 |
|
|
110 |
user->unlock(); |
|
111 |
|
|
112 |
//-------------------------------------------------------------------------- |
|
113 |
// Allocate the VMTemplate |
|
114 |
//-------------------------------------------------------------------------- |
|
115 |
rc = TemplateAllocate::tpool->allocate(uid, |
|
116 |
user_name, |
|
117 |
template_contents, |
|
118 |
&oid, |
|
119 |
error_str); |
|
120 |
|
|
121 |
if ( rc < 0 ) |
|
122 |
{ |
|
123 |
goto error_allocate; |
|
124 |
} |
|
125 |
|
|
126 |
arrayData.push_back(xmlrpc_c::value_boolean(true)); |
|
127 |
arrayData.push_back(xmlrpc_c::value_int(oid)); |
|
128 |
|
|
129 |
// Copy arrayresult into retval mem space |
|
130 |
arrayresult = new xmlrpc_c::value_array(arrayData); |
|
131 |
*retval = *arrayresult; |
|
132 |
|
|
133 |
delete arrayresult; // and get rid of the original |
|
134 |
|
|
135 |
return; |
|
136 |
|
|
137 |
|
|
138 |
error_user_get: |
|
139 |
oss.str(get_error(method_name, "USER", uid)); |
|
140 |
|
|
141 |
delete template_contents; |
|
142 |
goto error_common; |
|
143 |
|
|
144 |
error_authenticate: |
|
145 |
oss.str(authenticate_error(method_name)); |
|
146 |
goto error_common; |
|
147 |
|
|
148 |
error_authorize: |
|
149 |
oss.str(authorization_error(method_name, "CREATE", "TEMPLATE", uid, -1)); |
|
150 |
delete template_contents; |
|
151 |
goto error_common; |
|
152 |
|
|
153 |
error_parse: |
|
154 |
oss << action_error(method_name, "PARSE", "VM TEMPLATE",-2,rc); |
|
155 |
if (error_msg != 0) |
|
156 |
{ |
|
157 |
oss << ". Reason: " << error_msg; |
|
158 |
free(error_msg); |
|
159 |
} |
|
160 |
|
|
161 |
delete template_contents; |
|
162 |
goto error_common; |
|
163 |
|
|
164 |
error_allocate: |
|
165 |
oss << action_error(method_name, "CREATE", "TEMPLATE", -2, 0); |
|
166 |
oss << " " << error_str; |
|
167 |
goto error_common; |
|
168 |
|
|
169 |
error_common: |
|
170 |
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE |
|
171 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
172 |
|
|
173 |
NebulaLog::log("ReM",Log::ERROR,oss); |
|
174 |
|
|
175 |
xmlrpc_c::value_array arrayresult_error(arrayData); |
|
176 |
|
|
177 |
*retval = arrayresult_error; |
|
178 |
|
|
179 |
return; |
|
180 |
} |
|
181 |
|
|
182 |
/* -------------------------------------------------------------------------- */ |
|
183 |
/* -------------------------------------------------------------------------- */ |
src/rm/RequestManagerTemplateDelete.cc | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#include "RequestManager.h" |
|
18 |
|
|
19 |
#include "NebulaLog.h" |
|
20 |
#include "Nebula.h" |
|
21 |
|
|
22 |
#include "AuthManager.h" |
|
23 |
|
|
24 |
/* -------------------------------------------------------------------------- */ |
|
25 |
/* -------------------------------------------------------------------------- */ |
|
26 |
|
|
27 |
void RequestManager::TemplateDelete::execute( |
|
28 |
xmlrpc_c::paramList const& paramList, |
|
29 |
xmlrpc_c::value * const retval) |
|
30 |
{ |
|
31 |
string session; |
|
32 |
|
|
33 |
int oid; |
|
34 |
int uid; |
|
35 |
int rc; |
|
36 |
|
|
37 |
int owner; |
|
38 |
bool is_public; |
|
39 |
|
|
40 |
VMTemplate * vm_template; |
|
41 |
|
|
42 |
ostringstream oss; |
|
43 |
|
|
44 |
const string method_name = "TemplateDelete"; |
|
45 |
|
|
46 |
vector<xmlrpc_c::value> arrayData; |
|
47 |
xmlrpc_c::value_array * arrayresult; |
|
48 |
|
|
49 |
|
|
50 |
NebulaLog::log("ReM",Log::DEBUG,"TemplateDelete invoked"); |
|
51 |
|
|
52 |
session = xmlrpc_c::value_string(paramList.getString(0)); |
|
53 |
oid = xmlrpc_c::value_int (paramList.getInt(1)); |
|
54 |
|
|
55 |
|
|
56 |
// First, we need to authenticate the user |
|
57 |
uid = TemplateDelete::upool->authenticate(session); |
|
58 |
|
|
59 |
if ( uid == -1 ) |
|
60 |
{ |
|
61 |
goto error_authenticate; |
|
62 |
} |
|
63 |
|
|
64 |
// Get template from the pool |
|
65 |
vm_template = TemplateDelete::tpool->get(oid,true); |
|
66 |
|
|
67 |
if ( vm_template == 0 ) |
|
68 |
{ |
|
69 |
goto error_get; |
|
70 |
} |
|
71 |
|
|
72 |
owner = vm_template->get_uid(); |
|
73 |
is_public = vm_template->isPublic(); |
|
74 |
|
|
75 |
vm_template->unlock(); |
|
76 |
|
|
77 |
//Authorize the operation |
|
78 |
if ( uid != 0 ) // uid == 0 means oneadmin |
|
79 |
{ |
|
80 |
AuthRequest ar(uid); |
|
81 |
|
|
82 |
ar.add_auth(AuthRequest::TEMPLATE, |
|
83 |
oid, |
|
84 |
AuthRequest::DELETE, |
|
85 |
owner, |
|
86 |
is_public); |
|
87 |
|
|
88 |
if (UserPool::authorize(ar) == -1) |
|
89 |
{ |
|
90 |
goto error_authorize; |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
// Get template from the pool |
|
95 |
vm_template = TemplateDelete::tpool->get(oid,true); |
|
96 |
|
|
97 |
if ( vm_template == 0 ) |
|
98 |
{ |
|
99 |
goto error_get; |
|
100 |
} |
|
101 |
|
|
102 |
rc = TemplateDelete::tpool->drop(vm_template); |
|
103 |
|
|
104 |
vm_template->unlock(); |
|
105 |
|
|
106 |
if ( rc < 0 ) |
|
107 |
{ |
|
108 |
goto error_delete; |
|
109 |
} |
|
110 |
|
|
111 |
arrayData.push_back(xmlrpc_c::value_boolean(true)); |
|
112 |
arrayData.push_back(xmlrpc_c::value_int(oid)); |
|
113 |
|
|
114 |
// Copy arrayresult into retval mem space |
|
115 |
arrayresult = new xmlrpc_c::value_array(arrayData); |
|
116 |
*retval = *arrayresult; |
|
117 |
|
|
118 |
delete arrayresult; // and get rid of the original |
|
119 |
|
|
120 |
return; |
|
121 |
|
|
122 |
error_authenticate: |
|
123 |
oss.str(authenticate_error(method_name)); |
|
124 |
goto error_common; |
|
125 |
|
|
126 |
error_get: |
|
127 |
oss.str(get_error(method_name, "TEMPLATE", oid)); |
|
128 |
goto error_common; |
|
129 |
|
|
130 |
error_authorize: |
|
131 |
oss.str(authorization_error(method_name, "DELETE", "TEMPLATE", uid, oid)); |
|
132 |
goto error_common; |
|
133 |
|
|
134 |
error_delete: |
|
135 |
oss.str(action_error(method_name, "DELETE", "TEMPLATE", oid, rc)); |
|
136 |
vm_template->unlock(); |
|
137 |
goto error_common; |
|
138 |
|
|
139 |
error_common: |
|
140 |
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE |
|
141 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
142 |
|
|
143 |
NebulaLog::log("ReM",Log::ERROR,oss); |
|
144 |
|
|
145 |
xmlrpc_c::value_array arrayresult_error(arrayData); |
|
146 |
|
|
147 |
*retval = arrayresult_error; |
|
148 |
|
|
149 |
return; |
|
150 |
} |
|
151 |
|
|
152 |
/* -------------------------------------------------------------------------- */ |
|
153 |
/* -------------------------------------------------------------------------- */ |
src/rm/RequestManagerTemplateInfo.cc | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#include "RequestManager.h" |
|
18 |
#include "NebulaLog.h" |
|
19 |
|
|
20 |
#include "AuthManager.h" |
|
21 |
|
|
22 |
/* -------------------------------------------------------------------------- */ |
|
23 |
/* -------------------------------------------------------------------------- */ |
|
24 |
|
|
25 |
void RequestManager::TemplateInfo::execute( |
|
26 |
xmlrpc_c::paramList const& paramList, |
|
27 |
xmlrpc_c::value * const retval) |
|
28 |
{ |
|
29 |
string session; |
|
30 |
|
|
31 |
int oid; |
|
32 |
int uid; // owner user id |
|
33 |
int rc; // Requesting user id |
|
34 |
VMTemplate * vm_template; |
|
35 |
|
|
36 |
ostringstream oss; |
|
37 |
|
|
38 |
const string method_name = "TemplateInfo"; |
|
39 |
|
|
40 |
/* -- RPC specific vars -- */ |
|
41 |
vector<xmlrpc_c::value> arrayData; |
|
42 |
xmlrpc_c::value_array * arrayresult; |
|
43 |
|
|
44 |
NebulaLog::log("ReM",Log::DEBUG,"TemplateInfo method invoked"); |
|
45 |
|
|
46 |
// Get the parameters |
|
47 |
session = xmlrpc_c::value_string(paramList.getString(0)); |
|
48 |
oid = xmlrpc_c::value_int (paramList.getInt(1)); |
|
49 |
|
|
50 |
// Get template from the pool |
|
51 |
vm_template = TemplateInfo::tpool->get(oid,true); |
|
52 |
|
|
53 |
if ( vm_template == 0 ) |
|
54 |
{ |
|
55 |
goto error_get; |
|
56 |
} |
|
57 |
|
|
58 |
uid = vm_template->get_uid(); |
|
59 |
|
|
60 |
// Check if it is a valid user |
|
61 |
rc = TemplateInfo::upool->authenticate(session); |
|
62 |
|
|
63 |
if ( rc == -1 ) |
|
64 |
{ |
|
65 |
goto error_authenticate; |
|
66 |
} |
|
67 |
|
|
68 |
oss << *vm_template; |
|
69 |
|
|
70 |
vm_template->unlock(); |
|
71 |
|
|
72 |
// All nice, return the host info to the client |
|
73 |
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS |
|
74 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
75 |
|
|
76 |
// Copy arrayresult into retval mem space |
|
77 |
arrayresult = new xmlrpc_c::value_array(arrayData); |
|
78 |
*retval = *arrayresult; |
|
79 |
|
|
80 |
delete arrayresult; // and get rid of the original |
|
81 |
|
|
82 |
return; |
|
83 |
|
|
84 |
error_get: |
|
85 |
oss.str(get_error(method_name, "TEMPLATE", oid)); |
|
86 |
goto error_common; |
|
87 |
|
|
88 |
error_authenticate: |
|
89 |
oss.str(authenticate_error(method_name)); |
|
90 |
vm_template->unlock(); |
|
91 |
goto error_common; |
|
92 |
|
|
93 |
error_common: |
|
94 |
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE |
|
95 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
96 |
|
|
97 |
NebulaLog::log("ReM",Log::ERROR,oss); |
|
98 |
|
|
99 |
xmlrpc_c::value_array arrayresult_error(arrayData); |
|
100 |
|
|
101 |
*retval = arrayresult_error; |
|
102 |
|
|
103 |
return; |
|
104 |
} |
|
105 |
|
|
106 |
/* -------------------------------------------------------------------------- */ |
|
107 |
/* -------------------------------------------------------------------------- */ |
src/rm/RequestManagerTemplatePoolInfo.cc | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#include "RequestManager.h" |
|
18 |
#include "NebulaLog.h" |
|
19 |
|
|
20 |
/* -------------------------------------------------------------------------- */ |
|
21 |
/* -------------------------------------------------------------------------- */ |
|
22 |
|
|
23 |
void RequestManager::TemplatePoolInfo::execute( |
|
24 |
xmlrpc_c::paramList const& paramList, |
|
25 |
xmlrpc_c::value * const retval) |
|
26 |
{ |
|
27 |
string session; |
|
28 |
|
|
29 |
ostringstream oss; |
|
30 |
ostringstream where_string; |
|
31 |
|
|
32 |
int rc; |
|
33 |
int filter_flag; |
|
34 |
|
|
35 |
const string method_name = "TemplatePoolInfo"; |
|
36 |
|
|
37 |
/* -- RPC specific vars -- */ |
|
38 |
vector<xmlrpc_c::value> arrayData; |
|
39 |
xmlrpc_c::value_array * arrayresult; |
|
40 |
|
|
41 |
NebulaLog::log("ReM",Log::DEBUG,"TemplatePoolInfo method invoked"); |
|
42 |
|
|
43 |
// Get the parameters |
|
44 |
session = xmlrpc_c::value_string(paramList.getString(0)); |
|
45 |
filter_flag = xmlrpc_c::value_int(paramList.getInt(1)); |
|
46 |
|
|
47 |
// Check if it is a valid user |
|
48 |
rc = TemplatePoolInfo::upool->authenticate(session); |
|
49 |
|
|
50 |
if ( rc == -1 ) |
|
51 |
{ |
|
52 |
goto error_authenticate; |
|
53 |
} |
|
54 |
|
|
55 |
/** Filter flag meaning table |
|
56 |
* -2 :: All Templates |
|
57 |
* -1 :: User's Templates AND public templates belonging to any user |
|
58 |
* >= 0 :: UID User's Templates |
|
59 |
**/ |
|
60 |
if ( filter_flag < -2 ) |
|
61 |
{ |
|
62 |
goto error_filter_flag; |
|
63 |
} |
|
64 |
|
|
65 |
switch(filter_flag) |
|
66 |
{ |
|
67 |
case -2: |
|
68 |
break; |
|
69 |
case -1: |
|
70 |
where_string << "UID=" << rc << " OR PUBLIC=1"; |
|
71 |
break; |
|
72 |
default: |
|
73 |
where_string << "UID=" << filter_flag; |
|
74 |
} |
|
75 |
|
|
76 |
// Call the template pool dump |
|
77 |
rc = TemplatePoolInfo::tpool->dump(oss,where_string.str()); |
|
78 |
|
|
79 |
if ( rc != 0 ) |
|
80 |
{ |
|
81 |
goto error_dump; |
|
82 |
} |
|
83 |
|
|
84 |
// All nice, return pool info to the client |
|
85 |
arrayData.push_back(xmlrpc_c::value_boolean(true)); // SUCCESS |
|
86 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
87 |
|
|
88 |
arrayresult = new xmlrpc_c::value_array(arrayData); |
|
89 |
|
|
90 |
// Copy arrayresult into retval mem space |
|
91 |
*retval = *arrayresult; |
|
92 |
|
|
93 |
// and get rid of the original |
|
94 |
delete arrayresult; |
|
95 |
|
|
96 |
return; |
|
97 |
|
|
98 |
error_authenticate: |
|
99 |
oss.str(authenticate_error(method_name)); |
|
100 |
goto error_common; |
|
101 |
|
|
102 |
error_filter_flag: |
|
103 |
oss << "Incorrect filter_flag, must be >= -2."; |
|
104 |
goto error_common; |
|
105 |
|
|
106 |
error_dump: |
|
107 |
oss.str(get_error(method_name, "TEMPLATE", -1)); |
|
108 |
goto error_common; |
|
109 |
|
|
110 |
error_common: |
|
111 |
arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE |
|
112 |
arrayData.push_back(xmlrpc_c::value_string(oss.str())); |
|
113 |
|
|
114 |
NebulaLog::log("ReM",Log::ERROR,oss); |
|
115 |
|
|
116 |
xmlrpc_c::value_array arrayresult_error(arrayData); |
|
117 |
|
|
118 |
*retval = arrayresult_error; |
|
119 |
|
|
120 |
return; |
|
121 |
} |
|
122 |
|
|
123 |
/* -------------------------------------------------------------------------- */ |
|
124 |
/* -------------------------------------------------------------------------- */ |
src/rm/RequestManagerTemplatePublish.cc | ||
---|---|---|
1 |
/* -------------------------------------------------------------------------- */ |
|
2 |
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) */ |
|
3 |
/* */ |
|
4 |
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ |
|
5 |
/* not use this file except in compliance with the License. You may obtain */ |
|
6 |
/* a copy of the License at */ |
|
7 |
/* */ |
|
8 |
/* http://www.apache.org/licenses/LICENSE-2.0 */ |
|
9 |
/* */ |
|
10 |
/* Unless required by applicable law or agreed to in writing, software */ |
|
11 |
/* distributed under the License is distributed on an "AS IS" BASIS, */ |
|
12 |
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ |
|
13 |
/* See the License for the specific language governing permissions and */ |
|
14 |
/* limitations under the License. */ |
|
15 |
/* -------------------------------------------------------------------------- */ |
|
16 |
|
|
17 |
#include "RequestManager.h" |
|
18 |
|
|
19 |
#include "NebulaLog.h" |
|
20 |
#include "Nebula.h" |
|
21 |
|
|
22 |
#include "AuthManager.h" |
|
23 |
|
|
24 |
/* -------------------------------------------------------------------------- */ |
|
25 |
/* -------------------------------------------------------------------------- */ |
Also available in: Unified diff