provider/opc: Add debug logging

Adds debug logging, fixes a failing instance acceptance test, and updates vendored dep
This commit is contained in:
Jake Champlin 2017-04-06 13:59:16 -04:00
parent 86a87d8b24
commit 3433850c9c
No known key found for this signature in database
GPG Key ID: DC31F41958EF4AC2
7 changed files with 31 additions and 7 deletions

View File

@ -2,11 +2,14 @@ package opc
import (
"fmt"
"net/http"
"log"
"net/url"
"strings"
"github.com/fsouza/go-dockerclient/external/github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-oracle-terraform/compute"
"github.com/hashicorp/go-oracle-terraform/opc"
"github.com/hashicorp/terraform/helper/logging"
)
type Config struct {
@ -33,9 +36,26 @@ func (c *Config) Client() (*compute.Client, error) {
Username: &c.User,
Password: &c.Password,
APIEndpoint: u,
HTTPClient: http.DefaultClient,
HTTPClient: cleanhttp.DefaultClient(),
}
if logging.IsDebugOrHigher() {
config.LogLevel = opc.LogDebug
config.Logger = opcLogger{}
}
// TODO: http client wrapping / log level
return compute.NewComputeClient(&config)
}
type opcLogger struct{}
func (l opcLogger) Log(args ...interface{}) {
tokens := make([]string, 0, len(args))
for _, arg := range args {
if token, ok := arg.(string); ok {
tokens = append(tokens, token)
}
}
log.Printf("[DEBUG] [go-oracle-terraform]: %s", strings.Join(tokens, " "))
}

View File

@ -36,6 +36,7 @@ func Provider() terraform.ResourceProvider {
Description: "The HTTP endpoint for OPC API operations.",
},
// TODO Actually implement this
"max_retry_timeout": {
Type: schema.TypeInt,
Optional: true,

View File

@ -188,7 +188,7 @@ resource "opc_compute_instance" "test" {
image_list = "/oracle/public/oel_6.7_apaas_16.4.5_1610211300"
instance_attributes = <<JSON
{
"foo" = "bar"
"foo": "bar"
}
JSON
}`, rInt)

View File

@ -44,6 +44,8 @@ func NewComputeClient(c *opc.Config) (*Client, error) {
// Setup logger; defaults to stdout
if c.Logger == nil {
client.logger = opc.NewDefaultLogger()
} else {
client.logger = c.Logger
}
// If LogLevel was not set to something different,

View File

@ -13,7 +13,7 @@ func (c *Client) debugLogString(str string) {
if c.loglevel != opc.LogDebug {
return
}
c.logger.Log(fmt.Sprintf("[DEBUG]: %s", str))
c.logger.Log(str)
}
func (c *Client) debugLogReq(req *http.Request) {

View File

@ -187,6 +187,7 @@ type GetStorageVolumeInput struct {
}
func (c *StorageVolumeClient) success(result *StorageVolumeInfo) (*StorageVolumeInfo, error) {
c.unqualify(&result.ImageList)
c.unqualify(&result.Name)
c.unqualify(&result.Snapshot)

6
vendor/vendor.json vendored
View File

@ -1970,10 +1970,10 @@
"revision": "d30f09973e19c1dfcd120b2d9c4f168e68d6b5d5"
},
{
"checksumSHA1": "mVLpbxsm+8TlXKgkezrh3c5I7+4=",
"checksumSHA1": "QmBTE/boTriUYw0meIg7xOXo6ns=",
"path": "github.com/hashicorp/go-oracle-terraform/compute",
"revision": "381402af3554bcca5fa7eeda94d47003e6ba7ee7",
"revisionTime": "2017-04-06T04:33:22Z"
"revision": "5508daed82ecd55b71d45e8a149e99d24825e5bb",
"revisionTime": "2017-04-06T17:51:51Z"
},
{
"checksumSHA1": "DzK7lYwHt5Isq5Zf73cnQqBO2LI=",