Fix general comments by @phinze

This commit is contained in:
Julien Vey 2015-03-24 13:59:55 +01:00 committed by Jon Perritt
parent f011462e30
commit 2e37784065
17 changed files with 67 additions and 300 deletions

View File

@ -111,7 +111,7 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{}
Metadata: resourceContainerMetadataV2(d),
}
log.Printf("[INFO] Requesting volume creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
v, err := volumes.Create(blockStorageClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack volume: %s", err)
@ -156,48 +156,15 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{})
return CheckDeleted(d, err, "volume")
}
log.Printf("\n\ngot volume: %+v\n\n", v)
log.Printf("[DEBUG] Retreived volume %s: %+v", d.Id(), v)
d.Set("region", d.Get("region").(string))
d.Set("size", v.Size)
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", v.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", v.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("snapshot_id"); exists && t != "" {
d.Set("snapshot_id", v.SnapshotID)
} else {
d.Set("snapshot_id", "")
}
if t, exists := d.GetOk("source_vol_id"); exists && t != "" {
d.Set("source_vol_id", v.SourceVolID)
} else {
d.Set("source_vol_id", "")
}
if t, exists := d.GetOk("volume_type"); exists && t != "" {
d.Set("volume_type", v.VolumeType)
} else {
d.Set("volume_type", "")
}
if t, exists := d.GetOk("metadata"); exists && t != "" {
d.Set("metadata", v.Metadata)
} else {
d.Set("metadata", "")
}
d.Set("description", v.Description)
d.Set("name", v.Name)
d.Set("snapshot_id", v.SnapshotID)
d.Set("source_vol_id", v.SourceVolID)
d.Set("volume_type", v.VolumeType)
d.Set("metadata", v.Metadata)
if len(v.Attachments) > 0 {
attachments := make([]map[string]interface{}, len(v.Attachments))

View File

@ -30,12 +30,6 @@ func resourceComputeFloatingIPV2() *schema.Resource {
DefaultFunc: envDefaultFunc("OS_POOL_NAME"),
},
// exported
"id": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},
"address": &schema.Schema{
Type: schema.TypeString,
Computed: true,
@ -64,6 +58,7 @@ func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{})
createOpts := &floatingip.CreateOpts{
Pool: d.Get("pool").(string),
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
newFip, err := floatingip.Create(computeClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating Floating IP: %s", err)
@ -88,8 +83,6 @@ func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Retrieved Floating IP %s: %+v", d.Id(), fip)
d.Set("id", d.Id())
d.Set("region", d.Get("region").(string))
d.Set("pool", fip.Pool)
d.Set("instance_id", fip.InstanceID)
d.Set("address", fip.IP)

View File

@ -241,7 +241,7 @@ func resourceComputeInstanceV2Create(d *schema.ResourceData, meta interface{}) e
}
}
log.Printf("[INFO] Requesting instance creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
server, err := servers.Create(computeClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack server: %s", err)
@ -320,7 +320,6 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
log.Printf("[DEBUG] Retreived Server %s: %+v", d.Id(), server)
d.Set("region", d.Get("region").(string))
d.Set("name", server.Name)
d.Set("access_ip_v4", server.AccessIPv4)
d.Set("access_ip_v6", server.AccessIPv6)
@ -360,7 +359,7 @@ func resourceComputeInstanceV2Read(d *schema.ResourceData, meta interface{}) err
publicAddresses := publicAddressesRaw.([]interface{})
for _, paRaw := range publicAddresses {
pa := paRaw.(map[string]interface{})
if pa["version"].(float64) == 4 {
if pa["version"].(float64) == 6 {
hostv6 = fmt.Sprintf("[%s]", pa["addr"].(string))
break
}
@ -594,6 +593,7 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
resizeOpts := &servers.ResizeOpts{
FlavorRef: flavorId,
}
log.Printf("[DEBUG] Resize configuration: %#v", resizeOpts)
err = servers.Resize(computeClient, d.Id(), resizeOpts).ExtractErr()
if err != nil {
return fmt.Errorf("Error resizing OpenStack server: %s", err)

View File

@ -2,6 +2,7 @@ package openstack
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs"
@ -46,6 +47,7 @@ func resourceComputeKeypairV2Create(d *schema.ResourceData, meta interface{}) er
PublicKey: d.Get("public_key").(string),
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
kp, err := keypairs.Create(computeClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack keypair: %s", err)
@ -68,7 +70,6 @@ func resourceComputeKeypairV2Read(d *schema.ResourceData, meta interface{}) erro
return CheckDeleted(d, err, "keypair")
}
d.Set("region", d.Get("region").(string))
d.Set("name", kp.Name)
d.Set("public_key", kp.PublicKey)

View File

@ -94,6 +94,7 @@ func resourceComputeSecGroupV2Create(d *schema.ResourceData, meta interface{}) e
Description: d.Get("description").(string),
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
sg, err := secgroups.Create(computeClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack security group: %s", err)
@ -124,7 +125,6 @@ func resourceComputeSecGroupV2Read(d *schema.ResourceData, meta interface{}) err
return CheckDeleted(d, err, "security group")
}
d.Set("region", d.Get("region").(string))
d.Set("name", sg.Name)
d.Set("description", sg.Description)
rtm := rulesToMap(sg.Rules)

View File

@ -109,35 +109,11 @@ func resourceFWFirewallV1Read(d *schema.ResourceData, meta interface{}) error {
return CheckDeleted(d, err, "LB pool")
}
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", firewall.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", firewall.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("policy_id"); exists && t != "" {
d.Set("policy_id", firewall.PolicyID)
} else {
d.Set("policy_id", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", firewall.AdminStateUp)
} else {
d.Set("admin_state_up", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", firewall.TenantID)
} else {
d.Set("tenant_id", "")
}
d.Set("name", firewall.Name)
d.Set("description", firewall.Description)
d.Set("policy_id", firewall.PolicyID)
d.Set("admin_state_up", firewall.AdminStateUp)
d.Set("tenant_id", firewall.TenantID)
return nil
}

View File

@ -97,7 +97,7 @@ func resourceFWPolicyV1Create(d *schema.ResourceData, meta interface{}) error {
return err
}
log.Printf("[DEBUG] Firewall policy craeted: %#v", policy)
log.Printf("[DEBUG] Firewall policy created: %#v", policy)
d.SetId(policy.ID)
@ -119,36 +119,11 @@ func resourceFWPolicyV1Read(d *schema.ResourceData, meta interface{}) error {
return CheckDeleted(d, err, "LB pool")
}
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", policy.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", policy.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("shared"); exists && t != "" {
d.Set("shared", policy.Shared)
} else {
d.Set("shared", "")
}
if t, exists := d.GetOk("audited"); exists && t != "" {
d.Set("audited", policy.Audited)
} else {
d.Set("audited", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", policy.TenantID)
} else {
d.Set("tenant_id", "")
}
d.Set("name", policy.Name)
d.Set("description", policy.Description)
d.Set("shared", policy.Shared)
d.Set("audited", policy.Audited)
d.Set("tenant_id", policy.TenantID)
return nil
}

View File

@ -131,53 +131,14 @@ func resourceFWRuleV1Read(d *schema.ResourceData, meta interface{}) error {
d.Set("protocol", rule.Protocol)
d.Set("action", rule.Action)
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", rule.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("description"); exists && t != "" {
d.Set("description", rule.Description)
} else {
d.Set("description", "")
}
if t, exists := d.GetOk("ip_version"); exists && t != "" {
d.Set("ip_version", rule.IPVersion)
} else {
d.Set("ip_version", "")
}
if t, exists := d.GetOk("source_ip_address"); exists && t != "" {
d.Set("source_ip_address", rule.SourceIPAddress)
} else {
d.Set("source_ip_address", "")
}
if t, exists := d.GetOk("destination_ip_address"); exists && t != "" {
d.Set("destination_ip_address", rule.DestinationIPAddress)
} else {
d.Set("destination_ip_address", "")
}
if t, exists := d.GetOk("source_port"); exists && t != "" {
d.Set("source_port", rule.SourcePort)
} else {
d.Set("source_port", "")
}
if t, exists := d.GetOk("destination_port"); exists && t != "" {
d.Set("destination_port", rule.DestinationPort)
} else {
d.Set("destination_port", "")
}
if t, exists := d.GetOk("enabled"); exists && t != "" {
d.Set("enabled", rule.Enabled)
} else {
d.Set("enabled", "")
}
d.Set("name", rule.Name)
d.Set("description", rule.Description)
d.Set("ip_version", rule.IPVersion)
d.Set("source_ip_address", rule.SourceIPAddress)
d.Set("destination_ip_address", rule.DestinationIPAddress)
d.Set("source_port", rule.SourcePort)
d.Set("destination_port", rule.DestinationPort)
d.Set("enabled", rule.Enabled)
return nil
}

View File

@ -99,7 +99,7 @@ func resourceLBMonitorV1Create(d *schema.ResourceData, meta interface{}) error {
createOpts.AdminStateUp = &asu
}
log.Printf("[INFO] Requesting lb monitor creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
m, err := monitors.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack LB Monitor: %s", err)
@ -125,41 +125,15 @@ func resourceLBMonitorV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retreived OpenStack LB Monitor %s: %+v", d.Id(), m)
d.Set("region", d.Get("region").(string))
d.Set("type", m.Type)
d.Set("delay", m.Delay)
d.Set("timeout", m.Timeout)
d.Set("max_retries", m.MaxRetries)
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", m.TenantID)
} else {
d.Set("tenant_id", "")
}
if t, exists := d.GetOk("url_path"); exists && t != "" {
d.Set("url_path", m.URLPath)
} else {
d.Set("url_path", "")
}
if t, exists := d.GetOk("http_method"); exists && t != "" {
d.Set("http_method", m.HTTPMethod)
} else {
d.Set("http_method", "")
}
if t, exists := d.GetOk("expected_codes"); exists && t != "" {
d.Set("expected_codes", m.ExpectedCodes)
} else {
d.Set("expected_codes", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}
d.Set("tenant_id", m.TenantID)
d.Set("url_path", m.URLPath)
d.Set("http_method", m.HTTPMethod)
d.Set("expected_codes", m.ExpectedCodes)
d.Set("admin_state_up", strconv.FormatBool(m.AdminStateUp))
return nil
}

View File

@ -115,7 +115,7 @@ func resourceLBPoolV1Create(d *schema.ResourceData, meta interface{}) error {
TenantID: d.Get("tenant_id").(string),
}
log.Printf("[INFO] Requesting lb pool creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
p, err := pools.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack LB pool: %s", err)
@ -159,18 +159,11 @@ func resourceLBPoolV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retreived OpenStack LB Pool %s: %+v", d.Id(), p)
d.Set("region", d.Get("region").(string))
d.Set("name", p.Name)
d.Set("protocol", p.Protocol)
d.Set("subnet_id", p.SubnetID)
d.Set("lb_method", p.LBMethod)
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", p.TenantID)
} else {
d.Set("tenant_id", "")
}
d.Set("tenant_id", p.TenantID)
d.Set("monitor_ids", p.MonitorIDs)
d.Set("member_ids", p.MemberIDs)

View File

@ -112,7 +112,7 @@ func resourceLBVipV1Create(d *schema.ResourceData, meta interface{}) error {
createOpts.AdminStateUp = &asu
}
log.Printf("[INFO] Requesting lb vip creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
p, err := vips.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack LB VIP: %s", err)
@ -138,7 +138,6 @@ func resourceLBVipV1Read(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG] Retreived OpenStack LB VIP %s: %+v", d.Id(), p)
d.Set("region", d.Get("region").(string))
d.Set("name", p.Name)
d.Set("subnet_id", p.SubnetID)
d.Set("protocol", p.Protocol)

View File

@ -2,6 +2,7 @@ package openstack
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
@ -49,9 +50,11 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
if len(poolID) == 0 {
return fmt.Errorf("No network found with name: %s", d.Get("pool").(string))
}
floatingIP, err := floatingips.Create(networkClient, floatingips.CreateOpts{
createOpts := floatingips.CreateOpts{
FloatingNetworkID: poolID,
}).Extract()
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
floatingIP, err := floatingips.Create(networkClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error allocating floating IP: %s", err)
}
@ -73,7 +76,6 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
return CheckDeleted(d, err, "floating IP")
}
d.Set("region", d.Get("region").(string))
d.Set("address", floatingIP.FloatingIP)
poolName, err := getNetworkName(d, meta, floatingIP.FloatingNetworkID)
if err != nil {

View File

@ -77,7 +77,7 @@ func resourceNetworkingNetworkV2Create(d *schema.ResourceData, meta interface{})
createOpts.Shared = &shared
}
log.Printf("[INFO] Requesting network creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
n, err := networks.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron network: %s", err)
@ -103,31 +103,10 @@ func resourceNetworkingNetworkV2Read(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Retreived Network %s: %+v", d.Id(), n)
d.Set("region", d.Get("region").(string))
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", n.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}
if t, exists := d.GetOk("shared"); exists && t != "" {
d.Set("shared", strconv.FormatBool(n.Shared))
} else {
d.Set("shared", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", n.TenantID)
} else {
d.Set("tenant_id", "")
}
d.Set("name", n.Name)
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
d.Set("shared", strconv.FormatBool(n.Shared))
d.Set("tenant_id", n.TenantID)
return nil
}

View File

@ -48,7 +48,7 @@ func resourceNetworkingRouterInterfaceV2Create(d *schema.ResourceData, meta inte
SubnetID: d.Get("subnet_id").(string),
}
log.Printf("[INFO] Requesting router interface creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
n, err := routers.AddInterface(networkingClient, d.Get("router_id").(string), createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron router interface: %s", err)
@ -83,8 +83,6 @@ func resourceNetworkingRouterInterfaceV2Read(d *schema.ResourceData, meta interf
log.Printf("[DEBUG] Retreived Router Interface %s: %+v", d.Id(), n)
d.Set("region", d.Get("region").(string))
return nil
}

View File

@ -77,7 +77,7 @@ func resourceNetworkingRouterV2Create(d *schema.ResourceData, meta interface{})
createOpts.GatewayInfo = &gatewayInfo
}
log.Printf("[INFO] Requesting router creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
n, err := routers.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron router: %s", err)
@ -112,31 +112,10 @@ func resourceNetworkingRouterV2Read(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Retreived Router %s: %+v", d.Id(), n)
d.Set("region", d.Get("region").(string))
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", n.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("admin_state_up"); exists && t != "" {
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
} else {
d.Set("admin_state_up", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", n.TenantID)
} else {
d.Set("tenant_id", "")
}
if t, exists := d.GetOk("external_gateway"); exists && t != "" {
d.Set("external_gateway", n.GatewayInfo.NetworkID)
} else {
d.Set("external_gateway", "")
}
d.Set("name", n.Name)
d.Set("admin_state_up", strconv.FormatBool(n.AdminStateUp))
d.Set("tenant_id", n.TenantID)
d.Set("external_gateway", n.GatewayInfo.NetworkID)
return nil
}

View File

@ -134,7 +134,7 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
createOpts.EnableDHCP = &ed
}
log.Printf("[INFO] Requesting subnet creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
s, err := subnets.Create(networkingClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack Neutron subnet: %s", err)
@ -160,46 +160,16 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
log.Printf("[DEBUG] Retreived Subnet %s: %+v", d.Id(), s)
d.Set("region", d.Get("region").(string))
d.Set("newtork_id", s.NetworkID)
d.Set("cidr", s.CIDR)
d.Set("ip_version", s.IPVersion)
if t, exists := d.GetOk("name"); exists && t != "" {
d.Set("name", s.Name)
} else {
d.Set("name", "")
}
if t, exists := d.GetOk("tenant_id"); exists && t != "" {
d.Set("tenant_id", s.TenantID)
} else {
d.Set("tenant_id", "")
}
if _, exists := d.GetOk("allocation_pools"); exists {
d.Set("allocation_pools", s.AllocationPools)
}
if t, exists := d.GetOk("gateway_ip"); exists && t != "" {
d.Set("gateway_ip", s.GatewayIP)
} else {
d.Set("gateway_ip", "")
}
if t, exists := d.GetOk("enable_dhcp"); exists && t != "" {
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
} else {
d.Set("enable_dhcp", "")
}
if _, exists := d.GetOk("dns_nameservers"); exists {
d.Set("dns_nameservers", s.DNSNameservers)
}
if _, exists := d.GetOk("host_routes"); exists {
d.Set("host_routes", s.HostRoutes)
}
d.Set("name", s.Name)
d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP)
d.Set("enable_dhcp", strconv.FormatBool(s.EnableDHCP))
d.Set("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes)
return nil
}

View File

@ -79,7 +79,7 @@ func resourceObjectStorageContainerV1Create(d *schema.ResourceData, meta interfa
Metadata: resourceContainerMetadataV2(d),
}
log.Printf("[INFO] Requesting container creation")
log.Printf("[DEBUG] Create Options: %#v", createOpts)
_, err = containers.Create(objectStorageClient, cn, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating OpenStack container: %s", err)