forked from vmware-tanzu/tanzu-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
discovery.go
42 lines (33 loc) · 1.15 KB
/
discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2022 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package wcp provides helpers to interact with a vSphere Supervisor.
package wcp
import (
"context"
"fmt"
"net/http"
"github.com/vmware-tanzu/tanzu-plugin-runtime/log"
)
const (
SupervisorVIPConfigMapName = "vip-cluster-info"
)
// IsVSphereSupervisor probes the given endpoint on a well known vSphere
// Supervisor 'login banner' endpoint.
// Returns true iff it was able to successfully determine that the endpoint was
// a vSphere Supervisor.
func IsVSphereSupervisor(endpoint string, httpClient *http.Client) (bool, error) {
loginBannerURL := fmt.Sprintf("%s/wcp/loginbanner", endpoint)
req, _ := http.NewRequestWithContext(context.Background(), "GET", loginBannerURL, http.NoBody)
resp, err := httpClient.Do(req)
if err != nil {
log.Infof("Failed to test for vSphere supervisor: %+v", err)
return false, err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
log.V(4).Info("Got login banner from server")
return true, nil
}
log.Infof("Could not get login banner from server, response code = %+v", resp.StatusCode)
return false, nil
}