@@ -3,13 +3,15 @@ package main
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
- "strings"
7
-
6
+ log "github.com/Sirupsen/logrus"
8
7
"github.com/docker/infrakit/discovery"
9
8
"github.com/docker/infrakit/spi/flavor"
10
9
flavor_plugin "github.com/docker/infrakit/spi/http/flavor"
11
10
"github.com/docker/infrakit/spi/instance"
12
11
"github.com/spf13/cobra"
12
+ "io/ioutil"
13
+ "os"
14
+ "strings"
13
15
)
14
16
15
17
func flavorPluginCommand (plugins func () discovery.Plugins ) * cobra.Command {
@@ -34,12 +36,23 @@ func flavorPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
34
36
cmd .PersistentFlags ().StringVar (& name , "name" , name , "Name of plugin" )
35
37
36
38
validate := & cobra.Command {
37
- Use : "validate" ,
38
- Short : "validate input " ,
39
+ Use : "validate <flavor configuration file> " ,
40
+ Short : "validate a flavor configuration " ,
39
41
RunE : func (cmd * cobra.Command , args []string ) error {
40
42
assertNotNil ("no plugin" , flavorPlugin )
41
43
42
- alloc , err := flavorPlugin .Validate (json .RawMessage (getInput (args )))
44
+ if len (args ) != 1 {
45
+ cmd .Usage ()
46
+ os .Exit (1 )
47
+ }
48
+
49
+ buff , err := ioutil .ReadFile (args [0 ])
50
+ if err != nil {
51
+ log .Error (err )
52
+ os .Exit (1 )
53
+ }
54
+
55
+ alloc , err := flavorPlugin .Validate (json .RawMessage (buff ))
43
56
if err == nil {
44
57
if buff , err2 := json .MarshalIndent (alloc , " " , " " ); err2 == nil {
45
58
fmt .Println ("validate" , string (buff ))
@@ -53,22 +66,34 @@ func flavorPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
53
66
54
67
flavorPropertiesFile := ""
55
68
prepare := & cobra.Command {
56
- Use : "prepare" ,
57
- Short : "prepare the provision data " ,
69
+ Use : "prepare <instance Spec JSON file> " ,
70
+ Short : "prepare provisioning inputs for an instance " ,
58
71
RunE : func (cmd * cobra.Command , args []string ) error {
59
72
assertNotNil ("no plugin" , flavorPlugin )
60
73
61
- buff := getInput (args )
62
- spec := instance.Spec {}
63
- err := json .Unmarshal (buff , & spec )
74
+ if len (args ) != 1 {
75
+ cmd .Usage ()
76
+ os .Exit (1 )
77
+ }
78
+
79
+ buff , err := ioutil .ReadFile (args [0 ])
64
80
if err != nil {
81
+ log .Error (err )
82
+ os .Exit (1 )
83
+ }
84
+
85
+ spec := instance.Spec {}
86
+ if err := json .Unmarshal (buff , & spec ); err != nil {
65
87
return err
66
88
}
67
89
68
- // the flavor's config is in a flag.
69
- buffFlavor := getInput ([]string {flavorPropertiesFile })
90
+ buff , err = ioutil .ReadFile (args [0 ])
91
+ if err != nil {
92
+ log .Error (err )
93
+ os .Exit (1 )
94
+ }
70
95
71
- spec , err = flavorPlugin .Prepare (json .RawMessage (buffFlavor ), spec )
96
+ spec , err = flavorPlugin .Prepare (json .RawMessage (buff ), spec )
72
97
if err == nil {
73
98
buff , err = json .MarshalIndent (spec , " " , " " )
74
99
if err == nil {
@@ -78,14 +103,18 @@ func flavorPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
78
103
return err
79
104
},
80
105
}
81
- prepare .Flags ().StringVar (& flavorPropertiesFile , "properties" , flavorPropertiesFile , "Path to flavor properties" )
106
+ prepare .Flags ().StringVar (
107
+ & flavorPropertiesFile ,
108
+ "properties" ,
109
+ flavorPropertiesFile ,
110
+ "Path to flavor properties" )
82
111
83
112
tags := []string {}
84
113
id := ""
85
114
logicalID := ""
86
115
healthy := & cobra.Command {
87
116
Use : "healthy" ,
88
- Short : "checks for health " ,
117
+ Short : "checks if an instance is considered healthy " ,
89
118
RunE : func (cmd * cobra.Command , args []string ) error {
90
119
assertNotNil ("no plugin" , flavorPlugin )
91
120
0 commit comments