|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "os" |
| 7 | + |
| 8 | + sdk "github.com/openshift-online/ocm-sdk-go" |
| 9 | + cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" |
| 10 | + "github.com/openshift-online/ocm-sdk-go/logging" |
| 11 | +) |
| 12 | + |
| 13 | +func main() { |
| 14 | + // Create a context: |
| 15 | + ctx := context.Background() |
| 16 | + |
| 17 | + // Create a logger that has the debug level enabled: |
| 18 | + logger, err := logging.NewGoLoggerBuilder(). |
| 19 | + Debug(true). |
| 20 | + Build() |
| 21 | + if err != nil { |
| 22 | + fmt.Fprintf(os.Stderr, "Can't build logger: %v\n", err) |
| 23 | + os.Exit(1) |
| 24 | + } |
| 25 | + |
| 26 | + // Create the connection, and remember to close it: |
| 27 | + token := os.Getenv("OCM_TOKEN") |
| 28 | + connection, err := sdk.NewConnectionBuilder(). |
| 29 | + Logger(logger). |
| 30 | + Tokens(token). |
| 31 | + Build() |
| 32 | + if err != nil { |
| 33 | + fmt.Fprintf(os.Stderr, "Can't build connection: %v\n", err) |
| 34 | + os.Exit(1) |
| 35 | + } |
| 36 | + defer connection.Close() |
| 37 | + |
| 38 | + // Get the client for the resource that manages the collection of clusters: |
| 39 | + |
| 40 | + clusterId := "2726d3ceb9q7qso3nceqdlm3j2fh7oqg" |
| 41 | + body, err := cmv1.NewNetworkVerification().ClusterId(clusterId).Build() |
| 42 | + if err != nil { |
| 43 | + fmt.Fprintf(os.Stderr, "Can't build request body: %v\n", err) |
| 44 | + os.Exit(1) |
| 45 | + } |
| 46 | + |
| 47 | + networkVerifyResponse, err := connection.ClustersMgmt(). |
| 48 | + V1().NetworkVerifications().Add().Body(body).SendContext(ctx) |
| 49 | + if err != nil { |
| 50 | + fmt.Fprintf(os.Stderr, |
| 51 | + "Can't send request to network verifier using cluster id: %v\n", clusterId) |
| 52 | + os.Exit(1) |
| 53 | + } |
| 54 | + |
| 55 | + // Print the result |
| 56 | + fmt.Printf("%#v", networkVerifyResponse.Body()) |
| 57 | + |
| 58 | + // Check the inflight check (egress type) after a couple of minutes |
| 59 | + // to see the update applied from the network verifier |
| 60 | + inflightResponse, err := connection.ClustersMgmt(). |
| 61 | + V1().Clusters().Cluster(clusterId).InflightChecks().List().SendContext(ctx) |
| 62 | + if err != nil { |
| 63 | + fmt.Fprintf(os.Stderr, |
| 64 | + "Can't retrieve inflight request using cluster id: %v\n", clusterId) |
| 65 | + os.Exit(1) |
| 66 | + } |
| 67 | + inflights := inflightResponse.Items() |
| 68 | + // Print the result |
| 69 | + fmt.Printf("%#v", inflights) |
| 70 | + |
| 71 | +} |
0 commit comments