1
0
mirror of https://github.com/rancher/os.git synced 2025-09-13 21:51:33 +00:00

Add aliyun datasource (#2169)

This commit is contained in:
niusmallnan
2017-12-19 14:33:44 +08:00
committed by GitHub
parent 7e912e12e8
commit 60909e435f
7 changed files with 312 additions and 145 deletions

View File

@@ -15,6 +15,8 @@
package metadata
import (
"bufio"
"bytes"
"fmt"
"net/http"
"strings"
@@ -84,3 +86,25 @@ func (ms Service) MetadataURL() string {
func (ms Service) UserdataURL() string {
return (ms.Root + ms.UserdataPath)
}
func (ms Service) FetchAttributes(key string) ([]string, error) {
url := ms.MetadataURL() + key
resp, err := ms.FetchData(url)
if err != nil {
return nil, err
}
scanner := bufio.NewScanner(bytes.NewBuffer(resp))
data := make([]string, 0)
for scanner.Scan() {
data = append(data, scanner.Text())
}
return data, scanner.Err()
}
func (ms Service) FetchAttribute(key string) (string, error) {
attrs, err := ms.FetchAttributes(key)
if err == nil && len(attrs) > 0 {
return attrs[0], nil
}
return "", err
}