Make maxRetryTimeout (in seconds) configurable

This commit is contained in:
Nicki Watt 2015-11-18 23:56:17 +00:00
parent 815ff7ac63
commit f1c2be9772
13 changed files with 73 additions and 60 deletions

View File

@ -13,15 +13,23 @@ type Config struct {
Org string Org string
Href string Href string
VDC string VDC string
MaxRetryTimeout int
} }
func (c *Config) Client() (*govcd.VCDClient, error) { type VCDClient struct {
*govcd.VCDClient
MaxRetryTimeout int
}
func (c *Config) Client() (*VCDClient, error) {
u, err := url.ParseRequestURI(c.Href) u, err := url.ParseRequestURI(c.Href)
if err != nil { if err != nil {
return nil, fmt.Errorf("Something went wrong: %s", err) return nil, fmt.Errorf("Something went wrong: %s", err)
} }
vcdclient := govcd.NewVCDClient(*u) vcdclient := &VCDClient{
govcd.NewVCDClient(*u),
c.MaxRetryTimeout}
org, vcd, err := vcdclient.Authenticate(c.User, c.Password, c.Org, c.VDC) org, vcd, err := vcdclient.Authenticate(c.User, c.Password, c.Org, c.VDC)
if err != nil { if err != nil {
return nil, fmt.Errorf("Something went wrong: %s", err) return nil, fmt.Errorf("Something went wrong: %s", err)

View File

@ -36,12 +36,20 @@ func Provider() terraform.ResourceProvider {
DefaultFunc: schema.EnvDefaultFunc("VCD_URL", nil), DefaultFunc: schema.EnvDefaultFunc("VCD_URL", nil),
Description: "The vcd url for vcd API operations.", Description: "The vcd url for vcd API operations.",
}, },
"vdc": &schema.Schema{ "vdc": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VCD_VDC", ""), DefaultFunc: schema.EnvDefaultFunc("VCD_VDC", ""),
Description: "The name of the VDC to run operations on", Description: "The name of the VDC to run operations on",
}, },
"maxRetryTimeout": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("VCD_MAX_RETRY_TIMEOUT", 30),
Description: "Max num seconds to wait for successful response when operating on resources within vCloud (defaults to 30)",
},
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{
@ -63,6 +71,7 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
Org: d.Get("org").(string), Org: d.Get("org").(string),
Href: d.Get("url").(string), Href: d.Get("url").(string),
VDC: d.Get("vdc").(string), VDC: d.Get("vdc").(string),
MaxRetryTimeout: d.Get("maxRetryTimeout").(int),
} }
return config.Client() return config.Client()

View File

