environment-manager 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +13 -0
- data/README.md +14 -0
- data/lib/environment-manager.rb +1 -0
- data/lib/environment_manager/api.rb +1185 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e40ec0c9df97646e44d28b6be00ddafc6af36e31
|
4
|
+
data.tar.gz: 9463bd37d1afe0be970782bddac5ddd7abadb0f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a964bfbe799d58563f46201d4d58e9a94a2fa34c99740926c97b1868e7bfcd2cabbf81444c90aa1f6ff33c34b6ee466e4c915b6b13956f8d7ee9fc625732aeb
|
7
|
+
data.tar.gz: 20a18eb6ef4d452550a7c4e1014f496dfb681601f63af29d8406ae2b45913a2b1327277b71741b84fedbdafd3de30b065e583388ee41e07caddd80a406c8ca6d
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2015-2016 Trainline.com Ltd
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
## Ruby Environment Manager
|
2
|
+
|
3
|
+
Ruby client library for [Environment Manager](https://github.com/trainline/environment-manager)
|
4
|
+
|
5
|
+
### tl;dr
|
6
|
+
|
7
|
+
Normal use of the Client
|
8
|
+
|
9
|
+
```
|
10
|
+
em_session = new = EnvironmentManager::Api.new(server,user,password)
|
11
|
+
results = em_session.get_upstreams_config()
|
12
|
+
```
|
13
|
+
|
14
|
+
For the full list of methods available from the API you can check [here](https://github.com/trainline/ruby-environment_manager/blob/master/lib/environment_manager/api.rb)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'environment_manager/api'
|
@@ -0,0 +1,1185 @@
|
|
1
|
+
# Copyright (c) Trainline Limited, 2017. All rights reserved. See LICENSE.txt in the project root for license information.
|
2
|
+
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
|
3
|
+
|
4
|
+
require "rest-client"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
module EnvironmentManager
|
8
|
+
class Api
|
9
|
+
|
10
|
+
def initialize(server, user, password, retries=5)
|
11
|
+
# Instantiate variables
|
12
|
+
@server = server
|
13
|
+
@user = user
|
14
|
+
@password = password
|
15
|
+
@retries = retries
|
16
|
+
# Sanitise input
|
17
|
+
if server.empty? or user.empty? or password.empty?
|
18
|
+
raise(IndexError, "API(server: SERVERNAME, user: USERNAME, password: PASSWORD, [retries: N])")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def api_auth()
|
24
|
+
# Authenticate in environment manager
|
25
|
+
base_url = "https://#{@server}"
|
26
|
+
token_payload = {grant_type: "password",
|
27
|
+
username: @user,
|
28
|
+
password: @password}
|
29
|
+
token = nil
|
30
|
+
no_token = true
|
31
|
+
retries = 0
|
32
|
+
while no_token and retries < @retries
|
33
|
+
em_token_url = "#{base_url}/api/token"
|
34
|
+
begin
|
35
|
+
em_token = RestClient::Request.execute(url: em_token_url, method: :post, payload: token_payload, verify_ssl: false, open_timeout: 10)
|
36
|
+
if em_token.code == 200
|
37
|
+
token = em_token.body
|
38
|
+
no_token = false
|
39
|
+
else
|
40
|
+
sleep 2
|
41
|
+
end
|
42
|
+
rescue
|
43
|
+
sleep 2
|
44
|
+
end
|
45
|
+
retries += 1
|
46
|
+
end
|
47
|
+
if not token.to_s.strip.empty?
|
48
|
+
token_bearer = "Bearer #{token}"
|
49
|
+
return token_bearer
|
50
|
+
else
|
51
|
+
raise("No token returned from Environment Manager")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def query(query_endpoint, data=nil, query_type="get", headers={}, retries=5, backoff=2)
|
57
|
+
# Sanitise input
|
58
|
+
if query_endpoint.to_s.strip.empty? or data.to_s.strip.empty?
|
59
|
+
raise("No endpoint specified, cannot continue")
|
60
|
+
end
|
61
|
+
if query_endpoint.downcase == "post"
|
62
|
+
if data.nil?
|
63
|
+
raise("We need data for this method but nothing was specified")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
retry_num = 0
|
67
|
+
while retry_num < retries
|
68
|
+
retry_num += 1
|
69
|
+
token = api_auth()
|
70
|
+
base_url = "https://#{@server}"
|
71
|
+
request_url = "#{base_url}#{query_endpoint}"
|
72
|
+
query_headers = {"Accept" => "application/json", "Content-Type" => "application/json", "Authorization" => token}
|
73
|
+
headers.each do |header|
|
74
|
+
query_headers.merge!(header)
|
75
|
+
end
|
76
|
+
# Add any extra headers
|
77
|
+
if query_type.downcase == "get"
|
78
|
+
request = RestClient::Request.execute(url: request_url, method: :get, headers: query_headers, verify_ssl: false, open_timeout: 10)
|
79
|
+
elsif query_type.downcase == "post"
|
80
|
+
request = RestClient::Request.execute(url: request_url, method: :post, payload: data, headers: query_headers, verify_ssl: false, open_timeout: 10)
|
81
|
+
elsif query_type.downcase == "put"
|
82
|
+
request = RestClient::Request.execute(url: request_url, method: :put, payload: data, headers: query_headers, verify_ssl: false, open_timeout: 10)
|
83
|
+
elsif query_type.downcase == "patch"
|
84
|
+
request = RestClient::Request.execute(url: request_url, method: :patch, payload: data, headers: query_headers, verify_ssl: false, open_timeout: 10)
|
85
|
+
elsif query_type.downcase == "delete"
|
86
|
+
request = RestClient::Request.execute(url: request_url, method: :delete, headers: query_headers, verify_ssl: false, open_timeout: 10)
|
87
|
+
else
|
88
|
+
raise("Cannot process query type #{query_type}")
|
89
|
+
end
|
90
|
+
if request.code.to_s[0].to_i == 2
|
91
|
+
return JSON.parse(request.body)
|
92
|
+
elsif request.code.to_s[0].to_i == 2 or request.code.to_s[0].to_i == 5
|
93
|
+
raise(request)
|
94
|
+
else
|
95
|
+
sleep backoff
|
96
|
+
end
|
97
|
+
end
|
98
|
+
raise("Max number of retries (#{retry_num}) querying Environment Manager, last http code is #{request.code}, will abort for now")
|
99
|
+
end
|
100
|
+
|
101
|
+
##########################
|
102
|
+
# Public API methods
|
103
|
+
##########################
|
104
|
+
|
105
|
+
## Accounts
|
106
|
+
public
|
107
|
+
def get_accounts_config()
|
108
|
+
# List the AWS Accounts that associated with Environment Manager
|
109
|
+
request_endpoint = "/api/v1/config/accounts"
|
110
|
+
return query(request_endpoint, query_type: "GET")
|
111
|
+
end
|
112
|
+
|
113
|
+
public
|
114
|
+
def post_accounts_config(data=Hash.new)
|
115
|
+
# Add an association to an AWS Account
|
116
|
+
request_endpoint = "/api/v1/config/accounts"
|
117
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
118
|
+
end
|
119
|
+
|
120
|
+
public
|
121
|
+
def put_account_config(accountnumber=nil, data=Hash.new)
|
122
|
+
# Update an associated AWS Account
|
123
|
+
if accountnumber.nil?
|
124
|
+
raise("acountnumber has not been specified")
|
125
|
+
end
|
126
|
+
request_endpoint = "/api/v1/config/accounts/#{accountnumber}"
|
127
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
128
|
+
end
|
129
|
+
|
130
|
+
public
|
131
|
+
def delete_account_config(accountnumber=nil)
|
132
|
+
# Remove an AWS Account association
|
133
|
+
if accountnumber.nil?
|
134
|
+
raise("Required value has not been specified")
|
135
|
+
end
|
136
|
+
request_endpoint = "/api/v1/config/accounts/#{accountnumber}"
|
137
|
+
return query(request_endpoint, query_type: "DELETE")
|
138
|
+
end
|
139
|
+
|
140
|
+
## AMI
|
141
|
+
public
|
142
|
+
def get_images(account=nil)
|
143
|
+
# Get the list of available AMI images. Only those that are privately published under associated accounts are included
|
144
|
+
if account.nil?
|
145
|
+
account_qs = ""
|
146
|
+
else
|
147
|
+
account_qs = "?account=#{account}"
|
148
|
+
end
|
149
|
+
request_endpoint = "/api/v1/images#{account_qs}"
|
150
|
+
return query(request_endpoint, query_type: "GET")
|
151
|
+
end
|
152
|
+
|
153
|
+
## ASG
|
154
|
+
public
|
155
|
+
def get_asgs(account="Non-Prod")
|
156
|
+
# List ASGS matching the given criteria. By default returns all ASGs across all accounts
|
157
|
+
request_endpoint = "/api/v1/asgs?account=#{account}"
|
158
|
+
return query(request_endpoint, query_type: "GET")
|
159
|
+
end
|
160
|
+
|
161
|
+
public
|
162
|
+
def get_asg(environment=nil, asgname=nil)
|
163
|
+
# Get a single ASG for the given environment
|
164
|
+
if environment.nil? or asgname.nil?
|
165
|
+
raise("Either environment or asgname has not been specified")
|
166
|
+
end
|
167
|
+
request_endpoint = "/api/v1/asgs/#{asgname}?environment=#{environment}"
|
168
|
+
return query(request_endpoint, query_type: "GET")
|
169
|
+
end
|
170
|
+
|
171
|
+
public
|
172
|
+
def put_asg(environment=nil, asgname=nil, data=Hash.new)
|
173
|
+
# Update properties of an ASG
|
174
|
+
if environment.nil? or asgname.nil?
|
175
|
+
raise("Either environment or asgname has not been specified")
|
176
|
+
end
|
177
|
+
request_endpoint = "/api/v1/asgs/#{asgname}?environment=#{environment}"
|
178
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
179
|
+
end
|
180
|
+
|
181
|
+
public
|
182
|
+
def delete_asg(environment=nil, asgname=nil)
|
183
|
+
# Delete ASG and it"s target state
|
184
|
+
if environment.nil? or asgname.nil?
|
185
|
+
raise("Either environment or asgname has not been specified")
|
186
|
+
end
|
187
|
+
request_endpoint = "/api/v1/asgs/#{asgname}?environment=#{environment}"
|
188
|
+
return query(request_endpoint, query_type: "DELETE")
|
189
|
+
end
|
190
|
+
|
191
|
+
public
|
192
|
+
def get_asg_ready(environment=nil, asgname=nil)
|
193
|
+
# Determine if an ASG is ready to deploy to, eg. at least one instance is present and all are "InService"
|
194
|
+
if environment.nil? or asgname.nil?
|
195
|
+
raise("Either environment or asgname has not been specified")
|
196
|
+
end
|
197
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/ready?environment=#{environment}"
|
198
|
+
return query(request_endpoint, query_type: "GET")
|
199
|
+
end
|
200
|
+
|
201
|
+
public
|
202
|
+
def get_asg_ips(environment=nil, asgname=nil)
|
203
|
+
# Get IPs associated with an ASG in the given environment
|
204
|
+
if environment.nil? or asgname.nil?
|
205
|
+
raise("Either environment or asgname has not been specified")
|
206
|
+
end
|
207
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/ips?environment=#{environment}"
|
208
|
+
return query(request_endpoint, query_type: "GET")
|
209
|
+
end
|
210
|
+
|
211
|
+
public
|
212
|
+
def get_asg_scaling_schedule(environment=nil, asgname=nil)
|
213
|
+
# Get scaling schedule actions for given ASG
|
214
|
+
if environment.nil? or asgname.nil?
|
215
|
+
raise("Either environment or asgname has not been specified")
|
216
|
+
end
|
217
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/scaling-schedule?environment=#{environment}"
|
218
|
+
return query(request_endpoint, query_type: "GET")
|
219
|
+
end
|
220
|
+
|
221
|
+
public
|
222
|
+
def put_asg_scaling_schedule(environment=nil, asgname=nil, data=Hash.new)
|
223
|
+
# Update scaling schedule actions for given ASG
|
224
|
+
if environment.nil? or asgname.nil?
|
225
|
+
raise("Either environment or asgname has not been specified")
|
226
|
+
end
|
227
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/scaling-schedule?environment=#{environment}"
|
228
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
229
|
+
end
|
230
|
+
|
231
|
+
public
|
232
|
+
def put_asg_size(environment=nil, asgname=nil, data=Hash.new)
|
233
|
+
# Resize an ASG in the given environment
|
234
|
+
if environment.nil? or asgname.nil?
|
235
|
+
raise("Either environment or asgname has not been specified")
|
236
|
+
end
|
237
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/size?environment=#{environment}"
|
238
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
239
|
+
end
|
240
|
+
|
241
|
+
public
|
242
|
+
def get_asg_launch_config(environment=nil, asgname=nil)
|
243
|
+
# Get the launch config associated with an ASG in the given environment
|
244
|
+
if environment.nil? or asgname.nil?
|
245
|
+
raise("Either environment or asgname has not been specified")
|
246
|
+
end
|
247
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/launch-config?environment=#{environment}"
|
248
|
+
return query(request_endpoint, query_type: "GET")
|
249
|
+
end
|
250
|
+
|
251
|
+
public
|
252
|
+
def put_asg_launch_config(environment=nil, asgname=nil, data=Hash.new)
|
253
|
+
# Update the launch config associated with an ASG in the given environment
|
254
|
+
if environment.nil? or asgname.nil?
|
255
|
+
raise("Either environment or asgname has not been specified")
|
256
|
+
end
|
257
|
+
request_endpoint = "/api/v1/asgs/#{asgname}/launch-config?environment=#{environment}"
|
258
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
259
|
+
end
|
260
|
+
|
261
|
+
## Audit
|
262
|
+
public
|
263
|
+
def get_audit_config(since_time=nil, until_time=nil)
|
264
|
+
# Get Audit Logs for a given time period. Default values are "since yesterday" and "until now"
|
265
|
+
if since_time.nil?
|
266
|
+
since_time_qs = ""
|
267
|
+
else
|
268
|
+
since_time_qs = "since=#{since_time}"
|
269
|
+
end
|
270
|
+
if until_time.nil?
|
271
|
+
until_time_qs = ""
|
272
|
+
else
|
273
|
+
until_time_qs = "until=#{until_time}"
|
274
|
+
end
|
275
|
+
# Construct qs
|
276
|
+
if since_time.nil? and not until_time.nil?
|
277
|
+
constructed_qs = "?#{until_time_qs}"
|
278
|
+
elsif not since_time.nil? and until_time.nil?
|
279
|
+
constructed_qs = "?#{since_time_qs}"
|
280
|
+
elsif not since_time.nil? and not until_time.nil?
|
281
|
+
constructed_qs = "?#{since_time_qs}&#{until_qs}"
|
282
|
+
else
|
283
|
+
constructed_qs = ""
|
284
|
+
end
|
285
|
+
request_endpoint = "/api/v1/config/audit#{constructed_qs}"
|
286
|
+
return query(request_endpoint, query_type: "GET")
|
287
|
+
end
|
288
|
+
|
289
|
+
public
|
290
|
+
def get_audit_key_config(key=nil)
|
291
|
+
# Get a specific audit log
|
292
|
+
if key.nil?
|
293
|
+
raise("Key has not been specified")
|
294
|
+
end
|
295
|
+
request_endpoint = "/api/v1/config/audit/#{key}"
|
296
|
+
return query(request_endpoint, query_type: "GET")
|
297
|
+
end
|
298
|
+
|
299
|
+
## Cluster
|
300
|
+
public
|
301
|
+
def get_clusters_config()
|
302
|
+
# Get all Cluster configurations
|
303
|
+
request_endpoint = "/api/v1/config/clusters"
|
304
|
+
return query(request_endpoint, query_type: "GET")
|
305
|
+
end
|
306
|
+
|
307
|
+
public
|
308
|
+
def post_clusters_config(data=Hash.new)
|
309
|
+
# Create a Cluster configuration
|
310
|
+
request_endpoint = "/api/v1/config/clusters"
|
311
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
312
|
+
end
|
313
|
+
|
314
|
+
public
|
315
|
+
def get_cluster_config(cluster=nil)
|
316
|
+
# Get a specific Cluster configuration
|
317
|
+
if cluster.nil?
|
318
|
+
raise("Cluster name has not been specified")
|
319
|
+
end
|
320
|
+
request_endpoint = "/api/v1/config/clusters/#{cluster}"
|
321
|
+
return query(request_endpoint, query_type: "GET")
|
322
|
+
end
|
323
|
+
|
324
|
+
public
|
325
|
+
def put_cluster_config(cluster=nil, data=Hash.new)
|
326
|
+
# Update a Cluster configuration
|
327
|
+
if cluster.nil?
|
328
|
+
raise("Cluster name has not been specified")
|
329
|
+
end
|
330
|
+
request_endpoint = "/api/v1/config/clusters/#{cluster}"
|
331
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
332
|
+
end
|
333
|
+
|
334
|
+
public
|
335
|
+
def delete_cluster_config(cluster=nil)
|
336
|
+
# Delete a Cluster configuration
|
337
|
+
if cluster.nil?
|
338
|
+
raise("Cluster name has not been specified")
|
339
|
+
end
|
340
|
+
request_endpoint = "/api/v1/config/clusters/#{cluster}"
|
341
|
+
return query(request_endpoint, query_type: "DELETE")
|
342
|
+
end
|
343
|
+
|
344
|
+
## Deployment
|
345
|
+
public
|
346
|
+
def get_deployments()
|
347
|
+
# List all deployments matching the given criteria. If no parameters are provided, the default is "since yesterday"
|
348
|
+
request_endpoint = "/api/v1/deployments"
|
349
|
+
return query(request_endpoint, query_type: "GET")
|
350
|
+
end
|
351
|
+
|
352
|
+
public
|
353
|
+
def post_deployments(dry_run=False, data=Hash.new)
|
354
|
+
# Create a new deployment. This will provision any required infrastructure and update the required target-state
|
355
|
+
request_endpoint = "/api/v1/deployments?dry_run=#{dry_run}"
|
356
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
357
|
+
end
|
358
|
+
|
359
|
+
public
|
360
|
+
def get_deployment(deployment_id=nil)
|
361
|
+
# Get information for a deployment
|
362
|
+
if deployment_id.nil?
|
363
|
+
raise("Deployment id has not been specified")
|
364
|
+
end
|
365
|
+
request_endpoint = "/api/v1/deployments/#{deployment_id}"
|
366
|
+
return query(request_endpoint, query_type: "GET")
|
367
|
+
end
|
368
|
+
|
369
|
+
public
|
370
|
+
def patch_deployment(deployment_id=nil, data=Hash.new)
|
371
|
+
# Modify deployment - cancel in-progress, or modify Action
|
372
|
+
if deployment_id.nil?
|
373
|
+
raise("Deployment id has not been specified")
|
374
|
+
end
|
375
|
+
request_endpoint = "/api/v1/deployments/#{deployment_id}"
|
376
|
+
return query(request_endpoint, query_type: "PATCH", data: data)
|
377
|
+
end
|
378
|
+
|
379
|
+
public
|
380
|
+
def get_deployment_log(deployment_id=nil, account="Non-Prod", instance=nil)
|
381
|
+
# Retrieve logs for a particular deployment
|
382
|
+
if deployment_id.nil?
|
383
|
+
raise("Deployment id has not been specified")
|
384
|
+
end
|
385
|
+
if instance.nil?
|
386
|
+
raise("Instance id has not been specified")
|
387
|
+
end
|
388
|
+
request_endpoint = "/api/v1/deployments/#{deployment_id}/log?account=#{account}&instance=#{instance}"
|
389
|
+
return query(request_endpoint, query_type: "GET")
|
390
|
+
end
|
391
|
+
|
392
|
+
## Deployment Map
|
393
|
+
public
|
394
|
+
def get_deployment_maps()
|
395
|
+
# Get all deployment map configurations
|
396
|
+
request_endpoint = "/api/v1/config/deployments-maps"
|
397
|
+
return query(request_endpoint, query_type: "GET")
|
398
|
+
end
|
399
|
+
|
400
|
+
public
|
401
|
+
def post_deployment_maps(data=Hash.new)
|
402
|
+
# Create a deployment map configuration
|
403
|
+
request_endpoint = "/api/v1/config/deployments-maps"
|
404
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
405
|
+
end
|
406
|
+
|
407
|
+
public
|
408
|
+
def get_deployment_map(deployment_name=nil)
|
409
|
+
# Get a specific deployment map configuration
|
410
|
+
if deployment_name.nil?
|
411
|
+
raise("Deployment name has not been specified")
|
412
|
+
end
|
413
|
+
request_endpoint = "/api/v1/deployment-maps/#{deployment_name}"
|
414
|
+
return query(request_endpoint, query_type: "GET")
|
415
|
+
end
|
416
|
+
|
417
|
+
public
|
418
|
+
def put_deployment_map(deployment_name=nil, expected_version=nil, data=Hash.new)
|
419
|
+
# Update a deployment map configuration
|
420
|
+
if deployment_name.nil?
|
421
|
+
raise("Deployment name has not been specified")
|
422
|
+
end
|
423
|
+
if expected_version.nil?
|
424
|
+
headers = ""
|
425
|
+
else
|
426
|
+
headers = {"expected-version" => expected_version}
|
427
|
+
end
|
428
|
+
request_endpoint = "/api/v1/deployment-maps/#{deployment_name}"
|
429
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
430
|
+
end
|
431
|
+
|
432
|
+
public
|
433
|
+
def delete_deployment_map(deployment_name=nil)
|
434
|
+
# Delete a deployment map configuration
|
435
|
+
if deployment_name.nil?
|
436
|
+
raise("Deployment name has not been specified")
|
437
|
+
end
|
438
|
+
request_endpoint = "/api/v1/deployment-maps/#{deployment_name}"
|
439
|
+
return query(request_endpoint, query_type: "DELETE")
|
440
|
+
end
|
441
|
+
|
442
|
+
## Environment
|
443
|
+
public
|
444
|
+
def get_environments()
|
445
|
+
# Get all environments
|
446
|
+
request_endpoint = "/api/v1/environments"
|
447
|
+
return query(request_endpoint, query_type: "GET")
|
448
|
+
end
|
449
|
+
|
450
|
+
public
|
451
|
+
def get_environment(environment=nil)
|
452
|
+
# Get an environment
|
453
|
+
if environment.nil?
|
454
|
+
raise("Environment has not been specified")
|
455
|
+
end
|
456
|
+
request_endpoint = "/api/v1/environments/#{environment}"
|
457
|
+
return query(request_endpoint, query_type: "GET")
|
458
|
+
end
|
459
|
+
|
460
|
+
public
|
461
|
+
def get_environment_protected(environment=nil, action=nil)
|
462
|
+
# Find if environment is protected from action
|
463
|
+
if environment.nil? or action.nil?
|
464
|
+
raise("Environment or Action has not been specified")
|
465
|
+
end
|
466
|
+
request_endpoint = "/api/v1/environments/#{environment}/protected?action=#{action}"
|
467
|
+
return query(request_endpoint, query_type: "GET")
|
468
|
+
end
|
469
|
+
|
470
|
+
public
|
471
|
+
def get_environment_servers(environment=nil)
|
472
|
+
# Get the list of servers in an environment
|
473
|
+
if environment.nil?
|
474
|
+
raise("Environment has not been specified")
|
475
|
+
end
|
476
|
+
request_endpoint = "/api/v1/environments/#{environment}/servers"
|
477
|
+
return query(request_endpoint, query_type: "GET")
|
478
|
+
end
|
479
|
+
|
480
|
+
public
|
481
|
+
def get_environment_asg_servers(environment=nil, asgname=nil)
|
482
|
+
# Get a specific server in a given environment
|
483
|
+
if environment.nil? or asgname.nil?
|
484
|
+
raise("Either environment or asgname has not been specified")
|
485
|
+
end
|
486
|
+
request_endpoint = "/api/v1/environments/#{environment}/servers/#{asgname}"
|
487
|
+
return query(request_endpoint, query_type: "GET")
|
488
|
+
end
|
489
|
+
|
490
|
+
public
|
491
|
+
def get_environment_schedule(environment=nil)
|
492
|
+
# Get schedule for an environment
|
493
|
+
if environment.nil?
|
494
|
+
raise("Environment has not been specified")
|
495
|
+
end
|
496
|
+
request_endpoint = "/api/v1/environments/#{environment}/schedule"
|
497
|
+
return query(request_endpoint, query_type: "GET")
|
498
|
+
end
|
499
|
+
|
500
|
+
public
|
501
|
+
def put_environment_schedule(environment=nil, expected_version=nil, data=Hash.new)
|
502
|
+
# Set the schedule for an environment
|
503
|
+
if environment.nil?
|
504
|
+
raise("Environment has not been specified")
|
505
|
+
end
|
506
|
+
if expected_version.nil?
|
507
|
+
headers = nil
|
508
|
+
else
|
509
|
+
headers = {"expected-version" => expected_version}
|
510
|
+
end
|
511
|
+
request_endpoint = "/api/v1/environments/#{environment}/schedule"
|
512
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
513
|
+
end
|
514
|
+
|
515
|
+
public
|
516
|
+
def get_environment_account_name(environment=nil)
|
517
|
+
# Get account name for given environment
|
518
|
+
if environment.nil?
|
519
|
+
raise("Environment has not been specified")
|
520
|
+
end
|
521
|
+
request_endpoint = "/api/v1/environments/#{environment}/accountName"
|
522
|
+
return query(request_endpoint, query_type: "GET")
|
523
|
+
end
|
524
|
+
|
525
|
+
public
|
526
|
+
def get_environment_schedule_status(environment=nil, at_time=nil)
|
527
|
+
# Get the schedule status for a given environment at a given time. If no "at" parameter is provided, the current status is returned
|
528
|
+
if environment.nil?
|
529
|
+
raise("Environment has not been specified")
|
530
|
+
end
|
531
|
+
if at_time.nil?
|
532
|
+
at_qs = ""
|
533
|
+
else
|
534
|
+
at_qs = "?at=#{at_time}"
|
535
|
+
end
|
536
|
+
request_endpoint = "/api/v1/environments/#{environment}/schedule-status#{at_qs}"
|
537
|
+
return query(request_endpoint, query_type: "GET")
|
538
|
+
end
|
539
|
+
|
540
|
+
public
|
541
|
+
def get_environments_config(environmenttype=nil, cluster=nil)
|
542
|
+
# Get all environment configurations
|
543
|
+
if environmenttype.nil?
|
544
|
+
environmenttype_qs = ""
|
545
|
+
else
|
546
|
+
environmenttype_qs = "environmentType=#{environmenttype}"
|
547
|
+
end
|
548
|
+
if cluster.nil?
|
549
|
+
cluster_qs = ""
|
550
|
+
else
|
551
|
+
cluster_qs = "cluster=#{cluster}"
|
552
|
+
end
|
553
|
+
# Construct qs
|
554
|
+
if environmenttype.nil? and not cluster.nil?
|
555
|
+
constructed_qs = "?#{cluster_qs}"
|
556
|
+
elsif not environmenttype.nil? and cluster.nil?
|
557
|
+
constructed_qs = "?#{environmenttype_qs}"
|
558
|
+
elsif not environmenttype.nil? and not cluster.nil?
|
559
|
+
constructed_qs = "?#{environmenttype_qs}&#{cluster_qs}"
|
560
|
+
else
|
561
|
+
constructed_qs = ""
|
562
|
+
end
|
563
|
+
request_endpoint = "/api/v1/config/environments#{constructed_qs}"
|
564
|
+
return query(request_endpoint, query_type: "GET")
|
565
|
+
end
|
566
|
+
|
567
|
+
public
|
568
|
+
def post_environments_config(data=Hash.new)
|
569
|
+
# Create a new environment configuration
|
570
|
+
request_endpoint = "/api/v1/config/environments"
|
571
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
572
|
+
end
|
573
|
+
|
574
|
+
public
|
575
|
+
def get_environment_config(environment=nil)
|
576
|
+
# Get a specific environment configuration
|
577
|
+
if environment.nil?
|
578
|
+
raise("Environment has not been specified")
|
579
|
+
end
|
580
|
+
request_endpoint = "/api/v1/config/environments/#{environment}"
|
581
|
+
return query(request_endpoint, query_type: "GET")
|
582
|
+
end
|
583
|
+
|
584
|
+
public
|
585
|
+
def put_environment_config(environment=nil, expected_version=nil, data=Hash.new)
|
586
|
+
# Update an environment configuration
|
587
|
+
if environment.nil?
|
588
|
+
raise("Environment has not been specified")
|
589
|
+
end
|
590
|
+
if expected_version.nil?
|
591
|
+
headers = ""
|
592
|
+
else
|
593
|
+
headers = {"expected-version" => expected_version}
|
594
|
+
end
|
595
|
+
request_endpoint = "/api/v1/config/environments/#{environment}"
|
596
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
597
|
+
end
|
598
|
+
|
599
|
+
public
|
600
|
+
def delete_environment_config(environment=nil)
|
601
|
+
# Delete an environment configuration
|
602
|
+
if environment.nil?
|
603
|
+
raise("Environment has not been specified")
|
604
|
+
end
|
605
|
+
request_endpoint = "/api/v1/config/environments/#{environment}"
|
606
|
+
return query(request_endpoint, query_type: "DELETE")
|
607
|
+
end
|
608
|
+
|
609
|
+
## Environment Type
|
610
|
+
public
|
611
|
+
def get_environmenttypes_config()
|
612
|
+
# Get all environment type configurations
|
613
|
+
request_endpoint = "/api/v1/config/environment-types"
|
614
|
+
return query(request_endpoint, query_type: "GET")
|
615
|
+
end
|
616
|
+
|
617
|
+
public
|
618
|
+
def post_environmenttypes_config(data=Hash.new)
|
619
|
+
# Create an Environment Type configuration
|
620
|
+
request_endpoint = "/api/v1/config/environment-types"
|
621
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
622
|
+
end
|
623
|
+
|
624
|
+
public
|
625
|
+
def get_environmenttype_config(environmenttype=nil)
|
626
|
+
# Get an specific environment type configuration
|
627
|
+
if environmenttype.nil?
|
628
|
+
raise("Environment type has not been specified")
|
629
|
+
end
|
630
|
+
request_endpoint = "/api/v1/config/environment-types/#{environmenttype}"
|
631
|
+
return query(request_endpoint, query_type: "GET")
|
632
|
+
end
|
633
|
+
|
634
|
+
public
|
635
|
+
def put_environmenttype_config(environmenttype=nil, expected_version=nil, data=Hash.new)
|
636
|
+
# Update an environment type configuration
|
637
|
+
if environmenttype.nil?
|
638
|
+
raise("Environment type has not been specified")
|
639
|
+
end
|
640
|
+
if expected_version.nil?
|
641
|
+
headers = ""
|
642
|
+
else
|
643
|
+
headers = {"expected-version" => expected_version}
|
644
|
+
end
|
645
|
+
request_endpoint = "/api/v1/config/environment-types/#{environmenttype}"
|
646
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
647
|
+
end
|
648
|
+
|
649
|
+
public
|
650
|
+
def delete_environmenttype_config(environmenttype=nil)
|
651
|
+
# Delete an environment type
|
652
|
+
if environmenttype.nil?
|
653
|
+
raise("Environment type has not been specified")
|
654
|
+
end
|
655
|
+
request_endpoint = "/api/v1/config/environment-types/#{environmenttype}"
|
656
|
+
return query(request_endpoint, query_type: "DELETE")
|
657
|
+
end
|
658
|
+
|
659
|
+
## Export
|
660
|
+
public
|
661
|
+
def export_resource(resource=nil, account=nil)
|
662
|
+
# Export a configuration resources dynamo table
|
663
|
+
if resource.nil? or account.nil?
|
664
|
+
raise("Resource or account has not been specified")
|
665
|
+
end
|
666
|
+
request_endpoint = "/api/v1/config/export/#{resource}?account=#{account}"
|
667
|
+
return query(request_endpoint, query_type: "GET")
|
668
|
+
end
|
669
|
+
|
670
|
+
## Import
|
671
|
+
public
|
672
|
+
def import_resource(resource=nil, account=nil, mode=nil, data=Hash.new)
|
673
|
+
# Import a configuration resources dynamo table
|
674
|
+
if resource.nil? or account.nil? or mode.nil?
|
675
|
+
raise("Resource or account has not been specified")
|
676
|
+
end
|
677
|
+
request_endpoint = "/api/v1/config/import/#{resource}?account=#{account}&mode=#{mode}"
|
678
|
+
return query(request_endpoint, query_type: "PUT", data: data)
|
679
|
+
end
|
680
|
+
|
681
|
+
## Instance
|
682
|
+
public
|
683
|
+
def get_instances()
|
684
|
+
# Get all instances matching the given criteria
|
685
|
+
request_endpoint = "/api/v1/instances"
|
686
|
+
return query(request_endpoint, query_type: "GET")
|
687
|
+
end
|
688
|
+
|
689
|
+
public
|
690
|
+
def get_instance(instance_id=nil)
|
691
|
+
# Get a specific instance
|
692
|
+
if instance_id.nil?
|
693
|
+
raise("Instance id has not been specified")
|
694
|
+
end
|
695
|
+
request_endpoint = "/api/v1/instances/#{instance_id}"
|
696
|
+
return query(request_endpoint, query_type: "GET")
|
697
|
+
end
|
698
|
+
|
699
|
+
public
|
700
|
+
def get_instance_connect(instance_id=nil)
|
701
|
+
# Connect to the instance via remote desktop
|
702
|
+
if instance_id.nil?
|
703
|
+
raise("Instance id has not been specified")
|
704
|
+
end
|
705
|
+
request_endpoint = "/api/v1/instances/#{instance_id}/connect"
|
706
|
+
return query(request_endpoint, query_type: "GET")
|
707
|
+
end
|
708
|
+
|
709
|
+
public
|
710
|
+
def put_instance_maintenance(instance_id=nil, data=Hash.new)
|
711
|
+
# Update the ASG standby-state of a given instance
|
712
|
+
if instance_id.nil?
|
713
|
+
raise("Instance id has not been specified")
|
714
|
+
end
|
715
|
+
request_endpoint = "/api/v1/instances/#{instance_id}/maintenance"
|
716
|
+
return query(request_endpoint, query_type: "PUT")
|
717
|
+
end
|
718
|
+
|
719
|
+
## Load Balancers
|
720
|
+
public
|
721
|
+
def get_loadbalancer(id=nil)
|
722
|
+
# Get load balancer data
|
723
|
+
if id.nil?
|
724
|
+
raise("Load Balancer ID has not been specified")
|
725
|
+
end
|
726
|
+
request_endpoint = "/api/v1/config/load-balancer/#{id}"
|
727
|
+
return query(request_endpoint, query_type: "GET")
|
728
|
+
end
|
729
|
+
|
730
|
+
public
|
731
|
+
def get_lbsettings_config()
|
732
|
+
# List all load balancer settings
|
733
|
+
request_endpoint = "/api/v1/config/lb-settings"
|
734
|
+
return query(request_endpoint, query_type: "GET")
|
735
|
+
end
|
736
|
+
|
737
|
+
public
|
738
|
+
def post_lbsettings_config(data=Hash.new)
|
739
|
+
# Create a load balancer setting
|
740
|
+
request_endpoint = "/api/v1/config/lb-settings"
|
741
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
742
|
+
end
|
743
|
+
|
744
|
+
public
|
745
|
+
def get_lbsettings_vhost_config(environment=nil, vhostname=nil)
|
746
|
+
# Get a specific load balancer setting
|
747
|
+
if environment.nil?
|
748
|
+
raise("Environment has not been specified")
|
749
|
+
end
|
750
|
+
if vhostname.nil?
|
751
|
+
raise("Virtual Host Name (vhostname) has not been specified")
|
752
|
+
end
|
753
|
+
request_endpoint = "/api/v1/config/lb-settings/#{environment}/#{vhostname}"
|
754
|
+
return query(request_endpoint, query_type: "GET")
|
755
|
+
end
|
756
|
+
|
757
|
+
public
|
758
|
+
def put_lbsettings_vhost_config(environment=nil, vhostname=nil, expected_version=nil, data=Hash.new)
|
759
|
+
# Update a load balancer setting
|
760
|
+
if environment.nil?
|
761
|
+
raise("Environment has not been specified")
|
762
|
+
end
|
763
|
+
if vhostname.nil?
|
764
|
+
raise("Virtual Host Name (vhostname) has not been specified")
|
765
|
+
end
|
766
|
+
if expected_version.nil?
|
767
|
+
headers = ""
|
768
|
+
else
|
769
|
+
headers = {"expected-version" => expected_version}
|
770
|
+
end
|
771
|
+
request_endpoint = "/api/v1/config/lb-settings/#{environment}/#{vhostname}"
|
772
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
773
|
+
end
|
774
|
+
|
775
|
+
public
|
776
|
+
def delete_lbsettings_vhost_config(environment=nil, vhostname=nil)
|
777
|
+
# Delete an load balancer setting
|
778
|
+
if environment.nil?
|
779
|
+
raise("Environment has not been specified")
|
780
|
+
end
|
781
|
+
if vhostname.nil?
|
782
|
+
raise("Virtual Host Name (vhostname) has not been specified")
|
783
|
+
end
|
784
|
+
request_endpoint = "/api/v1/config/lb-settings/#{environment}/#{vhostname}"
|
785
|
+
return query(request_endpoint, query_type: "DELETE")
|
786
|
+
end
|
787
|
+
|
788
|
+
## Notifications
|
789
|
+
public
|
790
|
+
def get_notificationsettings_config()
|
791
|
+
# List Notification settings
|
792
|
+
request_endpoint = "/api/v1/config/notification-settings"
|
793
|
+
return query(request_endpoint, query_type: "GET")
|
794
|
+
end
|
795
|
+
|
796
|
+
public
|
797
|
+
def post_notificationsettings_config(data=Hash.new)
|
798
|
+
# Post new Notification settings
|
799
|
+
request_endpoint = "/api/v1/config/notification-settings"
|
800
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
801
|
+
end
|
802
|
+
|
803
|
+
public
|
804
|
+
def get_notificationsetting_config(notification_id=nil)
|
805
|
+
# Get Notification settings
|
806
|
+
if notification_id.nil?
|
807
|
+
raise("Notification id has not been specified")
|
808
|
+
end
|
809
|
+
request_endpoint = "/api/v1/notification-settings/#{notification_id}"
|
810
|
+
return query(request_endpoint, query_type: "GET")
|
811
|
+
end
|
812
|
+
|
813
|
+
public
|
814
|
+
def put_notificationsetting_config(notification_id=nil, expected_version=nil, data=Hash.new)
|
815
|
+
# Update an associated AWS Account
|
816
|
+
if notification_id.nil?
|
817
|
+
raise("Notification id has not been specified")
|
818
|
+
end
|
819
|
+
if expected_version.nil?
|
820
|
+
headers = ""
|
821
|
+
else
|
822
|
+
headers = {"expected-version" => expected_version}
|
823
|
+
end
|
824
|
+
request_endpoint = "/api/v1/notification-settings/#{notification_id}"
|
825
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
826
|
+
end
|
827
|
+
|
828
|
+
public
|
829
|
+
def delete_notificationsetting_config(notification_id=nil)
|
830
|
+
# Remove Notification settings
|
831
|
+
if notification_id.nil?
|
832
|
+
raise("Notification id has not been specified")
|
833
|
+
end
|
834
|
+
request_endpoint = "/api/v1/notification-settings/#{notification_id}"
|
835
|
+
return query(request_endpoint, query_type: "DELETE")
|
836
|
+
end
|
837
|
+
|
838
|
+
## Upload Package
|
839
|
+
# TODO Slice
|
840
|
+
public
|
841
|
+
def get_package_upload_url_environment(service=nil, version=nil, environment=nil)
|
842
|
+
# Upload an environment-specific package
|
843
|
+
if service.nil? or version.nil? or environment.nil?
|
844
|
+
raise("Parameter has not been specified")
|
845
|
+
end
|
846
|
+
request_endpoint = "/api/v1/package-upload-url/#{service}/#{version}/#{environment}"
|
847
|
+
return query(request_endpoint, query_type: "GET")
|
848
|
+
end
|
849
|
+
|
850
|
+
public
|
851
|
+
def get_package_upload_url(service=nil, version=nil)
|
852
|
+
# Upload an environment-independent package
|
853
|
+
if service.nil? or version.nil?
|
854
|
+
raise("Parameter has not been specified")
|
855
|
+
end
|
856
|
+
request_endpoint = "/api/v1/package-upload-url/#{service}/#{version}"
|
857
|
+
return query(request_endpoint, query_type: "GET")
|
858
|
+
end
|
859
|
+
|
860
|
+
## Permissions
|
861
|
+
public
|
862
|
+
def get_permissions_config()
|
863
|
+
# Get all permission configurations
|
864
|
+
request_endpoint = "/api/v1/config/permissions"
|
865
|
+
return query(request_endpoint, query_type: "GET")
|
866
|
+
end
|
867
|
+
|
868
|
+
public
|
869
|
+
def post_permissions_config(data=Hash.new)
|
870
|
+
# Create a new permission configuration"""
|
871
|
+
request_endpoint = "/api/v1/config/permissions"
|
872
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
873
|
+
end
|
874
|
+
|
875
|
+
public
|
876
|
+
def get_permission_config(name=nil)
|
877
|
+
# Get a specific permission configuration
|
878
|
+
if name.nil?
|
879
|
+
raise("Permission name has not been specified")
|
880
|
+
end
|
881
|
+
request_endpoint = "/api/v1/config/permissions/#{name}"
|
882
|
+
return query(request_endpoint, query_type: "GET")
|
883
|
+
end
|
884
|
+
|
885
|
+
public
|
886
|
+
def put_permission_config(name=nil, expected_version=nil, data=Hash.new)
|
887
|
+
# Update a permission configuration
|
888
|
+
if name.nil?
|
889
|
+
raise("Permission name has not been specified")
|
890
|
+
end
|
891
|
+
if expected_version.nil?
|
892
|
+
headers = ""
|
893
|
+
else
|
894
|
+
headers = {"expected-version" => expected_version}
|
895
|
+
end
|
896
|
+
request_endpoint = "/api/v1/config/permissions/#{name}"
|
897
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
898
|
+
end
|
899
|
+
|
900
|
+
public
|
901
|
+
def delete_permission_config(name=nil)
|
902
|
+
# Delete a permissions configuration
|
903
|
+
if name.nil?
|
904
|
+
raise("Permission name has not been specified")
|
905
|
+
end
|
906
|
+
request_endpoint = "/api/v1/config/permissions/#{name}"
|
907
|
+
return query(request_endpoint, query_type: "DELETE")
|
908
|
+
end
|
909
|
+
|
910
|
+
## Service
|
911
|
+
public
|
912
|
+
def get_services()
|
913
|
+
# Get the list of currently deployed services
|
914
|
+
request_endpoint = "/api/v1/services"
|
915
|
+
return query(request_endpoint, query_type: "GET")
|
916
|
+
end
|
917
|
+
|
918
|
+
public
|
919
|
+
def get_service(service=nil)
|
920
|
+
# Get a currently deployed service
|
921
|
+
if service.nil?
|
922
|
+
raise("Service has not been specified")
|
923
|
+
end
|
924
|
+
request_endpoint = "/api/v1/services/#{service}"
|
925
|
+
return query(request_endpoint, query_type: "GET")
|
926
|
+
end
|
927
|
+
|
928
|
+
public
|
929
|
+
def get_service_asgs(service=nil, environment=nil, slice=nil)
|
930
|
+
# Get the ASGs to which a service is deployed
|
931
|
+
if service.nil?
|
932
|
+
raise("Service has not been specified")
|
933
|
+
end
|
934
|
+
if environment.nil?
|
935
|
+
raise("Environment has not been specified")
|
936
|
+
end
|
937
|
+
if slice.nil?
|
938
|
+
slice_qs = ""
|
939
|
+
else
|
940
|
+
slice_qs = "&slice=#{slice}"
|
941
|
+
end
|
942
|
+
request_endpoint = "/api/v1/services/#{service}/asgs?environment=#{environment}#{slice_qs}"
|
943
|
+
return query(request_endpoint, query_type: "GET")
|
944
|
+
end
|
945
|
+
|
946
|
+
public
|
947
|
+
def get_service_overall_health(service=nil, environment=nil)
|
948
|
+
# Get a overall health for a deployed service
|
949
|
+
if service.nil?
|
950
|
+
raise("Service has not been specified")
|
951
|
+
end
|
952
|
+
if environment.nil?
|
953
|
+
raise("Environment has not been specified")
|
954
|
+
end
|
955
|
+
request_endpoint = "/api/v1/services/#{service}/health?environment=#{environment}"
|
956
|
+
return query(request_endpoint, query_type: "GET")
|
957
|
+
end
|
958
|
+
|
959
|
+
public
|
960
|
+
def get_service_health(service=nil, environment=nil, slice=nil, server_role=nil)
|
961
|
+
# Get health for a specific service
|
962
|
+
if service.nil?
|
963
|
+
raise("Service has not been specified")
|
964
|
+
end
|
965
|
+
if environment.nil?
|
966
|
+
raise("Environment has not been specified")
|
967
|
+
end
|
968
|
+
if slice.nil?
|
969
|
+
raise("Slice has not been specified")
|
970
|
+
end
|
971
|
+
request_endpoint = "/api/v1/services/#{service}/health/#{slice}?environment=#{environment}"
|
972
|
+
if not server_role.nil?
|
973
|
+
request_endpoint = "#{request_endpoint}&serverRole=#{server_role}"
|
974
|
+
end
|
975
|
+
return query(request_endpoint, query_type: "GET")
|
976
|
+
end
|
977
|
+
|
978
|
+
public
|
979
|
+
def get_service_slices(service=nil, environment=nil, active=nil)
|
980
|
+
# Get slices for a deployed service
|
981
|
+
if service.nil?
|
982
|
+
raise SyntaxError("Service has not been specified")
|
983
|
+
end
|
984
|
+
if environment.nil?
|
985
|
+
raise SyntaxError("Environment has not been specified")
|
986
|
+
end
|
987
|
+
request_endpoint = "/api/v1/services/#{service}/slices?environment=#{environment}"
|
988
|
+
if not active.nil?
|
989
|
+
request_endpoint = "#{request_endpoint}&active=#{active}"
|
990
|
+
end
|
991
|
+
return query(request_endpoint, query_type: "GET")
|
992
|
+
end
|
993
|
+
|
994
|
+
public
|
995
|
+
def put_service_slices_toggle(service=nil, environment=nil)
|
996
|
+
# Toggle the slices for a deployed service
|
997
|
+
if service.nil?
|
998
|
+
raise("Service has not been specified")
|
999
|
+
end
|
1000
|
+
if environment.nil?
|
1001
|
+
raise("Environment has not been specified")
|
1002
|
+
end
|
1003
|
+
request_endpoint = "/api/v1/services/#{service}/slices/toggle?environment=#{environment}"
|
1004
|
+
return query(request_endpoint, query_type: "PUT")
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
public
|
1008
|
+
def get_services_config()
|
1009
|
+
# Get all service configurations
|
1010
|
+
request_endpoint = "/api/v1/config/services"
|
1011
|
+
return query(request_endpoint, query_type: "GET")
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
public
|
1015
|
+
def post_services_config(data=Hash.new)
|
1016
|
+
# Create a service configuration
|
1017
|
+
request_endpoint = "/api/v1/config/services"
|
1018
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
public
|
1022
|
+
def get_service_config(service=nil, cluster=nil)
|
1023
|
+
# Get a specific service configuration
|
1024
|
+
if service.nil?
|
1025
|
+
raise("Service has not been specified")
|
1026
|
+
end
|
1027
|
+
if cluster.nil?
|
1028
|
+
raise("Cluster name (team) has not been specified")
|
1029
|
+
end
|
1030
|
+
request_endpoint = "/api/v1/config/services/#{service}/#{cluster}"
|
1031
|
+
return query(request_endpoint, query_type: "GET")
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
public
|
1035
|
+
def put_service_config(service=nil, cluster=nil, expected_version=nil, data=Hash.new)
|
1036
|
+
# Update a service configuration
|
1037
|
+
if service.nil?
|
1038
|
+
raise("Service has not been specified")
|
1039
|
+
end
|
1040
|
+
if cluster.nil?
|
1041
|
+
raise("Cluster name (team) has not been specified")
|
1042
|
+
end
|
1043
|
+
if expected_version.nil?
|
1044
|
+
headers = ""
|
1045
|
+
else
|
1046
|
+
headers = {"expected-version" => expected_version}
|
1047
|
+
end
|
1048
|
+
request_endpoint = "/api/v1/config/services/#{service}/#{cluster}"
|
1049
|
+
return query(request_endpoint, query_type: "POST", data: data, headers: headers)
|
1050
|
+
end
|
1051
|
+
|
1052
|
+
public
|
1053
|
+
def delete_service_config(service=nil, cluster=nil)
|
1054
|
+
# Delete a service configuration
|
1055
|
+
if service.nil?
|
1056
|
+
raise("Service has not been specified")
|
1057
|
+
end
|
1058
|
+
if cluster.nil?
|
1059
|
+
raise("Cluster name (team) has not been specified")
|
1060
|
+
end
|
1061
|
+
request_endpoint = "/api/v1/config/services/#{service}/#{cluster}"
|
1062
|
+
return query(request_endpoint, query_type: "DELETE")
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
## Status
|
1066
|
+
public
|
1067
|
+
def get_status()
|
1068
|
+
# Get version and status information
|
1069
|
+
request_endpoint = "/api/v1/diagnostics/healthcheck"
|
1070
|
+
return query(request_endpoint, query_type: "GET")
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
## Target State
|
1074
|
+
public
|
1075
|
+
def get_target_state(environment=nil)
|
1076
|
+
# Get the target state for a given environment
|
1077
|
+
if environment.nil?
|
1078
|
+
raise("Environment has not been specified")
|
1079
|
+
end
|
1080
|
+
request_endpoint = "/api/v1/target-state/#{environment}"
|
1081
|
+
return query(request_endpoint, query_type: "GET")
|
1082
|
+
end
|
1083
|
+
|
1084
|
+
public
|
1085
|
+
def delete_target_state(environment=nil)
|
1086
|
+
# Remove the target state for all services in a given environment
|
1087
|
+
if environment.nil?
|
1088
|
+
raise("Environment has not been specified")
|
1089
|
+
end
|
1090
|
+
request_endpoint = "/api/v1/target-state/#{environment}"
|
1091
|
+
return query(request_endpoint, query_type: "DELETE")
|
1092
|
+
end
|
1093
|
+
|
1094
|
+
public
|
1095
|
+
def delete_target_state_service(environment=nil, service=nil)
|
1096
|
+
# Remove the target state for all versions of a service
|
1097
|
+
if environment.nil? or service.nil?
|
1098
|
+
raise("Environment or Service has not been specified")
|
1099
|
+
end
|
1100
|
+
request_endpoint = "/api/v1/target-state/#{environment}/#{service}"
|
1101
|
+
return query(request_endpoint, query_type: "DELETE")
|
1102
|
+
end
|
1103
|
+
|
1104
|
+
public
|
1105
|
+
def delete_target_state_service_version(environment=nil, service=nil, version=nil)
|
1106
|
+
# Remove the target state for a specific version of a service
|
1107
|
+
if environment.nil? or service.nil? or version.nil?
|
1108
|
+
raise("Environment or Service has not been specified")
|
1109
|
+
end
|
1110
|
+
request_endpoint = "/api/v1/target-state/#{environment}/#{service}/#{version}"
|
1111
|
+
return query(request_endpoint, query_type: "DELETE")
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
## Upstream
|
1115
|
+
public
|
1116
|
+
def get_upstream_slices(upstream=nil)
|
1117
|
+
# Get slices for a given upstream
|
1118
|
+
if upstream.nil?
|
1119
|
+
raise("Upstream name has not been specified")
|
1120
|
+
end
|
1121
|
+
request_endpoint = "/api/v1/upstreams/#{upstream}/slices"
|
1122
|
+
return query(request_endpoint, query_type: "GET")
|
1123
|
+
end
|
1124
|
+
|
1125
|
+
public
|
1126
|
+
def put_upstream_slices_toggle(upstream=nil, environment=nil)
|
1127
|
+
# Toggle the slices for a given upstream
|
1128
|
+
if upstream.nil? or environment.nil?
|
1129
|
+
raise("Upstream name or Service name has not been specified")
|
1130
|
+
end
|
1131
|
+
request_endpoint = "/api/v1/upstreams/#{upstream}/slices/toggle?environment=#{environment}"
|
1132
|
+
return query(request_endpoint, query_type: "GET")
|
1133
|
+
end
|
1134
|
+
|
1135
|
+
public
|
1136
|
+
def get_upstreams_config()
|
1137
|
+
# Get all upstream configurations
|
1138
|
+
request_endpoint = "/api/v1/config/upstreams"
|
1139
|
+
return query(request_endpoint, query_type: "GET")
|
1140
|
+
end
|
1141
|
+
|
1142
|
+
public
|
1143
|
+
def post_upstreams_config(data=Hash.new)
|
1144
|
+
# Create an upstream configuration
|
1145
|
+
request_endpoint = "/api/v1/config/upstreams"
|
1146
|
+
return query(request_endpoint, query_type: "POST", data: data)
|
1147
|
+
end
|
1148
|
+
|
1149
|
+
public
|
1150
|
+
def get_upstream_config(upstream=nil, account="Non-Prod")
|
1151
|
+
# Get an a specific upstream configuration
|
1152
|
+
if upstream.nil?
|
1153
|
+
raise("Upstream name has not been specified")
|
1154
|
+
end
|
1155
|
+
request_endpoint = "/api/v1/config/upstreams/#{upstream}?account=#{account}"
|
1156
|
+
return query(request_endpoint, query_type: "GET")
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
public
|
1160
|
+
def put_upstream_config(upstream=nil, expected_version=nil, data=Hash.new)
|
1161
|
+
# Update an upstream configuration
|
1162
|
+
if upstream.nil?
|
1163
|
+
raise("Upstream name has not been specified")
|
1164
|
+
end
|
1165
|
+
if expected_version.nil?
|
1166
|
+
headers = ""
|
1167
|
+
else
|
1168
|
+
headers = {"expected-version" => expected_version}
|
1169
|
+
end
|
1170
|
+
request_endpoint = "/api/v1/config/upstreams/#{upstream}"
|
1171
|
+
return query(request_endpoint, query_type: "PUT", headers: headers, data: data)
|
1172
|
+
end
|
1173
|
+
|
1174
|
+
public
|
1175
|
+
def delete_upstream_config(upstream=nil, account="Non-Prod")
|
1176
|
+
# Delete an upstream configuration
|
1177
|
+
if upstream.nil?
|
1178
|
+
raise("Upstream name has not been specified")
|
1179
|
+
end
|
1180
|
+
request_endpoint = "/api/v1/config/upstreams/#{upstream}?account=#{account}"
|
1181
|
+
return query(request_endpoint, query_type: "DELETE")
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
end
|
1185
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: environment-manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marc Cluet
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
33
|
+
description: " Ruby client that supports all API endpoints for Environment Manager "
|
34
|
+
email: marc.cluet@thetrainline.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files:
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
files:
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- lib/environment-manager.rb
|
44
|
+
- lib/environment_manager/api.rb
|
45
|
+
homepage: https://github.com/trainline/ruby-environment_manager
|
46
|
+
licenses:
|
47
|
+
- Apache-2.0
|
48
|
+
metadata: {}
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.9.2
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.6.10
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Ruby client for Environment Manager
|
69
|
+
test_files: []
|