datasource: Add FetchNetworkConfig
FetchNetworkConfig is currently only used by ConfigDrive to read the network config file from the disk.
This commit is contained in:
parent
c39dd5cc67
commit
604ef7ecb4
@ -132,6 +132,17 @@ func main() {
|
||||
fmt.Printf("Failed to parse meta-data: %v\n", err)
|
||||
die()
|
||||
}
|
||||
|
||||
if ccm != nil {
|
||||
fmt.Printf("Fetching network config from datasource of type %q\n", ds.Type())
|
||||
netconfBytes, err := ds.FetchNetworkConfig(ccm.NetworkConfigPath)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed fetching network config from datasource: %v\n", err)
|
||||
die()
|
||||
}
|
||||
ccm.NetworkConfig = string(netconfBytes)
|
||||
}
|
||||
|
||||
if ud, err := initialize.ParseUserData(userdata); err != nil {
|
||||
fmt.Printf("Failed to parse user-data: %v\n", err)
|
||||
die()
|
||||
|
@ -41,6 +41,10 @@ func (cd *configDrive) FetchUserdata() ([]byte, error) {
|
||||
return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "user_data"))
|
||||
}
|
||||
|
||||
func (cd *configDrive) FetchNetworkConfig(filename string) ([]byte, error) {
|
||||
return cd.tryReadFile(path.Join(cd.openstackRoot(), filename))
|
||||
}
|
||||
|
||||
func (cd *configDrive) Type() string {
|
||||
return "cloud-drive"
|
||||
}
|
||||
|
@ -6,5 +6,6 @@ type Datasource interface {
|
||||
ConfigRoot() string
|
||||
FetchMetadata() ([]byte, error)
|
||||
FetchUserdata() ([]byte, error)
|
||||
FetchNetworkConfig(string) ([]byte, error)
|
||||
Type() string
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ func (f *localFile) FetchUserdata() ([]byte, error) {
|
||||
return ioutil.ReadFile(f.path)
|
||||
}
|
||||
|
||||
func (f *localFile) FetchNetworkConfig(filename string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *localFile) Type() string {
|
||||
return "local-file"
|
||||
}
|
||||
|
@ -126,6 +126,10 @@ func (scs *serverContextService) FetchUserdata() ([]byte, error) {
|
||||
return []byte(userData), nil
|
||||
}
|
||||
|
||||
func (scs *serverContextService) FetchNetworkConfig(a string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func isBase64Encoded(field string, userdata map[string]string) bool {
|
||||
base64Fields, ok := userdata["base64_fields"]
|
||||
if !ok {
|
||||
|
@ -38,6 +38,10 @@ func (ms MetadataService) FetchUserdata() ([]byte, error) {
|
||||
return ms.FetchData(ms.UserdataUrl())
|
||||
}
|
||||
|
||||
func (ms MetadataService) FetchNetworkConfig(filename string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (ms MetadataService) FetchData(url string) ([]byte, error) {
|
||||
if data, err := ms.Client.GetRetry(url); err == nil {
|
||||
return data, err
|
||||
|
@ -66,6 +66,10 @@ func (c *procCmdline) FetchUserdata() ([]byte, error) {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func (c *procCmdline) FetchNetworkConfig(filename string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *procCmdline) Type() string {
|
||||
return "proc-cmdline"
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package url
|
||||
|
||||
import "github.com/coreos/coreos-cloudinit/pkg"
|
||||
import (
|
||||
"github.com/coreos/coreos-cloudinit/pkg"
|
||||
)
|
||||
|
||||
type remoteFile struct {
|
||||
url string
|
||||
@ -33,6 +35,10 @@ func (f *remoteFile) FetchUserdata() ([]byte, error) {
|
||||
return client.GetRetry(f.url)
|
||||
}
|
||||
|
||||
func (f *remoteFile) FetchNetworkConfig(filename string) ([]byte, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *remoteFile) Type() string {
|
||||
return "url"
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package initialize
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"path"
|
||||
|
||||
@ -42,6 +41,7 @@ type CloudConfig struct {
|
||||
Users []system.User
|
||||
ManageEtcHosts EtcHosts `yaml:"manage_etc_hosts"`
|
||||
NetworkConfigPath string
|
||||
NetworkConfig string
|
||||
}
|
||||
|
||||
type warner func(format string, v ...interface{})
|
||||
@ -258,17 +258,11 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
||||
}
|
||||
|
||||
if env.NetconfType() != "" {
|
||||
filename := path.Join(env.ConfigRoot(), cfg.NetworkConfigPath)
|
||||
log.Printf("Attempting to read config from %q\n", filename)
|
||||
netconfBytes, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var interfaces []network.InterfaceGenerator
|
||||
var err error
|
||||
switch env.NetconfType() {
|
||||
case "debian":
|
||||
interfaces, err = network.ProcessDebianNetconf(string(netconfBytes))
|
||||
interfaces, err = network.ProcessDebianNetconf(cfg.NetworkConfig)
|
||||
default:
|
||||
return fmt.Errorf("Unsupported network config format %q", env.NetconfType())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user