configdrive: Remove broken support for ec2 metadata
As it turns out, certain metadata is only present in the ec2 flavor of metadata (e.g. public_ipv4) and other data is only present in the openstack flavor (e.g. network_config). For now, just read the openstack metadata.
This commit is contained in:
parent
24b44e86a6
commit
f0b9eaf2fe
@ -1,13 +1,13 @@
|
|||||||
package configdrive
|
package configdrive
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ec2ApiVersion = "2009-04-04"
|
|
||||||
openstackApiVersion = "latest"
|
openstackApiVersion = "latest"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -33,34 +33,28 @@ func (cd *configDrive) ConfigRoot() string {
|
|||||||
return cd.openstackRoot()
|
return cd.openstackRoot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchMetadata attempts to retrieve metadata from ec2/2009-04-04/meta-data.json.
|
|
||||||
func (cd *configDrive) FetchMetadata() ([]byte, error) {
|
func (cd *configDrive) FetchMetadata() ([]byte, error) {
|
||||||
return cd.tryReadFile(path.Join(cd.ec2Root(), "meta-data.json"))
|
return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "meta_data.json"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchUserdata attempts to retrieve the userdata from ec2/2009-04-04/user-data.
|
|
||||||
// If no data is found, it will attempt to read from openstack/latest/user_data.
|
|
||||||
func (cd *configDrive) FetchUserdata() ([]byte, error) {
|
func (cd *configDrive) FetchUserdata() ([]byte, error) {
|
||||||
bytes, err := cd.tryReadFile(path.Join(cd.ec2Root(), "user-data"))
|
return cd.tryReadFile(path.Join(cd.openstackVersionRoot(), "user_data"))
|
||||||
if bytes == nil && err == nil {
|
|
||||||
bytes, err = cd.tryReadFile(path.Join(cd.openstackRoot(), "user_data"))
|
|
||||||
}
|
|
||||||
return bytes, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cd *configDrive) Type() string {
|
func (cd *configDrive) Type() string {
|
||||||
return "cloud-drive"
|
return "cloud-drive"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cd *configDrive) ec2Root() string {
|
func (cd *configDrive) openstackRoot() string {
|
||||||
return path.Join(cd.root, "ec2", ec2ApiVersion)
|
return path.Join(cd.root, "openstack")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cd *configDrive) openstackRoot() string {
|
func (cd *configDrive) openstackVersionRoot() string {
|
||||||
return path.Join(cd.root, "openstack", openstackApiVersion)
|
return path.Join(cd.openstackRoot(), openstackApiVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cd *configDrive) tryReadFile(filename string) ([]byte, error) {
|
func (cd *configDrive) tryReadFile(filename string) ([]byte, error) {
|
||||||
|
fmt.Printf("Attempting to read from %q\n", filename)
|
||||||
data, err := cd.readFile(filename)
|
data, err := cd.readFile(filename)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -16,7 +16,7 @@ func (m mockFilesystem) readFile(filename string) ([]byte, error) {
|
|||||||
return nil, os.ErrNotExist
|
return nil, os.ErrNotExist
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCDFetchMetadata(t *testing.T) {
|
func TestFetchMetadata(t *testing.T) {
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
root string
|
root string
|
||||||
filename string
|
filename string
|
||||||
@ -29,13 +29,13 @@ func TestCDFetchMetadata(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"/",
|
"/",
|
||||||
"/ec2/2009-04-04/meta-data.json",
|
"/openstack/latest/meta_data.json",
|
||||||
mockFilesystem([]string{"/ec2/2009-04-04/meta-data.json"}),
|
mockFilesystem([]string{"/openstack/latest/meta_data.json"}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"/media/configdrive",
|
"/media/configdrive",
|
||||||
"/media/configdrive/ec2/2009-04-04/meta-data.json",
|
"/media/configdrive/openstack/latest/meta_data.json",
|
||||||
mockFilesystem([]string{"/media/configdrive/ec2/2009-04-04/meta-data.json"}),
|
mockFilesystem([]string{"/media/configdrive/openstack/latest/meta_data.json"}),
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
cd := configDrive{tt.root, tt.files.readFile}
|
cd := configDrive{tt.root, tt.files.readFile}
|
||||||
@ -49,7 +49,7 @@ func TestCDFetchMetadata(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCDFetchUserdata(t *testing.T) {
|
func TestFetchUserdata(t *testing.T) {
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
root string
|
root string
|
||||||
filename string
|
filename string
|
||||||
@ -60,25 +60,15 @@ func TestCDFetchUserdata(t *testing.T) {
|
|||||||
"",
|
"",
|
||||||
mockFilesystem{},
|
mockFilesystem{},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"/",
|
|
||||||
"/ec2/2009-04-04/user-data",
|
|
||||||
mockFilesystem([]string{"/ec2/2009-04-04/user-data"}),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"/",
|
"/",
|
||||||
"/openstack/latest/user_data",
|
"/openstack/latest/user_data",
|
||||||
mockFilesystem([]string{"/openstack/latest/user_data"}),
|
mockFilesystem([]string{"/openstack/latest/user_data"}),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"/",
|
|
||||||
"/ec2/2009-04-04/user-data",
|
|
||||||
mockFilesystem([]string{"/openstack/latest/user_data", "/ec2/2009-04-04/user-data"}),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"/media/configdrive",
|
"/media/configdrive",
|
||||||
"/media/configdrive/ec2/2009-04-04/user-data",
|
"/media/configdrive/openstack/latest/user_data",
|
||||||
mockFilesystem([]string{"/media/configdrive/ec2/2009-04-04/user-data"}),
|
mockFilesystem([]string{"/media/configdrive/openstack/latest/user_data"}),
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
cd := configDrive{tt.root, tt.files.readFile}
|
cd := configDrive{tt.root, tt.files.readFile}
|
||||||
@ -92,18 +82,18 @@ func TestCDFetchUserdata(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCDConfigRoot(t *testing.T) {
|
func TestConfigRoot(t *testing.T) {
|
||||||
for _, tt := range []struct {
|
for _, tt := range []struct {
|
||||||
root string
|
root string
|
||||||
configRoot string
|
configRoot string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"/",
|
"/",
|
||||||
"/openstack/latest",
|
"/openstack",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"/media/configdrive",
|
"/media/configdrive",
|
||||||
"/media/configdrive/openstack/latest",
|
"/media/configdrive/openstack",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
cd := configDrive{tt.root, nil}
|
cd := configDrive{tt.root, nil}
|
||||||
|
@ -258,7 +258,9 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if env.NetconfType() != "" {
|
if env.NetconfType() != "" {
|
||||||
netconfBytes, err := ioutil.ReadFile(path.Join(env.ConfigRoot(), cfg.NetworkConfigPath))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user