package main import ( "context" "fmt" "log" "github.com/vmware/govmomi/vim25/types" "github.com/vmware/govmomi/vim25/soap" "github.com/vmware/govmomi/view" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/object" ) func main() { url := "https://localhost/sdk" ctx := context.Background() // Connect to vSphere API endpoint client, err := soap.NewClient(ctx, url, true) if err != nil { log.Fatal(err) } // Get a view of all datastores in the vSphere cluster m := view.NewManager(client) v, err := m.CreateContainerView(ctx, client.ServiceContent.RootFolder, []string{"Datastore"}, true) if err != nil { log.Fatal(err) } defer v.Destroy(ctx) // Retrieve a list of datastore objects and print their names var datastores []mo.Datastore err = v.Retrieve(ctx, []string{"Datastore"}, nil, &datastores) if err != nil { log.Fatal(err) } for _, ds := range datastores { fmt.Println(ds.Info.Name) } }
package main import ( "context" "log" "github.com/vmware/govmomi/vim25/types" "github.com/vmware/govmomi/property" "github.com/vmware/govmomi/vim25/soap" "github.com/vmware/govmomi/view" "github.com/vmware/govmomi/vim25/mo" "github.com/vmware/govmomi/object" ) func main() { url := "https://localhost/sdk" ctx := context.Background() // Connect to vSphere API endpoint client, err := soap.NewClient(ctx, url, true) if err != nil { log.Fatal(err) } // Set datastore creation options dsSpec := types.DatastoreCreateSpec{ Name: "new_datastore", DatastoreType: "VMFS", VmfsSpec: &types.VmfsDatastoreCreateSpec{ BlockSize: 1024, Extent: []types.DatastoreExtentSpec{ { DiskName: "/vmfs/devices/disks/mpx.vmhba32:C0:T0:L0", }, }, }, } // Create new datastore finder := object.NewFinder(client) dc, err := finder.DefaultDatacenter(ctx) if err != nil { log.Fatal(err) } folders, err := dc.Folders(ctx) if err != nil { log.Fatal(err) } ds, err := folders.DatastoreFolder.CreateDatastore(ctx, dsSpec) if err != nil { log.Fatal(err) } log.Println("New datastore created:", ds.Name()) }Determining package library: The package library for this module appears to be "github.com/vmware/govmomi/object." This is because the Datastore type is defined in the `github.com/vmware/govmomi/object` package, and the examples make use of functions and structures provided by other modules in the `object` package, such as `finder`, `folders`, and `CreateDatastore`.