metadata: Merge the network config

This commit is contained in:
Alex Crawford 2014-08-29 16:18:16 -04:00
parent e9ec78ac6f
commit abe43537da
2 changed files with 17 additions and 0 deletions

View File

@ -209,6 +209,13 @@ func mergeCloudConfig(mdcc, udcc initialize.CloudConfig) (cc initialize.CloudCon
udcc.NetworkConfigPath = mdcc.NetworkConfigPath udcc.NetworkConfigPath = mdcc.NetworkConfigPath
} }
} }
if mdcc.NetworkConfig != "" {
if udcc.NetworkConfig != "" {
fmt.Printf("Warning: user-data NetworkConfig %s overrides metadata NetworkConfig %s\n", udcc.NetworkConfig, mdcc.NetworkConfig)
} else {
udcc.NetworkConfig = mdcc.NetworkConfig
}
}
return udcc return udcc
} }

View File

@ -12,6 +12,7 @@ func TestMergeCloudConfig(t *testing.T) {
SSHAuthorizedKeys: []string{"abc", "def"}, SSHAuthorizedKeys: []string{"abc", "def"},
Hostname: "foobar", Hostname: "foobar",
NetworkConfigPath: "/path/somewhere", NetworkConfigPath: "/path/somewhere",
NetworkConfig: `{}`,
} }
for i, tt := range []struct { for i, tt := range []struct {
udcc initialize.CloudConfig udcc initialize.CloudConfig
@ -36,6 +37,7 @@ func TestMergeCloudConfig(t *testing.T) {
initialize.CloudConfig{ initialize.CloudConfig{
Hostname: "meta-hostname", Hostname: "meta-hostname",
NetworkConfigPath: "/path/meta", NetworkConfigPath: "/path/meta",
NetworkConfig: `{"hostname":"test"}`,
}, },
simplecc, simplecc,
}, },
@ -45,6 +47,7 @@ func TestMergeCloudConfig(t *testing.T) {
SSHAuthorizedKeys: []string{"abc", "def"}, SSHAuthorizedKeys: []string{"abc", "def"},
Hostname: "user-hostname", Hostname: "user-hostname",
NetworkConfigPath: "/path/somewhere", NetworkConfigPath: "/path/somewhere",
NetworkConfig: `{"hostname":"test"}`,
}, },
initialize.CloudConfig{ initialize.CloudConfig{
SSHAuthorizedKeys: []string{"woof", "qux"}, SSHAuthorizedKeys: []string{"woof", "qux"},
@ -54,6 +57,7 @@ func TestMergeCloudConfig(t *testing.T) {
SSHAuthorizedKeys: []string{"abc", "def", "woof", "qux"}, SSHAuthorizedKeys: []string{"abc", "def", "woof", "qux"},
Hostname: "user-hostname", Hostname: "user-hostname",
NetworkConfigPath: "/path/somewhere", NetworkConfigPath: "/path/somewhere",
NetworkConfig: `{"hostname":"test"}`,
}, },
}, },
{ {
@ -64,11 +68,13 @@ func TestMergeCloudConfig(t *testing.T) {
initialize.CloudConfig{ initialize.CloudConfig{
SSHAuthorizedKeys: []string{"zaphod", "beeblebrox"}, SSHAuthorizedKeys: []string{"zaphod", "beeblebrox"},
NetworkConfigPath: "/dev/fun", NetworkConfigPath: "/dev/fun",
NetworkConfig: `{"hostname":"test"}`,
}, },
initialize.CloudConfig{ initialize.CloudConfig{
Hostname: "supercool", Hostname: "supercool",
SSHAuthorizedKeys: []string{"zaphod", "beeblebrox"}, SSHAuthorizedKeys: []string{"zaphod", "beeblebrox"},
NetworkConfigPath: "/dev/fun", NetworkConfigPath: "/dev/fun",
NetworkConfig: `{"hostname":"test"}`,
}, },
}, },
{ {
@ -80,11 +86,13 @@ func TestMergeCloudConfig(t *testing.T) {
initialize.CloudConfig{ initialize.CloudConfig{
Hostname: "youyouyou", Hostname: "youyouyou",
NetworkConfigPath: "meta-meta-yo", NetworkConfigPath: "meta-meta-yo",
NetworkConfig: `{"hostname":"test"}`,
}, },
initialize.CloudConfig{ initialize.CloudConfig{
Hostname: "mememe", Hostname: "mememe",
ManageEtcHosts: initialize.EtcHosts("lolz"), ManageEtcHosts: initialize.EtcHosts("lolz"),
NetworkConfigPath: "meta-meta-yo", NetworkConfigPath: "meta-meta-yo",
NetworkConfig: `{"hostname":"test"}`,
}, },
}, },
{ {
@ -95,10 +103,12 @@ func TestMergeCloudConfig(t *testing.T) {
initialize.CloudConfig{ initialize.CloudConfig{
ManageEtcHosts: initialize.EtcHosts("lolz"), ManageEtcHosts: initialize.EtcHosts("lolz"),
NetworkConfigPath: "meta-meta-yo", NetworkConfigPath: "meta-meta-yo",
NetworkConfig: `{"hostname":"test"}`,
}, },
initialize.CloudConfig{ initialize.CloudConfig{
Hostname: "mememe", Hostname: "mememe",
NetworkConfigPath: "meta-meta-yo", NetworkConfigPath: "meta-meta-yo",
NetworkConfig: `{"hostname":"test"}`,
}, },
}, },
} { } {