This is a courtesy helper function, which in some cases may not work as expected!
(name string, opts ...OptionFunc)
| 548 | |
| 549 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 550 | func (s *VMGroupService) GetInstanceGroupID(name string, opts ...OptionFunc) (string, int, error) { |
| 551 | p := &ListInstanceGroupsParams{} |
| 552 | p.p = make(map[string]interface{}) |
| 553 | |
| 554 | p.p["name"] = name |
| 555 | |
| 556 | for _, fn := range append(s.cs.options, opts...) { |
| 557 | if err := fn(s.cs, p); err != nil { |
| 558 | return "", -1, err |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | l, err := s.ListInstanceGroups(p) |
| 563 | if err != nil { |
| 564 | return "", -1, err |
| 565 | } |
| 566 | |
| 567 | if l.Count == 0 { |
| 568 | return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) |
| 569 | } |
| 570 | |
| 571 | if l.Count == 1 { |
| 572 | return l.InstanceGroups[0].Id, l.Count, nil |
| 573 | } |
| 574 | |
| 575 | if l.Count > 1 { |
| 576 | for _, v := range l.InstanceGroups { |
| 577 | if v.Name == name { |
| 578 | return v.Id, l.Count, nil |
| 579 | } |
| 580 | } |
| 581 | } |
| 582 | return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) |
| 583 | } |
| 584 | |
| 585 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 586 | func (s *VMGroupService) GetInstanceGroupByName(name string, opts ...OptionFunc) (*InstanceGroup, int, error) { |
no test coverage detected