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