361edeebc6
Move the old metadata-service datasource to url datasource. This new datasource checks for the existance of meta-data.json and if it doesn't exist, walks the meta-data directory to build a metadata blob.
40 lines
719 B
Go
40 lines
719 B
Go
package datasource
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"path"
|
|
)
|
|
|
|
type configDrive struct {
|
|
root string
|
|
}
|
|
|
|
func NewConfigDrive(root string) *configDrive {
|
|
return &configDrive{path.Join(root, "openstack")}
|
|
}
|
|
|
|
func (cd *configDrive) ConfigRoot() string {
|
|
return cd.root
|
|
}
|
|
|
|
func (cd *configDrive) FetchMetadata() ([]byte, error) {
|
|
return cd.readFile("meta_data.json")
|
|
}
|
|
|
|
func (cd *configDrive) FetchUserdata() ([]byte, error) {
|
|
return cd.readFile("user_data")
|
|
}
|
|
|
|
func (cd *configDrive) Type() string {
|
|
return "cloud-drive"
|
|
}
|
|
|
|
func (cd *configDrive) readFile(filename string) ([]byte, error) {
|
|
data, err := ioutil.ReadFile(path.Join(cd.root, "latest", filename))
|
|
if os.IsNotExist(err) {
|
|
err = nil
|
|
}
|
|
return data, err
|
|
}
|