This repository was archived by the owner on Aug 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguestfs.py
8643 lines (6915 loc) · 312 KB
/
guestfs.py
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
# coding: utf-8
# libguestfs generated file
# WARNING: THIS FILE IS GENERATED FROM:
# generator/ *.ml
# ANY CHANGES YOU MAKE TO THIS FILE WILL BE LOST.
#
# Copyright (C) 2009-2013 Red Hat Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
"""Python bindings for libguestfs
import guestfs
g = guestfs.GuestFS (python_return_dict=True)
g.add_drive_opts ("guest.img", format="raw")
g.launch ()
parts = g.list_partitions ()
The guestfs module provides a Python binding to the libguestfs API
for examining and modifying virtual machine disk images.
Amongst the things this is good for: making batch configuration
changes to guests, getting disk used/free statistics (see also:
virt-df), migrating between virtualization systems (see also:
virt-p2v), performing partial backups, performing partial guest
clones, cloning guests and changing registry/UUID/hostname info, and
much else besides.
Libguestfs uses Linux kernel and qemu code, and can access any type of
guest filesystem that Linux and qemu can, including but not limited
to: ext2/3/4, btrfs, FAT and NTFS, LVM, many different disk partition
schemes, qcow, qcow2, vmdk.
Libguestfs provides ways to enumerate guest storage (eg. partitions,
LVs, what filesystem is in each LV, etc.). It can also run commands
in the context of the guest. Also you can access filesystems over
FUSE.
Errors which happen while using the API are turned into Python
RuntimeError exceptions.
To create a guestfs handle you usually have to perform the following
sequence of calls:
# Create the handle, call add_drive* at least once, and possibly
# several times if the guest has multiple block devices:
g = guestfs.GuestFS ()
g.add_drive_opts ("guest.img", format="raw")
# Launch the qemu subprocess and wait for it to become ready:
g.launch ()
# Now you can issue commands, for example:
logvols = g.lvs ()
"""
import libguestfsmod
EVENT_CLOSE = 0x1
EVENT_SUBPROCESS_QUIT = 0x2
EVENT_LAUNCH_DONE = 0x4
EVENT_PROGRESS = 0x8
EVENT_APPLIANCE = 0x10
EVENT_LIBRARY = 0x20
EVENT_TRACE = 0x40
EVENT_ENTER = 0x80
EVENT_LIBVIRT_AUTH = 0x100
EVENT_ALL = 0x1ff
def event_to_string (events):
"""Return a printable string from an event or event bitmask"""
return libguestfsmod.event_to_string (events)
class ClosedHandle(ValueError):
pass
class GuestFS(object):
"""Instances of this class are libguestfs API handles."""
def __init__ (self, python_return_dict=False,
environment=True, close_on_exit=True):
"""Create a new libguestfs handle.
Note about "python_return_dict" flag:
Setting this flag to 'True' causes all functions
that internally return hashes to return a dict. This is
natural for Python, and all new code should use
python_return_dict=True.
If this flag is not present then hashes are returned
as lists of pairs. This was the only possible behaviour
in libguestfs <= 1.20.
"""
flags = 0
if not environment: flags |= 1
if not close_on_exit: flags |= 2
self._o = libguestfsmod.create (flags)
self._python_return_dict = python_return_dict
def __del__ (self):
if self._o:
libguestfsmod.close (self._o)
def _check_not_closed (self):
if not self._o:
raise ClosedHandle ("GuestFS: method called on closed handle")
def _maybe_convert_to_dict (self, r):
if self._python_return_dict == True:
r = dict (r)
return r
def close (self):
"""Explicitly close the guestfs handle.
The handle is closed implicitly when its reference count goes
to zero (eg. when it goes out of scope or the program ends).
This call is only needed if you want to force the handle to
close now. After calling this, the program must not call
any method on the handle (except the implicit call to
__del__ which happens when the final reference is cleaned up).
"""
self._check_not_closed ()
libguestfsmod.close (self._o)
self._o = None
def set_event_callback (self, cb, event_bitmask):
"""Register an event callback.
Register "cb" as a callback function for all of the
events in "event_bitmask". "event_bitmask" should be
one or more "guestfs.EVENT_*" flags logically or'd together.
This function returns an event handle which can be used
to delete the callback (see "delete_event_callback").
The callback function receives 4 parameters:
cb (event, event_handle, buf, array)
"event" is one of the "EVENT_*" flags. "buf" is a
message buffer (only for some types of events). "array"
is an array of integers (only for some types of events).
You should read the documentation for
"guestfs_set_event_callback" in guestfs(3) before using
this function.
"""
self._check_not_closed ()
return libguestfsmod.set_event_callback (self._o, cb, event_bitmask)
def delete_event_callback (self, event_handle):
"""Delete an event callback."""
self._check_not_closed ()
libguestfsmod.delete_event_callback (self._o, event_handle)
def internal_test (self, str, optstr, strlist, b, integer, integer64, filein, fileout, bufferin, obool=None, oint=None, oint64=None, ostring=None, ostringlist=None):
strlist = list (strlist)
self._check_not_closed ()
r = libguestfsmod.internal_test (self._o, str, optstr, strlist, b, integer, integer64, filein, fileout, bufferin, obool, oint, oint64, ostring, ostringlist)
return r
def internal_test_only_optargs (self, test=None):
self._check_not_closed ()
r = libguestfsmod.internal_test_only_optargs (self._o, test)
return r
def internal_test_63_optargs (self, opt1=None, opt2=None, opt3=None, opt4=None, opt5=None, opt6=None, opt7=None, opt8=None, opt9=None, opt10=None, opt11=None, opt12=None, opt13=None, opt14=None, opt15=None, opt16=None, opt17=None, opt18=None, opt19=None, opt20=None, opt21=None, opt22=None, opt23=None, opt24=None, opt25=None, opt26=None, opt27=None, opt28=None, opt29=None, opt30=None, opt31=None, opt32=None, opt33=None, opt34=None, opt35=None, opt36=None, opt37=None, opt38=None, opt39=None, opt40=None, opt41=None, opt42=None, opt43=None, opt44=None, opt45=None, opt46=None, opt47=None, opt48=None, opt49=None, opt50=None, opt51=None, opt52=None, opt53=None, opt54=None, opt55=None, opt56=None, opt57=None, opt58=None, opt59=None, opt60=None, opt61=None, opt62=None, opt63=None):
self._check_not_closed ()
r = libguestfsmod.internal_test_63_optargs (self._o, opt1, opt2, opt3, opt4, opt5, opt6, opt7, opt8, opt9, opt10, opt11, opt12, opt13, opt14, opt15, opt16, opt17, opt18, opt19, opt20, opt21, opt22, opt23, opt24, opt25, opt26, opt27, opt28, opt29, opt30, opt31, opt32, opt33, opt34, opt35, opt36, opt37, opt38, opt39, opt40, opt41, opt42, opt43, opt44, opt45, opt46, opt47, opt48, opt49, opt50, opt51, opt52, opt53, opt54, opt55, opt56, opt57, opt58, opt59, opt60, opt61, opt62, opt63)
return r
def internal_test_rint (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rint (self._o, val)
return r
def internal_test_rinterr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rinterr (self._o)
return r
def internal_test_rint64 (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rint64 (self._o, val)
return r
def internal_test_rint64err (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rint64err (self._o)
return r
def internal_test_rbool (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rbool (self._o, val)
return r
def internal_test_rboolerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rboolerr (self._o)
return r
def internal_test_rconststring (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rconststring (self._o, val)
return r
def internal_test_rconststringerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rconststringerr (self._o)
return r
def internal_test_rconstoptstring (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rconstoptstring (self._o, val)
return r
def internal_test_rconstoptstringerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rconstoptstringerr (self._o)
return r
def internal_test_rstring (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstring (self._o, val)
return r
def internal_test_rstringerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstringerr (self._o)
return r
def internal_test_rstringlist (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstringlist (self._o, val)
return r
def internal_test_rstringlisterr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstringlisterr (self._o)
return r
def internal_test_rstruct (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstruct (self._o, val)
return r
def internal_test_rstructerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstructerr (self._o)
return r
def internal_test_rstructlist (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstructlist (self._o, val)
return r
def internal_test_rstructlisterr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rstructlisterr (self._o)
return r
def internal_test_rhashtable (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rhashtable (self._o, val)
r = self._maybe_convert_to_dict (r)
return r
def internal_test_rhashtableerr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rhashtableerr (self._o)
r = self._maybe_convert_to_dict (r)
return r
def internal_test_rbufferout (self, val):
self._check_not_closed ()
r = libguestfsmod.internal_test_rbufferout (self._o, val)
return r
def internal_test_rbufferouterr (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_rbufferouterr (self._o)
return r
def internal_test_set_output (self, filename):
self._check_not_closed ()
r = libguestfsmod.internal_test_set_output (self._o, filename)
return r
def internal_test_close_output (self):
self._check_not_closed ()
r = libguestfsmod.internal_test_close_output (self._o)
return r
def launch (self):
"""Internally libguestfs is implemented by running a
virtual machine using qemu(1).
You should call this after configuring the handle (eg.
adding drives) but before performing any actions.
Do not call "g.launch" twice on the same handle.
Although it will not give an error (for historical
reasons), the precise behaviour when you do this is not
well defined. Handles are very cheap to create, so
create a new one for each launch.
"""
self._check_not_closed ()
r = libguestfsmod.launch (self._o)
return r
def wait_ready (self):
"""This function is a no op.
In versions of the API < 1.0.71 you had to call this
function just after calling "g.launch" to wait for the
launch to complete. However this is no longer necessary
because "g.launch" now does the waiting.
If you see any calls to this function in code then you
can just remove them, unless you want to retain
compatibility with older versions of the API.
*This function is deprecated.* In new code, use the
"launch" call instead.
Deprecated functions will not be removed from the API,
but the fact that they are deprecated indicates that
there are problems with correct use of these functions.
"""
self._check_not_closed ()
r = libguestfsmod.wait_ready (self._o)
return r
def kill_subprocess (self):
"""This kills the qemu subprocess.
Do not call this. See: "g.shutdown" instead.
*This function is deprecated.* In new code, use the
"shutdown" call instead.
Deprecated functions will not be removed from the API,
but the fact that they are deprecated indicates that
there are problems with correct use of these functions.
"""
self._check_not_closed ()
r = libguestfsmod.kill_subprocess (self._o)
return r
def add_cdrom (self, filename):
"""This function adds a virtual CD-ROM disk image to the
guest.
Do not use this function! ISO files are just ordinary
read-only disk images. Use "g.add_drive_ro" instead.
*This function is deprecated.* In new code, use the
"add_drive" call instead.
Deprecated functions will not be removed from the API,
but the fact that they are deprecated indicates that
there are problems with correct use of these functions.
"""
self._check_not_closed ()
r = libguestfsmod.add_cdrom (self._o, filename)
return r
def add_drive_ro (self, filename):
"""This function is the equivalent of calling
"g.add_drive_opts" with the optional parameter
"GUESTFS_ADD_DRIVE_OPTS_READONLY" set to 1, so the disk
is added read-only, with the format being detected
automatically.
"""
self._check_not_closed ()
r = libguestfsmod.add_drive_ro (self._o, filename)
return r
def config (self, qemuparam, qemuvalue):
"""This can be used to add arbitrary qemu command line
parameters of the form *-param value*. Actually it's not
quite arbitrary - we prevent you from setting some
parameters which would interfere with parameters that we
use.
The first character of "qemuparam" string must be a "-"
(dash).
"qemuvalue" can be NULL.
"""
self._check_not_closed ()
r = libguestfsmod.config (self._o, qemuparam, qemuvalue)
return r
def set_qemu (self, qemu):
"""Set the qemu binary that we will use.
The default is chosen when the library was compiled by
the configure script.
You can also override this by setting the
"LIBGUESTFS_QEMU" environment variable.
Setting "qemu" to "NULL" restores the default qemu
binary.
Note that you should call this function as early as
possible after creating the handle. This is because some
pre-launch operations depend on testing qemu features
(by running "qemu -help"). If the qemu binary changes,
we don't retest features, and so you might see
inconsistent results. Using the environment variable
"LIBGUESTFS_QEMU" is safest of all since that picks the
qemu binary at the same time as the handle is created.
"""
self._check_not_closed ()
r = libguestfsmod.set_qemu (self._o, qemu)
return r
def get_qemu (self):
"""Return the current qemu binary.
This is always non-NULL. If it wasn't set already, then
this will return the default qemu binary name.
"""
self._check_not_closed ()
r = libguestfsmod.get_qemu (self._o)
return r
def set_path (self, searchpath):
"""Set the path that libguestfs searches for kernel and
initrd.img.
The default is "$libdir/guestfs" unless overridden by
setting "LIBGUESTFS_PATH" environment variable.
Setting "path" to "NULL" restores the default path.
"""
self._check_not_closed ()
r = libguestfsmod.set_path (self._o, searchpath)
return r
def get_path (self):
"""Return the current search path.
This is always non-NULL. If it wasn't set already, then
this will return the default path.
"""
self._check_not_closed ()
r = libguestfsmod.get_path (self._o)
return r
def set_append (self, append):
"""This function is used to add additional options to the
guest kernel command line.
The default is "NULL" unless overridden by setting
"LIBGUESTFS_APPEND" environment variable.
Setting "append" to "NULL" means *no* additional options
are passed (libguestfs always adds a few of its own).
"""
self._check_not_closed ()
r = libguestfsmod.set_append (self._o, append)
return r
def get_append (self):
"""Return the additional kernel options which are added to
the guest kernel command line.
If "NULL" then no options are added.
"""
self._check_not_closed ()
r = libguestfsmod.get_append (self._o)
return r
def set_autosync (self, autosync):
"""If "autosync" is true, this enables autosync. Libguestfs
will make a best effort attempt to make filesystems
consistent and synchronized when the handle is closed
(also if the program exits without closing handles).
This is enabled by default (since libguestfs 1.5.24,
previously it was disabled by default).
"""
self._check_not_closed ()
r = libguestfsmod.set_autosync (self._o, autosync)
return r
def get_autosync (self):
"""Get the autosync flag.
"""
self._check_not_closed ()
r = libguestfsmod.get_autosync (self._o)
return r
def set_verbose (self, verbose):
"""If "verbose" is true, this turns on verbose messages.
Verbose messages are disabled unless the environment
variable "LIBGUESTFS_DEBUG" is defined and set to 1.
Verbose messages are normally sent to "stderr", unless
you register a callback to send them somewhere else (see
"g.set_event_callback").
"""
self._check_not_closed ()
r = libguestfsmod.set_verbose (self._o, verbose)
return r
def get_verbose (self):
"""This returns the verbose messages flag.
"""
self._check_not_closed ()
r = libguestfsmod.get_verbose (self._o)
return r
def is_ready (self):
"""This returns true iff this handle is ready to accept
commands (in the "READY" state).
For more information on states, see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.is_ready (self._o)
return r
def is_config (self):
"""This returns true iff this handle is being configured
(in the "CONFIG" state).
For more information on states, see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.is_config (self._o)
return r
def is_launching (self):
"""This returns true iff this handle is launching the
subprocess (in the "LAUNCHING" state).
For more information on states, see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.is_launching (self._o)
return r
def is_busy (self):
"""This always returns false. This function is deprecated
with no replacement. Do not use this function.
For more information on states, see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.is_busy (self._o)
return r
def get_state (self):
"""This returns the current state as an opaque integer.
This is only useful for printing debug and internal
error messages.
For more information on states, see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.get_state (self._o)
return r
def set_memsize (self, memsize):
"""This sets the memory size in megabytes allocated to the
qemu subprocess. This only has any effect if called
before "g.launch".
You can also change this by setting the environment
variable "LIBGUESTFS_MEMSIZE" before the handle is
created.
For more information on the architecture of libguestfs,
see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.set_memsize (self._o, memsize)
return r
def get_memsize (self):
"""This gets the memory size in megabytes allocated to the
qemu subprocess.
If "g.set_memsize" was not called on this handle, and if
"LIBGUESTFS_MEMSIZE" was not set, then this returns the
compiled-in default value for memsize.
For more information on the architecture of libguestfs,
see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.get_memsize (self._o)
return r
def get_pid (self):
"""Return the process ID of the qemu subprocess. If there
is no qemu subprocess, then this will return an error.
This is an internal call used for debugging and testing.
"""
self._check_not_closed ()
r = libguestfsmod.get_pid (self._o)
return r
def version (self):
"""Return the libguestfs version number that the program is
linked against.
Note that because of dynamic linking this is not
necessarily the version of libguestfs that you compiled
against. You can compile the program, and then at
runtime dynamically link against a completely different
"libguestfs.so" library.
This call was added in version 1.0.58. In previous
versions of libguestfs there was no way to get the
version number. From C code you can use dynamic linker
functions to find out if this symbol exists (if it
doesn't, then it's an earlier version).
The call returns a structure with four elements. The
first three ("major", "minor" and "release") are numbers
and correspond to the usual version triplet. The fourth
element ("extra") is a string and is normally empty, but
may be used for distro-specific information.
To construct the original version string:
"$major.$minor.$release$extra"
See also: "LIBGUESTFS VERSION NUMBERS" in guestfs(3).
*Note:* Don't use this call to test for availability of
features. In enterprise distributions we backport
features from later versions into earlier versions,
making this an unreliable way to test for features. Use
"g.available" or "g.feature_available" instead.
This function returns a dictionary, with keys matching
the various fields in the guestfs_version structure.
"""
self._check_not_closed ()
r = libguestfsmod.version (self._o)
return r
def set_selinux (self, selinux):
"""This sets the selinux flag that is passed to the
appliance at boot time. The default is "selinux=0"
(disabled).
Note that if SELinux is enabled, it is always in
Permissive mode ("enforcing=0").
For more information on the architecture of libguestfs,
see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.set_selinux (self._o, selinux)
return r
def get_selinux (self):
"""This returns the current setting of the selinux flag
which is passed to the appliance at boot time. See
"g.set_selinux".
For more information on the architecture of libguestfs,
see guestfs(3).
"""
self._check_not_closed ()
r = libguestfsmod.get_selinux (self._o)
return r
def set_trace (self, trace):
"""If the command trace flag is set to 1, then libguestfs
calls, parameters and return values are traced.
If you want to trace C API calls into libguestfs (and
other libraries) then possibly a better way is to use
the external ltrace(1) command.
Command traces are disabled unless the environment
variable "LIBGUESTFS_TRACE" is defined and set to 1.
Trace messages are normally sent to "stderr", unless you
register a callback to send them somewhere else (see
"g.set_event_callback").
"""
self._check_not_closed ()
r = libguestfsmod.set_trace (self._o, trace)
return r
def get_trace (self):
"""Return the command trace flag.
"""
self._check_not_closed ()
r = libguestfsmod.get_trace (self._o)
return r
def set_direct (self, direct):
"""If the direct appliance mode flag is enabled, then stdin
and stdout are passed directly through to the appliance
once it is launched.
One consequence of this is that log messages aren't
caught by the library and handled by
"g.set_log_message_callback", but go straight to stdout.
You probably don't want to use this unless you know what
you are doing.
The default is disabled.
"""
self._check_not_closed ()
r = libguestfsmod.set_direct (self._o, direct)
return r
def get_direct (self):
"""Return the direct appliance mode flag.
"""
self._check_not_closed ()
r = libguestfsmod.get_direct (self._o)
return r
def set_recovery_proc (self, recoveryproc):
"""If this is called with the parameter "false" then
"g.launch" does not create a recovery process. The
purpose of the recovery process is to stop runaway qemu
processes in the case where the main program aborts
abruptly.
This only has any effect if called before "g.launch",
and the default is true.
About the only time when you would want to disable this
is if the main process will fork itself into the
background ("daemonize" itself). In this case the
recovery process thinks that the main program has
disappeared and so kills qemu, which is not very
helpful.
"""
self._check_not_closed ()
r = libguestfsmod.set_recovery_proc (self._o, recoveryproc)
return r
def get_recovery_proc (self):
"""Return the recovery process enabled flag.
"""
self._check_not_closed ()
r = libguestfsmod.get_recovery_proc (self._o)
return r
def add_drive_with_if (self, filename, iface):
"""This is the same as "g.add_drive" but it allows you to
specify the QEMU interface emulation to use at run time.
*This function is deprecated.* In new code, use the
"add_drive" call instead.
Deprecated functions will not be removed from the API,
but the fact that they are deprecated indicates that
there are problems with correct use of these functions.
"""
self._check_not_closed ()
r = libguestfsmod.add_drive_with_if (self._o, filename, iface)
return r
def add_drive_ro_with_if (self, filename, iface):
"""This is the same as "g.add_drive_ro" but it allows you
to specify the QEMU interface emulation to use at run
time.
*This function is deprecated.* In new code, use the
"add_drive" call instead.
Deprecated functions will not be removed from the API,
but the fact that they are deprecated indicates that
there are problems with correct use of these functions.
"""
self._check_not_closed ()
r = libguestfsmod.add_drive_ro_with_if (self._o, filename, iface)
return r
def file_architecture (self, filename):
"""This detects the architecture of the binary "filename",
and returns it if known.
Currently defined architectures are:
"i386"
This string is returned for all 32 bit i386, i486,
i586, i686 binaries irrespective of the precise
processor requirements of the binary.
"x86_64"
64 bit x86-64.
"sparc"
32 bit SPARC.
"sparc64"
64 bit SPARC V9 and above.
"ia64"
Intel Itanium.
"ppc"
32 bit Power PC.
"ppc64"
64 bit Power PC.
Libguestfs may return other architecture strings in
future.
The function works on at least the following types of
files:
* many types of Un*x and Linux binary
* many types of Un*x and Linux shared library
* Windows Win32 and Win64 binaries
* Windows Win32 and Win64 DLLs
Win32 binaries and DLLs return "i386".
Win64 binaries and DLLs return "x86_64".
* Linux kernel modules
* Linux new-style initrd images
* some non-x86 Linux vmlinuz kernels
What it can't do currently:
* static libraries (libfoo.a)
* Linux old-style initrd as compressed ext2 filesystem
(RHEL 3)
* x86 Linux vmlinuz kernels
x86 vmlinuz images (bzImage format) consist of a mix
of 16-, 32- and compressed code, and are horribly
hard to unpack. If you want to find the architecture
of a kernel, use the architecture of the associated
initrd or kernel module(s) instead.
"""
self._check_not_closed ()
r = libguestfsmod.file_architecture (self._o, filename)
return r
def inspect_os (self):
"""This function uses other libguestfs functions and
certain heuristics to inspect the disk(s) (usually disks
belonging to a virtual machine), looking for operating
systems.
The list returned is empty if no operating systems were
found.
If one operating system was found, then this returns a
list with a single element, which is the name of the
root filesystem of this operating system. It is also
possible for this function to return a list containing
more than one element, indicating a dual-boot or
multi-boot virtual machine, with each element being the
root filesystem of one of the operating systems.
You can pass the root string(s) returned to other
"g.inspect_get_*" functions in order to query further
information about each operating system, such as the
name and version.
This function uses other libguestfs features such as
"g.mount_ro" and "g.umount_all" in order to mount and
unmount filesystems and look at the contents. This
should be called with no disks currently mounted. The
function may also use Augeas, so any existing Augeas
handle will be closed.
This function cannot decrypt encrypted disks. The caller
must do that first (supplying the necessary keys) if the
disk is encrypted.
Please read "INSPECTION" in guestfs(3) for more details.
See also "g.list_filesystems".
This function returns a list of strings.
"""
self._check_not_closed ()
r = libguestfsmod.inspect_os (self._o)
return r
def inspect_get_type (self, root):
"""This returns the type of the inspected operating system.
Currently defined types are:
"linux"
Any Linux-based operating system.
"windows"
Any Microsoft Windows operating system.
"freebsd"
FreeBSD.
"netbsd"
NetBSD.
"openbsd"
OpenBSD.
"hurd"
GNU/Hurd.
"dos"
MS-DOS, FreeDOS and others.
"unknown"
The operating system type could not be determined.
Future versions of libguestfs may return other strings
here. The caller should be prepared to handle any
string.
Please read "INSPECTION" in guestfs(3) for more details.
"""
self._check_not_closed ()
r = libguestfsmod.inspect_get_type (self._o, root)
return r
def inspect_get_arch (self, root):
"""This returns the architecture of the inspected operating
system. The possible return values are listed under
"g.file_architecture".
If the architecture could not be determined, then the
string "unknown" is returned.
Please read "INSPECTION" in guestfs(3) for more details.
"""
self._check_not_closed ()
r = libguestfsmod.inspect_get_arch (self._o, root)
return r
def inspect_get_distro (self, root):
"""This returns the distro (distribution) of the inspected
operating system.
Currently defined distros are:
"archlinux"
Arch Linux.
"buildroot"
Buildroot-derived distro, but not one we
specifically recognize.
"centos"
CentOS.
"cirros"
Cirros.
"debian"
Debian.
"fedora"
Fedora.
"freedos"
FreeDOS.
"gentoo"
Gentoo.