refactor(env): Add the config root and netconf type to datasource and env

This commit is contained in:
Alex Crawford
2014-06-18 11:36:06 -07:00
parent 259c7e1fe2
commit 29ed6b38bd
8 changed files with 44 additions and 13 deletions

View File

@@ -7,21 +7,29 @@ import (
)
type configDrive struct {
path string
root string
}
func NewConfigDrive(path string) *configDrive {
return &configDrive{path}
func NewConfigDrive(root string) *configDrive {
return &configDrive{path.Join(root, "openstack")}
}
func (self *configDrive) ConfigRoot() string {
return self.root
}
func (self *configDrive) Fetch() ([]byte, error) {
data, err := ioutil.ReadFile(path.Join(self.path, "openstack", "latest", "user_data"))
if os.IsNotExist(err) {
err = nil
}
return data, err
return self.readFile("user_data")
}
func (self *configDrive) Type() string {
return "cloud-drive"
}
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
}

View File

@@ -1,6 +1,7 @@
package datasource
type Datasource interface {
ConfigRoot() string
Fetch() ([]byte, error)
Type() string
}

View File

@@ -12,6 +12,10 @@ func NewLocalFile(path string) *localFile {
return &localFile{path}
}
func (self *localFile) ConfigRoot() string {
return ""
}
func (self *localFile) Fetch() ([]byte, error) {
return ioutil.ReadFile(self.path)
}

View File

@@ -10,6 +10,10 @@ func NewMetadataService(url string) *metadataService {
return &metadataService{url}
}
func (self *metadataService) ConfigRoot() string {
return ""
}
func (ms *metadataService) Fetch() ([]byte, error) {
client := pkg.NewHttpClient()
return client.Get(ms.url)

View File

@@ -14,7 +14,7 @@ const (
ProcCmdlineCloudConfigFlag = "cloud-config-url"
)
type procCmdline struct{
type procCmdline struct {
Location string
}
@@ -22,6 +22,10 @@ func NewProcCmdline() *procCmdline {
return &procCmdline{Location: ProcCmdlineLocation}
}
func (self *procCmdline) ConfigRoot() string {
return ""
}
func (self *procCmdline) Fetch() ([]byte, error) {
contents, err := ioutil.ReadFile(self.Location)
if err != nil {