-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from gondor/Issue21_25
- Loading branch information
Showing
10 changed files
with
317 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
VERSION = 0.15 | ||
VERSION = 0.16 | ||
GO_FMT = gofmt -s -w -l . | ||
GO_XC = goxc -os="linux" -tasks-="rmbin" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,71 @@ | ||
package drivers | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
log "github.com/Sirupsen/logrus" | ||
"github.com/docker/go-plugins-helpers/volume" | ||
"sync" | ||
) | ||
|
||
type DriverType int | ||
|
||
const ( | ||
CIFS DriverType = iota | ||
NFS | ||
EFS | ||
) | ||
|
||
var driverTypes = []string{ | ||
"cifs", | ||
"nfs", | ||
"efs", | ||
type volumeDriver struct { | ||
root string | ||
mountm *mountManager | ||
m *sync.Mutex | ||
} | ||
|
||
func (dt DriverType) String() string { | ||
return driverTypes[dt] | ||
func newVolumeDriver(root string) volumeDriver { | ||
return volumeDriver{ | ||
root: root, | ||
mountm: NewVolumeManager(), | ||
m: &sync.Mutex{}, | ||
} | ||
} | ||
|
||
func createDest(dest string) error { | ||
fi, err := os.Lstat(dest) | ||
func (v volumeDriver) Create(r volume.Request) volume.Response { | ||
log.Debugf("Entering Create: name: %s, options %v", r.Name, r.Options) | ||
|
||
v.m.Lock() | ||
defer v.m.Unlock() | ||
|
||
log.Debugf("Create volume -> name: %s, %v", r.Name, r.Options) | ||
|
||
if os.IsNotExist(err) { | ||
if err := os.MkdirAll(dest, 0755); err != nil { | ||
return err | ||
} | ||
} else if err != nil { | ||
return err | ||
dest := mountpoint(v.root, r.Name) | ||
if err := createDest(dest); err != nil { | ||
return volume.Response{Err: err.Error()} | ||
} | ||
v.mountm.Create(r.Name, dest, r.Options) | ||
return volume.Response{} | ||
} | ||
|
||
func (v volumeDriver) Remove(r volume.Request) volume.Response { | ||
log.Debugf("Entering Remove: name: %s, options %v", r.Name, r.Options) | ||
v.m.Lock() | ||
defer v.m.Unlock() | ||
|
||
if fi != nil && !fi.IsDir() { | ||
return fmt.Errorf("%v already exist and it's not a directory", dest) | ||
if err := v.mountm.Delete(r.Name); err != nil { | ||
return volume.Response{Err: err.Error()} | ||
} | ||
return nil | ||
return volume.Response{} | ||
} | ||
|
||
func mountpoint(root, name string) string { | ||
return filepath.Join(root, name) | ||
func (v volumeDriver) Path(r volume.Request) volume.Response { | ||
log.Debugf("Host path for %s is at %s", r.Name, mountpoint(v.root, r.Name)) | ||
return volume.Response{Mountpoint: mountpoint(v.root, r.Name)} | ||
} | ||
|
||
func run(cmd string) error { | ||
if out, err := exec.Command("sh", "-c", cmd).CombinedOutput(); err != nil { | ||
log.Println(string(out)) | ||
return err | ||
func (v volumeDriver) Get(r volume.Request) volume.Response { | ||
log.Debugf("Entering Get: %v", r) | ||
v.m.Lock() | ||
defer v.m.Unlock() | ||
hostdir := mountpoint(v.root, r.Name) | ||
|
||
if v.mountm.HasMount(r.Name) { | ||
log.Debugf("Get: mount found for %s, host directory: %s", r.Name, hostdir) | ||
return volume.Response{Volume: &volume.Volume{Name: r.Name, Mountpoint: hostdir}} | ||
} | ||
return nil | ||
return volume.Response{} | ||
} | ||
|
||
func (v volumeDriver) List(r volume.Request) volume.Response { | ||
log.Debugf("Entering List: %v", r) | ||
return volume.Response{Volumes: v.mountm.GetVolumes(v.root)} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package drivers | ||
|
||
type DriverType int | ||
|
||
const ( | ||
CIFS DriverType = iota | ||
NFS | ||
EFS | ||
) | ||
|
||
var driverTypes = []string{ | ||
"cifs", | ||
"nfs", | ||
"efs", | ||
} | ||
|
||
func (dt DriverType) String() string { | ||
return driverTypes[dt] | ||
} |
Oops, something went wrong.