Compare commits
2 Commits
5d64335135
...
e91a444354
Author | SHA1 | Date | |
---|---|---|---|
|
e91a444354 | ||
|
202814d46c |
51
main.go
Normal file
51
main.go
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
"encoding/json"
|
||||||
|
/*
|
||||||
|
"fmt"
|
||||||
|
*/
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Create a slice to insert the ID of the current droplet
|
||||||
|
url_slice := []string{"https://api.digitalocean.com/v2/droplets/", get_droplet_id("foo"), "/actions"}
|
||||||
|
// Construct the string from the slice
|
||||||
|
droplet_actions_url := strings.Join(url_slice, "")
|
||||||
|
// Create the json object to be posted
|
||||||
|
post_body, _ := json.Marshal(map[string]string{"type": "power_off"})
|
||||||
|
// Open a buffer for the post response body
|
||||||
|
response_body := bytes.NewBuffer(post_body)
|
||||||
|
// instantiate the POST object
|
||||||
|
http_response, err := http.Post(droplet_actions_url, "application/json", response_body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Respones Error: %v", err)
|
||||||
|
}
|
||||||
|
// Pause thread until response is read and http connection closes (I think?)
|
||||||
|
defer http_response.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(response_body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln(err)
|
||||||
|
}
|
||||||
|
// Turn the http response object into a string
|
||||||
|
response_body_string := string(body)
|
||||||
|
log.Printf(response_body_string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_droplet_id(hostname string) string {
|
||||||
|
/*
|
||||||
|
Eventually, the goal is to use droplet tags to group the cluster,
|
||||||
|
use the droplet tags api to list all droplets, differentially
|
||||||
|
identify 'other' nodes with knowledge of our current droplet properties,
|
||||||
|
and finally return the droplet_id that corresponds to the supplied hostname
|
||||||
|
*/
|
||||||
|
|
||||||
|
// var droplet_id string = "253365345"
|
||||||
|
var droplet_id string = "253365347"
|
||||||
|
return droplet_id
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user