Skip to content

Commit 4f4bce7

Browse files
committed
VMware vSphere Driver
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.
1 parent 8570256 commit 4f4bce7

File tree

17 files changed

+2206
-21
lines changed

17 files changed

+2206
-21
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// +build linux
2+
// +build !libstorage_storage_executor libstorage_storage_executor_vmw
3+
4+
package executor
5+
6+
import (
7+
gofig "github.com/akutz/gofig/types"
8+
9+
"github.com/codedellemc/libstorage/api/registry"
10+
"github.com/codedellemc/libstorage/api/types"
11+
"github.com/codedellemc/libstorage/drivers/storage/vmw"
12+
)
13+
14+
type driver struct {
15+
config gofig.Config
16+
}
17+
18+
func init() {
19+
registry.RegisterStorageExecutor(vmw.Name, newDriver)
20+
}
21+
22+
func newDriver() types.StorageExecutor {
23+
return &driver{}
24+
}
25+
26+
func (d *driver) Name() string {
27+
return vmw.Name
28+
}
29+
30+
func (d *driver) Supported(
31+
ctx types.Context,
32+
opts types.Store) (bool, error) {
33+
34+
return true, nil
35+
}
36+
37+
func (d *driver) Init(ctx types.Context, config gofig.Config) error {
38+
d.config = config
39+
return nil
40+
}
41+
42+
// InstanceID returns the local system's InstanceID.
43+
func (d *driver) InstanceID(
44+
ctx types.Context,
45+
opts types.Store) (*types.InstanceID, error) {
46+
47+
iid := &types.InstanceID{Driver: vmw.Name}
48+
iid.ID = vmw.Name
49+
return iid, nil
50+
}
51+
52+
// NextDevice returns the next available device.
53+
func (d *driver) NextDevice(
54+
ctx types.Context,
55+
opts types.Store) (string, error) {
56+
57+
return "", nil
58+
}
59+
60+
// LocalDevices returns a map of the system's local devices.
61+
func (d *driver) LocalDevices(
62+
ctx types.Context,
63+
opts *types.LocalDevicesOpts) (*types.LocalDevices, error) {
64+
65+
return &types.LocalDevices{DeviceMap: map[string]string{}}, nil
66+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
// +build linux
2+
// +build !libstorage_storage_driver libstorage_storage_driver_vmw
3+
4+
package storage
5+
6+
import (
7+
gofig "github.com/akutz/gofig/types"
8+
9+
"github.com/codedellemc/libstorage/api/registry"
10+
"github.com/codedellemc/libstorage/api/types"
11+
12+
"github.com/codedellemc/libstorage/drivers/storage/vmw"
13+
14+
// load the vmci pkg
15+
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/vmci"
16+
//_ "github.com/vmware/docker-volume-vsphere/vmdk_plugin/drivers/vmdk/vmdkops"
17+
)
18+
19+
const (
20+
minSizeGiB = 1
21+
)
22+
23+
type driver struct {
24+
ctx types.Context
25+
config gofig.Config
26+
}
27+
28+
func init() {
29+
registry.RegisterStorageDriver(vmw.Name, newDriver)
30+
}
31+
32+
func newDriver() types.StorageDriver {
33+
return &driver{}
34+
}
35+
36+
func (d *driver) Name() string {
37+
return vmw.Name
38+
}
39+
40+
func (d *driver) Type(ctx types.Context) (types.StorageType, error) {
41+
return types.Block, nil
42+
}
43+
44+
func (d *driver) Init(ctx types.Context, config gofig.Config) error {
45+
d.ctx = ctx
46+
d.config = config
47+
cmd := &utils.EsxVmdkCmd{}
48+
return nil
49+
}
50+
51+
func (d *driver) NextDeviceInfo(
52+
ctx types.Context) (*types.NextDeviceInfo, error) {
53+
return &types.NextDeviceInfo{
54+
Ignore: true,
55+
}, nil
56+
}
57+
58+
func (d *driver) InstanceInspect(
59+
ctx types.Context,
60+
opts types.Store) (*types.Instance, error) {
61+
62+
return nil, nil
63+
}
64+
65+
func (d *driver) Volumes(
66+
ctx types.Context,
67+
opts *types.VolumesOpts) ([]*types.Volume, error) {
68+
69+
return nil, nil
70+
}
71+
72+
func (d *driver) VolumeInspect(
73+
ctx types.Context,
74+
volumeID string,
75+
opts *types.VolumeInspectOpts) (*types.Volume, error) {
76+
77+
return nil, nil
78+
}
79+
80+
func (d *driver) VolumeCreate(
81+
ctx types.Context,
82+
name string,
83+
opts *types.VolumeCreateOpts) (*types.Volume, error) {
84+
85+
return nil, nil
86+
}
87+
88+
func (d *driver) VolumeCreateFromSnapshot(
89+
ctx types.Context,
90+
snapshotID, volumeName string,
91+
opts *types.VolumeCreateOpts) (*types.Volume, error) {
92+
93+
return nil, nil
94+
}
95+
96+
func (d *driver) VolumeCopy(
97+
ctx types.Context,
98+
volumeID, volumeName string,
99+
opts types.Store) (*types.Volume, error) {
100+
101+
return nil, nil
102+
}
103+
104+
func (d *driver) VolumeSnapshot(
105+
ctx types.Context,
106+
volumeID, snapshotName string,
107+
opts types.Store) (*types.Snapshot, error) {
108+
109+
return nil, nil
110+
}
111+
112+
func (d *driver) VolumeRemove(
113+
ctx types.Context,
114+
volumeID string,
115+
opts *types.VolumeRemoveOpts) error {
116+
117+
return nil
118+
}
119+
120+
func (d *driver) VolumeAttach(
121+
ctx types.Context,
122+
volumeID string,
123+
opts *types.VolumeAttachOpts) (*types.Volume, string, error) {
124+
125+
return nil, "", nil
126+
}
127+
128+
func (d *driver) VolumeDetach(
129+
ctx types.Context,
130+
volumeID string,
131+
opts *types.VolumeDetachOpts) (*types.Volume, error) {
132+
133+
return nil, nil
134+
}
135+
136+
func (d *driver) Snapshots(
137+
ctx types.Context,
138+
opts types.Store) ([]*types.Snapshot, error) {
139+
140+
return nil, nil
141+
}
142+
143+
func (d *driver) SnapshotInspect(
144+
ctx types.Context,
145+
snapshotID string,
146+
opts types.Store) (*types.Snapshot, error) {
147+
148+
return nil, nil
149+
}
150+
151+
func (d *driver) SnapshotCopy(
152+
ctx types.Context,
153+
snapshotID, snapshotName, destinationID string,
154+
opts types.Store) (*types.Snapshot, error) {
155+
156+
return nil, nil
157+
}
158+
159+
func (d *driver) SnapshotRemove(
160+
ctx types.Context,
161+
snapshotID string,
162+
opts types.Store) error {
163+
164+
return nil
165+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VMW_COVERPKG := $(ROOT_IMPORT_PATH)/drivers/storage/vmw
2+
TEST_COVERPKG_./drivers/storage/vmw/tests := $(VMW_COVERPKG),$(VMW_COVERPKG)/executor
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// +build linux
2+
// +build !libstorage_storage_driver libstorage_storage_driver_vmw
3+
4+
package tests
5+
6+
import (
7+
"os"
8+
"testing"
9+
10+
_ "github.com/codedellemc/libstorage/api/tests"
11+
_ "github.com/codedellemc/libstorage/drivers/storage/vmw/storage"
12+
)
13+
14+
func TestMain(m *testing.M) {
15+
os.Exit(m.Run())
16+
}
17+
18+
func TestHello(t *testing.T) {
19+
t.Log("hello")
20+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2016 VMware, Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Shared info (magic, err. codes, etc) on vSocket command channel
16+
17+
#ifndef _CONNECTION_TYPES_H_
18+
#define _CONNECTION_TYPES_H_
19+
20+
#define MAGIC 0xbadbeef
21+
22+
// -1 always indicates failure
23+
#define CONN_FAILURE (-1)
24+
25+
// 0 is usually success. Note: sometimes we return socket FD on success
26+
#define CONN_SUCCESS (0)
27+
28+
// First non privileged port
29+
#define START_NON_PRIVILEGED_PORT 1024
30+
31+
/*
32+
* Check and set errno helper
33+
* Useful when send/recv gets us less than we wanted, and we want to set errno
34+
* for the caller to know about the protocol Issue
35+
*/
36+
#define CHECK_ERRNO(_ret) {if (_ret >= 0 && errno == 0) { errno = EBADMSG; }}
37+
38+
/*
39+
* This function acquires and returns address family for vSockets.
40+
* On failure returns -1 an sets errno (if not set by VMCISock_GetAFValue ())
41+
*
42+
* The address family for vSockets must be acquired, it is not static.
43+
* The code opens and keeps FD to /dev/vsock to indicate to the kernel
44+
* that VMCI driver is used by this process.
45+
* Needs to be called once per process.
46+
* <af> is expected to be closed by process completion
47+
*/
48+
static inline int
49+
vsock_get_family(void)
50+
{
51+
static int af = -1;
52+
53+
errno = 0;
54+
if (af == -1) { // TODO: for multi-thread will need a lock. Issue #35
55+
af = VMCISock_GetAFValue();
56+
}
57+
if (af == -1 && errno == 0) {
58+
errno = EAFNOSUPPORT; // report "family not supported" upstairs
59+
}
60+
return af;
61+
}
62+
63+
#endif // _CONNECTION_TYPES_H_

0 commit comments

Comments
 (0)