Skip to content

Commit

Permalink
show images details the same as the VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Jun 13, 2020
1 parent c1d1594 commit 77cf4e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ $ vermin create ubuntu/focal ~/sample.sh -cpus 1 -mem 512
To get list of all available images use:
```shell script
$ vermin images
alpine/3.11 (cached)
centos/8 (cached)
ubuntu/focal
IMAGE NAME CACHED DISK
centos/8 true 0.8GB
ubuntu/focal true 1.1GB
alpine/3.11
```
> The *cached* flag means, the image has been already downloaded and cached before.
Expand Down
2 changes: 1 addition & 1 deletion images/cached.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Remove(imageName string) error {
return errors.New("Image not found")
}

if err := os.RemoveAll(db.ImagesDir + string(os.PathSeparator) + imageName + ova); err != nil {
if err := os.RemoveAll(db.GetImageFilePath(imageName)); err != nil {
return err
}

Expand Down
20 changes: 17 additions & 3 deletions images/images.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package images

import (
"fmt"
"github.com/mhewedy/vermin/db"
"os"
)

var (
format = "%-25s%-20s%-10s\n"
header = fmt.Sprintf(format, "IMAGE NAME", "CACHED", "DISK")
)

func List() ([]string, error) {
list, err := list(false)
if err != nil {
Expand All @@ -19,12 +30,15 @@ func Display(purgeCache bool) (string, error) {
return "", err
}

var result string
result := header

for i := range list {
if list[i].cached {
result += list[i].name + "\t\t(cached)\n"
stat, _ := os.Stat(db.GetImageFilePath(list[i].name))
result += fmt.Sprintf(format, list[i].name, "true",
fmt.Sprintf("%.1fGB", float64(stat.Size())/(1042*1024*1024.0)))
} else {
result += list[i].name + "\n"
result += fmt.Sprintf(format, list[i].name, "", "")
}
}
return result, nil
Expand Down

0 comments on commit 77cf4e2

Please sign in to comment.