Revision 2ce40099
include/VirtualMachine.h | ||
---|---|---|
656 | 656 |
* @param img_id ID of the image this disk will be saved to. |
657 | 657 |
* @return 0 if success |
658 | 658 |
*/ |
659 |
int save_disk(int disk_id, int img_id); |
|
659 |
int save_disk(int disk_id, int img_id, string& error_str);
|
|
660 | 660 |
|
661 | 661 |
private: |
662 | 662 |
|
src/rm/RequestManagerImagePersistent.cc | ||
---|---|---|
137 | 137 |
|
138 | 138 |
error_persistent: |
139 | 139 |
image->unlock(); |
140 |
oss << action_error(method_name, "MANAGE", "IMAGE", iid, 0) |
|
141 |
<< " Is the image public? An Image cannot be public and persistent."; |
|
140 |
oss.str(action_error(method_name, "MANAGE", "IMAGE", iid, 0)); |
|
142 | 141 |
goto error_common; |
143 | 142 |
|
144 | 143 |
error_common: |
src/rm/RequestManagerSaveDisk.cc | ||
---|---|---|
39 | 39 |
int rc; |
40 | 40 |
int uid; |
41 | 41 |
string estr; |
42 |
char * error_str; |
|
42 |
char * error_char; |
|
43 |
string error_str; |
|
43 | 44 |
|
44 | 45 |
const string method_name = "VirtualMachineSaveDisk"; |
45 | 46 |
|
... | ... | |
48 | 49 |
ImageTemplate * img_template; |
49 | 50 |
User * user; |
50 | 51 |
|
52 |
Image * source_img; |
|
53 |
int source_img_id; |
|
54 |
bool source_img_persistent = false; |
|
55 |
|
|
51 | 56 |
vector<xmlrpc_c::value> arrayData; |
52 | 57 |
xmlrpc_c::value_array * arrayresult; |
53 | 58 |
|
... | ... | |
92 | 97 |
|
93 | 98 |
if ( image != 0 ) |
94 | 99 |
{ |
95 |
goto error_image_get;
|
|
100 |
goto error_image_exists;
|
|
96 | 101 |
} |
97 | 102 |
|
98 | 103 |
oss << "NAME= " << img_name << endl; |
... | ... | |
101 | 106 |
|
102 | 107 |
img_template = new ImageTemplate; |
103 | 108 |
|
104 |
img_template->parse(oss.str(),&error_str);
|
|
109 |
img_template->parse(oss.str(),&error_char);
|
|
105 | 110 |
|
106 | 111 |
oss.str(""); |
107 | 112 |
|
... | ... | |
158 | 163 |
oss.str(""); |
159 | 164 |
|
160 | 165 |
//-------------------------------------------------------------------------- |
161 |
// Store image id to save the disk in the VM template
|
|
166 |
// Get the VM
|
|
162 | 167 |
//-------------------------------------------------------------------------- |
163 | 168 |
vm = VirtualMachineSaveDisk::vmpool->get(vm_id,true); |
164 | 169 |
|
... | ... | |
167 | 172 |
goto error_vm_get; |
168 | 173 |
} |
169 | 174 |
|
170 |
rc = vm->save_disk(disk_id, iid); |
|
175 |
//-------------------------------------------------------------------------- |
|
176 |
// Check if the disk has a persistent source image |
|
177 |
//-------------------------------------------------------------------------- |
|
178 |
oss << "/VM/TEMPLATE/DISK[DISK_ID=" << disk_id << "]/IMAGE_ID"; |
|
179 |
rc = vm->xpath(source_img_id, oss.str().c_str(), -1); |
|
180 |
oss.str(""); |
|
181 |
|
|
182 |
if( rc == 0 ) // The disk was created from an Image |
|
183 |
{ |
|
184 |
source_img = VirtualMachineSaveDisk::ipool->get(source_img_id, true); |
|
185 |
|
|
186 |
if( source_img != 0 ) // The Image still exists |
|
187 |
{ |
|
188 |
source_img_persistent = source_img->isPersistent(); |
|
189 |
source_img->unlock(); |
|
190 |
|
|
191 |
if( source_img_persistent ) |
|
192 |
{ |
|
193 |
vm->unlock(); |
|
194 |
goto error_img_persistent; |
|
195 |
} |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
//-------------------------------------------------------------------------- |
|
200 |
// Store image id to save the disk in the VM template |
|
201 |
//-------------------------------------------------------------------------- |
|
202 |
|
|
203 |
rc = vm->save_disk(disk_id, iid, error_str); |
|
171 | 204 |
|
172 | 205 |
if ( rc == -1 ) |
173 | 206 |
{ |
... | ... | |
193 | 226 |
|
194 | 227 |
return; |
195 | 228 |
|
196 |
error_image_get:
|
|
229 |
error_image_exists:
|
|
197 | 230 |
oss << action_error(method_name, "CREATE", "IMAGE", -2, 0); |
198 |
oss << ". Image " << img_name << " already exists in the repository.";
|
|
231 |
oss << " Image " << img_name << " already exists in the repository."; |
|
199 | 232 |
goto error_common; |
200 | 233 |
|
201 | 234 |
error_vm_get: |
202 | 235 |
oss.str(get_error(method_name, "VM", vm_id)); |
203 | 236 |
goto error_common; |
204 | 237 |
|
238 |
error_img_persistent: |
|
239 |
oss << action_error(method_name, "SAVEDISK", "DISK", disk_id, 0); |
|
240 |
oss << " Source IMAGE " << source_img_id << " is persistent."; |
|
241 |
|
|
242 |
goto error_common; |
|
243 |
|
|
205 | 244 |
error_vm_get_disk_id: |
206 | 245 |
oss.str(get_error(method_name, "DISK from VM", vm_id)); |
207 |
oss << ". Deleting Image " << img_name; |
|
246 |
oss << " " << error_str; |
|
247 |
oss << " Deleting Image " << img_name; |
|
208 | 248 |
imagem->delete_image(iid); |
209 | 249 |
goto error_common; |
210 | 250 |
|
src/vm/VirtualMachine.cc | ||
---|---|---|
951 | 951 |
/* -------------------------------------------------------------------------- */ |
952 | 952 |
/* -------------------------------------------------------------------------- */ |
953 | 953 |
|
954 |
int VirtualMachine::save_disk(int disk_id, int img_id) |
|
954 |
int VirtualMachine::save_disk(int disk_id, int img_id, string& error_str)
|
|
955 | 955 |
{ |
956 | 956 |
int num_disks; |
957 | 957 |
vector<Attribute * > disks; |
... | ... | |
959 | 959 |
|
960 | 960 |
string disk_id_str; |
961 | 961 |
int tmp_disk_id; |
962 |
string tmp_img_id_str; |
|
963 |
int tmp_img_id; |
|
962 | 964 |
|
963 | 965 |
ostringstream oss; |
964 | 966 |
istringstream iss; |
... | ... | |
982 | 984 |
|
983 | 985 |
if( tmp_disk_id == disk_id ) |
984 | 986 |
{ |
987 |
if( disk->vector_value("SAVE_AS") != "" ) |
|
988 |
{ |
|
989 |
goto error_saved; |
|
990 |
} |
|
991 |
|
|
985 | 992 |
disk->replace("SAVE", "YES"); |
986 | 993 |
|
987 | 994 |
oss << (img_id); |
... | ... | |
991 | 998 |
} |
992 | 999 |
} |
993 | 1000 |
|
1001 |
goto error_not_found; |
|
1002 |
|
|
1003 |
error_saved: |
|
1004 |
oss << "The DISK " << disk_id << " is already suppossed to be saved."; |
|
1005 |
goto error_common; |
|
1006 |
|
|
1007 |
error_not_found: |
|
1008 |
oss << "The DISK " << disk_id << " does not exist for VM " << oid << "."; |
|
1009 |
|
|
1010 |
error_common: |
|
1011 |
NebulaLog::log("VM",Log::ERROR, oss); |
|
1012 |
error_str = oss.str(); |
|
1013 |
|
|
994 | 1014 |
return -1; |
995 | 1015 |
} |
996 | 1016 |
|
Also available in: Unified diff