Skip to content
This repository has been archived by the owner on Jan 17, 2018. It is now read-only.

Make storage base host configurable #43

Merged
merged 1 commit into from
Jul 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contrib/init/systemd/azurefile-dockervolumedriver.default
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Environment file for azurefile-dockervolumedriver.service
#
# AF_OPTS=--debug
# AZURE_STORAGE_BASE=core.windows.net

AZURE_STORAGE_ACCOUNT=youraccount
AZURE_STORAGE_ACCOUNT_KEY=yourkey
2 changes: 2 additions & 0 deletions contrib/init/upstart/azurefile-dockervolumedriver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,7 @@ script
echo "Parsed configuration correctly."
export AZURE_STORAGE_ACCOUNT="$AF_ACCOUNT_NAME"
export AZURE_STORAGE_ACCOUNT_KEY="$AF_ACCOUNT_KEY"
export AZURE_STORAGE_BASE="$AZURE_STORAGE_BASE"

exec "$AF_CMD" $AF_OPTS 2>&1
end script
1 change: 1 addition & 0 deletions contrib/init/upstart/azurefile-dockervolumedriver.default
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#
# Additional arguments to executable:
# AF_OPTS=--debug
# AZURE_STORAGE_BASE=core.windows.net

AF_ACCOUNT_NAME=youraccount
AF_ACCOUNT_KEY=yourkey
12 changes: 7 additions & 5 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ type volumeDriver struct {
meta *metadataDriver
accountName string
accountKey string
storageBase string
mountpoint string
removeShares bool
}

func newVolumeDriver(accountName, accountKey, mountpoint, metadataRoot string, removeShares bool) (*volumeDriver, error) {
storageClient, err := azure.NewBasicClient(accountName, accountKey)
func newVolumeDriver(accountName, accountKey, storageBase, mountpoint, metadataRoot string, removeShares bool) (*volumeDriver, error) {
storageClient, err := azure.NewClient(accountName, accountKey, storageBase, azure.DefaultAPIVersion, true)
if err != nil {
return nil, fmt.Errorf("error creating azure client: %v", err)
}
Expand All @@ -39,6 +40,7 @@ func newVolumeDriver(accountName, accountKey, mountpoint, metadataRoot string, r
meta: metaDriver,
accountName: accountName,
accountKey: accountKey,
storageBase: storageBase,
mountpoint: mountpoint,
removeShares: removeShares,
}, nil
Expand Down Expand Up @@ -133,7 +135,7 @@ func (v *volumeDriver) Mount(req volume.Request) (resp volume.Response) {
return
}

if err := mount(v.accountName, v.accountKey, path, meta.Options); err != nil {
if err := mount(v.accountName, v.accountKey, v.storageBase, path, meta.Options); err != nil {
resp.Err = err.Error()
logctx.Error(resp.Err)
return
Expand Down Expand Up @@ -281,7 +283,7 @@ func (v *volumeDriver) pathForVolume(name string) string {
return filepath.Join(v.mountpoint, name)
}

func mount(accountName, accountKey, mountpoint string, options VolumeOptions) error {
func mount(accountName, accountKey, shareName, storageBase string, options VolumeOptions) error {
// Set defaults
if len(options.FileMode) == 0 {
options.FileMode = "0777"
Expand All @@ -295,7 +297,7 @@ func mount(accountName, accountKey, mountpoint string, options VolumeOptions) er
if len(options.GID) == 0 {
options.GID = "0"
}
mount := fmt.Sprintf("//%s.file.core.windows.net/%s", accountName, options.Share)
mount := fmt.Sprintf("//%s.file.%s/%s", accountName, storageBase, options.Share)
opts := []string{
"vers=3.0",
fmt.Sprintf("username=%s", accountName),
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"os"

azure "github.com/Azure/azure-sdk-for-go/storage"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/go-plugins-helpers/volume"
Expand Down Expand Up @@ -32,6 +33,12 @@ func main() {
Usage: "Azure storage account key",
EnvVar: "AZURE_STORAGE_ACCOUNT_KEY",
},
cli.StringFlag{
Name: "storage-base",
Usage: "Base domain for Azure Storage endpoint",
EnvVar: "AZURE_STORAGE_BASE",
Value: azure.DefaultBaseURL,
},
cli.BoolFlag{
Name: "remove-shares",
Usage: "remove associated Azure File Share when volume is removed",
Expand Down Expand Up @@ -59,6 +66,7 @@ func main() {

accountName := c.String("account-name")
accountKey := c.String("account-key")
storageBase := c.String("storage-base")
mountpoint := c.String("mountpoint")
metaDir := c.String("metadata")
removeShares := c.Bool("remove-shares")
Expand All @@ -73,7 +81,7 @@ func main() {
"removeShares": removeShares,
}).Debug("Starting server.")

driver, err := newVolumeDriver(accountName, accountKey, mountpoint, metaDir, removeShares)
driver, err := newVolumeDriver(accountName, accountKey, storageBase, mountpoint, metaDir, removeShares)
if err != nil {
log.Fatal(err)
}
Expand Down