This is a courtesy helper function, which in some cases may not work as expected!
(name string, opts ...OptionFunc)
| 648 | |
| 649 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 650 | func (s *SystemVMService) GetSystemVmID(name string, opts ...OptionFunc) (string, int, error) { |
| 651 | p := &ListSystemVmsParams{} |
| 652 | p.p = make(map[string]interface{}) |
| 653 | |
| 654 | p.p["name"] = name |
| 655 | |
| 656 | for _, fn := range append(s.cs.options, opts...) { |
| 657 | if err := fn(s.cs, p); err != nil { |
| 658 | return "", -1, err |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | l, err := s.ListSystemVms(p) |
| 663 | if err != nil { |
| 664 | return "", -1, err |
| 665 | } |
| 666 | |
| 667 | if l.Count == 0 { |
| 668 | return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l) |
| 669 | } |
| 670 | |
| 671 | if l.Count == 1 { |
| 672 | return l.SystemVms[0].Id, l.Count, nil |
| 673 | } |
| 674 | |
| 675 | if l.Count > 1 { |
| 676 | for _, v := range l.SystemVms { |
| 677 | if v.Name == name { |
| 678 | return v.Id, l.Count, nil |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l) |
| 683 | } |
| 684 | |
| 685 | // This is a courtesy helper function, which in some cases may not work as expected! |
| 686 | func (s *SystemVMService) GetSystemVmByName(name string, opts ...OptionFunc) (*SystemVm, int, error) { |
no test coverage detected