From 391b6b086a6f838f90a39c7b5797efba9adc6c43 Mon Sep 17 00:00:00 2001 From: Camilo Aguilar Date: Fri, 19 Sep 2014 17:51:14 -0400 Subject: [PATCH] Removes dead code, prepares vswitch resource stubs with new Terraform plugin API --- provider/config.go | 9 --- provider/provider.go | 17 ++++- provider/resource_vix_vm.go | 22 +++---- provider/resource_vix_vswitch.go | 110 +++++++++++++------------------ provider/resources.go | 35 ---------- 5 files changed, 70 insertions(+), 123 deletions(-) delete mode 100644 provider/config.go delete mode 100644 provider/resources.go diff --git a/provider/config.go b/provider/config.go deleted file mode 100644 index 03f51ab..0000000 --- a/provider/config.go +++ /dev/null @@ -1,9 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -package provider - -type Config struct { - Product string - VerifySSL bool -} diff --git a/provider/provider.go b/provider/provider.go index 36735d8..d8ea19f 100644 --- a/provider/provider.go +++ b/provider/provider.go @@ -4,11 +4,24 @@ package provider import ( + "fmt" "log" + "os" "github.com/hashicorp/terraform/helper/schema" ) +type Config struct { + Product string + VerifySSL bool +} + +func init() { + // Terraform is already adding the timestamp for us + log.SetFlags(log.Lshortfile) + log.SetPrefix(fmt.Sprintf("pid-%d-", os.Getpid())) +} + func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ @@ -23,8 +36,8 @@ func Provider() *schema.Provider { }, ResourcesMap: map[string]*schema.Resource{ - "vix_vm": resourceVixVm(), - //"vix_vswitch": resourceVixVSwitch(), + "vix_vm": resourceVIXVM(), + "vix_vswitch": resourceVIXVSwitch(), }, ConfigureFunc: providerConfigure, diff --git a/provider/resource_vix_vm.go b/provider/resource_vix_vm.go index 3eb5000..56c403b 100644 --- a/provider/resource_vix_vm.go +++ b/provider/resource_vix_vm.go @@ -18,12 +18,12 @@ import ( "github.com/hashicorp/terraform/helper/schema" ) -func resourceVixVm() *schema.Resource { +func resourceVIXVM() *schema.Resource { return &schema.Resource{ - Create: resourceVixVmCreate, - Read: resourceVixVmRead, - Update: resourceVixVmUpdate, - Delete: resourceVixVmDelete, + Create: resourceVIXVMCreate, + Read: resourceVIXVMRead, + Update: resourceVIXVMUpdate, + Delete: resourceVIXVMDelete, Schema: map[string]*schema.Schema{ "name": &schema.Schema{ @@ -400,7 +400,7 @@ func net_vix_to_tf(vm *vix.VM, d *schema.ResourceData) error { return nil } -func resourceVixVmCreate(d *schema.ResourceData, meta interface{}) error { +func resourceVIXVMCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) vm := new(vix.VM) @@ -425,10 +425,10 @@ func resourceVixVmCreate(d *schema.ResourceData, meta interface{}) error { "host": vm.IPAddress, }) - return resourceVixVmRead(d, meta) + return resourceVIXVMRead(d, meta) } -func resourceVixVmUpdate(d *schema.ResourceData, meta interface{}) error { +func resourceVIXVMUpdate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) vm := new(vix.VM) @@ -443,10 +443,10 @@ func resourceVixVmUpdate(d *schema.ResourceData, meta interface{}) error { return err } - return resourceVixVmRead(d, meta) + return resourceVIXVMRead(d, meta) } -func resourceVixVmDelete(d *schema.ResourceData, meta interface{}) error { +func resourceVIXVMDelete(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) vmxFile := d.Id() @@ -461,7 +461,7 @@ func resourceVixVmDelete(d *schema.ResourceData, meta interface{}) error { return vm.Destroy(vmxFile) } -func resourceVixVmRead(d *schema.ResourceData, meta interface{}) error { +func resourceVIXVMRead(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config) vmxFile := d.Id() diff --git a/provider/resource_vix_vswitch.go b/provider/resource_vix_vswitch.go index 79e1db3..1f48b6a 100644 --- a/provider/resource_vix_vswitch.go +++ b/provider/resource_vix_vswitch.go @@ -3,84 +3,62 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. package provider -import ( - "github.com/cloudescape/govix" - "github.com/hashicorp/terraform/helper/config" - "github.com/hashicorp/terraform/helper/diff" - "github.com/hashicorp/terraform/terraform" -) - -func resource_vix_vswitch_validation() *config.Validator { - return &config.Validator{ - Required: []string{ - "name", - }, - - Optional: []string{ - "nat", - "dhcp", - "range", - "host_access", +import "github.com/hashicorp/terraform/helper/schema" + +func resourceVIXVSwitch() *schema.Resource { + return &schema.Resource{ + Create: resourceVIXVSwitchCreate, + Read: resourceVIXVSwitchRead, + Update: resourceVIXVSwitchUpdate, + Delete: resourceVIXVSwitchDelete, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "nat": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "dhcp": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "host_access": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Default: true, + }, + "range": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, } } -func resource_vix_vswitch_create( - s *terraform.ResourceState, - d *terraform.ResourceDiff, - meta interface{}) (*terraform.ResourceState, error) { - //p := meta.(*ResourceProvider) - - return nil, nil -} - -func resource_vix_vswitch_update( - s *terraform.ResourceState, - d *terraform.ResourceDiff, - meta interface{}) (*terraform.ResourceState, error) { - //p := meta.(*ResourceProvider) - - return nil, nil -} - -func resource_vix_vswitch_destroy( - s *terraform.ResourceState, - meta interface{}) error { - // p := meta.(*ResourceProvider) - // client := p.client +func resourceVIXVSwitchCreate(d *schema.ResourceData, meta interface{}) error { + //config := meta.(*Config) return nil } -func resource_vix_vswitch_diff( - s *terraform.ResourceState, - c *terraform.ResourceConfig, - meta interface{}) (*terraform.ResourceDiff, error) { - - b := &diff.ResourceBuilder{ - // We have to choose whether a change in an attribute triggers a new - // resource creation or updates the existing resource. - Attrs: map[string]diff.AttrType{ - "nat": diff.AttrTypeUpdate, - "dhcp": diff.AttrTypeUpdate, - "range": diff.AttrTypeUpdate, - "host_access": diff.AttrTypeUpdate, - }, - } - - return b.Diff(s, c) +func resourceVIXVSwitchRead(d *schema.ResourceData, meta interface{}) error { + return nil } -func resource_vix_vswitch_refresh( - s *terraform.ResourceState, - meta interface{}) (*terraform.ResourceState, error) { +func resourceVIXVSwitchUpdate(d *schema.ResourceData, meta interface{}) error { + //config := meta.(*Config) - return nil, nil + return nil } -func resource_vix_vswitch_update_state( - s *terraform.ResourceState, - vswitch *vix.VSwitch) (*terraform.ResourceState, error) { +func resourceVIXVSwitchDelete(d *schema.ResourceData, meta interface{}) error { + //config := meta.(*Config) - return nil, nil + return nil } diff --git a/provider/resources.go b/provider/resources.go deleted file mode 100644 index 68f88a5..0000000 --- a/provider/resources.go +++ /dev/null @@ -1,35 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -package provider - -import ( - "fmt" - "log" - "os" - - "github.com/hashicorp/terraform/helper/resource" -) - -// resourceMap is the mapping of resources we support to their basic -// operations. This makes it easy to implement new resource types. -var resourceMap *resource.Map - -func init() { - // Terraform is already adding the timestamp for us - log.SetFlags(log.Lshortfile) - log.SetPrefix(fmt.Sprintf("pid-%d-", os.Getpid())) - - resourceMap = &resource.Map{ - Mapping: map[string]resource.Resource{ - "vix_vswitch": resource.Resource{ - ConfigValidator: resource_vix_vswitch_validation(), - Create: resource_vix_vswitch_create, - Destroy: resource_vix_vswitch_destroy, - Diff: resource_vix_vswitch_diff, - Refresh: resource_vix_vswitch_refresh, - Update: resource_vix_vswitch_update, - }, - }, - } -}