]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
count existing images and issue warning if number is greater then 10
authorHolger Levsen <holger@layer-acht.org>
Tue, 26 Feb 2013 18:16:05 +0000 (19:16 +0100)
committerHolger Levsen <holger@layer-acht.org>
Tue, 26 Feb 2013 18:16:05 +0000 (19:16 +0100)
cleanup_liveboot.py
debian_repos2db.sh

index 4fff2effaf62b7fedf40d1c5abb54315f479331f..928c2391a11f93f28b287fd2f90c79c19411eed8 100755 (executable)
@@ -27,6 +27,18 @@ def liveboot_to_keep(name):
     if cur.fetchone():
         return True
 
+def count_liveboots():
+    con = db_connect()
+    cur = con.cursor()
+    try:
+        cur.execute("SELECT COUNT(keep_image) FROM liveboot WHERE keep_image = true")
+    except psycopg2.DatabaseError as e:
+        logger.debug("SELECT COUNT(keep_image) FROM liveboot WHERE keep_image = true")
+        return False
+    print cur.fetchone()[0]
+    return True
+
+
 def set_liveboot_to_delete(name):
     con = db_connect()
     cur = con.cursor()
@@ -38,7 +50,10 @@ def set_liveboot_to_delete(name):
         return False
 
 if __name__ == '__main__':
-    if len(sys.argv) != 3 or sys.argv[1] not in ('keep', 'delete'):
+    if len(sys.argv) == 1:
+        count_liveboots()
+        sys.exit(0)
+    elif len(sys.argv) != 3 or sys.argv[1] not in ('keep', 'delete'):
         print("usage: %s keep $liveboot_name")
         print("            will return true or false, depending if 'keep_image' is set for this image")
         print("usage: %s delete $liveboot_name")
index fd266678761af338f800d31fed57d465c1a4722b..5aae8cf0141c66e65584068dd883a895a9531946 100755 (executable)
@@ -31,3 +31,10 @@ for REPO in $(seq 0 $REPOS) ; do
                done
        done
 done
+
+EXISTING_IMAGES=$(./cleanup_liveboot.py)
+
+if [ "$EXISTING_IMAGES" -gt 10 ] ; then
+       figlet WARNING
+       echo "$EXISTING_IMAGES liveboot images exist, you probably need to delete some..."
+fi