-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update-deps * Fix update + refactor * Fix mistake * Improve integration testing * Fix count * Setup env vars * Fix read of env vars * Remove fuse-opts * Allow multiple host via glusterfs command + test it at create * Update man * Improve integration tests * Remove un-used var * Fix build * Tweek sleep times * fix coverage report * Fix tests + MountExist * Run test as admin to access docker * Fix trailling voluri " * Preserve env for make test * escape params * Try fix for travis
- Loading branch information
Showing
29 changed files
with
493 additions
and
260 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
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
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,158 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"sync" | ||
|
||
log "github.com/Sirupsen/logrus" | ||
|
||
"github.com/docker/go-plugins-helpers/volume" | ||
) | ||
|
||
//Driver needed interface for some commons interactions | ||
type Driver interface { | ||
GetLock() *sync.RWMutex | ||
GetVolumes() map[string]Volume | ||
GetMounts() map[string]Mount | ||
SaveConfig() error | ||
RunCmd(string) error | ||
} | ||
|
||
//Volume needed interface for some commons interactions | ||
type Volume interface { | ||
increasable | ||
GetMount() string | ||
GetRemote() string | ||
GetStatus() map[string]interface{} | ||
} | ||
|
||
//Mount needed interface for some commons interactions | ||
type Mount interface { | ||
increasable | ||
GetPath() string | ||
} | ||
|
||
type increasable interface { | ||
GetConnections() int | ||
SetConnections(int) | ||
} | ||
|
||
func getMount(d Driver, mPath string) (Mount, error) { | ||
m, ok := d.GetMounts()[mPath] | ||
if !ok { | ||
return nil, fmt.Errorf("mount %s not found", mPath) | ||
} | ||
log.Debugf("Mount found: %s", m) | ||
return m, nil | ||
} | ||
|
||
func getVolumeMount(d Driver, vName string) (Volume, Mount, error) { | ||
v, ok := d.GetVolumes()[vName] | ||
if !ok { | ||
return nil, nil, fmt.Errorf("volume %s not found", vName) | ||
} | ||
log.Debugf("Volume found: %s", v) | ||
m, err := getMount(d, v.GetMount()) | ||
return v, m, err | ||
} | ||
|
||
//List wrapper around github.com/docker/go-plugins-helpers/volume | ||
func List(d Driver) (*volume.ListResponse, error) { | ||
log.Debugf("Entering List") | ||
d.GetLock().Lock() | ||
defer d.GetLock().Unlock() | ||
var vols []*volume.Volume | ||
for name, v := range d.GetVolumes() { | ||
log.Debugf("Volume found: %s", v) | ||
m, err := getMount(d, v.GetMount()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
vols = append(vols, &volume.Volume{Name: name, Status: v.GetStatus(), Mountpoint: m.GetPath()}) | ||
} | ||
return &volume.ListResponse{Volumes: vols}, nil | ||
} | ||
|
||
//Get wrapper around github.com/docker/go-plugins-helpers/volume | ||
func Get(d Driver, vName string) (Volume, Mount, error) { | ||
log.Debugf("Entering Get: name: %s", vName) | ||
d.GetLock().RLock() | ||
defer d.GetLock().RUnlock() | ||
return getVolumeMount(d, vName) | ||
} | ||
|
||
//Remove wrapper around github.com/docker/go-plugins-helpers/volume | ||
func Remove(d Driver, vName string) error { | ||
log.Debugf("Entering Remove: name: %s", vName) | ||
d.GetLock().Lock() | ||
defer d.GetLock().Unlock() | ||
v, m, err := getVolumeMount(d, vName) | ||
if err != nil { | ||
return err | ||
} | ||
if v.GetConnections() == 0 { | ||
if m.GetConnections() == 0 { | ||
if err := os.Remove(m.GetPath()); err != nil { | ||
return err | ||
} | ||
delete(d.GetMounts(), v.GetMount()) | ||
} | ||
delete(d.GetVolumes(), vName) | ||
return d.SaveConfig() | ||
} | ||
return fmt.Errorf("volume %s is currently used by a container", vName) | ||
} | ||
|
||
//MountExist wrapper around github.com/docker/go-plugins-helpers/volume | ||
func MountExist(d Driver, vName string) (Volume, Mount, error) { | ||
log.Debugf("Entering MountExist: name: %s", vName) | ||
d.GetLock().Lock() | ||
defer d.GetLock().Unlock() | ||
return getVolumeMount(d, vName) | ||
} | ||
|
||
func SetN(val int, oList ...increasable) { | ||
for _, o := range oList { | ||
o.SetConnections(val) | ||
} | ||
} | ||
|
||
func AddN(val int, oList ...increasable) { | ||
for _, o := range oList { | ||
o.SetConnections(o.GetConnections() + val) | ||
} | ||
} | ||
|
||
//Unmount wrapper around github.com/docker/go-plugins-helpers/volume | ||
func Unmount(d Driver, vName string) error { | ||
log.Debugf("Entering Unmount: name: %s", vName) | ||
d.GetLock().Lock() | ||
defer d.GetLock().Unlock() | ||
v, m, err := getVolumeMount(d, vName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if m.GetConnections() <= 1 { | ||
cmd := fmt.Sprintf("/usr/bin/umount %s", m.GetPath()) | ||
if err := d.RunCmd(cmd); err != nil { | ||
return err | ||
} | ||
SetN(0, m, v) | ||
} else { | ||
AddN(-1, m, v) | ||
} | ||
|
||
return d.SaveConfig() | ||
} | ||
|
||
//Capabilities wrapper around github.com/docker/go-plugins-helpers/volume | ||
func Capabilities() *volume.CapabilitiesResponse { | ||
log.Debugf("Entering Capabilities") | ||
return &volume.CapabilitiesResponse{ | ||
Capabilities: volume.Capability{ | ||
Scope: "local", | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}, | ||
} | ||
} |
Oops, something went wrong.
Just a question,,, why would you use "local" here vs "global"?