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