/
server_plan_cmd.go
60 lines (51 loc) · 1.65 KB
/
server_plan_cmd.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
53
54
55
56
57
58
59
60
package cmd
import (
"github.com/codegangsta/cli"
"github.com/flexiant/concerto/api/cloud"
"github.com/flexiant/concerto/utils"
"github.com/flexiant/concerto/utils/format"
)
// WireUpServerPlan prepares common resources to send request to Concerto API
func WireUpServerPlan(c *cli.Context) (ds *cloud.ServerPlanService, f format.Formatter) {
f = format.GetFormatter()
config, err := utils.GetConcertoConfig()
if err != nil {
f.PrintFatal("Couldn't wire up config", err)
}
hcs, err := utils.NewHTTPConcertoService(config)
if err != nil {
f.PrintFatal("Couldn't wire up concerto service", err)
}
ds, err = cloud.NewServerPlanService(hcs)
if err != nil {
f.PrintFatal("Couldn't wire up serverPlan service", err)
}
return ds, f
}
// ServerPlanList subcommand function
func ServerPlanList(c *cli.Context) error {
debugCmdFuncInfo(c)
serverPlanSvc, formatter := WireUpServerPlan(c)
serverPlans, err := serverPlanSvc.GetServerPlanList(c.String("cloud_provider_id"))
if err != nil {
formatter.PrintFatal("Couldn't receive serverPlan data", err)
}
if err = formatter.PrintList(serverPlans); err != nil {
formatter.PrintFatal("Couldn't print/format result", err)
}
return nil
}
// ServerPlanShow subcommand function
func ServerPlanShow(c *cli.Context) error {
debugCmdFuncInfo(c)
serverPlanSvc, formatter := WireUpServerPlan(c)
checkRequiredFlags(c, []string{"id"}, formatter)
serverPlan, err := serverPlanSvc.GetServerPlan(c.String("id"))
if err != nil {
formatter.PrintFatal("Couldn't receive serverPlan data", err)
}
if err = formatter.PrintItem(*serverPlan); err != nil {
formatter.PrintFatal("Couldn't print/format result", err)
}
return nil
}