support storage class in Cinder provisioner

Signed-off-by: Huamin Chen <hchen@redhat.com>
This commit is contained in:
Huamin Chen
2016-08-17 15:24:53 -04:00
parent cfe7a4391a
commit 259bce370e
7 changed files with 47 additions and 8 deletions

View File

@@ -391,7 +391,7 @@ func (testcase *testcase) GetAttachmentDiskPath(instanceID string, diskName stri
return expected.retPath, expected.ret
}
func (testcase *testcase) CreateVolume(name string, size int, tags *map[string]string) (volumeName string, err error) {
func (testcase *testcase) CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (volumeName string, err error) {
return "", errors.New("Not implemented")
}

View File

@@ -45,7 +45,7 @@ type CinderProvider interface {
AttachDisk(instanceID string, diskName string) (string, error)
DetachDisk(instanceID string, partialDiskId string) error
DeleteVolume(volumeName string) error
CreateVolume(name string, size int, tags *map[string]string) (volumeName string, err error)
CreateVolume(name string, size int, vtype, availability string, tags *map[string]string) (volumeName string, err error)
GetDevicePath(diskId string) string
InstanceID() (string, error)
GetAttachmentDiskPath(instanceID string, diskName string) (string, error)

View File

@@ -18,7 +18,9 @@ package cinder
import (
"errors"
"fmt"
"os"
"strings"
"time"
"github.com/golang/glog"
@@ -139,7 +141,26 @@ func (util *CinderDiskUtil) CreateVolume(c *cinderVolumeProvisioner) (volumeID s
// Cinder works with gigabytes, convert to GiB with rounding up
volSizeGB := int(volume.RoundUpSize(volSizeBytes, 1024*1024*1024))
name := volume.GenerateVolumeName(c.options.ClusterName, c.options.PVName, 255) // Cinder volume name can have up to 255 characters
name, err = cloud.CreateVolume(name, volSizeGB, c.options.CloudTags)
vtype := ""
availability := ""
// Apply ProvisionerParameters (case-insensitive). We leave validation of
// the values to the cloud provider.
for k, v := range c.options.Parameters {
switch strings.ToLower(k) {
case "type":
vtype = v
case "availability":
availability = v
default:
return "", 0, fmt.Errorf("invalid option %q for volume plugin %s", k, c.plugin.GetPluginName())
}
}
// TODO: implement c.options.ProvisionerSelector parsing
if c.options.Selector != nil {
return "", 0, fmt.Errorf("claim.Spec.Selector is not supported for dynamic provisioning on Cinder")
}
name, err = cloud.CreateVolume(name, volSizeGB, vtype, availability, c.options.CloudTags)
if err != nil {
glog.V(2).Infof("Error creating cinder volume: %v", err)
return "", 0, err