@@ -32,136 +32,108 @@ import (
32
32
"github.com/elastic/ecctl/pkg/util"
33
33
)
34
34
35
- const createLong = `Creates a deployment from a file definition with an automatically generated idempotency token.
36
- On creation failure, please use the displayed idempotency token to retry the cluster creation with --request-id=<token>.
37
- To track the creation of the resources toggle the --track flag.
38
-
39
- Read more about the deployment definition in https://www.elastic.co/guide/en/cloud-enterprise/current/Deployment_-_CRUD.html`
40
-
41
- var createExample = `
42
- $ cat deployment_example.json
43
- {
44
- "name": "my example cluster",
45
- "resources": {
46
- "apm": [
47
- {
48
- "display_name": "my apm instance",
49
- "ref_id": "my-apm-instance",
50
- "elasticsearch_cluster_ref_id": "my-es-cluster",
51
- "plan": {
52
- "apm": {
53
- "version": "6.8.4"
54
- },
55
- "cluster_topology": [{
56
- "instance_configuration_id": "apm",
57
- "size": {
58
- "resource": "memory",
59
- "value": 512
60
- },
61
- "zone_count": 1
62
- }]
63
- }
64
- }
65
- ],
66
- "elasticsearch": [
67
- {
68
- "display_name": "my elasticsearch cluster",
69
- "ref_id": "my-es-cluster",
70
- "plan": {
71
- "deployment_template": {
72
- "id": "default"
73
- },
74
- "elasticsearch": {
75
- "version": "6.8.4"
76
- },
77
- "cluster_topology": [
78
- {
79
- "instance_configuration_id": "data.default",
80
- "memory_per_node": 1024,
81
- "node_count_per_zone": 1,
82
- "node_type": {
83
- "data": true,
84
- "ingest": true,
85
- "master": true,
86
- "ml": false
87
- },
88
- "zone_count": 1
89
- }
90
- ]
91
- }
92
- }
93
- ],
94
- "kibana": [
95
- {
96
- "display_name": "my kibana instance",
97
- "ref_id": "my-kibana-instance",
98
- "elasticsearch_cluster_ref_id": "my-es-cluster",
99
- "plan": {
100
- "kibana": {
101
- "version": "6.8.4"
102
- },
103
- "cluster_topology": [
104
- {
105
- "instance_configuration_id": "kibana",
106
- "memory_per_node": 1024,
107
- "node_count_per_zone": 1,
108
- "zone_count": 1
109
- }
110
- ]
111
- }
112
- }
113
- ]
114
- }
115
- }
116
- $ ecctl deployment create -f deployment_example.json --version=7.4.1
117
- [...]
118
-
119
- ## If the previous deployment creation failed
120
- $ ecctl deployment create -f deployment_example.json --name adeploy --version=7.4.1
121
- The deployment creation returned with an error, please use the displayed idempotency token
122
- to recreate the deployment resources
123
- Idempotency token: GMZPMRrcMYqHdmxjIQkHbdjnhPIeBElcwrHwzVlhGUSMXrEIzVXoBykSVRsKncNb
124
- unknown error (status 500)
125
- $ ecctl deployment create -f deployment_example.json --name adeploy --version=7.4.1 --request-id=GMZPMRrcMYqHdmxjIQkHbdjnhPIeBElcwrHwzVlhGUSMXrEIzVXoBykSVRsKncNb
126
- [...]` [1 :]
127
-
128
35
var createCmd = & cobra.Command {
129
- Use : `create -f <file definition.json>` ,
130
- Short : "Creates a deployment from a file definition, allowing certain flag overrides" ,
36
+ Use : "create {--file | --size <int> --zones <string> | --topology-element <obj>}" ,
37
+ Short : "Creates a deployment" ,
38
+ PreRunE : cobra .MaximumNArgs (0 ),
131
39
Long : createLong ,
132
40
Example : createExample ,
133
- PreRunE : cobra .NoArgs ,
134
41
RunE : func (cmd * cobra.Command , args []string ) error {
135
- filename , _ := cmd .Flags ().GetString ("file" )
136
- var r models.DeploymentCreateRequest
137
- if err := sdkcmdutil .DecodeFile (filename , & r ); err != nil {
138
- return err
42
+ var track , _ = cmd .Flags ().GetBool ("track" )
43
+ var generatePayload , _ = cmd .Flags ().GetBool ("generate-payload" )
44
+ var name , _ = cmd .Flags ().GetString ("name" )
45
+ var version , _ = cmd .Flags ().GetString ("version" )
46
+ var dt , _ = cmd .Flags ().GetString ("deployment-template" )
47
+
48
+ var zoneCount , _ = cmd .Flags ().GetInt32 ("zones" )
49
+ var size , _ = cmd .Flags ().GetInt32 ("size" )
50
+ var esRefID , _ = cmd .Flags ().GetString ("ref-id" )
51
+ var te , _ = cmd .Flags ().GetStringArray ("topology-element" )
52
+ var plugin , _ = cmd .Flags ().GetStringSlice ("plugin" )
53
+
54
+ var kibanaZoneCount , _ = cmd .Flags ().GetInt32 ("kibana-zones" )
55
+ var kibanaSize , _ = cmd .Flags ().GetInt32 ("kibana-size" )
56
+ var kibanaRefID , _ = cmd .Flags ().GetString ("kibana-ref-id" )
57
+
58
+ var apmEnable , _ = cmd .Flags ().GetBool ("apm" )
59
+ var apmZoneCount , _ = cmd .Flags ().GetInt32 ("apm-zones" )
60
+ var apmSize , _ = cmd .Flags ().GetInt32 ("apm-size" )
61
+ var apmRefID , _ = cmd .Flags ().GetString ("apm-ref-id" )
62
+
63
+ var appsearchEnable , _ = cmd .Flags ().GetBool ("appsearch" )
64
+ var appsearchZoneCount , _ = cmd .Flags ().GetInt32 ("appsearch-zones" )
65
+ var appsearchSize , _ = cmd .Flags ().GetInt32 ("appsearch-size" )
66
+ var appsearchRefID , _ = cmd .Flags ().GetString ("appsearch-ref-id" )
67
+
68
+ region := ecctl .Get ().Config .Region
69
+ if region == "" {
70
+ region = cmdutil .DefaultECERegion
139
71
}
140
72
141
- var region = ecctl .Get ().Config .Region
142
- if ecctl .Get ().Config .Region == "" {
143
- region = cmdutil .DefaultECERegion
73
+ var payload * models.DeploymentCreateRequest
74
+ if err := sdkcmdutil .FileOrStdin (cmd , "file" ); err == nil {
75
+ err := sdkcmdutil .DecodeDefinition (cmd , "file" , & payload )
76
+ if err != nil && err != sdkcmdutil .ErrNodefinitionLoaded {
77
+ return err
78
+ }
79
+ }
80
+
81
+ if payload == nil {
82
+ var err error
83
+ payload , err = depresource .New (depresource.NewParams {
84
+ API : ecctl .Get ().API ,
85
+ Name : name ,
86
+ DeploymentTemplateID : dt ,
87
+ Version : version ,
88
+ Region : region ,
89
+ Writer : ecctl .Get ().Config .ErrorDevice ,
90
+ Plugins : plugin ,
91
+ TopologyElements : te ,
92
+ ApmEnable : apmEnable ,
93
+ AppsearchEnable : appsearchEnable ,
94
+ ElasticsearchInstance : depresource.InstanceParams {
95
+ RefID : esRefID ,
96
+ Size : size ,
97
+ ZoneCount : zoneCount ,
98
+ },
99
+ KibanaInstance : depresource.InstanceParams {
100
+ RefID : kibanaRefID ,
101
+ Size : kibanaSize ,
102
+ ZoneCount : kibanaZoneCount ,
103
+ },
104
+ ApmInstance : depresource.InstanceParams {
105
+ RefID : apmRefID ,
106
+ Size : apmSize ,
107
+ ZoneCount : apmZoneCount ,
108
+ },
109
+ AppsearchInstance : depresource.InstanceParams {
110
+ RefID : appsearchRefID ,
111
+ Size : appsearchSize ,
112
+ ZoneCount : appsearchZoneCount ,
113
+ },
114
+ })
115
+ if err != nil {
116
+ return err
117
+ }
144
118
}
145
119
146
- name , _ := cmd .Flags ().GetString ("name" )
147
- version , _ := cmd .Flags ().GetString ("version" )
120
+ // Returns the DeploymentCreateRequest skipping the creation of the resources.
121
+ if generatePayload {
122
+ return ecctl .Get ().Formatter .Format ("" , payload )
123
+ }
148
124
149
125
reqID , _ := cmd .Flags ().GetString ("request-id" )
150
126
if reqID == "" {
151
127
reqID = util .RandomString (64 )
152
128
}
153
129
154
- res , err := deployment . Create ( deployment.CreateParams {
130
+ var createParams = deployment.CreateParams {
155
131
API : ecctl .Get ().API ,
156
132
RequestID : reqID ,
157
- Request : & r ,
158
- Overrides : & deployment.PayloadOverrides {
159
- Name : name ,
160
- Region : region ,
161
- Version : version ,
162
- },
163
- })
133
+ Request : payload ,
134
+ }
164
135
136
+ res , err := deployment .Create (createParams )
165
137
if err != nil {
166
138
fmt .Fprintln (os .Stderr ,
167
139
"The deployment creation returned with an error, please use the displayed idempotency token to recreate the deployment resources" ,
@@ -170,27 +142,52 @@ var createCmd = &cobra.Command{
170
142
return err
171
143
}
172
144
173
- var track , _ = cmd .Flags ().GetBool ("track" )
174
- return cmdutil .Track (cmdutil.TrackParams {
175
- TrackResourcesParams : depresource.TrackResourcesParams {
176
- API : ecctl .Get ().API ,
177
- Resources : res .Resources ,
178
- OutputDevice : ecctl .Get ().Config .OutputDevice ,
179
- },
180
- Formatter : ecctl .Get ().Formatter ,
181
- Track : track ,
182
- Response : res ,
145
+ if err := ecctl .Get ().Formatter .Format ("" , res ); err != nil {
146
+ if ! track {
147
+ return err
148
+ }
149
+ fmt .Fprintln (ecctl .Get ().Config .OutputDevice , err )
150
+ }
151
+
152
+ if ! track {
153
+ return nil
154
+ }
155
+
156
+ return depresource .TrackResources (depresource.TrackResourcesParams {
157
+ API : ecctl .Get ().API ,
158
+ Resources : res .Resources ,
159
+ OutputDevice : ecctl .Get ().Config .OutputDevice ,
183
160
})
184
161
},
185
162
}
186
163
187
164
func init () {
188
165
Command .AddCommand (createCmd )
166
+ createCmd .Flags ().StringP ("file" , "f" , "" , "DeploymentCreateRequest file definition. See help for more information" )
167
+ createCmd .Flags ().String ("deployment-template" , "default" , "Deployment template ID on which to base the deployment from" )
168
+ createCmd .Flags ().String ("version" , "" , "Version to use, if not specified, the latest available stack version will be used" )
169
+ createCmd .Flags ().String ("name" , "" , "Optional name for the deployment" )
189
170
createCmd .Flags ().BoolP ("track" , "t" , false , cmdutil .TrackFlagMessage )
190
- createCmd .Flags ().String ("name" , "" , "Overrides the deployment name" )
191
- createCmd .Flags ().String ("version" , "" , "Overrides all the deployment's resources to the specified version" )
171
+ createCmd .Flags ().Bool ("generate-payload" , false , "Returns the deployment payload without actually creating the deployment resources" )
192
172
createCmd .Flags ().String ("request-id" , "" , "Optional idempotency token - Can be found in the Stderr device when a previous deployment creation failed, for more information see the examples in the help command page" )
193
- createCmd .Flags ().StringP ("file" , "f" , "" , "JSON file that contains JSON-style domain-specific deployment definition" )
194
- createCmd .MarkFlagRequired ("file" )
195
- createCmd .MarkFlagFilename ("file" , "*.json" )
173
+
174
+ createCmd .Flags ().String ("ref-id" , "main-elasticsearch" , "Optional RefId for the Elasticsearch deployment" )
175
+ createCmd .Flags ().Int32 ("zones" , 1 , "Number of zones the Elasticsearch instances will span" )
176
+ createCmd .Flags ().Int32 ("size" , 4096 , "Memory (RAM) in MB that each of the Elasticsearch instances will have" )
177
+ createCmd .Flags ().StringArrayP ("topology-element" , "e" , nil , "Optional Elasticsearch topology element definition. See help for more information" )
178
+ createCmd .Flags ().StringSlice ("plugin" , nil , "Additional plugins to add to the Elasticsearch deployment" )
179
+
180
+ createCmd .Flags ().String ("kibana-ref-id" , "main-kibana" , "Optional RefId for the Kibana deployment" )
181
+ createCmd .Flags ().Int32 ("kibana-zones" , 1 , "Number of zones the Kibana instances will span" )
182
+ createCmd .Flags ().Int32 ("kibana-size" , 1024 , "Memory (RAM) in MB that each of the Kibana instances will have" )
183
+
184
+ createCmd .Flags ().Bool ("apm" , false , "Enables APM for the deployment" )
185
+ createCmd .Flags ().String ("apm-ref-id" , "main-apm" , "Optional RefId for the APM deployment" )
186
+ createCmd .Flags ().Int32 ("apm-zones" , 1 , "Number of zones the APM instances will span" )
187
+ createCmd .Flags ().Int32 ("apm-size" , 512 , "Memory (RAM) in MB that each of the APM instances will have" )
188
+
189
+ createCmd .Flags ().Bool ("appsearch" , false , "Enables AppSearch for the deployment" )
190
+ createCmd .Flags ().String ("appsearch-ref-id" , "main-appsearch" , "Optional RefId for the AppSearch deployment" )
191
+ createCmd .Flags ().Int32 ("appsearch-zones" , 1 , "Number of zones the AppSearch instances will span" )
192
+ createCmd .Flags ().Int32 ("appsearch-size" , 2048 , "Memory (RAM) in MB that each of the AppSearch instances will have" )
196
193
}
0 commit comments