Skip to content

Instantly share code, notes, and snippets.

@tschf
Created October 5, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tschf/af858133719088627ae23e5170d1a91d to your computer and use it in GitHub Desktop.
Save tschf/af858133719088627ae23e5170d1a91d to your computer and use it in GitHub Desktop.
OCI compute listing example
package main
import (
"context"
"fmt"
"github.com/oracle/oci-go-sdk/common"
"github.com/oracle/oci-go-sdk/common/auth"
"github.com/oracle/oci-go-sdk/core"
)
// Demo to list properties of compute instances in a compartment
func main() {
compartmentID := common.String("TODO_COMPARTMENT_ID")
provider, _ := auth.InstancePrincipalConfigurationProvider()
request := core.ListInstancesRequest{
CompartmentId: compartmentID,
}
client, _ := core.NewComputeClientWithConfigurationProvider(provider)
computeInstances, _ := client.ListInstances(context.Background(), request)
for _, instance := range computeInstances.Items {
// List info about instance
// See for available properies: https://github.com/oracle/oci-go-sdk/blob/master/core/instance.go#L30
fmt.Printf(
"(name)%v\t(region)%v\t(created)%v\t(maintenance reboot)%v\n",
*instance.DisplayName,
*instance.Region,
instance.TimeCreated,
instance.TimeMaintenanceRebootDue,
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment