Skip to content

Instantly share code, notes, and snippets.

@deitch
Last active April 23, 2019 07:40
Show Gist options
  • Save deitch/d7bb7015898fb4b9f305fcd67fb4426f to your computer and use it in GitHub Desktop.
Save deitch/d7bb7015898fb4b9f305fcd67fb4426f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os"
"github.com/packethost/packngo"
)
func main() {
apiKey := os.Getenv("PACKET_API_KEY")
projectID := os.Getenv("PACKET_PROJECT_ID")
if apiKey == "" {
fmt.Println("Must have valid api key as env var PACKET_API_KEY")
os.Exit(1)
}
if projectID == "" {
fmt.Println("Must have valid project ID as env var PACKET_PROJECT_ID")
os.Exit(1)
}
client := packngo.NewClientWithAuth("avitest", apiKey, nil)
userdata := "#cloud-config\n"
serverCreateOpts := &packngo.DeviceCreateRequest{
Hostname: "packngo-test",
UserData: userdata,
ProjectID: projectID,
Facility: []string{"ewr1","sjc1","yyz1"},
BillingCycle: "hourly",
Plan: "t1.small.x86",
OS: "centos_7",
}
device, res, err := client.Devices.Create(serverCreateOpts)
if err != nil {
fmt.Printf("Error! err %s\n", err)
fmt.Printf("Error! res %v\n", res)
os.Exit(1)
}
fmt.Printf("Success! Device: %#v\n", device)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment