From 4942a57db6db36b715a18a67bafcf783bc25250e Mon Sep 17 00:00:00 2001 From: Kiall Mac Innes Date: Thu, 22 Sep 2016 11:07:13 +0100 Subject: [PATCH] Support OpenStack+ESXi Volumes in GetDevicePath GetDevicePath was currently coded to only support Nova+KVM style device paths, update so we also support Nova+ESXi and leave the code such that new pattern additions are easy. --- .../providers/openstack/openstack_volumes.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/cloudprovider/providers/openstack/openstack_volumes.go b/pkg/cloudprovider/providers/openstack/openstack_volumes.go index 7b65e522f43..8844897db92 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_volumes.go +++ b/pkg/cloudprovider/providers/openstack/openstack_volumes.go @@ -169,16 +169,25 @@ func (os *OpenStack) CreateVolume(name string, size int, vtype, availability str // GetDevicePath returns the path of an attached block storage volume, specified by its id. func (os *OpenStack) GetDevicePath(diskId string) string { + // Build a list of candidate device paths + candidateDeviceNodes := []string{ + // KVM + fmt.Sprintf("virtio-%s", diskId[:20]), + // ESXi + fmt.Sprintf("wwn-0x%s", strings.Replace(diskId, "-", "", -1)), + } + files, _ := ioutil.ReadDir("/dev/disk/by-id/") + for _, f := range files { - if strings.Contains(f.Name(), "virtio-") { - devid_prefix := f.Name()[len("virtio-"):len(f.Name())] - if strings.Contains(diskId, devid_prefix) { + for _, c := range candidateDeviceNodes { + if c == f.Name() { glog.V(4).Infof("Found disk attached as %q; full devicepath: %s\n", f.Name(), path.Join("/dev/disk/by-id/", f.Name())) return path.Join("/dev/disk/by-id/", f.Name()) } } } + glog.Warningf("Failed to find device for the diskid: %q\n", diskId) return "" }