Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Commit

Permalink
Add Resource Management
Browse files Browse the repository at this point in the history
  • Loading branch information
paurosello committed Jul 27, 2019
1 parent 1ff3b7f commit f5f8372
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions k8spin.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var api_base string = "https://console.beta.k8spin.cloud/api"
var debug bool
var token string
var set_config bool
var cpu_amount string
var memory_amount string
var storage_amount string

func check(e error) {
if e != nil {
Expand Down Expand Up @@ -146,18 +149,24 @@ func main() {
Name: "create",
Aliases: []string{"c"},
Usage: "create a namespace",
Flags: []cli.Flag{
cli.StringFlag{Name: "cpu", Value: "100", Destination: &cpu_amount},
cli.StringFlag{Name: "memory", Value: "128", Destination: &memory_amount},
cli.StringFlag{Name: "storage", Value: "0", Destination: &storage_amount},
},
Action: func(c *cli.Context) error {
var namespace = c.Args().First()
if namespace == "" {
fmt.Println("You have to set a namespace name")
return nil
}

var url = api_base+"/namespaces"

request := gorequest.New()
resp, _ , _ := request.Post(url).
Set("Authorization", "Bearer "+token).
Send(`{"namespace_name":"` + namespace + `"}`).
Send(`{"namespace_name":"` + namespace + `", "resources": { "cpu":` + cpu_amount + `, "mem":` + memory_amount + `, "disks_size":` + storage_amount + `} }`).
End()

if httpCodeCheck(resp) {
Expand Down Expand Up @@ -205,8 +214,12 @@ func httpCodeCheck(response gorequest.Response) bool {
fmt.Println(response.StatusCode)
fmt.Println("HTTP Request Headers:")
fmt.Println(response.Request.Header)

fmt.Println("HTTP Request:")
fmt.Println(response.Request.Body)
buf := new(bytes.Buffer)
buf.ReadFrom(response.Request.Body)
fmt.Println(buf.String())

fmt.Println("HTTP Response Headers:")
fmt.Println(response.Header)
fmt.Println("HTTP Response:")
Expand Down
Binary file added k8spin_cli
Binary file not shown.

0 comments on commit f5f8372

Please sign in to comment.