add feature: azurefile mount on windows node

fix according to review comments

add comments for SMB mount support on Windows
pull/6/head
andyzhangx 2017-09-14 03:38:08 +00:00
parent 02f48b6846
commit faffe82df7
2 changed files with 33 additions and 3 deletions

View File

@ -74,9 +74,25 @@ func (mounter *Mounter) Mount(source string, target string, fstype string, optio
return nil return nil
} }
// empty implementation for mounting azure file // currently only SMB mount is supported
cmdLine := fmt.Sprintf(`$User = "%s";$PWord = ConvertTo-SecureString -String "%s" -AsPlainText -Force;`+
`$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord`,
options[0], options[1])
driverLetter, err := getAvailableDriveLetter()
if err != nil {
return err
}
bindSource = driverLetter + ":"
cmdLine += fmt.Sprintf(";New-SmbGlobalMapping -LocalPath %s -RemotePath %s -Credential $Credential", bindSource, source)
if output, err := exec.Command("powershell", "/c", cmdLine).CombinedOutput(); err != nil {
// we don't return error here, even though New-SmbGlobalMapping failed, we still make it successful,
// will return error when Windows 2016 RS3 is ready on azure
glog.Errorf("azureMount: SmbGlobalMapping failed: %v, only SMB mount is supported now, output: %q", err, string(output))
return os.MkdirAll(target, 0755) return os.MkdirAll(target, 0755)
} }
}
if output, err := exec.Command("cmd", "/c", "mklink", "/D", target, bindSource).CombinedOutput(); err != nil { if output, err := exec.Command("cmd", "/c", "mklink", "/D", target, bindSource).CombinedOutput(); err != nil {
glog.Errorf("mklink failed: %v, source(%q) target(%q) output: %q", err, bindSource, target, string(output)) glog.Errorf("mklink failed: %v, source(%q) target(%q) output: %q", err, bindSource, target, string(output))
@ -178,6 +194,20 @@ func normalizeWindowsPath(path string) string {
return normalizedPath return normalizedPath
} }
func getAvailableDriveLetter() (string, error) {
cmd := "$used = Get-PSDrive | Select-Object -Expand Name | Where-Object { $_.Length -eq 1 }"
cmd += ";$drive = 67..90 | ForEach-Object { [string][char]$_ } | Where-Object { $used -notcontains $_ } | Select-Object -First 1;$drive"
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()
if err != nil {
return "", fmt.Errorf("getAvailableDriveLetter failed: %v, output: %q", err, string(output))
}
if len(output) == 0 {
return "", fmt.Errorf("azureMount: there is no available drive letter now")
}
return string(output)[:1], nil
}
// ValidateDiskNumber : disk number should be a number in [0, 99] // ValidateDiskNumber : disk number should be a number in [0, 99]
func ValidateDiskNumber(disk string) error { func ValidateDiskNumber(disk string) error {
diskNum, err := strconv.Atoi(disk) diskNum, err := strconv.Atoi(disk)

View File

@ -218,7 +218,7 @@ func (b *azureFileMounter) SetUpAt(dir string, fsGroup *int64) error {
source = fmt.Sprintf("%s%s%s.file.%s%s%s", osSeparator, osSeparator, accountName, getStorageEndpointSuffix(b.plugin.host.GetCloudProvider()), osSeparator, b.shareName) source = fmt.Sprintf("%s%s%s.file.%s%s%s", osSeparator, osSeparator, accountName, getStorageEndpointSuffix(b.plugin.host.GetCloudProvider()), osSeparator, b.shareName)
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
mountOptions = []string{accountName, accountKey} mountOptions = []string{fmt.Sprintf("AZURE\\%s", accountName), accountKey}
} else { } else {
os.MkdirAll(dir, 0700) os.MkdirAll(dir, 0700)
// parameters suggested by https://azure.microsoft.com/en-us/documentation/articles/storage-how-to-use-files-linux/ // parameters suggested by https://azure.microsoft.com/en-us/documentation/articles/storage-how-to-use-files-linux/