-
Notifications
You must be signed in to change notification settings - Fork 50
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 #394 from codenrhoden/feature/gce
Google Compute Engine (GCE) storage driver
- Loading branch information
Showing
22 changed files
with
2,362 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.vagrant |
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,109 @@ | ||
// +build !libstorage_storage_executor libstorage_storage_executor_gcepd | ||
|
||
package executor | ||
|
||
import ( | ||
"io/ioutil" | ||
"path" | ||
"regexp" | ||
|
||
gofig "github.com/akutz/gofig/types" | ||
|
||
"github.com/codedellemc/libstorage/api/registry" | ||
"github.com/codedellemc/libstorage/api/types" | ||
"github.com/codedellemc/libstorage/drivers/storage/gcepd" | ||
gceUtils "github.com/codedellemc/libstorage/drivers/storage/gcepd/utils" | ||
) | ||
|
||
const ( | ||
diskIDPath = "/dev/disk/by-id" | ||
diskPrefix = "google-" | ||
) | ||
|
||
// driver is the storage executor for the storage driver. | ||
type driver struct { | ||
config gofig.Config | ||
} | ||
|
||
func init() { | ||
registry.RegisterStorageExecutor(gcepd.Name, newDriver) | ||
} | ||
|
||
func newDriver() types.StorageExecutor { | ||
return &driver{} | ||
} | ||
|
||
func (d *driver) Init(ctx types.Context, config gofig.Config) error { | ||
d.config = config | ||
return nil | ||
} | ||
|
||
func (d *driver) Name() string { | ||
return gcepd.Name | ||
} | ||
|
||
// Supported returns a flag indicating whether or not the platform | ||
// implementing the executor is valid for the host on which the executor | ||
// resides. | ||
func (d *driver) Supported( | ||
ctx types.Context, | ||
opts types.Store) (bool, error) { | ||
|
||
return gceUtils.IsGCEInstance(ctx) | ||
} | ||
|
||
// InstanceID returns the instance ID from the current instance from metadata | ||
func (d *driver) InstanceID( | ||
ctx types.Context, | ||
opts types.Store) (*types.InstanceID, error) { | ||
|
||
return gceUtils.InstanceID(ctx) | ||
} | ||
|
||
// NextDevice returns the next available device. | ||
func (d *driver) NextDevice( | ||
ctx types.Context, | ||
opts types.Store) (string, error) { | ||
|
||
return "", types.ErrNotImplemented | ||
} | ||
|
||
// Retrieve device paths currently attached and/or mounted | ||
func (d *driver) LocalDevices( | ||
ctx types.Context, | ||
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) { | ||
|
||
files, err := ioutil.ReadDir(diskIDPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
persistentDiskRX, err := regexp.Compile( | ||
diskPrefix + `(` + gceUtils.DiskNameRX + `)`) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
attachedDisks, err := gceUtils.GetDisks(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ld := &types.LocalDevices{Driver: d.Name()} | ||
devMap := map[string]string{} | ||
for _, f := range files { | ||
if persistentDiskRX.MatchString(f.Name()) { | ||
matches := persistentDiskRX.FindStringSubmatch(f.Name()) | ||
volID := matches[1] | ||
if _, ok := attachedDisks[volID]; ok && volID != "" { | ||
devMap[volID] = path.Join(diskIDPath, f.Name()) | ||
} | ||
} | ||
} | ||
|
||
if len(devMap) > 0 { | ||
ld.DeviceMap = devMap | ||
} | ||
|
||
return ld, nil | ||
} |
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,44 @@ | ||
// +build !libstorage_storage_driver libstorage_storage_driver_gcepd | ||
|
||
package gcepd | ||
|
||
import ( | ||
gofigCore "github.com/akutz/gofig" | ||
gofig "github.com/akutz/gofig/types" | ||
) | ||
|
||
const ( | ||
// Name is the provider's name. | ||
Name = "gcepd" | ||
|
||
// InstanceIDFieldProjectID is the key to retrieve the ProjectID value | ||
// from the InstanceID Field map. | ||
InstanceIDFieldProjectID = "projectID" | ||
|
||
// InstanceIDFieldZone is the key to retrieve the zone value from the | ||
// InstanceID Field map. | ||
InstanceIDFieldZone = "zone" | ||
|
||
// DiskTypeSSD indicates an SSD based disk should be created | ||
DiskTypeSSD = "pd-ssd" | ||
|
||
// DiskTypeStandard indicates a standard (non-SSD) disk | ||
DiskTypeStandard = "pd-standard" | ||
|
||
// DefaultDiskType indicates what type of disk to create by default | ||
DefaultDiskType = DiskTypeSSD | ||
) | ||
|
||
func init() { | ||
r := gofigCore.NewRegistration("GCE") | ||
r.Key(gofig.String, "", "", | ||
"Required: JSON keyfile for service account", "gcepd.keyfile") | ||
r.Key(gofig.String, "", "", | ||
"If defined, limit GCE access to given zone", "gcepd.zone") | ||
r.Key(gofig.String, "", DefaultDiskType, "Default GCE disk type", | ||
"gcepd.defaultDiskType") | ||
r.Key(gofig.String, "", "", "Tag to apply and filter disks", | ||
"gcepd.tag") | ||
|
||
gofigCore.Register(r) | ||
} |
Oops, something went wrong.