Commit 6b16f80d authored by Federico Simoncelli's avatar Federico Simoncelli

aws: report the nodes external id

parent 1fc56aa0
...@@ -122,6 +122,28 @@ func (aws *AWSCloud) Zones() (cloudprovider.Zones, bool) { ...@@ -122,6 +122,28 @@ func (aws *AWSCloud) Zones() (cloudprovider.Zones, bool) {
// IPAddress is an implementation of Instances.IPAddress. // IPAddress is an implementation of Instances.IPAddress.
func (aws *AWSCloud) IPAddress(name string) (net.IP, error) { func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
inst, err := aws.getInstancesByDnsName(name)
if err != nil {
return nil, err
}
ip := net.ParseIP(inst.PrivateIpAddress)
if ip == nil {
return nil, fmt.Errorf("invalid network IP: %s", inst.PrivateIpAddress)
}
return ip, nil
}
// ExternalID returns the cloud provider ID of the specified instance.
func (aws *AWSCloud) ExternalID(name string) (string, error) {
inst, err := aws.getInstancesByDnsName(name)
if err != nil {
return "", err
}
return inst.InstanceId, nil
}
// Return the instances matching the relevant private dns name.
func (aws *AWSCloud) getInstancesByDnsName(name string) (*ec2.Instance, error) {
f := ec2.NewFilter() f := ec2.NewFilter()
f.Add("private-dns-name", name) f.Add("private-dns-name", name)
...@@ -142,17 +164,7 @@ func (aws *AWSCloud) IPAddress(name string) (net.IP, error) { ...@@ -142,17 +164,7 @@ func (aws *AWSCloud) IPAddress(name string) (net.IP, error) {
return nil, fmt.Errorf("multiple instances found for host: %s", name) return nil, fmt.Errorf("multiple instances found for host: %s", name)
} }
ipAddress := resp.Reservations[0].Instances[0].PrivateIpAddress return &resp.Reservations[0].Instances[0], nil
ip := net.ParseIP(ipAddress)
if ip == nil {
return nil, fmt.Errorf("invalid network IP: %s", ipAddress)
}
return ip, nil
}
// ExternalID returns the cloud provider ID of the specified instance.
func (aws *AWSCloud) ExternalID(name string) (string, error) {
return "", fmt.Errorf("unimplemented")
} }
// Return a list of instances matching regex string. // Return a list of instances matching regex string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment