func (ms *metadataService) FetchUserdata() ([]byte, error) {
	client := pkg.NewHttpClient()
	if data, err := client.GetRetry(Ec2UserdataUrl); err == nil {
		return data, err
	} else if _, ok := err.(pkg.ErrTimeout); ok {
		return data, err
	}

	if data, err := client.GetRetry(OpenstackUserdataUrl); err == nil {
		return data, err
	} else if _, ok := err.(pkg.ErrNotFound); ok {
		return []byte{}, nil
	} else {
		return data, err
	}
}
Exemplo n.º 2
0
func fetchUserKeys(url string) ([]string, error) {
	client := pkg.NewHttpClient()
	data, err := client.GetRetry(url)
	if err != nil {
		return nil, err
	}

	var userKeys []UserKey
	err = json.Unmarshal(data, &userKeys)
	if err != nil {
		return nil, err
	}
	keys := make([]string, 0)
	for _, key := range userKeys {
		keys = append(keys, key.Key)
	}
	return keys, err
}
func (c *procCmdline) FetchUserdata() ([]byte, error) {
	contents, err := ioutil.ReadFile(c.Location)
	if err != nil {
		return nil, err
	}

	cmdline := strings.TrimSpace(string(contents))
	url, err := findCloudConfigURL(cmdline)
	if err != nil {
		return nil, err
	}

	client := pkg.NewHttpClient()
	cfg, err := client.GetRetry(url)
	if err != nil {
		return nil, err
	}

	return cfg, nil
}
Exemplo n.º 4
0
func NewDatasource(root string) *metadataService {
	if !strings.HasSuffix(root, "/") {
		root += "/"
	}
	return &metadataService{root, pkg.NewHttpClient()}
}
Exemplo n.º 5
0
func urlDownload(url string) ([]byte, error) {
	client := pkg.NewHttpClient()
	return client.GetRetry(url)
}
func (ms *metadataService) FetchMetadata() ([]byte, error) {
	return fetchMetadata(pkg.NewHttpClient())
}
func (ms *metadataService) IsAvailable() bool {
	client := pkg.NewHttpClient()
	_, err := client.Get(BaseUrl)
	return (err == nil)
}
Exemplo n.º 8
0
func NewDatasource(root, apiVersion, userdataPath, metadataPath string) MetadataService {
	if !strings.HasSuffix(root, "/") {
		root += "/"
	}
	return MetadataService{root, pkg.NewHttpClient(), apiVersion, userdataPath, metadataPath}
}
Exemplo n.º 9
0
Arquivo: url.go Projeto: pirater/os
func (f *remoteFile) FetchUserdata() ([]byte, error) {
	client := pkg.NewHttpClient()
	return client.GetRetry(f.url)
}
Exemplo n.º 10
0
Arquivo: url.go Projeto: pirater/os
func (f *remoteFile) IsAvailable() bool {
	client := pkg.NewHttpClient()
	_, err := client.Get(f.url)
	return (err == nil)
}
Exemplo n.º 11
0
func (ms *metadataService) Fetch() ([]byte, error) {
	client := pkg.NewHttpClient()
	return client.Get(ms.url)
}