diff --git a/src/master/vclustermgr.py b/src/master/vclustermgr.py index b7ef839..a09a3a9 100755 --- a/src/master/vclustermgr.py +++ b/src/master/vclustermgr.py @@ -116,6 +116,8 @@ class VclusterMgr(object): def create_cluster(self, clustername, username, image, user_info, setting): if self.is_cluster(clustername, username): return [False, "cluster:%s already exists" % clustername] + if self.imgmgr.get_image_size(image) + 100 > int(setting["disk"]): + return [False, "the size of disk is not big enough for the image"] clustersize = int(self.defaultsize) logger.info ("starting cluster %s with %d containers for %s" % (clustername, int(clustersize), username)) workers = self.nodemgr.get_nodeips() @@ -202,6 +204,8 @@ class VclusterMgr(object): def scale_out_cluster(self,clustername,username, image,user_info, setting): if not self.is_cluster(clustername,username): return [False, "cluster:%s not found" % clustername] + if self.imgmgr.get_image_size(image) + 100 > int(setting["disk"]): + return [False, "the size of disk is not big enough for the image"] workers = self.nodemgr.get_nodeips() if (len(workers) == 0): logger.warning("no workers to start containers, scale out failed") diff --git a/src/utils/imagemgr.py b/src/utils/imagemgr.py index fcb8873..889023a 100755 --- a/src/utils/imagemgr.py +++ b/src/utils/imagemgr.py @@ -380,6 +380,29 @@ class ImageMgr(): return "" return image.description + def get_image_size(self, image): + imagename = image['name'] + imagetype = image['type'] + imageowner = image['owner'] + if imagename == "base" and imagetype == "base": + return 0 + if imagetype == "private": + imgpath = self.imgpath + "private/" + user + "/" + else: + imgpath = self.imgpath + "public/" + imageowner + "/" + return os.stat(os.path.join(imgpath, imagename)).st_size // (1024*1024) + + + def format_size(self, size_in_byte): + if size_in_byte < 1024: + return str(size_in_byte) + "B" + elif size_in_byte < 1024*1024: + return str(size_in_byte//1024) + "KB" + elif size_in_byte < 1024*1024*1024: + return str(size_in_byte//(1024*1024)) + "MB" + else: + return str(size_in_byte//(1024*1024*1024)) + "GB" + def list_images(self,user): images = {} images["private"] = [] @@ -398,6 +421,9 @@ class ImageMgr(): [time, description] = self.get_image_info(user, imagename, "private") fimage["time"] = time fimage["description"] = description + fimage["size"] = os.stat(os.path.join(imgpath, image)).st_size + fimage["size_format"] = self.format_size(fimage["size"]) + fimage["size_in_mb"] = fimage["size"] // (1024*1024) images["private"].append(fimage) except Exception as e: logger.error(e) @@ -423,6 +449,9 @@ class ImageMgr(): [time, description] = self.get_image_info(public_user, imagename, "public") fimage["time"] = time fimage["description"] = description + fimage["size"] = os.stat(os.path.join(imgpath, image)).st_size + fimage["size_format"] = self.format_size(fimage["size"]) + fimage["size_in_mb"] = fimage["size"] // (1024*1024) images["public"][public_user].append(fimage) except Exception as e: logger.error(e) diff --git a/web/templates/addCluster.html b/web/templates/addCluster.html index 1a7b8ca..de6ac2e 100644 --- a/web/templates/addCluster.html +++ b/web/templates/addCluster.html @@ -64,6 +64,7 @@ ImageName Type Owner + Size Description Choose @@ -73,16 +74,18 @@ base public docklet + -- A base image for you -
+
{% for image in images['private'] %} {{image['name']}} private {{user}} + {{image['size_format']}} {{image['description']}} -
+
{% endfor %} {% for p_user,p_images in images['public'].items() %} @@ -91,8 +94,9 @@ {{image['name']}} public {{p_user}} + {{image['size_format']}} {{image['description']}} -
+
{% endfor %} {% endfor %} @@ -125,7 +129,7 @@
-
{{usage['disk']}} MB/{{quota['disk']}}MB +
{{usage['disk']}} MB/{{quota['disk']}}MB (min value is the size of image + 100)
@@ -167,6 +171,12 @@ +