network_diagnostics.go 1010 B

123456789101112131415161718192021222324252627282930313233343536
  1. package storageos
  2. import (
  3. "encoding/json"
  4. "net/http"
  5. "path"
  6. "github.com/storageos/go-api/types"
  7. )
  8. var (
  9. // NetworkDiagnosticsAPIPrefix is a partial path to the HTTP endpoint for
  10. // the node connectivity diagnostics report.
  11. NetworkDiagnosticsAPIPrefix = "diagnostics/network"
  12. )
  13. // NetworkDiagnostics returns a collection of network connectivity reports. If
  14. // a reference to a node is given, it will only check connectivity from that
  15. // node. Otherwise, connectivity between all cluster nodes will be returned.
  16. func (c *Client) NetworkDiagnostics(ref string) (types.ConnectivityResults, error) {
  17. resp, err := c.do("GET", path.Join(NetworkDiagnosticsAPIPrefix, ref), doOptions{})
  18. if err != nil {
  19. if e, ok := err.(*Error); ok && e.Status == http.StatusNotFound {
  20. return nil, ErrNoSuchNode
  21. }
  22. return nil, err
  23. }
  24. defer resp.Body.Close()
  25. var results types.ConnectivityResults
  26. if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
  27. return nil, err
  28. }
  29. return results, nil
  30. }