Last active
April 23, 2019 07:40
-
-
Save deitch/d7bb7015898fb4b9f305fcd67fb4426f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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