]> git.ipfire.org Git - pakfire.git/commitdiff
PBS: Send amount of free disk space to server.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 Mar 2012 11:43:50 +0000 (12:43 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 3 Mar 2012 17:24:26 +0000 (18:24 +0100)
Also do not request new jobs when the free disk space is less than
2GB.

python/pakfire/client/base.py
python/pakfire/client/builder.py
python/pakfire/system.py
python/pakfire/transaction.py

index 3ac4bef5f75758b3e44cf7c5895aabae52101564..9c2e127942f74103ed20dbde2c099ae297373aff 100644 (file)
@@ -188,7 +188,7 @@ class PakfireUserClient(BuildMixin, PakfireClient):
 class PakfireBuilderClient(BuildMixin, PakfireClient):
        type = "builder"
 
-       def send_keepalive(self, overload=None):
+       def send_keepalive(self, overload=None, free_space=None):
                """
                        Sends a little keepalive to the server and
                        updates the hardware information if the server
@@ -199,7 +199,7 @@ class PakfireBuilderClient(BuildMixin, PakfireClient):
                # Collect the current loadavg and send it to the hub.
                loadavg = ", ".join(("%.2f" % round(l, 2) for l in os.getloadavg()))
 
-               needs_update = self.conn.send_keepalive(loadavg, overload)
+               needs_update = self.conn.send_keepalive(loadavg, overload, free_space)
 
                if needs_update:
                        log.debug("The hub is requesting an update.")
index 32dff2308250697ab057950489076ab003d704ac..0292f81c4b81d1e1ea307335c039cff2998cd670 100644 (file)
@@ -155,10 +155,20 @@ class PakfireDaemon(object):
                        # Return the number of processes.
                        return len(self.processes)
 
+               @property
+               def free_space(self):
+                       mp = system.get_mountpoint(BUILD_ROOT)
+
+                       return mp.space_left
+
                def get_job(self):
                        """
                                Get a build job from the hub.
                        """
+                       if not self.free_space >= 2 * 1024**3:
+                               log.warning(_("Less than 2GB of free space. Cannot request a new job."))
+                               return
+
                        log.info("Requesting a new job from the server...")
 
                        # Get some information about this system.
@@ -193,7 +203,12 @@ class PakfireDaemon(object):
                        if time.time() - self._last_keepalive < 30:
                                return
 
-                       self.client.send_keepalive(overload=self.has_overload())
+                       free_space = self.free_space / 1024**2
+
+                       self.client.send_keepalive(
+                               overload=self.has_overload(),
+                               free_space=free_space,
+                       )
                        self._last_keepalive = time.time()
 
                def remove_finished_builders(self):
index 8d99fb81554b7f1982a24e4e04b0f23ec4d24b8f..36d5da459e8098858d41881f9cf1392986a8d007 100644 (file)
@@ -140,14 +140,15 @@ class System(object):
 
                return memory
 
+       def get_mountpoint(self, path):
+               return Mountpoint(path)
+
 
 # Create an instance of this class to only keep it once in memory.
 system = System()
 
 class Mountpoints(object):
-       def __init__(self, pakfire, root="/"):
-               self.pakfire = pakfire
-
+       def __init__(self, root="/"):
                self._mountpoints = []
 
                # Scan for all mountpoints on the system.
@@ -163,7 +164,7 @@ class Mountpoints(object):
                # If root is not equal to /, we are in a chroot and
                # our root must be a mountpoint to count files.
                if not root == "/":
-                       mp = Mountpoint(self.pakfire, "/", root=root)
+                       mp = Mountpoint("/", root=root)
                        self._mountpoints.append(mp)
 
                f = open("/proc/mounts")
@@ -184,7 +185,7 @@ class Mountpoints(object):
                        else:
                                mountpoint = os.path.join("/", mountpoint)
 
-                       mp = Mountpoint(self.pakfire, mountpoint, root=root)
+                       mp = Mountpoint(mountpoint, root=root)
 
                        if not mp in self._mountpoints:
                                self._mountpoints.append(mp)
@@ -224,8 +225,7 @@ class Mountpoints(object):
 
 
 class Mountpoint(object):
-       def __init__(self, pakfire, path, root="/"):
-               self.pakfire = pakfire
+       def __init__(self, path, root="/"):
                self.path = path
                self.root = root
 
index afb5000b61a0e411f35f94a7a3c808b70168e4c4..f18f9453c324cdbe0da1e3e4d715f62acd6bc6c9 100644 (file)
@@ -54,7 +54,7 @@ class TransactionCheck(object):
                self.filelist = self.load_filelist()
 
                # Get information about the mounted filesystems.
-               self.mountpoints = system.Mountpoints(self.pakfire, root=self.pakfire.path)
+               self.mountpoints = system.Mountpoints(self.pakfire.path)
 
        @property
        def error_files(self):