forked from flynn/flynn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresource.go
52 lines (40 loc) · 1.08 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"fmt"
"log"
"github.com/flynn/flynn/Godeps/_workspace/src/github.com/flynn/go-docopt"
"github.com/flynn/flynn/controller/client"
ct "github.com/flynn/flynn/controller/types"
)
func init() {
register("resource", runResource, `
usage: flynn resource add <provider>
Manage resources for the app.
Commands:
add provisions a new resource for the app using <provider>.
`)
}
func runResource(args *docopt.Args, client *controller.Client) error {
if args.Bool["add"] {
return runResourceAdd(args, client)
}
return fmt.Errorf("Top-level command not implemented.")
}
func runResourceAdd(args *docopt.Args, client *controller.Client) error {
provider := args.String["<provider>"]
res, err := client.ProvisionResource(&ct.ResourceReq{ProviderID: provider, Apps: []string{mustApp()}})
if err != nil {
return err
}
env := make(map[string]*string)
for k, v := range res.Env {
s := v
env[k] = &s
}
releaseID, err := setEnv(client, "", env)
if err != nil {
return err
}
log.Printf("Created resource %s and release %s.", res.ID, releaseID)
return nil
}