// IPAddress returns the address of a particular machine instance.
IPAddress returns the address of a particular machine instance.
// IPAddress returns the address of a particular machine instance .
func (r *RightScaleCloud) IPAddress(instance string) (net.IP, error) {
	resp, err := r.sendRequest("/api/servers?filter[]=name%3d%3d" + instance + "?view=instance_detail")
	if err != nil {
		return net.IP{}, nil
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return net.IP{}, err
	}
	var servers []map[string]interface{}
	err = json.Unmarshal(body, &servers)
	if err != nil {
		return net.IP{}, err
	}
	if len(servers) == 0 {
		return nil, fmt.Errorf("Could not retrieve server with name %s", instance)
	}
	if len(servers) > 1 {
		return nil, fmt.Errorf("More than one server with name %s", instance)
	}
	current := servers[0]["current_instance"]
	if current == nil {
		return nil, fmt.Errorf("Failed to retrieve current instance of %s", instance)
	}
	cur := current.(map[string]interface{})
	ipAddresses := cur["private_ip_addresses"].([]string)
	if current == nil {
		return nil, fmt.Errorf("Failed to retrieve private IPs of %s", instance)
	}
	ip := net.ParseIP(ipAddresses[0])
	if ip == nil {
		return nil, fmt.Errorf("Invalid network IP: %s", ipAddresses[0])
	}
	return ip, nil
}
func ( r * RightScaleCloud ) IPAddress ( instance string ) ( net . IP , error ) { resp , err := r . sendRequest ( " " + instance + " " ) if err != nil { return net . IP { } , nil } defer resp . Body . Close ( ) body , err := ioutil . ReadAll ( resp . Body ) if err != nil { return net . IP { } , err } var servers [ ] map [ string ] interface { } err = json . Unmarshal ( body , & servers ) if err != nil { return net . IP { } , err } if len ( servers ) == 0 { return nil , fmt . Errorf ( " " , instance ) } if len ( servers ) > 1 { return nil , fmt . Errorf ( " " , instance ) } current := servers [ 0 ] [ " " ] if current == nil { return nil , fmt . Errorf ( " " , instance ) } cur := current . ( map [ string ] interface { } ) ipAddresses := cur [ " " ] . ( [ ] string ) if current == nil { return nil , fmt . Errorf ( " " , instance ) } ip := net . ParseIP ( ipAddresses [ 0 ] ) if ip == nil { return nil , fmt . Errorf ( " " , ipAddresses [ 0 ] ) } return ip , nil }
IPAddress returns the address of a particular machine instance.
IPAddress returns the address of a particular machine instance .