Refactoring multiple results

This commit is contained in:
Joe Topjian 2015-02-11 04:11:04 +00:00 committed by Jon Perritt
parent bad2c9f18d
commit 74482abc5b
1 changed files with 8 additions and 10 deletions

View File

@ -674,10 +674,14 @@ func getFloatingIPs(networkingClient *gophercloud.ServiceClient) ([]floatingips.
func getImageID(client *gophercloud.ServiceClient, d *schema.ResourceData) (string, error) { func getImageID(client *gophercloud.ServiceClient, d *schema.ResourceData) (string, error) {
imageId := d.Get("image_id").(string) imageId := d.Get("image_id").(string)
imageName := d.Get("image_name").(string)
imageCount := 0
if imageId == "" && imageName != "" { if imageId != "" {
return imageId, nil
}
imageCount := 0
imageName := d.Get("image_name").(string)
if imageName != "" {
pager := images.ListDetail(client, &images.ListOpts{ pager := images.ListDetail(client, &images.ListOpts{
Name: imageName, Name: imageName,
}) })
@ -705,11 +709,5 @@ func getImageID(client *gophercloud.ServiceClient, d *schema.ResourceData) (stri
return "", fmt.Errorf("Found %d images matching %s", imageCount, imageName) return "", fmt.Errorf("Found %d images matching %s", imageCount, imageName)
} }
} }
return "", fmt.Errorf("Neither an image ID nor an image name were able to be determined.")
if imageId == "" && imageName == "" {
return "", fmt.Errorf("Neither an image ID nor an image name were able to be determined.")
}
return imageId, nil
} }