refactor(env): Add the config root and netconf type to datasource and env
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package datasource
|
||||
|
||||
type Datasource interface {
|
||||
ConfigRoot() string
|
||||
Fetch() ([]byte, error)
|
||||
Type() string
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
|
@@ -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)
|
||||
|
@@ -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 {
|
||||
|
Reference in New Issue
Block a user