Remove duplication over GetIP

+ ip address proper validation

Signed-off-by: Olivier Gambier <olivier@docker.com>
This commit is contained in:
Olivier Gambier 2015-10-20 18:49:45 -07:00
parent b6462eb6d0
commit 99aacc7b79
4 changed files with 10 additions and 18 deletions

View File

@ -226,13 +226,6 @@ func (d *Driver) GetURL() (string, error) {
return fmt.Sprintf("tcp://%s:2376", ip), nil
}
func (d *Driver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
return d.IPAddress, nil
}
func (d *Driver) GetState() (state.State, error) {
droplet, _, err := d.getClient().Droplets.Get(d.DropletID)
if err != nil {

View File

@ -146,13 +146,6 @@ func (d *Driver) GetURL() (string, error) {
return fmt.Sprintf("tcp://%s:2376", ip), nil
}
func (d *Driver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
return d.IPAddress, nil
}
func (d *Driver) GetState() (state.State, error) {
client := egoscale.NewClient(d.URL, d.ApiKey, d.ApiSecretKey)
vm, err := client.GetVirtualMachine(d.Id)

View File

@ -121,11 +121,7 @@ func (d *Driver) GetURL() (string, error) {
return fmt.Sprintf("tcp://%s:2376", ip), nil
}
func (d *Driver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
return d.IPAddress, nil
}
func (d *Driver) GetState() (state.State, error) {

View File

@ -26,6 +26,16 @@ func (d *BaseDriver) DriverName() string {
}
// GetIP returns the ip
func (d *BaseDriver) GetIP() (string, error) {
if d.IPAddress == "" {
return "", fmt.Errorf("IP address is not set")
}
ip := net.ParseIP(d.IPAddress)
if ip == nil {
return "", fmt.Errorf("IP address is invalid")
}
return d.IPAddress, nil
}
func (d *BaseDriver) GetMachineName() string {
return d.MachineName
}