/
VirtualMachine.h
2229 lines (1945 loc) 路 65 KB
/
VirtualMachine.h
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -------------------------------------------------------------------------- */
/* Copyright 2002-2018, OpenNebula Project, OpenNebula Systems */
/* */
/* 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. */
/* -------------------------------------------------------------------------- */
#ifndef VIRTUAL_MACHINE_H_
#define VIRTUAL_MACHINE_H_
#include "VirtualMachineTemplate.h"
#include "VirtualMachineDisk.h"
#include "VirtualMachineNic.h"
#include "VirtualMachineMonitorInfo.h"
#include "PoolSQL.h"
#include "History.h"
#include "Image.h"
#include "Log.h"
#include "NebulaLog.h"
#include "NebulaUtil.h"
#include "Quotas.h"
#include <time.h>
#include <set>
#include <sstream>
using namespace std;
class AuthRequest;
class Snapshots;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/**
* The Virtual Machine class. It represents a VM...
*/
class VirtualMachine : public PoolObjectSQL
{
public:
// -------------------------------------------------------------------------
// VM States
// -------------------------------------------------------------------------
/**
* Global Virtual Machine state
*/
enum VmState
{
INIT = 0,
PENDING = 1,
HOLD = 2,
ACTIVE = 3,
STOPPED = 4,
SUSPENDED = 5,
DONE = 6,
//FAILED = 7,
POWEROFF = 8,
UNDEPLOYED = 9,
CLONING = 10,
CLONING_FAILURE = 11
};
/**
* Virtual Machine state associated to the Life-cycle Manager
*/
enum LcmState
{
LCM_INIT = 0,
PROLOG = 1,
BOOT = 2,
RUNNING = 3,
MIGRATE = 4,
SAVE_STOP = 5,
SAVE_SUSPEND = 6,
SAVE_MIGRATE = 7,
PROLOG_MIGRATE = 8,
PROLOG_RESUME = 9,
EPILOG_STOP = 10,
EPILOG = 11,
SHUTDOWN = 12,
//CANCEL = 13,
//FAILURE = 14,
CLEANUP_RESUBMIT = 15,
UNKNOWN = 16,
HOTPLUG = 17,
SHUTDOWN_POWEROFF = 18,
BOOT_UNKNOWN = 19,
BOOT_POWEROFF = 20,
BOOT_SUSPENDED = 21,
BOOT_STOPPED = 22,
CLEANUP_DELETE = 23,
HOTPLUG_SNAPSHOT = 24,
HOTPLUG_NIC = 25,
HOTPLUG_SAVEAS = 26,
HOTPLUG_SAVEAS_POWEROFF = 27,
HOTPLUG_SAVEAS_SUSPENDED = 28,
SHUTDOWN_UNDEPLOY = 29,
EPILOG_UNDEPLOY = 30,
PROLOG_UNDEPLOY = 31,
BOOT_UNDEPLOY = 32,
HOTPLUG_PROLOG_POWEROFF = 33,
HOTPLUG_EPILOG_POWEROFF = 34,
BOOT_MIGRATE = 35,
BOOT_FAILURE = 36,
BOOT_MIGRATE_FAILURE = 37,
PROLOG_MIGRATE_FAILURE = 38,
PROLOG_FAILURE = 39,
EPILOG_FAILURE = 40,
EPILOG_STOP_FAILURE = 41,
EPILOG_UNDEPLOY_FAILURE = 42,
PROLOG_MIGRATE_POWEROFF = 43,
PROLOG_MIGRATE_POWEROFF_FAILURE = 44,
PROLOG_MIGRATE_SUSPEND = 45,
PROLOG_MIGRATE_SUSPEND_FAILURE = 46,
BOOT_UNDEPLOY_FAILURE = 47,
BOOT_STOPPED_FAILURE = 48,
PROLOG_RESUME_FAILURE = 49,
PROLOG_UNDEPLOY_FAILURE = 50,
DISK_SNAPSHOT_POWEROFF = 51,
DISK_SNAPSHOT_REVERT_POWEROFF = 52,
DISK_SNAPSHOT_DELETE_POWEROFF = 53,
DISK_SNAPSHOT_SUSPENDED = 54,
DISK_SNAPSHOT_REVERT_SUSPENDED = 55,
DISK_SNAPSHOT_DELETE_SUSPENDED = 56,
DISK_SNAPSHOT = 57,
//DISK_SNAPSHOT_REVERT = 58,
DISK_SNAPSHOT_DELETE = 59,
PROLOG_MIGRATE_UNKNOWN = 60,
PROLOG_MIGRATE_UNKNOWN_FAILURE = 61,
DISK_RESIZE = 62,
DISK_RESIZE_POWEROFF = 63,
DISK_RESIZE_UNDEPLOYED = 64
};
/**
* Functions to convert to/from string the VM states
*/
static int vm_state_from_str(string& st, VmState& state);
static string& vm_state_to_str(string& st, VmState state);
static int lcm_state_from_str(string& st, LcmState& state);
static string& lcm_state_to_str(string& st, LcmState state);
/**
* Returns the VM state to string, using the lcm state if the current state
* is ACTIVE.
* @return the state sting
*/
string state_str();
/**
* Returns the VM state (Dispatch Manager)
* @return the VM state
*/
VmState get_state() const
{
return state;
};
VmState get_prev_state() const
{
return prev_state;
};
/**
* Returns the VM state (life-cycle Manager)
* @return the VM state
*/
LcmState get_lcm_state() const
{
return lcm_state;
};
LcmState get_prev_lcm_state() const
{
return prev_lcm_state;
};
/**
* Sets VM state
* @param s state
*/
void set_state(VmState s)
{
string st;
state = s;
log("VM", Log::INFO, "New state is " + vm_state_to_str(st, s));
};
/**
* Sets VM LCM state
* @param s state
*/
void set_state(LcmState s)
{
string st;
lcm_state = s;
log("VM", Log::INFO, "New LCM state is " + lcm_state_to_str(st, s));
};
/**
* Sets the previous state to the current one
*/
void set_prev_state()
{
prev_state = state;
prev_lcm_state = lcm_state;
};
/**
* Test if the VM has changed state since last time prev state was set
* @return true if VM changed state
*/
bool has_changed_state()
{
return (prev_lcm_state != lcm_state || prev_state != state);
}
/**
* Sets the re-scheduling flag
* @param set or unset the re-schedule flag
*/
void set_resched(bool do_sched)
{
resched = do_sched ? 1 : 0;
};
// -------------------------------------------------------------------------
// Log & Print
// -------------------------------------------------------------------------
/**
* writes a log message in vm.log. The class lock should be locked and
* the VM MUST BE obtained through the VirtualMachinePool get() method.
*/
void log(
const char * module,
const Log::MessageType type,
const ostringstream& message) const
{
if (_log != 0)
{
_log->log(module,type,message.str().c_str());
}
};
/**
* writes a log message in vm.log. The class lock should be locked and
* the VM MUST BE obtained through the VirtualMachinePool get() method.
*/
void log(
const char * module,
const Log::MessageType type,
const char * message) const
{
if (_log != 0)
{
_log->log(module,type,message);
}
};
/**
* writes a log message in vm.log. The class lock should be locked and
* the VM MUST BE obtained through the VirtualMachinePool get() method.
*/
void log(
const char * module,
const Log::MessageType type,
const string& message) const
{
log(module, type, message.c_str());
};
// ------------------------------------------------------------------------
// Dynamic Info
// ------------------------------------------------------------------------
/**
* Updates VM dynamic information (id).
* @param _deploy_id the VMM driver specific id
*/
void set_deploy_id (const string& _deploy_id)
{
deploy_id = _deploy_id;
};
/**
* Updates VM dynamic information (usage counters), and updates last_poll,
* and copies it to history record for acct.
*/
int update_info(const string& monitor_data);
/**
* Clears the VM monitor information usage counters (MEMORY, CPU),
* last_poll, custom attributes, and copies it to the history record
* for acct.
*/
void reset_info()
{
last_poll = time(0);
monitoring.replace("CPU","0.0");
monitoring.replace("MEMORY","0");
set_vm_info();
clear_template_monitor_error();
}
VirtualMachineMonitorInfo& get_info()
{
return monitoring;
}
/**
* Returns the deployment ID
* @return the VMM driver specific ID
*/
const string& get_deploy_id() const
{
return deploy_id;
};
/**
* Sets the VM exit time
* @param _et VM exit time (when it arrived DONE/FAILED states)
*/
void set_exit_time(time_t et)
{
etime = et;
};
/**
* Sets the KERNEL OS attribute (path to the kernel file). Used when
* the template is using a FILE Datastore for it
* @param path to the kernel (in the remote host)
*/
void set_kernel(const string& kernel)
{
VectorAttribute * os = obj_template->get("OS");
if ( os == 0 )
{
return;
}
os->replace("KERNEL", kernel);
};
/**
* Sets the INITRD OS attribute (path to the initrd file). Used when
* the template is using a FILE Datastore for it
* @param path to the initrd (in the remote host)
*/
void set_initrd(const string& initrd)
{
VectorAttribute * os = obj_template->get("OS");
if ( os == 0 )
{
return;
}
os->replace("INITRD", initrd);
};
// ------------------------------------------------------------------------
// Access to VM locations
// ------------------------------------------------------------------------
/**
* Returns the remote VM directory. The VM remote dir is in the form:
* $DATASTORE_LOCATION/$SYSTEM_DS_ID/$VM_ID. The system_dir stores
* disks for a running VM in the target host.
* @return the remote system directory for the VM
*/
const string& get_system_dir() const
{
return history->system_dir;
}
/**
* Returns the remote VM directory for the previous host. It maybe different
* if a system ds migration
* The hasPreviousHistory() function MUST be called before this one.
* @return the remote system directory for the VM
*/
const string & get_previous_system_dir() const
{
return previous_history->system_dir;
};
// ------------------------------------------------------------------------
// History
// ------------------------------------------------------------------------
/**
* Adds a new history record an writes it in the database.
*/
void add_history(
int hid,
int cid,
const string& hostname,
const string& vmm_mad,
const string& tm_mad,
int ds_id);
/**
* Duplicates the last history record. Only the host related fields are
* affected (i.e. no counter is copied nor initialized).
* @param reason explaining the new addition.
*/
void cp_history();
/**
* Duplicates the previous history record. Only the host related fields are
* affected (i.e. no counter is copied nor initialized).
* @param reason explaining the new addition.
*/
void cp_previous_history();
/**
* Checks if the VM has a valid history record. This function
* MUST be called before using any history related function.
* @return true if the VM has a record
*/
bool hasHistory() const
{
return (history!=0);
};
/**
* Checks if the VM has a valid previous history record. This function
* MUST be called before using any previous_history related function.
* @return true if the VM has a previous record
*/
bool hasPreviousHistory() const
{
return (previous_history!=0);
};
bool is_history_open() const
{
return (history != 0) && (history->etime == 0);
}
bool is_previous_history_open() const
{
return (previous_history != 0) && (previous_history->etime == 0);
}
/**
* Returns the VMM driver name for the current host. The hasHistory()
* function MUST be called before this one.
* @return the VMM mad name
*/
const string & get_vmm_mad() const
{
return history->vmm_mad_name;
};
/**
* Returns the VMM driver name for the previous host. The hasPreviousHistory()
* function MUST be called before this one.
* @return the VMM mad name
*/
const string & get_previous_vmm_mad() const
{
return previous_history->vmm_mad_name;
};
/**
* Returns the datastore ID of the system DS for the host. The hasHistory()
* function MUST be called before this one.
* @return the ds id
*/
int get_ds_id() const
{
return history->ds_id;
};
/**
* Returns the datastore ID of the system DS for the previous host.
* The hasPreviousHistory() function MUST be called before this one.
* @return the TM mad name
*/
int get_previous_ds_id() const
{
return previous_history->ds_id;
};
/**
* Returns the TM driver name for the current host. The hasHistory()
* function MUST be called before this one.
* @return the TM mad name
*/
const string & get_tm_mad() const
{
return history->tm_mad_name;
};
/**
* Returns the TM driver name for the previous host. The
* hasPreviousHistory() function MUST be called before this one.
* @return the TM mad name
*/
const string & get_previous_tm_mad() const
{
return previous_history->tm_mad_name;
};
/**
* Returns the transfer filename. The transfer file is in the form:
* $ONE_LOCATION/var/vms/$VM_ID/transfer.$SEQ
* or, in case that OpenNebula is installed in root
* /var/lib/one/vms/$VM_ID/transfer.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the transfer filename
*/
const string & get_transfer_file() const
{
return history->transfer_file;
};
/**
* Returns the deployment filename. The deployment file is in the form:
* $ONE_LOCATION/var/vms/$VM_ID/deployment.$SEQ
* or, in case that OpenNebula is installed in root
* /var/lib/one/vms/$VM_ID/deployment.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the deployment file path
*/
const string & get_deployment_file() const
{
return history->deployment_file;
};
/**
* Returns the context filename. The context file is in the form:
* $ONE_LOCATION/var/vms/$VM_ID/context.sh
* or, in case that OpenNebula is installed in root
* /var/lib/one/vms/$VM_ID/context.sh
* The hasHistory() function MUST be called before this one.
* @return the context file path
*/
const string & get_context_file() const
{
return history->context_file;
}
/**
* Returns the token filename. The token file is in the form:
* $ONE_LOCATION/var/vms/$VM_ID/token.txt
* or, in case that OpenNebula is installed in root
* /var/lib/one/vms/$VM_ID/token.txt
* The hasHistory() function MUST be called before this one.
* @return the token file path
*/
const string & get_token_file() const
{
return history->token_file;
}
/**
* Returns the remote deployment filename. The file is in the form:
* $DS_LOCATION/$SYSTEM_DS/$VM_ID/deployment.$SEQ
* The hasHistory() function MUST be called before this one.
* @return the deployment filename
*/
const string & get_remote_deployment_file() const
{
return history->rdeployment_file;
};
/**
* Returns the checkpoint filename for the current host. The checkpoint file
* is in the form:
* $DS_LOCATION/$SYSTEM_DS/$VM_ID/checkpoint
* The hasHistory() function MUST be called before this one.
* @return the checkpoint filename
*/
const string & get_checkpoint_file() const
{
return history->checkpoint_file;
};
/**
* Returns the checkpoint filename for the previous host.
* The hasPreviousHistory() function MUST be called before this one.
* @return the checkpoint filename
*/
const string & get_previous_checkpoint_file() const
{
return previous_history->checkpoint_file;
};
/**
* Returns the hostname for the current host. The hasHistory()
* function MUST be called before this one.
* @return the hostname
*/
const string & get_hostname() const
{
return history->hostname;
};
/**
* Returns if the host is a public cloud based on the system ds and tm_mad.
* The hasHistory() function MUST be called before this one.
* @return the hostname
*/
bool get_host_is_cloud() const
{
return ((history->ds_id == -1) && history->tm_mad_name.empty());
};
/**
* Updates the current hostname. The hasHistory()
* function MUST be called before this one.
* @param hostname New hostname
*/
void set_hostname(const string& hostname)
{
history->hostname = hostname;
};
/**
* Returns the hostname for the previous host. The hasPreviousHistory()
* function MUST be called before this one.
* @return the hostname
*/
const string & get_previous_hostname() const
{
return previous_history->hostname;
};
/**
* Returns the action that closed the current history record. The hasHistory()
* function MUST be called before this one.
* @return the action that closed the current history record
*/
const History::VMAction get_action() const
{
return history->action;
};
/**
* Returns the action that closed the history record in the previous host
* @return the action that closed the history record in the previous host
*/
const History::VMAction get_previous_action() const
{
return previous_history->action;
};
/**
* Get host id where the VM is or is going to execute. The hasHistory()
* function MUST be called before this one.
*/
int get_hid()
{
return history->hid;
}
/**
* Get host id where the VM was executing. The hasPreviousHistory()
* function MUST be called before this one.
*/
int get_previous_hid()
{
return previous_history->hid;
}
/**
* Get cluster id where the VM is or is going to execute. The hasHistory()
* function MUST be called before this one.
*/
int get_cid()
{
return history->cid;
}
/**
* Get cluster id where the VM was executing. The hasPreviousHistory()
* function MUST be called before this one.
*/
int get_previous_cid()
{
return previous_history->cid;
}
/**
* Sets start time of a VM.
* @param _stime time when the VM started
*/
void set_stime(time_t _stime)
{
history->stime=_stime;
};
/**
* Sets VM info (with monitoring info) in the history record
*/
void set_vm_info()
{
to_xml_extended(history->vm_info, 0);
};
/**
* Sets VM info (with monitoring info) in the previous history record
*/
void set_previous_vm_info()
{
to_xml_extended(previous_history->vm_info, 0);
};
/**
* Sets end time of a VM.
* @param _etime time when the VM finished
*/
void set_etime(time_t _etime)
{
history->etime=_etime;
};
/**
* Sets end time of a VM in the previous Host.
* @param _etime time when the VM finished
*/
void set_previous_etime(time_t _etime)
{
previous_history->etime=_etime;
};
/**
* Sets start time of VM prolog.
* @param _stime time when the prolog started
*/
void set_prolog_stime(time_t _stime)
{
history->prolog_stime=_stime;
};
/**
* Sets end time of VM prolog.
* @param _etime time when the prolog finished
*/
void set_prolog_etime(time_t _etime)
{
history->prolog_etime=_etime;
};
/**
* Sets start time of VM running state.
* @param _stime time when the running state started
*/
void set_running_stime(time_t _stime)
{
history->running_stime=_stime;
};
/**
* Gets the running start time for the VM
*/
time_t get_running_stime()
{
return history->running_stime;
}
/**
* Sets end time of VM running state.
* @param _etime time when the running state finished
*/
void set_running_etime(time_t _etime)
{
history->running_etime=_etime;
};
/**
* Sets end time of VM running state in the previous host.
* @param _etime time when the running state finished
*/
void set_previous_running_etime(time_t _etime)
{
previous_history->running_etime=_etime;
};
/**
* Sets start time of VM epilog.
* @param _stime time when the epilog started
*/
void set_epilog_stime(time_t _stime)
{
history->epilog_stime=_stime;
};
/**
* Sets end time of VM epilog.
* @param _etime time when the epilog finished
*/
void set_epilog_etime(time_t _etime)
{
history->epilog_etime=_etime;
};
/**
* Sets the action that closed the history record
* @param action that closed the history record
*/
void set_action(History::VMAction action, int uid, int gid, int req_id)
{
history->action = action;
history->uid = uid;
history->gid = gid;
history->req_id = req_id;
};
void set_internal_action(History::VMAction action)
{
history->action = action;
history->uid = -1;
history->gid = -1;
history->req_id = -1;
};
void clear_action()
{
history->action = History::NONE_ACTION;
history->uid = -1;
history->gid = -1;
history->req_id = -1;
}
void set_previous_action(History::VMAction action, int uid, int gid,int rid)
{
previous_history->action = action;
previous_history->uid = uid;
previous_history->gid = gid;
previous_history->req_id = rid;
};
// ------------------------------------------------------------------------
// Template & Object Representation
// ------------------------------------------------------------------------
/**
* Function to print the VirtualMachine object into a string in
* XML format
* @param xml the resulting XML string
* @return a reference to the generated string
*/
string& to_xml(string& xml) const
{
return to_xml_extended(xml, 1);
}
/**
* Function to print the VirtualMachine object into a string in
* XML format, with reduced information
* @param xml the resulting XML string
* @return a reference to the generated string
*/
string& to_xml_short(string& xml);
/**
* Function to print the VirtualMachine object into a string in
* XML format, with extended information (full history records)
* @param xml the resulting XML string
* @return a reference to the generated string
*/
string& to_xml_extended(string& xml) const
{
return to_xml_extended(xml, 2);
}
/**
* Rebuilds the object from an xml formatted string
* @param xml_str The xml-formatted string
*
* @return 0 on success, -1 otherwise
*/
int from_xml(const string &xml_str);
/**
* Factory method for virtual machine templates
*/
Template * get_new_template() const
{
return new VirtualMachineTemplate;
}
/**
* Returns a copy of the VirtualMachineTemplate
* @return A copy of the VirtualMachineTemplate
*/
VirtualMachineTemplate * clone_template() const
{
return new VirtualMachineTemplate(
*(static_cast<VirtualMachineTemplate *>(obj_template)));
};
/**
* This function replaces the *user template*.
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int replace_template(const string& tmpl_str, bool keep_restricted,
string& error);
/**
* Append new attributes to the *user template*.
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int append_template(const string& tmpl_str, bool keep_restricted,
string& error);
/**
* This function gets an attribute from the user template
* @param name of the attribute
* @param value of the attribute
*/
void get_user_template_attribute(const char * name, string& value) const
{
user_obj_template->get(name,value);
}
/**
* Sets an error message with timestamp in the template
* @param message Message string
*/
void set_template_error_message(const string& message);
/**
* Sets an error message with timestamp in the template
* @param name of the error attribute
* @param message Message string
*/
void set_template_error_message(const string& name, const string& message);
/**
* Deletes the error message from the template
*/
void clear_template_error_message();
/**
* Sets an error message with timestamp in the template (ERROR_MONITOR)
* @param message Message string
*/
void set_template_monitor_error(const string& message);
/**
* Deletes the error message from the template (ERROR_MONITOR)
* @param message Message string
*/
void clear_template_monitor_error();
// ------------------------------------------------------------------------
// Timers & Requirements
// ------------------------------------------------------------------------
/**
* Gets time from last information polling.
* @return time of last poll (epoch) or 0 if never polled
*/
time_t get_last_poll() const
{
return last_poll;
};
/**
* Sets time of last information polling.
* @param poll time in epoch, normally time(0)
*/
void set_last_poll(time_t poll)