Skip to content

Commit 19a468e

Browse files
committed
Make volume size configurable
Support specifying a volume size in GB via volume options.
1 parent 99a6fc8 commit 19a468e

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The plugin attaches block storage volumes to the compute instance running the pl
1212
* KVM w/ virtio
1313

1414

15-
## Usage
15+
## Setup
1616

1717
Provide configuration for the plugin:
1818

@@ -44,6 +44,14 @@ INFO Connected. endpoint="http://api.os.xopic
4444

4545
By default a `cinder.json` from the current working directory will be used.
4646

47+
## Usage
48+
49+
The default volume size is 10GB but can be overridden:
50+
51+
```
52+
$ docker volume create -d cinder -o size=20 volname
53+
```
54+
4755

4856
## Notes
4957

plugin.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"os"
99
"os/exec"
1010
"path/filepath"
11+
"strconv"
1112
"strings"
1213
"sync"
1314
"syscall"
@@ -84,8 +85,20 @@ func (d plugin) Create(r *volume.CreateRequest) error {
8485
d.mutex.Lock()
8586
defer d.mutex.Unlock()
8687

88+
// DEFAULT SIZE IN GB
89+
var size = 10
90+
var err error
91+
92+
if s, ok := r.Options["size"]; ok {
93+
size, err = strconv.Atoi(s)
94+
if err != nil {
95+
logger.WithError(err).Error("Error parsing size option")
96+
return fmt.Errorf("Invalid size option: %s", err.Error())
97+
}
98+
}
99+
87100
vol, err := volumes.Create(d.blockClient, volumes.CreateOpts{
88-
Size: 10,
101+
Size: size,
89102
Name: r.Name,
90103
}).Extract()
91104

0 commit comments

Comments
 (0)