]>
git.ipfire.org Git - people/ms/nitsi.git/blob - disk.py
11 logger
= logging
.getLogger("nitsi.disk")
15 def __init__(self
, disk
):
16 self
.log
= logger
.getChild(os
.path
.basename(disk
))
17 self
.log
.debug("Initiated a disk class for {}".format(disk
))
18 self
.con
= guestfs
.GuestFS(python_return_dict
=True)
19 self
.con
.add_drive_opts(disk
, format
="qcow2")
21 def mount(self
, uuid
, path
):
22 self
.log
.debug("Trying to mount the partion with uuid: {} under {}".format(uuid
, path
))
24 part
= self
.con
.findfs_uuid(uuid
)
25 self
.con
.mount(part
, path
)
27 def copy_in(self
, fr
, to
):
28 self
.log
.debug("Going to copy some files into the image.")
29 tmp
= tempfile
.mkstemp()
31 with tarfile
.open(tmp
, "w") as tar
:
33 self
.log
.debug("Adding {} to be copied into the image".format(file))
34 tar
.add(file, arcname
=os
.path
.basename(file))
36 self
.log
.debug("Going to copy the files into the image")
37 self
.con
.tar_in_opts(tmp
, to
)
39 def umount(self
, path
):
40 self
.log
.debug("Unmounting the image")
41 self
.con
.umount_opts(path
)
44 self
.log
.debug("Flush the image and closing the connection")
48 # test = disk("/var/lib/libvirt/images/alice.qcow2")
49 # test.mount("45598e92-3487-4a1b-961d-79aa3dd42a7d", "/")
50 # test.copy_in("/home/jonatan/nitsi/libguestfs-test", "/root/")