Skip to content

Commit

Permalink
Merge pull request #9407 from jtopjian/gophercloud-migration
Browse files Browse the repository at this point in the history
provider/openstack: Gophercloud Migration
  • Loading branch information
jtopjian authored Oct 23, 2016
2 parents 18308dd + 27c59bf commit a148180
Show file tree
Hide file tree
Showing 220 changed files with 15,874 additions and 795 deletions.
6 changes: 2 additions & 4 deletions builtin/providers/openstack/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import (
"io/ioutil"
"net/http"

"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack"
)

type Config struct {
Username string
UserID string
Password string
Token string
APIKey string
IdentityEndpoint string
TenantID string
TenantName string
Expand Down Expand Up @@ -45,7 +44,6 @@ func (c *Config) loadAndValidate() error {
UserID: c.UserID,
Password: c.Password,
TokenID: c.Token,
APIKey: c.APIKey,
IdentityEndpoint: c.IdentityEndpoint,
TenantID: c.TenantID,
TenantName: c.TenantName,
Expand Down
6 changes: 0 additions & 6 deletions builtin/providers/openstack/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ func Provider() terraform.ResourceProvider {
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("OS_AUTH_TOKEN", ""),
},
"api_key": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("OS_API_KEY", ""),
},
"domain_id": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -133,7 +128,6 @@ func configureProvider(d *schema.ResourceData) (interface{}, error) {
UserID: d.Get("user_id").(string),
Password: d.Get("password").(string),
Token: d.Get("token").(string),
APIKey: d.Get("api_key").(string),
TenantID: d.Get("tenant_id").(string),
TenantName: d.Get("tenant_name").(string),
DomainID: d.Get("domain_id").(string),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"log"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
)

func resourceBlockStorageVolumeV1() *schema.Resource {
Expand Down Expand Up @@ -169,7 +169,7 @@ func resourceBlockStorageVolumeV1Read(d *schema.ResourceData, meta interface{})
return CheckDeleted(d, err, "volume")
}

log.Printf("[DEBUG] Retreived volume %s: %+v", d.Id(), v)
log.Printf("[DEBUG] Retrieved volume %s: %+v", d.Id(), v)

d.Set("size", v.Size)
d.Set("description", v.Description)
Expand Down Expand Up @@ -306,11 +306,7 @@ func VolumeV1StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return func() (interface{}, string, error) {
v, err := volumes.Get(client, volumeID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return nil, "", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return v, "deleted", nil
}
return nil, "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/blockstorage/v1/volumes"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes"
)

func TestAccBlockStorageV1Volume_basic(t *testing.T) {
Expand Down Expand Up @@ -117,13 +117,10 @@ func testAccCheckBlockStorageV1VolumeDoesNotExist(t *testing.T, n string, volume

_, err = volumes.Get(blockStorageClient, volume.ID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}

return err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"log"
"time"

"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/blockstorage/v2/volumes"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/volumeattach"
)

func resourceBlockStorageVolumeV2() *schema.Resource {
Expand Down Expand Up @@ -181,7 +181,7 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{})
return CheckDeleted(d, err, "volume")
}

log.Printf("[DEBUG] Retreived volume %s: %+v", d.Id(), v)
log.Printf("[DEBUG] Retrieved volume %s: %+v", d.Id(), v)

d.Set("size", v.Size)
d.Set("description", v.Description)
Expand All @@ -195,9 +195,9 @@ func resourceBlockStorageVolumeV2Read(d *schema.ResourceData, meta interface{})
attachments := make([]map[string]interface{}, len(v.Attachments))
for i, attachment := range v.Attachments {
attachments[i] = make(map[string]interface{})
attachments[i]["id"] = attachment["id"]
attachments[i]["instance_id"] = attachment["server_id"]
attachments[i]["device"] = attachment["device"]
attachments[i]["id"] = attachment.ID
attachments[i]["instance_id"] = attachment.ServerID
attachments[i]["device"] = attachment.Device
log.Printf("[DEBUG] attachment: %v", attachment)
}
d.Set("attachment", attachments)
Expand Down Expand Up @@ -249,7 +249,7 @@ func resourceBlockStorageVolumeV2Delete(d *schema.ResourceData, meta interface{}
} else {
for _, volumeAttachment := range v.Attachments {
log.Printf("[DEBUG] Attachment: %v", volumeAttachment)
if err := volumeattach.Delete(computeClient, volumeAttachment["server_id"].(string), volumeAttachment["id"].(string)).ExtractErr(); err != nil {
if err := volumeattach.Delete(computeClient, volumeAttachment.ServerID, volumeAttachment.ID).ExtractErr(); err != nil {
return err
}
}
Expand Down Expand Up @@ -318,11 +318,7 @@ func VolumeV2StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string
return func() (interface{}, string, error) {
v, err := volumes.Get(client, volumeID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return nil, "", err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return v, "deleted", nil
}
return nil, "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/blockstorage/v2/volumes"
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes"
)

func TestAccBlockStorageV2Volume_basic(t *testing.T) {
Expand Down Expand Up @@ -130,11 +130,7 @@ func testAccCheckBlockStorageV2VolumeDoesNotExist(t *testing.T, n string, volume

_, err = volumes.Get(blockStorageClient, volume.ID).Extract()
if err != nil {
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
if !ok {
return err
}
if errCode.Actual == 404 {
if _, ok := err.(gophercloud.ErrDefault404); ok {
return nil
}
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"log"

"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
"github.com/hashicorp/terraform/helper/schema"
"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip"
)

func resourceComputeFloatingIPV2() *schema.Resource {
Expand Down Expand Up @@ -58,11 +58,11 @@ func resourceComputeFloatingIPV2Create(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

createOpts := &floatingip.CreateOpts{
createOpts := &floatingips.CreateOpts{
Pool: d.Get("pool").(string),
}
log.Printf("[DEBUG] Create Options: %#v", createOpts)
newFip, err := floatingip.Create(computeClient, createOpts).Extract()
newFip, err := floatingips.Create(computeClient, createOpts).Extract()
if err != nil {
return fmt.Errorf("Error creating Floating IP: %s", err)
}
Expand All @@ -79,7 +79,7 @@ func resourceComputeFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
return fmt.Errorf("Error creating OpenStack compute client: %s", err)
}

fip, err := floatingip.Get(computeClient, d.Id()).Extract()
fip, err := floatingips.Get(computeClient, d.Id()).Extract()
if err != nil {
return CheckDeleted(d, err, "floating ip")
}
Expand All @@ -102,7 +102,7 @@ func resourceComputeFloatingIPV2Delete(d *schema.ResourceData, meta interface{})
}

log.Printf("[DEBUG] Deleting Floating IP %s", d.Id())
if err := floatingip.Delete(computeClient, d.Id()).ExtractErr(); err != nil {
if err := floatingips.Delete(computeClient, d.Id()).ExtractErr(); err != nil {
return fmt.Errorf("Error deleting Floating IP: %s", err)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"

"github.com/rackspace/gophercloud/openstack/compute/v2/extensions/floatingip"
"github.com/rackspace/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
)

func TestAccComputeV2FloatingIP_basic(t *testing.T) {
var floatingIP floatingip.FloatingIP
var floatingIP floatingips.FloatingIP

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -32,7 +32,7 @@ func TestAccComputeV2FloatingIP_basic(t *testing.T) {

func TestAccComputeV2FloatingIP_attach(t *testing.T) {
var instance servers.Server
var fip floatingip.FloatingIP
var fip floatingips.FloatingIP
var testAccComputeV2FloatingIP_attach = fmt.Sprintf(`
resource "openstack_compute_floatingip_v2" "myip" {
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func testAccCheckComputeV2FloatingIPDestroy(s *terraform.State) error {
continue
}

_, err := floatingip.Get(computeClient, rs.Primary.ID).Extract()
_, err := floatingips.Get(computeClient, rs.Primary.ID).Extract()
if err == nil {
return fmt.Errorf("FloatingIP still exists")
}
Expand All @@ -86,7 +86,7 @@ func testAccCheckComputeV2FloatingIPDestroy(s *terraform.State) error {
return nil
}

func testAccCheckComputeV2FloatingIPExists(t *testing.T, n string, kp *floatingip.FloatingIP) resource.TestCheckFunc {
func testAccCheckComputeV2FloatingIPExists(t *testing.T, n string, kp *floatingips.FloatingIP) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand All @@ -103,7 +103,7 @@ func testAccCheckComputeV2FloatingIPExists(t *testing.T, n string, kp *floatingi
return fmt.Errorf("(testAccCheckComputeV2FloatingIPExists) Error creating OpenStack compute client: %s", err)
}

found, err := floatingip.Get(computeClient, rs.Primary.ID).Extract()
found, err := floatingips.Get(computeClient, rs.Primary.ID).Extract()
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit a148180

Please sign in to comment.