Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] vSphere provider support for SDRS with storage pods #7031

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions builtin/providers/vsphere/resource_vsphere_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type file struct {
datastore string
sourceFile string
destinationFile string
// use_sdrs bool // TODO
}

// TODO add DRS
func resourceVSphereFile() *schema.Resource {
return &schema.Resource{
Create: resourceVSphereFileCreate,
Expand Down Expand Up @@ -55,6 +57,7 @@ func resourceVSphereFile() *schema.Resource {

func resourceVSphereFileCreate(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] creating file: %#v", d)
client := meta.(*govmomi.Client)

Expand Down Expand Up @@ -123,6 +126,7 @@ func createFile(client *govmomi.Client, f *file) error {

func resourceVSphereFileRead(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] reading file: %#v", d)
f := file{}

Expand Down Expand Up @@ -173,6 +177,7 @@ func resourceVSphereFileRead(d *schema.ResourceData, meta interface{}) error {

func resourceVSphereFileUpdate(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] updating file: %#v", d)
if d.HasChange("destination_file") {
oldDestinationFile, newDestinationFile := d.GetChange("destination_file")
Expand Down Expand Up @@ -232,6 +237,7 @@ func resourceVSphereFileUpdate(d *schema.ResourceData, meta interface{}) error {

func resourceVSphereFileDelete(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] deleting file: %#v", d)
f := file{}

Expand Down Expand Up @@ -297,6 +303,7 @@ func deleteFile(client *govmomi.Client, f *file) error {
}

// getDatastore gets datastore object
// TODO add DRS functionality
func getDatastore(f *find.Finder, ds string) (*object.Datastore, error) {

if ds != "" {
Expand Down
1 change: 1 addition & 0 deletions builtin/providers/vsphere/resource_vsphere_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// Basic file creation
func TestAccVSphereFile_basic(t *testing.T) {
testVmdkFileData := []byte("# Disk DescriptorFile\n")
// TODO make this OS TMP dir ... run on windows
testVmdkFile := "/tmp/tf_test.vmdk"
err := ioutil.WriteFile(testVmdkFile, testVmdkFileData, 0644)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions builtin/providers/vsphere/resource_vsphere_folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ func resourceVSphereFolder() *schema.Resource {

func resourceVSphereFolderCreate(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)

client := meta.(*govmomi.Client)

f := folder{
Expand Down Expand Up @@ -117,6 +119,7 @@ func createFolder(client *govmomi.Client, f *folder) error {

func resourceVSphereFolderRead(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] reading folder: %#v", d)
client := meta.(*govmomi.Client)

Expand Down Expand Up @@ -145,6 +148,7 @@ func resourceVSphereFolderRead(d *schema.ResourceData, meta interface{}) error {

func resourceVSphereFolderDelete(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
f := folder{
path: strings.TrimRight(d.Get("path").(string), "/"),
existingPath: d.Get("existing_path").(string),
Expand Down
7 changes: 7 additions & 0 deletions builtin/providers/vsphere/resource_vsphere_virtual_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type virtualDisk struct {
adapterType string
datacenter string
datastore string
// use_sdrs bool // TODO implement sdrs
}

// Define VirtualDisk args
Expand Down Expand Up @@ -88,6 +89,8 @@ func resourceVSphereVirtualDisk() *schema.Resource {
}

func resourceVSphereVirtualDiskCreate(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[INFO] Creating Virtual Disk")
client := meta.(*govmomi.Client)

Expand Down Expand Up @@ -129,6 +132,8 @@ func resourceVSphereVirtualDiskCreate(d *schema.ResourceData, meta interface{})
}

func resourceVSphereVirtualDiskRead(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
log.Printf("[DEBUG] Reading virtual disk.")
client := meta.(*govmomi.Client)

Expand Down Expand Up @@ -192,6 +197,8 @@ func resourceVSphereVirtualDiskRead(d *schema.ResourceData, meta interface{}) er
}

func resourceVSphereVirtualDiskDelete(d *schema.ResourceData, meta interface{}) error {

log.SetFlags(log.Lshortfile)
client := meta.(*govmomi.Client)

vDisk := virtualDisk{}
Expand Down
31 changes: 23 additions & 8 deletions builtin/providers/vsphere/resource_vsphere_virtual_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ import (
"golang.org/x/net/context"
)

func testVirtualDiskPreCheck(t *testing.T) {
if v := os.Getenv("VSPHERE_INIT_TYPE"); v == "" {
t.Fatal("VSPHERE_INIT_TYPE must be set to test")
}
if v := os.Getenv("VSPHERE_ADAPTER_TYPE"); v == "" {
t.Fatal("VSPHERE_ADAPTER_TYPE must be set to test")
}
testAccPreCheck(t)
}

func TestAccVSphereVirtualDisk_basic(t *testing.T) {
var datacenterOpt string
var datastoreOpt string
Expand All @@ -32,19 +42,24 @@ func TestAccVSphereVirtualDisk_basic(t *testing.T) {
adapterTypeOpt += fmt.Sprintf(" adapter_type = \"%s\"\n", v)
}

config := fmt.Sprintf(
testAccCheckVSphereVirtuaDiskConfig_basic,
initTypeOpt,
adapterTypeOpt,
datacenterOpt,
datastoreOpt,
)

log.Printf("[DEBUG] template= %s", testAccCheckVSphereVirtuaDiskConfig_basic)
log.Printf("[DEBUG] template config= %s", config)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
PreCheck: func() { testVirtualDiskPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVSphereVirtualDiskDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: fmt.Sprintf(
testAccCheckVSphereVirtuaDiskConfig_basic,
initTypeOpt,
adapterTypeOpt,
datacenterOpt,
datastoreOpt,
),
Config: config,
Check: resource.ComposeTestCheckFunc(
testAccVSphereVirtualDiskExists("vsphere_virtual_disk.foo"),
),
Expand Down
Loading