diff --git a/coreos-cloudinit.go b/coreos-cloudinit.go index fefc3dc..963cb0a 100644 --- a/coreos-cloudinit.go +++ b/coreos-cloudinit.go @@ -188,7 +188,6 @@ func main() { var ccu *config.CloudConfig var script *config.Script - if ud, err := initialize.ParseUserData(userdata); err != nil { fmt.Printf("Failed to parse user-data: %v\nContinuing...\n", err) failure = true @@ -204,16 +203,6 @@ func main() { fmt.Println("Merging cloud-config from meta-data and user-data") cc := mergeConfigs(ccu, metadata) - if flags.convertNetconf != "" { - fmt.Printf("Fetching network config from datasource of type %q\n", ds.Type()) - netconfBytes, err := ds.FetchNetworkConfig(metadata.NetworkConfigPath) - if err != nil { - fmt.Printf("Failed fetching network config from datasource: %v\n", err) - os.Exit(1) - } - cc.Internal.NetworkConfig = netconfBytes - } - if err = initialize.Apply(cc, env); err != nil { fmt.Printf("Failed to apply cloud-config: %v\n", err) os.Exit(1) @@ -249,6 +238,7 @@ func mergeConfigs(cc *config.CloudConfig, md datasource.Metadata) (out config.Cl for _, key := range md.SSHPublicKeys { out.SSHAuthorizedKeys = append(out.SSHAuthorizedKeys, key) } + out.Internal.NetworkConfig = md.NetworkConfig return } diff --git a/datasource/configdrive/configdrive.go b/datasource/configdrive/configdrive.go index 4b5b2e7..3d9b459 100644 --- a/datasource/configdrive/configdrive.go +++ b/datasource/configdrive/configdrive.go @@ -69,7 +69,7 @@ func (cd *configDrive) FetchMetadata() (metadata datasource.Metadata, err error) metadata.SSHPublicKeys = m.SSHAuthorizedKeyMap metadata.Hostname = m.Hostname - metadata.NetworkConfigPath = m.NetworkConfig.ContentPath + metadata.NetworkConfig, err = cd.tryReadFile(path.Join(cd.openstackRoot(), m.NetworkConfig.ContentPath)) return } @@ -78,13 +78,6 @@ func (cd *configDrive) FetchUserdata() ([]byte, error) { return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "user_data")) } -func (cd *configDrive) FetchNetworkConfig(filename string) ([]byte, error) { - if filename == "" { - return []byte{}, nil - } - return cd.tryReadFile(path.Join(cd.openstackRoot(), filename)) -} - func (cd *configDrive) Type() string { return "cloud-drive" } diff --git a/datasource/configdrive/configdrive_test.go b/datasource/configdrive/configdrive_test.go index f53a5a4..0dd49a8 100644 --- a/datasource/configdrive/configdrive_test.go +++ b/datasource/configdrive/configdrive_test.go @@ -39,11 +39,14 @@ func TestFetchMetadata(t *testing.T) { metadata: datasource.Metadata{Hostname: "host"}, }, { - root: "/media/configdrive", - files: test.MockFilesystem{"/media/configdrive/openstack/latest/meta_data.json": `{"hostname": "host", "network_config": {"content_path": "path"}, "public_keys":{"1": "key1", "2": "key2"}}`}, + root: "/media/configdrive", + files: test.MockFilesystem{ + "/media/configdrive/openstack/latest/meta_data.json": `{"hostname": "host", "network_config": {"content_path": "config_file.json"}, "public_keys":{"1": "key1", "2": "key2"}}`, + "/media/configdrive/openstack/config_file.json": "make it work", + }, metadata: datasource.Metadata{ - Hostname: "host", - NetworkConfigPath: "path", + Hostname: "host", + NetworkConfig: []byte("make it work"), SSHPublicKeys: map[string]string{ "1": "key1", "2": "key2", diff --git a/datasource/datasource.go b/datasource/datasource.go index cf0f2f8..766f9a7 100644 --- a/datasource/datasource.go +++ b/datasource/datasource.go @@ -24,16 +24,15 @@ type Datasource interface { ConfigRoot() string FetchMetadata() (Metadata, error) FetchUserdata() ([]byte, error) - FetchNetworkConfig(string) ([]byte, error) Type() string } type Metadata struct { - PublicIPv4 net.IP - PublicIPv6 net.IP - PrivateIPv4 net.IP - PrivateIPv6 net.IP - Hostname string - SSHPublicKeys map[string]string - NetworkConfigPath string + PublicIPv4 net.IP + PublicIPv6 net.IP + PrivateIPv4 net.IP + PrivateIPv6 net.IP + Hostname string + SSHPublicKeys map[string]string + NetworkConfig []byte } diff --git a/datasource/file/file.go b/datasource/file/file.go index e4f2424..2700b46 100644 --- a/datasource/file/file.go +++ b/datasource/file/file.go @@ -50,10 +50,6 @@ 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" } diff --git a/datasource/metadata/cloudsigma/server_context.go b/datasource/metadata/cloudsigma/server_context.go index c3d58b8..b618e45 100644 --- a/datasource/metadata/cloudsigma/server_context.go +++ b/datasource/metadata/cloudsigma/server_context.go @@ -145,10 +145,6 @@ func (scs *serverContextService) FetchUserdata() ([]byte, error) { return []byte(userData), nil } -func (scs *serverContextService) FetchNetworkConfig(a string) ([]byte, error) { - return nil, nil -} - func (scs *serverContextService) findLocalIP(mac string) (net.IP, error) { ifaces, err := net.Interfaces() if err != nil { diff --git a/datasource/metadata/digitalocean/metadata.go b/datasource/metadata/digitalocean/metadata.go index 194cae0..a42796e 100644 --- a/datasource/metadata/digitalocean/metadata.go +++ b/datasource/metadata/digitalocean/metadata.go @@ -61,8 +61,6 @@ type Metadata struct { } type metadataService struct { - interfaces Interfaces - dns DNS metadata.MetadataService } @@ -81,9 +79,6 @@ func (ms *metadataService) FetchMetadata() (metadata datasource.Metadata, err er return } - ms.interfaces = m.Interfaces - ms.dns = m.DNS - if len(m.Interfaces.Public) > 0 { if m.Interfaces.Public[0].IPv4 != nil { metadata.PublicIPv4 = net.ParseIP(m.Interfaces.Public[0].IPv4.IPAddress) @@ -105,17 +100,11 @@ func (ms *metadataService) FetchMetadata() (metadata datasource.Metadata, err er for i, key := range m.PublicKeys { metadata.SSHPublicKeys[strconv.Itoa(i)] = key } + metadata.NetworkConfig = data return } -func (ms metadataService) FetchNetworkConfig(filename string) ([]byte, error) { - return json.Marshal(Metadata{ - Interfaces: ms.interfaces, - DNS: ms.dns, - }) -} - func (ms metadataService) Type() string { return "digitalocean-metadata-service" } diff --git a/datasource/metadata/digitalocean/metadata_test.go b/datasource/metadata/digitalocean/metadata_test.go index aa03b37..881a352 100644 --- a/datasource/metadata/digitalocean/metadata_test.go +++ b/datasource/metadata/digitalocean/metadata_test.go @@ -90,6 +90,34 @@ func TestFetchMetadata(t *testing.T) { "0": "publickey1", "1": "publickey2", }, + NetworkConfig: []byte(`{ + "droplet_id": 1, + "user_data": "hello", + "vendor_data": "hello", + "public_keys": [ + "publickey1", + "publickey2" + ], + "region": "nyc2", + "interfaces": { + "public": [ + { + "ipv4": { + "ip_address": "192.168.1.2", + "netmask": "255.255.255.0", + "gateway": "192.168.1.1" + }, + "ipv6": { + "ip_address": "fe00::", + "cidr": 126, + "gateway": "fe00::" + }, + "mac": "ab:cd:ef:gh:ij", + "type": "public" + } + ] + } +}`), }, }, { diff --git a/datasource/metadata/ec2/metadata.go b/datasource/metadata/ec2/metadata.go index ab1417f..35baa09 100644 --- a/datasource/metadata/ec2/metadata.go +++ b/datasource/metadata/ec2/metadata.go @@ -85,12 +85,6 @@ func (ms metadataService) FetchMetadata() (datasource.Metadata, error) { return metadata, err } - if contentPath, err := ms.fetchAttribute(fmt.Sprintf("%s/network_config/content_path", ms.MetadataUrl())); err == nil { - metadata.NetworkConfigPath = contentPath - } else if _, ok := err.(pkg.ErrNotFound); !ok { - return metadata, err - } - return metadata, nil } diff --git a/datasource/metadata/ec2/metadata_test.go b/datasource/metadata/ec2/metadata_test.go index f888175..ba463c2 100644 --- a/datasource/metadata/ec2/metadata_test.go +++ b/datasource/metadata/ec2/metadata_test.go @@ -162,40 +162,36 @@ func TestFetchMetadata(t *testing.T) { root: "/", metadataPath: "2009-04-04/meta-data", resources: map[string]string{ - "/2009-04-04/meta-data/hostname": "host", - "/2009-04-04/meta-data/local-ipv4": "1.2.3.4", - "/2009-04-04/meta-data/public-ipv4": "5.6.7.8", - "/2009-04-04/meta-data/public-keys": "0=test1\n", - "/2009-04-04/meta-data/public-keys/0": "openssh-key", - "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", - "/2009-04-04/meta-data/network_config/content_path": "path", + "/2009-04-04/meta-data/hostname": "host", + "/2009-04-04/meta-data/local-ipv4": "1.2.3.4", + "/2009-04-04/meta-data/public-ipv4": "5.6.7.8", + "/2009-04-04/meta-data/public-keys": "0=test1\n", + "/2009-04-04/meta-data/public-keys/0": "openssh-key", + "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", }, expect: datasource.Metadata{ - Hostname: "host", - PrivateIPv4: net.ParseIP("1.2.3.4"), - PublicIPv4: net.ParseIP("5.6.7.8"), - SSHPublicKeys: map[string]string{"test1": "key"}, - NetworkConfigPath: "path", + Hostname: "host", + PrivateIPv4: net.ParseIP("1.2.3.4"), + PublicIPv4: net.ParseIP("5.6.7.8"), + SSHPublicKeys: map[string]string{"test1": "key"}, }, }, { root: "/", metadataPath: "2009-04-04/meta-data", resources: map[string]string{ - "/2009-04-04/meta-data/hostname": "host domain another_domain", - "/2009-04-04/meta-data/local-ipv4": "1.2.3.4", - "/2009-04-04/meta-data/public-ipv4": "5.6.7.8", - "/2009-04-04/meta-data/public-keys": "0=test1\n", - "/2009-04-04/meta-data/public-keys/0": "openssh-key", - "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", - "/2009-04-04/meta-data/network_config/content_path": "path", + "/2009-04-04/meta-data/hostname": "host domain another_domain", + "/2009-04-04/meta-data/local-ipv4": "1.2.3.4", + "/2009-04-04/meta-data/public-ipv4": "5.6.7.8", + "/2009-04-04/meta-data/public-keys": "0=test1\n", + "/2009-04-04/meta-data/public-keys/0": "openssh-key", + "/2009-04-04/meta-data/public-keys/0/openssh-key": "key", }, expect: datasource.Metadata{ - Hostname: "host", - PrivateIPv4: net.ParseIP("1.2.3.4"), - PublicIPv4: net.ParseIP("5.6.7.8"), - SSHPublicKeys: map[string]string{"test1": "key"}, - NetworkConfigPath: "path", + Hostname: "host", + PrivateIPv4: net.ParseIP("1.2.3.4"), + PublicIPv4: net.ParseIP("5.6.7.8"), + SSHPublicKeys: map[string]string{"test1": "key"}, }, }, { diff --git a/datasource/metadata/metadata.go b/datasource/metadata/metadata.go index b29cb34..2baa4f1 100644 --- a/datasource/metadata/metadata.go +++ b/datasource/metadata/metadata.go @@ -52,10 +52,6 @@ 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 diff --git a/datasource/proc_cmdline/proc_cmdline.go b/datasource/proc_cmdline/proc_cmdline.go index 64e13aa..8423b25 100644 --- a/datasource/proc_cmdline/proc_cmdline.go +++ b/datasource/proc_cmdline/proc_cmdline.go @@ -81,10 +81,6 @@ 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" } diff --git a/datasource/url/url.go b/datasource/url/url.go index aa699bc..8a9c541 100644 --- a/datasource/url/url.go +++ b/datasource/url/url.go @@ -50,10 +50,6 @@ 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" } diff --git a/datasource/waagent/waagent.go b/datasource/waagent/waagent.go index fdc543b..d0460b9 100644 --- a/datasource/waagent/waagent.go +++ b/datasource/waagent/waagent.go @@ -103,10 +103,6 @@ func (a *waagent) FetchUserdata() ([]byte, error) { return a.tryReadFile(path.Join(a.root, "CustomData")) } -func (a *waagent) FetchNetworkConfig(filename string) ([]byte, error) { - return nil, nil -} - func (a *waagent) Type() string { return "waagent" }