2015-05-19 16:05:25 -04:00
|
|
|
package volumedrivers
|
|
|
|
|
|
|
|
import (
|
2015-05-22 13:37:00 -04:00
|
|
|
"fmt"
|
2015-05-19 16:05:25 -04:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/plugins"
|
|
|
|
"github.com/docker/docker/volume"
|
|
|
|
)
|
|
|
|
|
|
|
|
// currently created by hand. generation tool would generate this like:
|
|
|
|
// $ extpoint-gen Driver > volume/extpoint.go
|
|
|
|
|
|
|
|
var drivers = &driverExtpoint{extensions: make(map[string]volume.Driver)}
|
|
|
|
|
|
|
|
type driverExtpoint struct {
|
|
|
|
extensions map[string]volume.Driver
|
|
|
|
sync.Mutex
|
|
|
|
}
|
|
|
|
|
|
|
|
func Register(extension volume.Driver, name string) bool {
|
|
|
|
drivers.Lock()
|
|
|
|
defer drivers.Unlock()
|
|
|
|
if name == "" {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
_, exists := drivers.extensions[name]
|
|
|
|
if exists {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
drivers.extensions[name] = extension
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func Unregister(name string) bool {
|
|
|
|
drivers.Lock()
|
|
|
|
defer drivers.Unlock()
|
|
|
|
_, exists := drivers.extensions[name]
|
|
|
|
if !exists {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
delete(drivers.extensions, name)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2015-05-20 17:53:53 -04:00
|
|
|
func Lookup(name string) (volume.Driver, error) {
|
2015-05-19 16:05:25 -04:00
|
|
|
drivers.Lock()
|
|
|
|
defer drivers.Unlock()
|
|
|
|
ext, ok := drivers.extensions[name]
|
|
|
|
if ok {
|
2015-05-20 17:53:53 -04:00
|
|
|
return ext, nil
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
|
|
|
pl, err := plugins.Get(name, "VolumeDriver")
|
|
|
|
if err != nil {
|
2015-05-22 13:37:00 -04:00
|
|
|
return nil, fmt.Errorf("Error looking up volume plugin %s: %v", name, err)
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|
2015-05-22 13:37:00 -04:00
|
|
|
|
2015-05-19 16:05:25 -04:00
|
|
|
d := NewVolumeDriver(name, pl.Client)
|
|
|
|
drivers.extensions[name] = d
|
2015-05-20 17:53:53 -04:00
|
|
|
return d, nil
|
2015-05-19 16:05:25 -04:00
|
|
|
}
|