]>
git.ipfire.org Git - nitsi.git/blob - src/nitsi/disk.py
9 logger
= logging
.getLogger("nitsi.disk")
13 def __init__(self
, disk
):
14 self
.log
= logger
.getChild(os
.path
.basename(disk
))
15 self
.log
.debug("Initiated a disk class for {}".format(disk
))
16 self
.con
= guestfs
.GuestFS(python_return_dict
=True)
17 self
.con
.add_drive_opts(disk
, format
="qcow2")
19 def mount(self
, uuid
, path
):
20 self
.log
.info("Trying to mount the partion with uuid: {} under {}".format(uuid
, path
))
22 part
= self
.con
.findfs_uuid(uuid
)
23 self
.con
.mount(part
, path
)
25 def copy_in(self
, fr
, to
):
26 self
.log
.info("Going to copy some files into the image.")
27 tmp
= tempfile
.mkstemp()
29 self
.log
.debug("Path of tarfile is: {}".format(tmp
))
30 with tarfile
.open(tmp
, "w") as tar
:
32 self
.log
.debug("Adding {} to be copied into the image".format(file))
33 tar
.add(file, arcname
=os
.path
.basename(file))
35 self
.log
.info("Going to copy the files into the image")
36 self
.con
.tar_in_opts(tmp
, to
)
37 self
.log
.debug(self
.con
.ls(to
))
39 def umount(self
, path
):
40 self
.log
.info("Unmounting the image")
41 self
.con
.umount_opts(path
)
44 self
.log
.info("Flush the image and closing the connection")
48 # test = Disk("/var/lib/libvirt/images/ipfire-bob.qcow2")
49 # test.mount("1efb5389-0949-46bb-b688-5246acba9f6d", "/")
50 # test.copy_in("/home/jonatan/nitsi/libguestfs-test", "/root/")