mirror of https://github.com/docker/docs.git
add create command
This commit is contained in:
parent
05e95dfc7e
commit
45ca8472f1
|
@ -3,6 +3,7 @@ package discovery
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
@ -38,3 +39,13 @@ func RegisterSlave(addr, token string) error {
|
|||
_, err := http.Post(fmt.Sprintf("%s/%s/%s", DISCOVERY_URL, "clusters", token), "application/json", buf)
|
||||
return err
|
||||
}
|
||||
|
||||
// CreateCluster returns a unique cluster token
|
||||
func CreateCluster() (string, error) {
|
||||
resp, err := http.Post(fmt.Sprintf("%s/%s", DISCOVERY_URL, "clusters"), "", nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
token, err := ioutil.ReadAll(resp.Body)
|
||||
return string(token), err
|
||||
}
|
||||
|
|
18
main.go
18
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
|
@ -60,6 +61,19 @@ func main() {
|
|||
}
|
||||
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "create",
|
||||
ShortName: "c",
|
||||
Usage: "create a cluster",
|
||||
|
||||
Action: func(c *cli.Context) {
|
||||
token, err := discovery.CreateCluster()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(token)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "manage",
|
||||
ShortName: "m",
|
||||
|
@ -144,5 +158,7 @@ func main() {
|
|||
},
|
||||
}
|
||||
|
||||
log.Fatal(app.Run(os.Args))
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue