Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for relative paths #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"text/template"
Expand Down Expand Up @@ -196,13 +197,34 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
d.ISO = d.ResolveStorePath(isoFilename)
isoPath, err := absolutePath(d.ResolveStorePath(isoFilename))
if err != nil {
return errors.New("Cannot resolve ISO path to absolute location!")
}
d.ISO = isoPath
d.SSHUser = flags.String("kvm-ssh-user")
d.SSHPort = 22
d.DiskPath = d.ResolveStorePath(fmt.Sprintf("%s.img", d.MachineName))
imgPath, err := absolutePath(d.ResolveStorePath(fmt.Sprintf("%s.img", d.MachineName)))
if err != nil {
return errors.New("Cannot resolve image path to absolute location!")
}
d.DiskPath = imgPath
return nil
}

func absolutePath(fpath string) (string, error) {
if !path.IsAbs(fpath) {
cwd, err := os.Getwd()
if err == nil {
fpath = path.Join(cwd, fpath);
log.Debugf("Resolved relative path to: %s", fpath)
} else {
return fpath , err
}
}
return fpath, nil
}

func (d *Driver) GetURL() (string, error) {
log.Debugf("GetURL called")
ip, err := d.GetIP()
Expand Down Expand Up @@ -361,7 +383,7 @@ func (d *Driver) Create() error {

// Libvirt typically runs as a deprivileged service account and
// needs the execute bit set for directories that contain disks
for dir := d.ResolveStorePath("."); dir != "/"; dir = filepath.Dir(dir) {
for dir := d.ResolveStorePath("."); dir != "/" && dir != "." ; dir = filepath.Dir(dir) {
log.Debugf("Verifying executable bit set on %s", dir)
info, err := os.Stat(dir)
if err != nil {
Expand Down