diff --git a/Makefile b/Makefile index 2f4d7018b..fd7ad2c71 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ ECHO = $(DEBUG) echo test-esx: $(TAR) cz --no-recursion $(ESX_SRC)/*.py | $(SSH) root@$(ESX) "cd /tmp; $(TAR) xz" $(ECHO) Running unit tests for vmdk-opsd python code on $(ESX)... - $(SSH) root@$(ESX) "python /tmp/$(ESX_SRC)/tests_vmdk_ops.py" + $(SSH) root@$(ESX) "python /tmp/$(ESX_SRC)/vmdk_ops_test.py" $(SSH) root@$(ESX) rm -rf /tmp/$(ESX_SRC) testremote: test-esx test-vm diff --git a/plugin.go b/plugin.go index 67d7b1503..0ee8fb887 100644 --- a/plugin.go +++ b/plugin.go @@ -1,43 +1,14 @@ package main // -// A VMDK Docker Data Volume plugin -// (for now just an outline) +// VMWare VMDK Docker Data Volume plugin. // -// It checks that it can connect to ESX via vSocket , and then -// fakes the successful ops by returning success and printing a messafe, -// without doing anything useful (useful stuff is work in progress) +// Provide suport for --driver=vmdk in Docker, when Docker VM is running under ESX. // -// TBD: add check for the guest communicates from ROOT - check the doc wrt security -// TBD: check we are running inside ESX and tools installed - in CODE , not make - -// TODO: -// convert all to return error() and only response to docker to return msg -// -// make sure msg and err is properly initialized everywhere (and check in go if it's needed) +// This code received requests from Docker Engine and requests/coordinates +// related VMDK operations with vmdk-opsd service running on enclosing host ESX +// (see ./vmdkops-esxsrv) /// -//TODO : -// Potentially: add unit test , fully contained on 1 Linux machine: -//- make server code actually create a loop block device and do a bind mount for volume test -//- hardcode location for testing (/var/vmware/dvolplug/volumes/vol-name -// fallocate -d -l volume.img -// losetup -v /dev/loop$(id) -f volume.img -// mkfs.ext4 /dev/loop$(id) -// mount /dev/lopp$(id) /mnt/loop$(id) # mount all here. Or skip -// mount -o bind # bind mount where Docker asks -// Good refs: https://www.suse.com/communities/blog/accessing-file-systems-disk-block-image-files/ -//) -// for actual mounts: -//- add actual create/mount code instead of prints -// -// TODO: add volumes tracking per the following docker spec: -// -// multiple containers on the same docker engine may use the same vmdk volume -// thus we need to track the volumes already attached, and just do bind mount for them -// Also it means we need to serialize all ops with mutex - -// We also need to track volumes attached and mounted to save on this ops if requested -// On start, we need to list vmdks attached to the VM and polulate list of volumes from it import ( // "encoding/json" @@ -55,7 +26,7 @@ const ( ) type vmdkDriver struct { - m *sync.Mutex // create() serialization + m *sync.Mutex // create() serialization - FFU mockEsx bool ops vmdkops.VmdkOps } @@ -68,7 +39,6 @@ func newVmdkDriver(mockEsx bool) vmdkDriver { vmdkCmd = vmdkops.VmdkCmd{} } d := vmdkDriver{ - // TODO: volumes map(string)volinfo, (name->uuid/refcount/creationtime) m: &sync.Mutex{}, mockEsx: mockEsx, ops: vmdkops.VmdkOps{Cmd: vmdkCmd}, @@ -112,9 +82,10 @@ func (d vmdkDriver) mountVolume(r volume.Request, path string) error { return nil } - // TODO: refcount if the volume is already mounted (for other container) and + // TODO: Issue #28 + // - refcount if the volume is already mounted (for other container) and // just return volume.Response{Mountpoint: m} in this case - // TODO: save info abouf voliume mount , in memory + // - save info abouf voliume mount , in memory // d.volumes[m] = &volumeName{name: r.Name, connections: 1} if err := d.ops.Attach(r.Name, r.Options); err != nil { return err diff --git a/vmdkops-esxsrv/vmdk_ops.py b/vmdkops-esxsrv/vmdk_ops.py index 61656b58c..89b7a7e00 100755 --- a/vmdkops-esxsrv/vmdk_ops.py +++ b/vmdkops-esxsrv/vmdk_ops.py @@ -1,73 +1,20 @@ #!/usr/bin/env python ''' -TOP TODO - -0. extract attach/detach code and make sure it work fine without anything else -1. add WaitForTask in Python and drop sleep, Also add time track for reconfigure -2. Add scsi_resync to plugin.go. Check how mount is done in flocker and in VIC -3. Go over code, and collect TODO in one place (add TODO file) -4. add simple test script (or sketch it) -5. Look at cleaning up makefile and adding godeps -''' +ESX-side service handling VMDK create/attach requests from VMCI clients +The requests (create/delete/attach/detach) are JSON formatted. -# -# ESX-side service handling VMDK creat/attach requests from VMCI clients -# -# The requests (create/delete/attach/detach) are JSON formatted. -# -# All operations are using requester VM (docker host) datastore and -# "Name" in request refers to vmdk basename -# VMDK name is formed as [vmdatastore] dvol/"Name".vmdk -# -# Commands ("cmd" in request): -# "create" - create a VMDK in "[vmdatastore] dvol" -# "remove" - remove a VMDK. We assume it's not open, and fail if it is -# "list" - [future, need docker support] enumerate related VMDK -# "attach" - attach a VMDK to the requesting VM -# "detach" - detach a VMDK from the requesting VM (assuming it's unmounted) -# -# -# known issues: -# - need interrupt handler to restart listen() on control-c -# - call VirtualDiskManager directly instead of cmd line -# - todo/tbd below +All operations are using requester VM (docker host) datastore and +"Name" in request refers to vmdk basename +VMDK name is formed as [vmdatastore] dvol/"Name".vmdk -''' -TODO -== -Drop command line and use VDM for disk manipulation: -spec=vim.FileBackedVirtualDiskSpec(capacityKB=1024, profile = None ,adapterType='lsiLogic', diskType = 'thin') -vdm = si.content.virtualDiskManager -vdm.CreateVirtualDisk_Task(name="[datastore] eek/a1.vmdk", datadatacenter=dc, spec = spec) -vm = findVmByName()... ; vm.config.datastoreUrl[0].name is datastore -see https://opengrok.eng.vmware.com/source/xref/vmcore-main.perforce.1666/bora/vmkernel/tests/vsan/vsansparse_sanity.py#314 -or even better https://gist.github.com/hartsock/d8b9c56cd7f779c92a78 (fails if exists) -for examples -== - -make sure backend name is properly calculated - -OR replace it all with in-guest formatting (but then we'd need to locate the proper blockdevice() - -With the current approach, new device is found for mount with blkid -L , which is easier - -=== -check size format and handle policy on -o flags -== -make sure the NEW disk is really formatted if if it does not have -flat.vmdk -== -findChild seems to generate a task - too slow. Find out where and drop -== -Pass error as a code in the VMCI package, rather than a hack with server.c:vmci_reply - -=== - - * TBD: authorization/access config: - * - location configuration. And generally, configuration... host profile/adv.conf? - * - a local version, talking over Unix Socket, to debug all I can on Linux - with logic and fake responses (part of build unit test) - * - an ESX version, talking over http , to debug logic on a random ESX - with full vigor API usage - * - an ESX version, with vSocket (C I suppose) connection, to finalize debugging on actual guest/host story +Commands ("cmd" in request): + "create" - create a VMDK in "[vmdatastore] dvol" + "remove" - remove a VMDK. We assume it's not open, and fail if it is + "list" - [future, need docker support] enumerate related VMDK + "attach" - attach a VMDK to the requesting VM + "detach" - detach a VMDK from the requesting VM (assuming it's unmounted) ''' diff --git a/vmdkops-esxsrv/tests_vmdk_ops.py b/vmdkops-esxsrv/vmdk_ops_test.py similarity index 100% rename from vmdkops-esxsrv/tests_vmdk_ops.py rename to vmdkops-esxsrv/vmdk_ops_test.py diff --git a/vmdkops-esxsrv/tests_vol.py b/vmdkops-esxsrv/vol_test.py similarity index 100% rename from vmdkops-esxsrv/tests_vol.py rename to vmdkops-esxsrv/vol_test.py