2013-09-04 05:44:11 -04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
type DeviceSet interface {
|
|
|
|
AddDevice(hash, baseHash string) error
|
|
|
|
SetInitialized(hash string) error
|
|
|
|
DeactivateDevice(hash string) error
|
|
|
|
RemoveDevice(hash string) error
|
|
|
|
MountDevice(hash, path string) error
|
2013-09-09 06:39:42 -04:00
|
|
|
UnmountDevice(hash, path string) error
|
2013-09-04 05:44:11 -04:00
|
|
|
HasDevice(hash string) bool
|
|
|
|
HasInitializedDevice(hash string) bool
|
2013-09-09 07:47:29 -04:00
|
|
|
Shutdown() error
|
2013-09-04 05:44:11 -04:00
|
|
|
}
|
2013-09-06 08:37:04 -04:00
|
|
|
|
|
|
|
type DeviceSetWrapper struct {
|
|
|
|
wrapped DeviceSet
|
|
|
|
prefix string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) wrap(hash string) string {
|
|
|
|
if hash != "" {
|
|
|
|
hash = wrapper.prefix + "-" + hash
|
|
|
|
}
|
|
|
|
return hash
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) AddDevice(hash, baseHash string) error {
|
|
|
|
return wrapper.wrapped.AddDevice(wrapper.wrap(hash), wrapper.wrap(baseHash))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) SetInitialized(hash string) error {
|
|
|
|
return wrapper.wrapped.SetInitialized(wrapper.wrap(hash))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) DeactivateDevice(hash string) error {
|
|
|
|
return wrapper.wrapped.DeactivateDevice(wrapper.wrap(hash))
|
|
|
|
}
|
|
|
|
|
2013-09-09 07:47:29 -04:00
|
|
|
func (wrapper *DeviceSetWrapper) Shutdown() error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-09-06 08:37:04 -04:00
|
|
|
func (wrapper *DeviceSetWrapper) RemoveDevice(hash string) error {
|
|
|
|
return wrapper.wrapped.RemoveDevice(wrapper.wrap(hash))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) MountDevice(hash, path string) error {
|
|
|
|
return wrapper.wrapped.MountDevice(wrapper.wrap(hash), path)
|
|
|
|
}
|
|
|
|
|
2013-09-09 06:39:42 -04:00
|
|
|
func (wrapper *DeviceSetWrapper) UnmountDevice(hash, path string) error {
|
|
|
|
return wrapper.wrapped.UnmountDevice(wrapper.wrap(hash), path)
|
|
|
|
}
|
|
|
|
|
2013-09-06 08:37:04 -04:00
|
|
|
func (wrapper *DeviceSetWrapper) HasDevice(hash string) bool {
|
|
|
|
return wrapper.wrapped.HasDevice(wrapper.wrap(hash))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (wrapper *DeviceSetWrapper) HasInitializedDevice(hash string) bool {
|
|
|
|
return wrapper.wrapped.HasInitializedDevice(wrapper.wrap(hash))
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewDeviceSetWrapper(wrapped DeviceSet, prefix string) DeviceSet {
|
|
|
|
wrapper := &DeviceSetWrapper{
|
|
|
|
wrapped: wrapped,
|
|
|
|
prefix: prefix,
|
|
|
|
}
|
|
|
|
return wrapper
|
|
|
|
}
|