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")}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *configDrive) ConfigRoot() string {
|
|
|
|
return self.root
|
2014-05-23 00:48:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *configDrive) Fetch() ([]byte, error) {
|
2014-06-18 22:36:06 +04:00
|
|
|
return self.readFile("user_data")
|
2014-05-23 00:48:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self *configDrive) Type() string {
|
|
|
|
return "cloud-drive"
|
|
|
|
}
|
2014-06-18 22:36:06 +04:00
|
|
|
|
|
|
|
func (self *configDrive) readFile(filename string) ([]byte, error) {
|
|
|
|
data, err := ioutil.ReadFile(path.Join(self.root, "latest", filename))
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
return data, err
|
|
|
|
}
|