Created
October 5, 2020 06:26
-
-
Save tschf/af858133719088627ae23e5170d1a91d to your computer and use it in GitHub Desktop.
OCI compute listing example
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
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