Files
Packer-Cn/vendor/github.com/joyent/triton-go/network/network.go
T
stack72 b04796c2cc Bump Joyent/triton-go to modern version of the SDK
This brings packer into the same version of triton-go as that in Terraform, where we rewrote the package from a library with everything in 1 place to individual packages

I was able to successfully provision a machine on triton using this new change, you can find the output in the attached gist

https://gist.github.com/stack72/a64d745459107c5a16bcb156965597ce
2017-10-31 18:08:53 +02:00

79 lines
2.2 KiB
Go

package network
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/hashicorp/errwrap"
"github.com/joyent/triton-go/client"
)
type Network struct {
Id string `json:"id"`
Name string `json:"name"`
Public bool `json:"public"`
Fabric bool `json:"fabric"`
Description string `json:"description"`
Subnet string `json:"subnet"`
ProvisioningStartIP string `json:"provision_start_ip"`
ProvisioningEndIP string `json:"provision_end_ip"`
Gateway string `json:"gateway"`
Resolvers []string `json:"resolvers"`
Routes map[string]string `json:"routes"`
InternetNAT bool `json:"internet_nat"`
}
type ListInput struct{}
func (c *NetworkClient) List(ctx context.Context, _ *ListInput) ([]*Network, error) {
path := fmt.Sprintf("/%s/networks", c.Client.AccountName)
reqInputs := client.RequestInput{
Method: http.MethodGet,
Path: path,
}
respReader, err := c.Client.ExecuteRequest(ctx, reqInputs)
if respReader != nil {
defer respReader.Close()
}
if err != nil {
return nil, errwrap.Wrapf("Error executing ListNetworks request: {{err}}", err)
}
var result []*Network
decoder := json.NewDecoder(respReader)
if err = decoder.Decode(&result); err != nil {
return nil, errwrap.Wrapf("Error decoding ListNetworks response: {{err}}", err)
}
return result, nil
}
type GetInput struct {
ID string
}
func (c *NetworkClient) Get(ctx context.Context, input *GetInput) (*Network, error) {
path := fmt.Sprintf("/%s/networks/%s", c.Client.AccountName, input.ID)
reqInputs := client.RequestInput{
Method: http.MethodGet,
Path: path,
}
respReader, err := c.Client.ExecuteRequest(ctx, reqInputs)
if respReader != nil {
defer respReader.Close()
}
if err != nil {
return nil, errwrap.Wrapf("Error executing GetNetwork request: {{err}}", err)
}
var result *Network
decoder := json.NewDecoder(respReader)
if err = decoder.Decode(&result); err != nil {
return nil, errwrap.Wrapf("Error decoding GetNetwork response: {{err}}", err)
}
return result, nil
}