config: remove network config from CloudConfig

This commit is contained in:
Alex Crawford
2015-01-26 17:35:08 -08:00
parent 9605b5edf2
commit 536f8acf2a
5 changed files with 35 additions and 42 deletions

View File

@@ -42,7 +42,7 @@ type CloudConfigUnit interface {
// Apply renders a CloudConfig to an Environment. This can involve things like
// configuring the hostname, adding new users, writing various configuration
// files to disk, and manipulating systemd services.
func Apply(cfg config.CloudConfig, env *Environment) error {
func Apply(cfg config.CloudConfig, ifaces []network.InterfaceGenerator, env *Environment) error {
if cfg.Hostname != "" {
if err := system.SetHostname(cfg.Hostname); err != nil {
return err
@@ -165,23 +165,9 @@ func Apply(cfg config.CloudConfig, env *Environment) error {
}
}
if env.NetconfType() != "" {
var interfaces []network.InterfaceGenerator
var err error
switch env.NetconfType() {
case "debian":
interfaces, err = network.ProcessDebianNetconf(cfg.Internal.NetworkConfig)
case "digitalocean":
interfaces, err = network.ProcessDigitalOceanNetconf(cfg.Internal.NetworkConfig)
default:
err = fmt.Errorf("Unsupported network config format %q", env.NetconfType())
}
if err != nil {
return err
}
units = append(units, createNetworkingUnits(interfaces)...)
if err := system.RestartNetwork(interfaces); err != nil {
if len(ifaces) > 0 {
units = append(units, createNetworkingUnits(ifaces)...)
if err := system.RestartNetwork(ifaces); err != nil {
return err
}
}

View File

@@ -32,13 +32,12 @@ type Environment struct {
root string
configRoot string
workspace string
netconfType string
sshKeyName string
substitutions map[string]string
}
// TODO(jonboulle): this is getting unwieldy, should be able to simplify the interface somehow
func NewEnvironment(root, configRoot, workspace, netconfType, sshKeyName string, metadata datasource.Metadata) *Environment {
func NewEnvironment(root, configRoot, workspace, sshKeyName string, metadata datasource.Metadata) *Environment {
firstNonNull := func(ip net.IP, env string) string {
if ip == nil {
return env
@@ -51,7 +50,7 @@ func NewEnvironment(root, configRoot, workspace, netconfType, sshKeyName string,
"$public_ipv6": firstNonNull(metadata.PublicIPv6, os.Getenv("COREOS_PUBLIC_IPV6")),
"$private_ipv6": firstNonNull(metadata.PrivateIPv6, os.Getenv("COREOS_PRIVATE_IPV6")),
}
return &Environment{root, configRoot, workspace, netconfType, sshKeyName, substitutions}
return &Environment{root, configRoot, workspace, sshKeyName, substitutions}
}
func (e *Environment) Workspace() string {
@@ -66,10 +65,6 @@ func (e *Environment) ConfigRoot() string {
return e.configRoot
}
func (e *Environment) NetconfType() string {
return e.netconfType
}
func (e *Environment) SSHKeyName() string {
return e.sshKeyName
}

View File

@@ -95,7 +95,7 @@ addr: $private_ipv4
},
} {
env := NewEnvironment("./", "./", "./", "", "", tt.metadata)
env := NewEnvironment("./", "./", "./", "", tt.metadata)
got := env.Apply(tt.input)
if got != tt.out {
t.Fatalf("Environment incorrectly applied.\ngot:\n%s\nwant:\n%s", got, tt.out)
@@ -118,7 +118,7 @@ func TestEnvironmentFile(t *testing.T) {
}
defer os.RemoveAll(dir)
env := NewEnvironment("./", "./", "./", "", "", metadata)
env := NewEnvironment("./", "./", "./", "", metadata)
ef := env.DefaultEnvironmentFile()
err = system.WriteEnvFile(ef, dir)
if err != nil {
@@ -140,7 +140,7 @@ func TestEnvironmentFileNil(t *testing.T) {
os.Clearenv()
metadata := datasource.Metadata{}
env := NewEnvironment("./", "./", "./", "", "", metadata)
env := NewEnvironment("./", "./", "./", "", metadata)
ef := env.DefaultEnvironmentFile()
if ef != nil {
t.Fatalf("Environment file not nil: %v", ef)