-
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.
This patch introduces the new VMware vSphere Driver - "vmw". The driver uses VMCI Sockets (https://www.vmware.com/support/developer/vmci-sdk/) to communicate directly with a vSphere host, removing the need for the sizeable VMware SDK for Go library dependency.
- Loading branch information
Showing
17 changed files
with
2,206 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// +build linux | ||
// +build !libstorage_storage_executor libstorage_storage_executor_vmw | ||
|
||
package executor | ||
|
||
import ( | ||
gofig "github.com/akutz/gofig/types" | ||
|
||
"github.com/codedellemc/libstorage/api/registry" | ||
"github.com/codedellemc/libstorage/api/types" | ||
"github.com/codedellemc/libstorage/drivers/storage/vmw" | ||
) | ||
|
||
type driver struct { | ||
config gofig.Config | ||
} | ||
|
||
func init() { | ||
registry.RegisterStorageExecutor(vmw.Name, newDriver) | ||
} | ||
|
||
func newDriver() types.StorageExecutor { | ||
return &driver{} | ||
} | ||
|
||
func (d *driver) Name() string { | ||
return vmw.Name | ||
} | ||
|
||
func (d *driver) Supported( | ||
ctx types.Context, | ||
opts types.Store) (bool, error) { | ||
|
||
return true, nil | ||
} | ||
|
||
func (d *driver) Init(ctx types.Context, config gofig.Config) error { | ||
d.config = config | ||
return nil | ||
} | ||
|
||
// InstanceID returns the local system's InstanceID. | ||
func (d *driver) InstanceID( | ||
ctx types.Context, | ||
opts types.Store) (*types.InstanceID, error) { | ||
|
||
iid := &types.InstanceID{Driver: vmw.Name} | ||
iid.ID = vmw.Name | ||
return iid, nil | ||
} | ||
|
||
// NextDevice returns the next available device. | ||
func (d *driver) NextDevice( | ||
ctx types.Context, | ||
opts types.Store) (string, error) { | ||
|
||
return "", nil | ||
} | ||
|
||
// LocalDevices returns a map of the system's local devices. | ||
func (d *driver) LocalDevices( | ||
ctx types.Context, | ||
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) { | ||
|
||
return &types.LocalDevices{DeviceMap: map[string]string{}}, 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,165 @@ | ||
// +build linux | ||
// +build !libstorage_storage_driver libstorage_storage_driver_vmw | ||
|
||
package storage | ||
|
||
import ( | ||
gofig "github.com/akutz/gofig/types" | ||
|
||
"github.com/codedellemc/libstorage/api/registry" | ||
"github.com/codedellemc/libstorage/api/types" | ||
|
||
"github.com/codedellemc/libstorage/drivers/storage/vmw" | ||
|
||
// load the vmci pkg | ||
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/vmci" | ||
//_ "github.com/vmware/docker-volume-vsphere/vmdk_plugin/drivers/vmdk/vmdkops" | ||
) | ||
|
||
const ( | ||
minSizeGiB = 1 | ||
) | ||
|
||
type driver struct { | ||
ctx types.Context | ||
config gofig.Config | ||
} | ||
|
||
func init() { | ||
registry.RegisterStorageDriver(vmw.Name, newDriver) | ||
} | ||
|
||
func newDriver() types.StorageDriver { | ||
return &driver{} | ||
} | ||
|
||
func (d *driver) Name() string { | ||
return vmw.Name | ||
} | ||
|
||
func (d *driver) Type(ctx types.Context) (types.StorageType, error) { | ||
return types.Block, nil | ||
} | ||
|
||
func (d *driver) Init(ctx types.Context, config gofig.Config) error { | ||
d.ctx = ctx | ||
d.config = config | ||
cmd := &utils.EsxVmdkCmd{} | ||
return nil | ||
} | ||
|
||
func (d *driver) NextDeviceInfo( | ||
ctx types.Context) (*types.NextDeviceInfo, error) { | ||
return &types.NextDeviceInfo{ | ||
Ignore: true, | ||
}, nil | ||
} | ||
|
||
func (d *driver) InstanceInspect( | ||
ctx types.Context, | ||
opts types.Store) (*types.Instance, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) Volumes( | ||
ctx types.Context, | ||
opts *types.VolumesOpts) ([]*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeInspect( | ||
ctx types.Context, | ||
volumeID string, | ||
opts *types.VolumeInspectOpts) (*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeCreate( | ||
ctx types.Context, | ||
name string, | ||
opts *types.VolumeCreateOpts) (*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeCreateFromSnapshot( | ||
ctx types.Context, | ||
snapshotID, volumeName string, | ||
opts *types.VolumeCreateOpts) (*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeCopy( | ||
ctx types.Context, | ||
volumeID, volumeName string, | ||
opts types.Store) (*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeSnapshot( | ||
ctx types.Context, | ||
volumeID, snapshotName string, | ||
opts types.Store) (*types.Snapshot, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) VolumeRemove( | ||
ctx types.Context, | ||
volumeID string, | ||
opts *types.VolumeRemoveOpts) error { | ||
|
||
return nil | ||
} | ||
|
||
func (d *driver) VolumeAttach( | ||
ctx types.Context, | ||
volumeID string, | ||
opts *types.VolumeAttachOpts) (*types.Volume, string, error) { | ||
|
||
return nil, "", nil | ||
} | ||
|
||
func (d *driver) VolumeDetach( | ||
ctx types.Context, | ||
volumeID string, | ||
opts *types.VolumeDetachOpts) (*types.Volume, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) Snapshots( | ||
ctx types.Context, | ||
opts types.Store) ([]*types.Snapshot, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) SnapshotInspect( | ||
ctx types.Context, | ||
snapshotID string, | ||
opts types.Store) (*types.Snapshot, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) SnapshotCopy( | ||
ctx types.Context, | ||
snapshotID, snapshotName, destinationID string, | ||
opts types.Store) (*types.Snapshot, error) { | ||
|
||
return nil, nil | ||
} | ||
|
||
func (d *driver) SnapshotRemove( | ||
ctx types.Context, | ||
snapshotID string, | ||
opts types.Store) error { | ||
|
||
return 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,2 @@ | ||
VMW_COVERPKG := $(ROOT_IMPORT_PATH)/drivers/storage/vmw | ||
TEST_COVERPKG_./drivers/storage/vmw/tests := $(VMW_COVERPKG),$(VMW_COVERPKG)/executor |
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,20 @@ | ||
// +build linux | ||
// +build !libstorage_storage_driver libstorage_storage_driver_vmw | ||
|
||
package tests | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
_ "github.com/codedellemc/libstorage/api/tests" | ||
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/storage" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestHello(t *testing.T) { | ||
t.Log("hello") | ||
} |
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,63 @@ | ||
// Copyright 2016 VMware, Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Shared info (magic, err. codes, etc) on vSocket command channel | ||
|
||
#ifndef _CONNECTION_TYPES_H_ | ||
#define _CONNECTION_TYPES_H_ | ||
|
||
#define MAGIC 0xbadbeef | ||
|
||
// -1 always indicates failure | ||
#define CONN_FAILURE (-1) | ||
|
||
// 0 is usually success. Note: sometimes we return socket FD on success | ||
#define CONN_SUCCESS (0) | ||
|
||
// First non privileged port | ||
#define START_NON_PRIVILEGED_PORT 1024 | ||
|
||
/* | ||
* Check and set errno helper | ||
* Useful when send/recv gets us less than we wanted, and we want to set errno | ||
* for the caller to know about the protocol Issue | ||
*/ | ||
#define CHECK_ERRNO(_ret) {if (_ret >= 0 && errno == 0) { errno = EBADMSG; }} | ||
|
||
/* | ||
* This function acquires and returns address family for vSockets. | ||
* On failure returns -1 an sets errno (if not set by VMCISock_GetAFValue ()) | ||
* | ||
* The address family for vSockets must be acquired, it is not static. | ||
* The code opens and keeps FD to /dev/vsock to indicate to the kernel | ||
* that VMCI driver is used by this process. | ||
* Needs to be called once per process. | ||
* <af> is expected to be closed by process completion | ||
*/ | ||
static inline int | ||
vsock_get_family(void) | ||
{ | ||
static int af = -1; | ||
|
||
errno = 0; | ||
if (af == -1) { // TODO: for multi-thread will need a lock. Issue #35 | ||
af = VMCISock_GetAFValue(); | ||
} | ||
if (af == -1 && errno == 0) { | ||
errno = EAFNOSUPPORT; // report "family not supported" upstairs | ||
} | ||
return af; | ||
} | ||
|
||
#endif // _CONNECTION_TYPES_H_ |
Oops, something went wrong.