-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Example for Network Verifier
- Loading branch information
1 parent
6f4cd3e
commit 3f2548f
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
examples/network_verifier/network_verifier_with_cluster_id.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
sdk "github.com/openshift-online/ocm-sdk-go" | ||
cmv1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1" | ||
"github.com/openshift-online/ocm-sdk-go/logging" | ||
) | ||
|
||
func main() { | ||
// Create a context: | ||
ctx := context.Background() | ||
|
||
// Create a logger that has the debug level enabled: | ||
logger, err := logging.NewGoLoggerBuilder(). | ||
Debug(true). | ||
Build() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Can't build logger: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create the connection, and remember to close it: | ||
token := os.Getenv("OCM_TOKEN") | ||
connection, err := sdk.NewConnectionBuilder(). | ||
Logger(logger). | ||
Tokens(token). | ||
Build() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Can't build connection: %v\n", err) | ||
os.Exit(1) | ||
} | ||
defer connection.Close() | ||
|
||
// Get the client for the resource that manages the collection of clusters: | ||
|
||
clusterId := "2726d3ceb9q7qso3nceqdlm3j2fh7oqg" | ||
body, err := cmv1.NewNetworkVerification().ClusterId(clusterId).Build() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Can't build request body: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
networkVerifyResponse, err := connection.ClustersMgmt(). | ||
V1().NetworkVerifications().Add().Body(body).SendContext(ctx) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, | ||
"Can't send request to network verifier using cluster id: %v\n", clusterId) | ||
os.Exit(1) | ||
} | ||
|
||
// Print the result | ||
fmt.Printf("%#v", networkVerifyResponse.Body()) | ||
|
||
// Check the inflight check (egress type) after a couple of minutes | ||
// to see the update applied from the network verifier | ||
inflightResponse, err := connection.ClustersMgmt(). | ||
V1().Clusters().Cluster(clusterId).InflightChecks().List().SendContext(ctx) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, | ||
"Can't retrieve inflight request using cluster id: %v\n", clusterId) | ||
os.Exit(1) | ||
} | ||
inflights := inflightResponse.Items() | ||
// Print the result | ||
fmt.Printf("%#v", inflights) | ||
|
||
} |