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

Method GetSystemVmID

cloudstack/SystemVMService.go:650–683  ·  view source on GitHub ↗

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

(name string, opts ...OptionFunc)

Source from the content-addressed store, hash-verified

648
649// This is a courtesy helper function, which in some cases may not work as expected!
650func (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!
686func (s *SystemVMService) GetSystemVmByName(name string, opts ...OptionFunc) (*SystemVm, int, error) {

Callers 1

GetSystemVmByNameMethod · 0.95

Calls 1

ListSystemVmsMethod · 0.95

Tested by

no test coverage detected