diff --git a/api/registry/registry.go b/api/registry/registry.go index ac88ddd5..9bcccffe 100644 --- a/api/registry/registry.go +++ b/api/registry/registry.go @@ -16,9 +16,6 @@ var ( storExecsCtors = map[string]types.NewStorageExecutor{} storExecsCtorsRWL = &sync.RWMutex{} - clientDriverCtors = map[string]types.NewClientDriver{} - clientDriverCtorsRWL = &sync.RWMutex{} - storDriverCtors = map[string]types.NewStorageDriver{} storDriverCtorsRWL = &sync.RWMutex{} @@ -61,14 +58,6 @@ func RegisterStorageExecutor(name string, ctor types.NewStorageExecutor) { storExecsCtors[strings.ToLower(name)] = ctor } -// RegisterClientDriver registers a ClientDriver. -func RegisterClientDriver( - name string, ctor types.NewClientDriver) { - clientDriverCtorsRWL.Lock() - defer clientDriverCtorsRWL.Unlock() - clientDriverCtors[strings.ToLower(name)] = ctor -} - // RegisterStorageDriver registers a StorageDriver. func RegisterStorageDriver( name string, ctor types.NewStorageDriver) { @@ -111,27 +100,6 @@ func NewStorageExecutor(name string) (types.StorageExecutor, error) { return ctor(), nil } -// NewClientDriver returns a new instance of the driver specified by -// the driver name. -func NewClientDriver( - name string) (types.ClientDriver, error) { - - var ok bool - var ctor types.NewClientDriver - - func() { - clientDriverCtorsRWL.RLock() - defer clientDriverCtorsRWL.RUnlock() - ctor, ok = clientDriverCtors[strings.ToLower(name)] - }() - - if !ok { - return nil, goof.WithField("driver", name, "invalid driver name") - } - - return ctor(), nil -} - // NewStorageDriver returns a new instance of the driver specified by the // driver name. func NewStorageDriver(name string) (types.StorageDriver, error) { @@ -228,21 +196,6 @@ func StorageExecutors() <-chan types.StorageExecutor { return c } -// ClientDrivers returns a channel on which new instances of all -// registered remote local drivers can be received. -func ClientDrivers() <-chan types.ClientDriver { - c := make(chan types.ClientDriver) - go func() { - clientDriverCtorsRWL.RLock() - defer clientDriverCtorsRWL.RUnlock() - for _, ctor := range clientDriverCtors { - c <- ctor() - } - close(c) - }() - return c -} - // StorageDrivers returns a channel on which new instances of all // registered remote storage drivers can be received. func StorageDrivers() <-chan types.StorageDriver { diff --git a/api/types/types_drivers_client.go b/api/types/types_drivers_client.go deleted file mode 100644 index 7b6eaf4e..00000000 --- a/api/types/types_drivers_client.go +++ /dev/null @@ -1,142 +0,0 @@ -package types - -// NewClientDriver is a function that constructs a new ClientDriver. -type NewClientDriver func() ClientDriver - -// ClientDriver is the client-side driver that is able to inspect -// methods before and after they are invoked in order to both prevent their -// execution as well as mutate the results. -type ClientDriver interface { - Driver - - // InstanceInspectBefore may return an error, preventing the operation. - InstanceInspectBefore(ctx *Context) error - - // InstanceInspectAfter provides an opportunity to inspect/mutate the - // result. - InstanceInspectAfter(ctx Context, result *Instance) - - // VolumesBefore may return an error, preventing the operation. - VolumesBefore(ctx *Context) error - - // VolumesAfter provides an opportunity to inspect/mutate the result. - VolumesAfter(ctx Context, result *ServiceVolumeMap) - - // VolumesByServiceBefore may return an error, preventing the operation. - VolumesByServiceBefore(ctx *Context, service string) error - - // VolumesByServiceAfter provides an opportunity to inspect/mutate the - // result. - VolumesByServiceAfter( - ctx Context, service string, result *VolumeMap) - - // VolumeInspectBefore may return an error, preventing the operation. - VolumeInspectBefore( - ctx *Context, - service, volumeID string, - attachments VolumeAttachmentsTypes) error - - // VolumeInspectAfter provides an opportunity to inspect/mutate the result. - VolumeInspectAfter(ctx Context, result *Volume) - - // VolumeCreateBefore may return an error, preventing the operation. - VolumeCreateBefore( - ctx *Context, service string, - request *VolumeCreateRequest) error - - // VolumeCreateAfter provides an opportunity to inspect/mutate the result. - VolumeCreateAfter(ctx Context, result *Volume) - - // VolumeCreateFromSnapshotBefore may return an error, preventing the - // operation. - VolumeCreateFromSnapshotBefore( - ctx *Context, - service, snapshotID string, - request *VolumeCreateRequest) error - - // VolumeCreateFromSnapshotAfter provides an opportunity to inspect/mutate - // the result. - VolumeCreateFromSnapshotAfter(ctx Context, result *Volume) - - // VolumeCopyBefore may return an error, preventing the operation. - VolumeCopyBefore( - ctx *Context, - service, volumeID string, - request *VolumeCopyRequest) error - - // VolumeCopyAfter provides an opportunity to inspect/mutate the result. - VolumeCopyAfter(ctx Context, result *Volume) - - // VolumeRemoveBefore may return an error, preventing the operation. - VolumeRemoveBefore( - ctx *Context, - service, volumeID string) error - - // VolumeRemoveAfter provides an opportunity to inspect/mutate the result. - VolumeRemoveAfter(ctx Context, service, volumeID string) - - // VolumeSnapshotBefore may return an error, preventing the operation. - VolumeSnapshotBefore( - ctx *Context, - service, volumeID string, - request *VolumeSnapshotRequest) error - - // VolumeSnapshotAfter provides an opportunity to inspect/mutate the result. - VolumeSnapshotAfter(ctx Context, result *Snapshot) - - // VolumeAttachBefore may return an error, preventing the operation. - VolumeAttachBefore( - ctx *Context, - service, volumeID string, - request *VolumeAttachRequest) error - - // VolumeAttachAfter provides an opportunity to inspect/mutate the result. - VolumeAttachAfter(ctx Context, result *Volume) - - // VolumeDetachBefore may return an error, preventing the operation. - VolumeDetachBefore( - ctx *Context, - service, volumeID string, - request *VolumeDetachRequest) error - - // VolumeDetachAfter provides an opportunity to inspect/mutate the result. - VolumeDetachAfter(ctx Context, result *Volume) - - // SnapshotsBefore may return an error, preventing the operation. - SnapshotsBefore(ctx *Context) error - - // SnapshotsAfter provides an opportunity to inspect/mutate the result. - SnapshotsAfter(ctx Context, result *ServiceSnapshotMap) - - // SnapshotsByServiceBefore may return an error, preventing the operation. - SnapshotsByServiceBefore(ctx *Context, service string) error - - // SnapshotsByServiceAfter provides an opportunity to inspect/mutate the - // result. - SnapshotsByServiceAfter( - ctx Context, service string, result *SnapshotMap) - - // SnapshotInspectBefore may return an error, preventing the operation. - SnapshotInspectBefore( - ctx *Context, - service, snapshotID string) error - - // SnapshotInspectAfter provides an opportunity to inspect/mutate the - // result. - SnapshotInspectAfter(ctx Context, result *Volume) - - // SnapshotCopyBefore may return an error, preventing the operation. - SnapshotCopyBefore( - ctx *Context, - service, snapshotID, string, - request *SnapshotCopyRequest) error - - // SnapshotCopyAfter provides an opportunity to inspect/mutate the result. - SnapshotCopyAfter(ctx Context, result *Snapshot) - - // SnapshotRemoveBefore may return an error, preventing the operation. - SnapshotRemoveBefore(ctx *Context, service, snapshotID string) error - - // SnapshotRemoveAfter provides an opportunity to inspect/mutate the result. - SnapshotRemoveAfter(ctx Context, snapshotID string) -} diff --git a/drivers/storage/libstorage/libstorage_client_api.go b/drivers/storage/libstorage/libstorage_client_api.go index 5a22c094..646b25c3 100644 --- a/drivers/storage/libstorage/libstorage_client_api.go +++ b/drivers/storage/libstorage/libstorage_client_api.go @@ -3,7 +3,6 @@ package libstorage import ( "io" - "github.com/codedellemc/libstorage/api/registry" "github.com/codedellemc/libstorage/api/types" "github.com/codedellemc/libstorage/api/utils" ) @@ -121,27 +120,11 @@ func (c *client) VolumeCreate( } ctx = ctxA - lsd, _ := registry.NewClientDriver(service) - if lsd != nil { - if err := lsd.Init(ctx, c.config); err != nil { - return nil, err - } - - if err := lsd.VolumeCreateBefore( - &ctx, service, request); err != nil { - return nil, err - } - } - vol, err := c.APIClient.VolumeCreate(ctx, service, request) if err != nil { return nil, err } - if lsd != nil { - lsd.VolumeCreateAfter(ctx, vol) - } - return vol, nil } @@ -152,28 +135,12 @@ func (c *client) VolumeCreateFromSnapshot( ctx = c.withInstanceID(c.requireCtx(ctx), service) - lsd, _ := registry.NewClientDriver(service) - if lsd != nil { - if err := lsd.Init(ctx, c.config); err != nil { - return nil, err - } - - if err := lsd.VolumeCreateFromSnapshotBefore( - &ctx, service, snapshotID, request); err != nil { - return nil, err - } - } - vol, err := c.APIClient.VolumeCreateFromSnapshot( ctx, service, snapshotID, request) if err != nil { return nil, err } - if lsd != nil { - lsd.VolumeCreateFromSnapshotAfter(ctx, vol) - } - return vol, nil } @@ -184,27 +151,11 @@ func (c *client) VolumeCopy( ctx = c.withInstanceID(c.requireCtx(ctx), service) - lsd, _ := registry.NewClientDriver(service) - if lsd != nil { - if err := lsd.Init(ctx, c.config); err != nil { - return nil, err - } - - if err := lsd.VolumeCopyBefore( - &ctx, service, volumeID, request); err != nil { - return nil, err - } - } - vol, err := c.APIClient.VolumeCopy(ctx, service, volumeID, request) if err != nil { return nil, err } - if lsd != nil { - lsd.VolumeCopyAfter(ctx, vol) - } - return vol, nil } @@ -215,27 +166,11 @@ func (c *client) VolumeRemove( ctx = c.withInstanceID(c.requireCtx(ctx), service) - lsd, _ := registry.NewClientDriver(service) - if lsd != nil { - if err := lsd.Init(ctx, c.config); err != nil { - return err - } - - if err := lsd.VolumeRemoveBefore( - &ctx, service, volumeID); err != nil { - return err - } - } - err := c.APIClient.VolumeRemove(ctx, service, volumeID, force) if err != nil { return err } - if lsd != nil { - lsd.VolumeRemoveAfter(ctx, service, volumeID) - } - return nil } diff --git a/drivers/storage/vfs/client/vfs_client.go b/drivers/storage/vfs/client/vfs_client.go deleted file mode 100644 index 5083f169..00000000 --- a/drivers/storage/vfs/client/vfs_client.go +++ /dev/null @@ -1,201 +0,0 @@ -// +build !libstorage_storage_driver libstorage_storage_driver_vfs - -package client - -import ( - "os" - "path" - - gofig "github.com/akutz/gofig/types" - - "github.com/codedellemc/libstorage/api/registry" - "github.com/codedellemc/libstorage/api/types" - "github.com/codedellemc/libstorage/drivers/storage/vfs" -) - -type driver struct { - config gofig.Config -} - -func init() { - registry.RegisterClientDriver(vfs.Name, newDriver) -} - -func newDriver() types.ClientDriver { - return &driver{} -} - -func (d *driver) Name() string { - return vfs.Name -} - -func (d *driver) Init(ctx types.Context, config gofig.Config) error { - d.config = config - os.MkdirAll(vfs.VolumesDirPath(config), 0755) - return nil -} - -func (d *driver) InstanceInspectBefore(ctx *types.Context) error { - return nil -} - -func (d *driver) InstanceInspectAfter( - ctx types.Context, result *types.Instance) { -} - -func (d *driver) VolumesBefore(ctx *types.Context) error { - return nil -} - -func (d *driver) VolumesAfter( - ctx types.Context, result *types.ServiceVolumeMap) { -} - -func (d *driver) VolumesByServiceBefore( - ctx *types.Context, service string) error { - return nil -} - -func (d *driver) VolumesByServiceAfter( - ctx types.Context, service string, result *types.VolumeMap) { -} - -func (d *driver) VolumeInspectBefore( - ctx *types.Context, - service, volumeID string, - attachments types.VolumeAttachmentsTypes) error { - return nil -} - -func (d *driver) VolumeInspectAfter( - ctx types.Context, - result *types.Volume) { -} - -func (d *driver) VolumeCreateBefore( - ctx *types.Context, - service string, request *types.VolumeCreateRequest) error { - return nil -} - -func (d *driver) VolumeCreateAfter( - ctx types.Context, - result *types.Volume) { - volDir := path.Join(vfs.VolumesDirPath(d.config), result.ID) - os.MkdirAll(volDir, 0755) -} - -func (d *driver) VolumeCreateFromSnapshotBefore( - ctx *types.Context, - service, snapshotID string, - request *types.VolumeCreateRequest) error { - return nil -} - -func (d *driver) VolumeCreateFromSnapshotAfter( - ctx types.Context, result *types.Volume) { - volDir := path.Join(vfs.VolumesDirPath(d.config), result.ID) - os.MkdirAll(volDir, 0755) -} - -func (d *driver) VolumeCopyBefore( - ctx *types.Context, - service, volumeID string, request *types.VolumeCopyRequest) error { - return nil -} - -func (d *driver) VolumeCopyAfter( - ctx types.Context, - result *types.Volume) { - volDir := path.Join(vfs.VolumesDirPath(d.config), result.ID) - os.MkdirAll(volDir, 0755) -} - -func (d *driver) VolumeRemoveBefore( - ctx *types.Context, service, volumeID string) error { - return nil -} - -func (d *driver) VolumeRemoveAfter( - ctx types.Context, service, volumeID string) { - volDir := path.Join(vfs.VolumesDirPath(d.config), volumeID) - os.RemoveAll(volDir) -} - -func (d *driver) VolumeSnapshotBefore( - ctx *types.Context, - service, volumeID string, - request *types.VolumeSnapshotRequest) error { - return nil -} - -func (d *driver) VolumeSnapshotAfter( - ctx types.Context, result *types.Snapshot) { -} - -func (d *driver) VolumeAttachBefore( - ctx *types.Context, - service, volumeID string, - request *types.VolumeAttachRequest) error { - return nil -} - -func (d *driver) VolumeAttachAfter(ctx types.Context, result *types.Volume) { -} - -func (d *driver) VolumeDetachBefore( - ctx *types.Context, - service, volumeID string, - request *types.VolumeDetachRequest) error { - return nil -} - -func (d *driver) VolumeDetachAfter( - ctx types.Context, result *types.Volume) { -} - -func (d *driver) SnapshotsBefore(ctx *types.Context) error { - return nil -} - -func (d *driver) SnapshotsAfter( - ctx types.Context, result *types.ServiceSnapshotMap) { -} - -func (d *driver) SnapshotsByServiceBefore( - ctx *types.Context, service string) error { - return nil -} - -func (d *driver) SnapshotsByServiceAfter( - ctx types.Context, service string, result *types.SnapshotMap) { -} - -func (d *driver) SnapshotInspectBefore( - ctx *types.Context, - service, snapshotID string) error { - return nil -} - -func (d *driver) SnapshotInspectAfter( - ctx types.Context, result *types.Volume) { -} - -func (d *driver) SnapshotCopyBefore( - ctx *types.Context, - service, snapshotID, string, - request *types.SnapshotCopyRequest) error { - return nil -} - -func (d *driver) SnapshotCopyAfter( - ctx types.Context, result *types.Snapshot) { -} - -func (d *driver) SnapshotRemoveBefore( - ctx *types.Context, service, snapshotID string) error { - return nil -} - -func (d *driver) SnapshotRemoveAfter(ctx types.Context, snapshotID string) { -} diff --git a/drivers/storage/vfs/storage/vfs_storage.go b/drivers/storage/vfs/storage/vfs_storage.go index cbfd2e1f..2b963c36 100644 --- a/drivers/storage/vfs/storage/vfs_storage.go +++ b/drivers/storage/vfs/storage/vfs_storage.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "os" + "path" "time" gofig "github.com/akutz/gofig/types" @@ -272,6 +273,9 @@ func (d *driver) VolumeCreate( return nil, err } + volDir := path.Join(vfs.VolumesDirPath(d.config), v.ID) + os.MkdirAll(volDir, 0755) + return v, nil } @@ -324,6 +328,9 @@ func (d *driver) VolumeCreateFromSnapshot( return nil, err } + volDir := path.Join(vfs.VolumesDirPath(d.config), v.ID) + os.MkdirAll(volDir, 0755) + return v, nil } @@ -359,6 +366,9 @@ func (d *driver) VolumeCopy( return nil, err } + volDir := path.Join(vfs.VolumesDirPath(d.config), newVol.ID) + os.MkdirAll(volDir, 0755) + return newVol, nil } @@ -409,6 +419,9 @@ func (d *driver) VolumeRemove( return utils.NewNotFoundError(volumeID) } os.Remove(volJSONPath) + + volDir := path.Join(vfs.VolumesDirPath(d.config), volumeID) + os.RemoveAll(volDir) return nil } diff --git a/drivers/storage/vfs/tests/vfs_test.go b/drivers/storage/vfs/tests/vfs_test.go index b7c17721..38641c10 100644 --- a/drivers/storage/vfs/tests/vfs_test.go +++ b/drivers/storage/vfs/tests/vfs_test.go @@ -34,7 +34,6 @@ import ( // load the vfs driver packages "github.com/codedellemc/libstorage/drivers/storage/vfs" - _ "github.com/codedellemc/libstorage/drivers/storage/vfs/client" _ "github.com/codedellemc/libstorage/drivers/storage/vfs/storage" ) diff --git a/imports/local/imports_local_gofig.go b/imports/local/imports_local_gofig.go deleted file mode 100644 index e09f3d6d..00000000 --- a/imports/local/imports_local_gofig.go +++ /dev/null @@ -1,8 +0,0 @@ -// +build gofig,libstorage_storage_driver_vfs - -package local - -import ( - // load the packages - _ "github.com/codedellemc/libstorage/drivers/storage/vfs/client" -)