MCPcopy Index your code
hub / github.com/apache/cloudstack-go / GetIsoID

Method GetIsoID

cloudstack/ISOService.go:2259–2294  ·  view source on GitHub ↗

This is a courtesy helper function, which in some cases may not work as expected!

(name string, isofilter string, zoneid string, opts ...OptionFunc)

Source from the content-addressed store, hash-verified

2257
2258// This is a courtesy helper function, which in some cases may not work as expected!
2259func (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!
2297func (s *ISOService) GetIsoByName(name string, isofilter string, zoneid string, opts ...OptionFunc) (*Iso, int, error) {

Callers 1

GetIsoByNameMethod · 0.95

Calls 1

ListIsosMethod · 0.95

Tested by

no test coverage detected