| 1 |
package cloudapi |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/joyent/gosdc/cloudapi" |
| 7 |
) |
| 8 |
|
| 9 |
|
| 10 |
func (c *CloudAPI) ListImages(filters map[string]string) ([]cloudapi.Image, error) { |
| 11 |
if err := c.ProcessFunctionHook(c, filters); err != nil { |
| 12 |
return nil, err |
| 13 |
} |
| 14 |
|
| 15 |
availableImages := c.images |
| 16 |
|
| 17 |
if filters != nil { |
| 18 |
for k, f := range filters { |
| 19 |
|
| 20 |
if contains(imagesFilters, k) { |
| 21 |
imgs := []cloudapi.Image{} |
| 22 |
|
| 23 |
for _, i := range availableImages { |
| 24 |
if k == "name" && i.Name == f { |
| 25 |
imgs = append(imgs, i) |
| 26 |
} else if k == "os" && i.OS == f { |
| 27 |
imgs = append(imgs, i) |
| 28 |
} else if k == "version" && i.Version == f { |
| 29 |
imgs = append(imgs, i) |
| 30 |
} else if k == "public" && fmt.Sprintf("%v", i.Public) == f { |
| 31 |
imgs = append(imgs, i) |
| 32 |
} else if k == "state" && i.State == f { |
| 33 |
imgs = append(imgs, i) |
| 34 |
} else if k == "owner" && i.Owner == f { |
| 35 |
imgs = append(imgs, i) |
| 36 |
} else if k == "type" && i.Type == f { |
| 37 |
imgs = append(imgs, i) |
| 38 |
} |
| 39 |
} |
| 40 |
availableImages = imgs |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
return availableImages, nil |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
func (c *CloudAPI) GetImage(imageID string) (*cloudapi.Image, error) { |
| 50 |
if err := c.ProcessFunctionHook(c, imageID); err != nil { |
| 51 |
return nil, err |
| 52 |
} |
| 53 |
|
| 54 |
for _, image := range c.images { |
| 55 |
if image.Id == imageID { |
| 56 |
return &image, nil |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
return nil, fmt.Errorf("Image %s not found", imageID) |
| 61 |
} |