summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-03-30 22:36:25 +0200
committerGitHub <noreply@github.com>2021-03-30 22:36:25 +0200
commita373e2fdf38456b8ac584809e73cdb9f9521a796 (patch)
treeda598460aa5b6a28d43e78d376729df843ec4e1a /pkg
parentbd07179e9c608ff1075f052843aeb9b1c8b7c7e3 (diff)
parentef4e91a59eed957e56bf1536bc03df94cd096576 (diff)
downloadpodman-a373e2fdf38456b8ac584809e73cdb9f9521a796.tar.gz
podman-a373e2fdf38456b8ac584809e73cdb9f9521a796.tar.bz2
podman-a373e2fdf38456b8ac584809e73cdb9f9521a796.zip
Merge pull request #9885 from ashley-cui/machinels
Add podman machine ls
Diffstat (limited to 'pkg')
-rw-r--r--pkg/machine/config.go11
-rw-r--r--pkg/machine/qemu/machine.go50
2 files changed, 61 insertions, 0 deletions
diff --git a/pkg/machine/config.go b/pkg/machine/config.go
index 273deca00..554ea7c97 100644
--- a/pkg/machine/config.go
+++ b/pkg/machine/config.go
@@ -5,6 +5,7 @@ import (
"net/url"
"os"
"path/filepath"
+ "time"
"github.com/containers/storage/pkg/homedir"
"github.com/pkg/errors"
@@ -44,6 +45,16 @@ type Download struct {
VMName string
}
+type ListOptions struct{}
+
+type ListResponse struct {
+ Name string
+ CreatedAt time.Time
+ LastUp time.Time
+ Running bool
+ VMType string
+}
+
type SSHOptions struct {
Execute bool
Args []string
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index fdb528a86..b4427f160 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"strconv"
+ "strings"
"time"
"github.com/containers/podman/v3/pkg/machine"
@@ -426,3 +427,52 @@ func getDiskSize(path string) (uint64, error) {
}
return tmpInfo.VirtualSize, nil
}
+
+// List lists all vm's that use qemu virtualization
+func List(opts machine.ListOptions) ([]*machine.ListResponse, error) {
+ vmConfigDir, err := machine.GetConfDir(vmtype)
+ if err != nil {
+ return nil, err
+ }
+
+ var listed []*machine.ListResponse
+
+ if err = filepath.Walk(vmConfigDir, func(path string, info os.FileInfo, err error) error {
+ vm := new(MachineVM)
+ if strings.HasSuffix(info.Name(), ".json") {
+ fullPath := filepath.Join(vmConfigDir, info.Name())
+ b, err := ioutil.ReadFile(fullPath)
+ if err != nil {
+ return err
+ }
+ err = json.Unmarshal(b, vm)
+ if err != nil {
+ return err
+ }
+ listEntry := new(machine.ListResponse)
+
+ listEntry.Name = vm.Name
+ listEntry.VMType = "qemu"
+ fi, err := os.Stat(fullPath)
+ if err != nil {
+ return err
+ }
+ listEntry.CreatedAt = fi.ModTime()
+
+ fi, err = os.Stat(vm.ImagePath)
+ if err != nil {
+ return err
+ }
+ listEntry.LastUp = fi.ModTime()
+ if vm.isRunning() {
+ listEntry.Running = true
+ }
+
+ listed = append(listed, listEntry)
+ }
+ return nil
+ }); err != nil {
+ return nil, err
+ }
+ return listed, err
+}