@ -3,7 +3,6 @@ package vcd
import ( import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hmrc/vmware-govcd"
) )
func resourceVcdDNAT() *schema.Resource { func resourceVcdDNAT() *schema.Resource {
@ -41,7 +40,7 @@ func resourceVcdDNAT() *schema.Resource {
} }
func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error { func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as // Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an // the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client // operation we must wait until we can aquire a lock on the client
@ -60,7 +59,7 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
// constrained by out lock. If the edge gateway reurns with a busy error, wait // constrained by out lock. If the edge gateway reurns with a busy error, wait
// 3 seconds and then try again. Continue until a non-busy error or success // 3 seconds and then try again. Continue until a non-busy error or success
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := edgeGateway.AddNATMapping("DNAT", d.Get("external_ip").(string), task, err := edgeGateway.AddNATMapping("DNAT", d.Get("external_ip").(string),
d.Get("internal_ip").(string), d.Get("internal_ip").(string),
portString) portString)
@ -80,7 +79,7 @@ func resourceVcdDNATCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error { func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
e, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string)) e, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil { if err != nil {
@ -106,7 +105,7 @@ func resourceVcdDNATRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdDNATDelete(d *schema.ResourceData, meta interface{}) error { func resourceVcdDNATDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as // Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an // the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client // operation we must wait until we can aquire a lock on the client
@ -119,7 +118,7 @@ func resourceVcdDNATDelete(d *schema.ResourceData, meta interface{}) error {
if err != nil { if err != nil {
return fmt.Errorf("Unable to find edge gateway: %#v", err) return fmt.Errorf("Unable to find edge gateway: %#v", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := edgeGateway.RemoveNATMapping("DNAT", d.Get("external_ip").(string), task, err := edgeGateway.RemoveNATMapping("DNAT", d.Get("external_ip").(string),
d.Get("internal_ip").(string), d.Get("internal_ip").(string),
portString) portString)

View File

@ -50,7 +50,7 @@ func testAccCheckVcdDNATExists(n string, gateway *govcd.EdgeGateway) resource.Te
return fmt.Errorf("No DNAT ID is set") return fmt.Errorf("No DNAT ID is set")
} }
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
gatewayName := rs.Primary.Attributes["edge_gateway"] gatewayName := rs.Primary.Attributes["edge_gateway"]
edgeGateway, err := conn.OrgVdc.FindEdgeGateway(gatewayName) edgeGateway, err := conn.OrgVdc.FindEdgeGateway(gatewayName)
@ -79,7 +79,7 @@ func testAccCheckVcdDNATExists(n string, gateway *govcd.EdgeGateway) resource.Te
} }
func testAccCheckVcdDNATDestroy(s *terraform.State) error { func testAccCheckVcdDNATDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "vcd_dnat" { if rs.Type != "vcd_dnat" {
continue continue

View File

@ -3,7 +3,6 @@ package vcd
import ( import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hmrc/vmware-govcd"
types "github.com/hmrc/vmware-govcd/types/v56" types "github.com/hmrc/vmware-govcd/types/v56"
"log" "log"
"strings" "strings"
@ -82,7 +81,7 @@ func resourceVcdFirewallRules() *schema.Resource {
} }
func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) error { func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock() vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock() defer vcdClient.Mutex.Unlock()
@ -91,7 +90,7 @@ func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Unable to find edge gateway: %s", err) return fmt.Errorf("Unable to find edge gateway: %s", err)
} }
err = retryCall(5, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
edgeGateway.Refresh() edgeGateway.Refresh()
firewallRules, _ := expandFirewallRules(d, edgeGateway.EdgeGateway) firewallRules, _ := expandFirewallRules(d, edgeGateway.EdgeGateway)
task, err := edgeGateway.CreateFirewallRules(d.Get("default_action").(string), firewallRules) task, err := edgeGateway.CreateFirewallRules(d.Get("default_action").(string), firewallRules)
@ -112,7 +111,7 @@ func resourceVcdFirewallRulesCreate(d *schema.ResourceData, meta interface{}) er
} }
func resourceFirewallRulesDelete(d *schema.ResourceData, meta interface{}) error { func resourceFirewallRulesDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock() vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock() defer vcdClient.Mutex.Unlock()
@ -134,7 +133,7 @@ func resourceFirewallRulesDelete(d *schema.ResourceData, meta interface{}) error
} }
func resourceFirewallRulesRead(d *schema.ResourceData, meta interface{}) error { func resourceFirewallRulesRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string)) edgeGateway, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil { if err != nil {

View File

@ -44,7 +44,7 @@ func testAccCheckVcdFirewallRulesExists(n string, gateway *govcd.EdgeGateway) re
return fmt.Errorf("No Record ID is set") return fmt.Errorf("No Record ID is set")
} }
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
resp, err := conn.OrgVdc.FindEdgeGateway(rs.Primary.ID) resp, err := conn.OrgVdc.FindEdgeGateway(rs.Primary.ID)
if err != nil { if err != nil {
@ -77,6 +77,7 @@ func createFirewallRulesConfigs(existingRules *govcd.EdgeGateway) string {
Org: os.Getenv("VCD_ORG"), Org: os.Getenv("VCD_ORG"),
Href: os.Getenv("VCD_URL"), Href: os.Getenv("VCD_URL"),
VDC: os.Getenv("VCD_VDC"), VDC: os.Getenv("VCD_VDC"),
MaxRetryTimeout: 240,
} }
conn, err := config.Client() conn, err := config.Client()
if err != nil { if err != nil {

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hmrc/vmware-govcd"
types "github.com/hmrc/vmware-govcd/types/v56" types "github.com/hmrc/vmware-govcd/types/v56"
"strings" "strings"
) )
@ -121,7 +120,7 @@ func resourceVcdNetwork() *schema.Resource {
} }
func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error { func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
log.Printf("[TRACE] CLIENT: %#v", vcdClient) log.Printf("[TRACE] CLIENT: %#v", vcdClient)
vcdClient.Mutex.Lock() vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock() defer vcdClient.Mutex.Unlock()
@ -156,7 +155,7 @@ func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
log.Printf("[INFO] NETWORK: %#v", newnetwork) log.Printf("[INFO] NETWORK: %#v", newnetwork)
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
return vcdClient.OrgVdc.CreateOrgVDCNetwork(newnetwork) return vcdClient.OrgVdc.CreateOrgVDCNetwork(newnetwork)
}) })
if err != nil { if err != nil {
@ -174,7 +173,7 @@ func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
} }
if dhcp, ok := d.GetOk("dhcp_pool"); ok { if dhcp, ok := d.GetOk("dhcp_pool"); ok {
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := edgeGateway.AddDhcpPool(network.OrgVDCNetwork, dhcp.(*schema.Set).List()) task, err := edgeGateway.AddDhcpPool(network.OrgVDCNetwork, dhcp.(*schema.Set).List())
if err != nil { if err != nil {
return fmt.Errorf("Error adding DHCP pool: %#v", err) return fmt.Errorf("Error adding DHCP pool: %#v", err)
@ -194,7 +193,7 @@ func resourceVcdNetworkCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error { func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
log.Printf("[DEBUG] VCD Client configuration: %#v", vcdClient) log.Printf("[DEBUG] VCD Client configuration: %#v", vcdClient)
log.Printf("[DEBUG] VCD Client configuration: %#v", vcdClient.OrgVdc) log.Printf("[DEBUG] VCD Client configuration: %#v", vcdClient.OrgVdc)
@ -226,7 +225,7 @@ func resourceVcdNetworkRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdNetworkDelete(d *schema.ResourceData, meta interface{}) error { func resourceVcdNetworkDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
vcdClient.Mutex.Lock() vcdClient.Mutex.Lock()
defer vcdClient.Mutex.Unlock() defer vcdClient.Mutex.Unlock()
err := vcdClient.OrgVdc.Refresh() err := vcdClient.OrgVdc.Refresh()
@ -239,7 +238,7 @@ func resourceVcdNetworkDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error finding network: %#v", err) return fmt.Errorf("Error finding network: %#v", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := network.Delete() task, err := network.Delete()
if err != nil { if err != nil {
return fmt.Errorf("Error Deleting Network: %#v", err) return fmt.Errorf("Error Deleting Network: %#v", err)

View File

@ -50,7 +50,7 @@ func testAccCheckVcdNetworkExists(n string, network *govcd.OrgVDCNetwork) resour
return fmt.Errorf("No VAPP ID is set") return fmt.Errorf("No VAPP ID is set")
} }
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
resp, err := conn.OrgVdc.FindVDCNetwork(rs.Primary.ID) resp, err := conn.OrgVdc.FindVDCNetwork(rs.Primary.ID)
if err != nil { if err != nil {
@ -64,7 +64,7 @@ func testAccCheckVcdNetworkExists(n string, network *govcd.OrgVDCNetwork) resour
} }
func testAccCheckVcdNetworkDestroy(s *terraform.State) error { func testAccCheckVcdNetworkDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "vcd_network" { if rs.Type != "vcd_network" {

View File

@ -3,7 +3,6 @@ package vcd
import ( import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hmrc/vmware-govcd"
) )
func resourceVcdSNAT() *schema.Resource { func resourceVcdSNAT() *schema.Resource {
@ -35,7 +34,7 @@ func resourceVcdSNAT() *schema.Resource {
} }
func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error { func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as // Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an // the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client // operation we must wait until we can aquire a lock on the client
@ -51,7 +50,7 @@ func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Unable to find edge gateway: %#v", err) return fmt.Errorf("Unable to find edge gateway: %#v", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := edgeGateway.AddNATMapping("SNAT", d.Get("internal_ip").(string), task, err := edgeGateway.AddNATMapping("SNAT", d.Get("internal_ip").(string),
d.Get("external_ip").(string), d.Get("external_ip").(string),
"any") "any")
@ -69,7 +68,7 @@ func resourceVcdSNATCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdSNATRead(d *schema.ResourceData, meta interface{}) error { func resourceVcdSNATRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
e, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string)) e, err := vcdClient.OrgVdc.FindEdgeGateway(d.Get("edge_gateway").(string))
if err != nil { if err != nil {
@ -94,7 +93,7 @@ func resourceVcdSNATRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdSNATDelete(d *schema.ResourceData, meta interface{}) error { func resourceVcdSNATDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
// Multiple VCD components need to run operations on the Edge Gateway, as // Multiple VCD components need to run operations on the Edge Gateway, as
// the edge gatway will throw back an error if it is already performing an // the edge gatway will throw back an error if it is already performing an
// operation we must wait until we can aquire a lock on the client // operation we must wait until we can aquire a lock on the client
@ -106,7 +105,7 @@ func resourceVcdSNATDelete(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Unable to find edge gateway: %#v", err) return fmt.Errorf("Unable to find edge gateway: %#v", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := edgeGateway.RemoveNATMapping("SNAT", d.Get("internal_ip").(string), task, err := edgeGateway.RemoveNATMapping("SNAT", d.Get("internal_ip").(string),
d.Get("external_ip").(string), d.Get("external_ip").(string),
"") "")

View File

@ -50,7 +50,7 @@ func testAccCheckVcdSNATExists(n string, gateway *govcd.EdgeGateway) resource.Te
return fmt.Errorf("No SNAT ID is set") return fmt.Errorf("No SNAT ID is set")
} }
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
gatewayName := rs.Primary.Attributes["edge_gateway"] gatewayName := rs.Primary.Attributes["edge_gateway"]
edgeGateway, err := conn.OrgVdc.FindEdgeGateway(gatewayName) edgeGateway, err := conn.OrgVdc.FindEdgeGateway(gatewayName)
@ -79,7 +79,7 @@ func testAccCheckVcdSNATExists(n string, gateway *govcd.EdgeGateway) resource.Te
} }
func testAccCheckVcdSNATDestroy(s *terraform.State) error { func testAccCheckVcdSNATDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "vcd_snat" { if rs.Type != "vcd_snat" {
continue continue

View File

@ -3,7 +3,6 @@ package vcd
import ( import (
"fmt" "fmt"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hmrc/vmware-govcd"
types "github.com/hmrc/vmware-govcd/types/v56" types "github.com/hmrc/vmware-govcd/types/v56"
"log" "log"
) )
@ -80,7 +79,7 @@ func resourceVcdVApp() *schema.Resource {
} }
func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error { func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
catalog, err := vcdClient.Org.FindCatalog(d.Get("catalog_name").(string)) catalog, err := vcdClient.Org.FindCatalog(d.Get("catalog_name").(string))
if err != nil { if err != nil {
@ -133,7 +132,7 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
}, },
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
e := vcdClient.OrgVdc.InstantiateVAppTemplate(createvapp) e := vcdClient.OrgVdc.InstantiateVAppTemplate(createvapp)
if e != nil { if e != nil {
@ -152,7 +151,7 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Get("name").(string)) vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Get("name").(string))
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.ChangeVMName(d.Get("name").(string)) task, err := vapp.ChangeVMName(d.Get("name").(string))
if err != nil { if err != nil {
return fmt.Errorf("Error with vm name change: %#v", err) return fmt.Errorf("Error with vm name change: %#v", err)
@ -164,7 +163,7 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error changing vmname: %#v", err) return fmt.Errorf("Error changing vmname: %#v", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.ChangeNetworkConfig(d.Get("network_name").(string), d.Get("ip").(string)) task, err := vapp.ChangeNetworkConfig(d.Get("network_name").(string), d.Get("ip").(string))
if err != nil { if err != nil {
return fmt.Errorf("Error with Networking change: %#v", err) return fmt.Errorf("Error with Networking change: %#v", err)
@ -176,7 +175,7 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
} }
if initscript, ok := d.GetOk("initscript"); ok { if initscript, ok := d.GetOk("initscript"); ok {
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.RunCustomizationScript(d.Get("name").(string), initscript.(string)) task, err := vapp.RunCustomizationScript(d.Get("name").(string), initscript.(string))
if err != nil { if err != nil {
return fmt.Errorf("Error with setting init script: %#v", err) return fmt.Errorf("Error with setting init script: %#v", err)
@ -194,7 +193,7 @@ func resourceVcdVAppCreate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdVAppUpdate(d *schema.ResourceData, meta interface{}) error { func resourceVcdVAppUpdate(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id()) vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
if err != nil { if err != nil {
@ -246,7 +245,7 @@ func resourceVcdVAppUpdate(d *schema.ResourceData, meta interface{}) error {
} }
if d.HasChange("memory") { if d.HasChange("memory") {
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.ChangeMemorySize(d.Get("memory").(int)) task, err := vapp.ChangeMemorySize(d.Get("memory").(int))
if err != nil { if err != nil {
return fmt.Errorf("Error changing memory size: %#v", err) return fmt.Errorf("Error changing memory size: %#v", err)
@ -260,7 +259,7 @@ func resourceVcdVAppUpdate(d *schema.ResourceData, meta interface{}) error {
} }
if d.HasChange("cpus") { if d.HasChange("cpus") {
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.ChangeCPUcount(d.Get("cpus").(int)) task, err := vapp.ChangeCPUcount(d.Get("cpus").(int))
if err != nil { if err != nil {
return fmt.Errorf("Error changing cpu count: %#v", err) return fmt.Errorf("Error changing cpu count: %#v", err)
@ -290,7 +289,7 @@ func resourceVcdVAppUpdate(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdVAppRead(d *schema.ResourceData, meta interface{}) error { func resourceVcdVAppRead(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
err := vcdClient.OrgVdc.Refresh() err := vcdClient.OrgVdc.Refresh()
if err != nil { if err != nil {
@ -309,14 +308,14 @@ func resourceVcdVAppRead(d *schema.ResourceData, meta interface{}) error {
} }
func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error { func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
vcdClient := meta.(*govcd.VCDClient) vcdClient := meta.(*VCDClient)
vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id()) vapp, err := vcdClient.OrgVdc.FindVAppByName(d.Id())
if err != nil { if err != nil {
return fmt.Errorf("error finding vapp: %s", err) return fmt.Errorf("error finding vapp: %s", err)
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Undeploy() task, err := vapp.Undeploy()
if err != nil { if err != nil {
return fmt.Errorf("Error undeploying: %#v", err) return fmt.Errorf("Error undeploying: %#v", err)
@ -328,7 +327,7 @@ func resourceVcdVAppDelete(d *schema.ResourceData, meta interface{}) error {
return err return err
} }
err = retryCall(4, func() error { err = retryCall(vcdClient.MaxRetryTimeout, func() error {
task, err := vapp.Delete() task, err := vapp.Delete()
if err != nil { if err != nil {
return fmt.Errorf("Error deleting: %#v", err) return fmt.Errorf("Error deleting: %#v", err)

View File

@ -59,7 +59,7 @@ func testAccCheckVcdVAppExists(n string, vapp *govcd.VApp) resource.TestCheckFun
return fmt.Errorf("No VAPP ID is set") return fmt.Errorf("No VAPP ID is set")
} }
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
resp, err := conn.OrgVdc.FindVAppByName(rs.Primary.ID) resp, err := conn.OrgVdc.FindVAppByName(rs.Primary.ID)
if err != nil { if err != nil {
@ -73,7 +73,7 @@ func testAccCheckVcdVAppExists(n string, vapp *govcd.VApp) resource.TestCheckFun
} }
func testAccCheckVcdVAppDestroy(s *terraform.State) error { func testAccCheckVcdVAppDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*govcd.VCDClient) conn := testAccProvider.Meta().(*VCDClient)
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "vcd_vapp" { if rs.Type != "vcd_vapp" {

View File

@ -107,6 +107,6 @@ func getPortString(port int) string {
return portstring return portstring
} }
func retryCall(min int, f resource.RetryFunc) error { func retryCall(seconds int, f resource.RetryFunc) error {
return resource.Retry(time.Duration(min)*time.Minute, f) return resource.Retry(time.Duration(seconds)*time.Second, f)
} }