feat(config-drive): Add support for reading user-data from config-drive

The -config-drive flag tells cloudinit to read the user-data from
within the config-drive (./openstack/latest/user-data).
This commit is contained in:
Alex Crawford 2014-05-22 13:48:26 -07:00
parent db3f008543
commit a4035cffea
2 changed files with 33 additions and 1 deletions

View File

@ -28,6 +28,9 @@ func main() {
var file string var file string
flag.StringVar(&file, "from-file", "", "Read user-data from provided file") flag.StringVar(&file, "from-file", "", "Read user-data from provided file")
var configdrive string
flag.StringVar(&configdrive, "from-configdrive", "", "Read user-data from provided cloud-drive directory")
var url string var url string
flag.StringVar(&url, "from-url", "", "Download user-data from provided url") flag.StringVar(&url, "from-url", "", "Download user-data from provided url")
@ -52,10 +55,12 @@ func main() {
ds = datasource.NewLocalFile(file) ds = datasource.NewLocalFile(file)
} else if url != "" { } else if url != "" {
ds = datasource.NewMetadataService(url) ds = datasource.NewMetadataService(url)
} else if configdrive != "" {
ds = datasource.NewConfigDrive(configdrive)
} else if useProcCmdline { } else if useProcCmdline {
ds = datasource.NewProcCmdline() ds = datasource.NewProcCmdline()
} else { } else {
fmt.Println("Provide one of --from-file, --from-url or --from-proc-cmdline") fmt.Println("Provide one of --from-file, --from-configdrive, --from-url or --from-proc-cmdline")
os.Exit(1) os.Exit(1)
} }

27
datasource/configdrive.go Normal file
View File

@ -0,0 +1,27 @@
package datasource
import (
"io/ioutil"
"os"
"path"
)
type configDrive struct {
path string
}
func NewConfigDrive(path string) *configDrive {
return &configDrive{path}
}
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
}
func (self *configDrive) Type() string {
return "cloud-drive"
}