forked from hashicorp/terraform-provider-vsphere
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move getDatacenter to vsphere/datacenter_helper.go, add API handling
Moved getDatacenter to its own helper code, as a lot of other resources use it. Also added the ability of it to detect the connected API type (ESXi vs vCenter), and just use the default if on ESXi.
- Loading branch information
1 parent
658941d
commit 701a445
Showing
2 changed files
with
30 additions
and
12 deletions.
There are no files selected for viewing
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,30 @@ | ||
package vsphere | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vmware/govmomi" | ||
"github.com/vmware/govmomi/find" | ||
"github.com/vmware/govmomi/object" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
// getDatacenter gets the higher-level datacenter object for the datacenter | ||
// name supplied by dc. | ||
// | ||
// The default datacenter is denoted by using an empty string. When working | ||
// with ESXi directly, the default datacenter is always selected. | ||
func getDatacenter(c *govmomi.Client, dc string) (*object.Datacenter, error) { | ||
finder := find.NewFinder(c.Client, true) | ||
t := c.ServiceContent.About.ApiType | ||
switch t { | ||
case "HostAgent": | ||
return finder.DefaultDatacenter(context.TODO()) | ||
case "VirtualCenter": | ||
if dc != "" { | ||
return finder.Datacenter(context.TODO(), dc) | ||
} | ||
return finder.DefaultDatacenter(context.TODO()) | ||
} | ||
return nil, fmt.Errorf("unsupported ApiType: %s", t) | ||
} |
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