mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #2014 from kencochrane/more_aws_meta
Enhanced the AWS provider in the metadata package, to include more data.
This commit is contained in:
commit
a60de348ab
@ -47,6 +47,25 @@ func (p *ProviderAWS) Extract() ([]byte, error) {
|
||||
return nil, fmt.Errorf("AWS: Failed to write hostname: %s", err)
|
||||
}
|
||||
|
||||
// public ipv4
|
||||
awsMetaGet("public-ipv4", "public_ipv4", 0644)
|
||||
|
||||
// private ipv4
|
||||
awsMetaGet("local-ipv4", "local_ipv4", 0644)
|
||||
|
||||
// availability zone
|
||||
awsMetaGet("placement/availability-zone", "availability_zone", 0644)
|
||||
|
||||
// instance type
|
||||
awsMetaGet("instance-type", "instance_type", 0644)
|
||||
|
||||
// instance-id
|
||||
awsMetaGet("instance-id", "instance_id", 0644)
|
||||
|
||||
// local-hostname
|
||||
awsMetaGet("local-hostname", "local_hostname", 0644)
|
||||
|
||||
// ssh
|
||||
if err := p.handleSSH(); err != nil {
|
||||
log.Printf("AWS: Failed to get ssh data: %s", err)
|
||||
}
|
||||
@ -61,6 +80,21 @@ func (p *ProviderAWS) Extract() ([]byte, error) {
|
||||
return userData, nil
|
||||
}
|
||||
|
||||
// lookup a value (lookupName) in aws metaservice and store in given fileName
|
||||
func awsMetaGet(lookupName string, fileName string, fileMode os.FileMode) {
|
||||
if lookupValue, err := awsGet(metaDataURL + lookupName); err == nil {
|
||||
// we got a value from the metadata server, now save to filesystem
|
||||
err = ioutil.WriteFile(path.Join(ConfigPath, fileName), lookupValue, fileMode)
|
||||
if err != nil {
|
||||
// we couldn't save the file for some reason
|
||||
log.Printf("AWS: Failed to write %s:%s %s", fileName, lookupValue, err)
|
||||
}
|
||||
} else {
|
||||
// we did not get a value back from the metadata server
|
||||
log.Printf("AWS: Failed to get %s: %s", lookupName, err)
|
||||
}
|
||||
}
|
||||
|
||||
// awsGet requests and extracts the requested URL
|
||||
func awsGet(url string) ([]byte, error) {
|
||||
var client = &http.Client{
|
||||
|
Loading…
Reference in New Issue
Block a user