This is a courtesy helper function, which in some cases may not work as expected!
(name string, isofilter string, zoneid string, opts ...OptionFunc)
| 2257 | |
| 2258 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 2259 | func (s *ISOService) GetIsoID(name string, isofilter string, zoneid string, opts ...OptionFunc) (string, int, error) { |
| 2260 | p := &ListIsosParams{} |
| 2261 | p.p = make(map[string]interface{}) |
| 2262 | |
| 2263 | p.p["name"] = name |
| 2264 | p.p["isofilter"] = isofilter |
| 2265 | p.p["zoneid"] = zoneid |
| 2266 | |
| 2267 | for _, fn := range append(s.cs.options, opts...) { |
| 2268 | if err := fn(s.cs, p); err != nil { |
| 2269 | return "", -1, err |
| 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | l, err := s.ListIsos(p) |
| 2274 | if err != nil { |
| 2275 | return "", -1, err |
| 2276 | } |
| 2277 | |
| 2278 | if l.Count == 0 { |
| 2279 | return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) |
| 2280 | } |
| 2281 | |
| 2282 | if l.Count == 1 { |
| 2283 | return l.Isos[0].Id, l.Count, nil |
| 2284 | } |
| 2285 | |
| 2286 | if l.Count > 1 { |
| 2287 | for _, v := range l.Isos { |
| 2288 | if v.Name == name { |
| 2289 | return v.Id, l.Count, nil |
| 2290 | } |
| 2291 | } |
| 2292 | } |
| 2293 | return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) |
| 2294 | } |
| 2295 | |
| 2296 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 2297 | func (s *ISOService) GetIsoByName(name string, isofilter string, zoneid string, opts ...OptionFunc) (*Iso, int, error) { |