Skip to content

Commit

Permalink
Merge pull request #53 from StackPointCloud/packet
Browse files Browse the repository at this point in the history
Packet documentation
  • Loading branch information
pearkes authored Jul 17, 2018
2 parents 20d4345 + f8ca019 commit 09fcce7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function.
* SoftLayer [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/softlayer/softlayer_discover.go#L16-L25)
* Triton [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/triton/triton_discover.go#L17-L27)
* vSphere [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/vsphere/vsphere_discover.go#L148-L155)
* Packet [Config options](https://github.com/hashicorp/go-discover/blob/master/provider/packet/packet_discover.go#L25-L35)

HashiCorp maintains acceptance tests that regularly allocate and run tests with
real resources to verify the behavior of several of these providers. Those
Expand Down Expand Up @@ -68,6 +69,9 @@ provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_
# vSphere
provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false]
# Packet
provider=packet auth_token=token project=uuid url=... address_type=...
```

## Command Line Tool Usage
Expand Down
25 changes: 15 additions & 10 deletions provider/packet/packet_discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ func (p *Provider) SetUserAgent(s string) {
// Help function
func (p *Provider) Help() string {
return `Packet:
provider: "packet"
packet_project: UUID of packet project
packet_url: Packet REST URL
packet_auth_token: Packet authentication token
address_type: "private_v4", "public_v4" or "public_v6". Defaults to "private_v4".
`
provider: "packet"
project: UUID of packet project. Required
auth_token: Packet authentication token. Required
url: Packet REST URL. Optional
address_type: "private_v4", "public_v4" or "public_v6". Defaults to "private_v4". Optional
Variables can also be provided by environmental variables:
export PACKET_PROJECT for project
export PACKET_URL for url
export PACKET_AUTH_TOKEN for auth_token
`
}

// Addrs function
func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) {
authToken := argsOrEnv(args, "packet_auth_token", "PACKET_AUTH_TOKEN")
projectID := argsOrEnv(args, "packet_project", "PACKET_PROJECT")
packetURL := argsOrEnv(args, "packet_url", "PACKET_URL")
authToken := argsOrEnv(args, "auth_token", "PACKET_AUTH_TOKEN")
projectID := argsOrEnv(args, "project", "PACKET_PROJECT")
packetURL := argsOrEnv(args, "url", "PACKET_URL")
addressType := args["address_type"]

if addressType != "private_v4" && addressType != "public_v4" && addressType != "public_v6" {
Expand All @@ -51,7 +56,7 @@ func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error
var devices []packngo.Device

if projectID == "" {
return nil, fmt.Errorf("discover-packet: 'packet_project' parameter must be provider")
return nil, fmt.Errorf("discover-packet: 'project' parameter must be provider")
}

devices, _, err = c.Devices.List(projectID, nil)
Expand Down
34 changes: 17 additions & 17 deletions provider/packet/packet_discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ var _ discover.ProviderWithUserAgent = (*packet.Provider)(nil)

func TestAddrsDefault(t *testing.T) {
args := discover.Config{
"provider": "packet",
"packet_auth_token": os.Getenv("PACKET_TOKEN"),
"packet_project": os.Getenv("PACKET_PROJECT"),
"provider": "packet",
"auth_token": os.Getenv("PACKET_TOKEN"),
"project": os.Getenv("PACKET_PROJECT"),
}

if args["packet_auth_token"] == "" {
if args["auth_token"] == "" {
t.Skip("Packet credentials missing")
}

if args["packet_project"] == "" {
if args["project"] == "" {
t.Skip("Packet project UUID missing")
}

Expand All @@ -43,17 +43,17 @@ func TestAddrsDefault(t *testing.T) {

func TestAddrsPublicV6(t *testing.T) {
args := discover.Config{
"provider": "packet",
"packet_auth_token": os.Getenv("PACKET_TOKEN"),
"packet_project": os.Getenv("PACKET_PROJECT"),
"address_type": "public_v6",
"provider": "packet",
"auth_token": os.Getenv("PACKET_TOKEN"),
"project": os.Getenv("PACKET_PROJECT"),
"address_type": "public_v6",
}

if args["packet_auth_token"] == "" {
if args["auth_token"] == "" {
t.Skip("Packet credentials missing")
}

if args["packet_project"] == "" {
if args["project"] == "" {
t.Skip("Packet project UUID missing")
}

Expand All @@ -73,17 +73,17 @@ func TestAddrsPublicV6(t *testing.T) {

func TestAddrsPublicV4(t *testing.T) {
args := discover.Config{
"provider": "packet",
"packet_auth_token": os.Getenv("PACKET_TOKEN"),
"packet_project": os.Getenv("PACKET_PROJECT"),
"address_type": "public_v4",
"provider": "packet",
"auth_token": os.Getenv("PACKET_TOKEN"),
"project": os.Getenv("PACKET_PROJECT"),
"address_type": "public_v4",
}

if args["packet_auth_token"] == "" {
if args["auth_token"] == "" {
t.Skip("Packet credentials missing")
}

if args["packet_project"] == "" {
if args["project"] == "" {
t.Skip("Packet project UUID missing")
}

Expand Down

0 comments on commit 09fcce7

Please sign in to comment.