2014-05-22 13:48:26 -07:00
|
|
|
package datasource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
)
|
|
|
|
|
|
|
|
type configDrive struct {
|
2014-06-18 11:36:06 -07:00
|
|
|
root string
|
2014-05-22 13:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-06-18 11:36:06 -07:00
|
|
|
func NewConfigDrive(root string) *configDrive {
|
|
|
|
return &configDrive{path.Join(root, "openstack")}
|
|
|
|
}
|
|
|
|
|
2014-06-26 15:17:53 -07:00
|
|
|
func (cd *configDrive) IsAvailable() bool {
|
|
|
|
_, err := os.Stat(cd.root)
|
|
|
|
return !os.IsNotExist(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cd *configDrive) AvailabilityChanges() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-06-20 21:11:57 -07:00
|
|
|
func (cd *configDrive) ConfigRoot() string {
|
|
|
|
return cd.root
|
2014-05-22 13:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:11:57 -07:00
|
|
|
func (cd *configDrive) FetchMetadata() ([]byte, error) {
|
|
|
|
return cd.readFile("meta_data.json")
|
2014-06-18 11:58:18 -07:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:11:57 -07:00
|
|
|
func (cd *configDrive) FetchUserdata() ([]byte, error) {
|
|
|
|
return cd.readFile("user_data")
|
2014-05-22 13:48:26 -07:00
|
|
|
}
|
|
|
|
|
2014-06-20 21:11:57 -07:00
|
|
|
func (cd *configDrive) Type() string {
|
2014-05-22 13:48:26 -07:00
|
|
|
return "cloud-drive"
|
|
|
|
}
|
2014-06-18 11:36:06 -07:00
|
|
|
|
2014-06-20 21:11:57 -07:00
|
|
|
func (cd *configDrive) readFile(filename string) ([]byte, error) {
|
|
|
|
data, err := ioutil.ReadFile(path.Join(cd.root, "latest", filename))
|
2014-06-18 11:36:06 -07:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return data, err
|
|
|
|
}
|