kitchen-scalr 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8ed1f4e7e3d101bfe6107378dc25ff7fbfbed1e3
4
- data.tar.gz: 734761f4cc1be9162f1219a4b10877a09db2c752
2
+ SHA256:
3
+ metadata.gz: 8d98764d098645a987936f906da189ec83f648837d7682c603bfeffe409ee55f
4
+ data.tar.gz: 1ef55e6731cf0632791ff32925dfdba73a684d655121de52096225cbd776b5e0
5
5
  SHA512:
6
- metadata.gz: cc271796f6409665cad6181b940ccb74c11ded4708466878a71722d72cf155133442763eb54821f655490a21473cef8ffeffaf2ae08ebd2b518daa09cc6183a2
7
- data.tar.gz: c27b8242b2793201af2cce6d9d9b213d895c280ef965989b7e5e3cc9f8836e7acaa7e19cb55f5c8159fd4a07ba11bfe7459eb24d11538832c43b3f2442930f60
6
+ metadata.gz: 8c69a8c03da69535edd05389c90b73c3e41b912a023cab35ebf9ba01a35e45d15ddfc9107f74f1d45bd456b32d3eaf6e0178a8d03ec7124aa03caaa7cdc0d1d7
7
+ data.tar.gz: cc2a824e00bd5f1eed517953a7e2478c66ffeb74b8d604a8f664a1df15d797506cae04f9d88056a7c44c8ac5b7e4df2c329d0c6b8bfb57cb30a8d10cf98d4821
@@ -1,3 +1,6 @@
1
+ ## 0.2.7
2
+ * Add scalr_global_variables setting
3
+
1
4
  ## 0.2.6
2
5
  * Compatibility with Scalr 7.7.7
3
6
 
data/README.md CHANGED
@@ -8,60 +8,102 @@ A Test Kitchen Driver for Scalr. This driver creates an instance on Scalr by cre
8
8
 
9
9
  ## <a name="installation"></a> Installation and Setup
10
10
 
11
+ In short:
12
+ ```
13
+ gem install kitchen-scalr
14
+ ```
15
+
11
16
  Please read the [Driver usage][driver_usage] page for more details.
12
17
 
13
18
  ## <a name="config"></a> Configuration
19
+
14
20
  ### scalr_api_url
15
21
  **Required** This is the URL of the Scalr server that will be reached by the driver.
22
+
16
23
  ### scalr_env_id
17
24
  **Required** This is a string corresponding to the environment id used by the plugin.
25
+
18
26
  ### scalr_api_key_id and scalr_api_key_secret
19
27
  **Required except on macOS and Windows** These are respectively the API KEY ID and API KEY secret used to make the API calls to Scalr. This option **SHOULD NOT** be used on Windows and macOS because kitchen scalr integrates natively with these OSes to ensure secure storage of the Scalr credentials. In this case, Kitchen-Scalr will prompt for credentials at the first use, and memorize them for further calls.
28
+
20
29
  ### scalr_project_id
21
30
  **Required** This is a string corresponding to the project identifier used to create the farm in Scalr. This is used in Scalr for accountability and cost management.
31
+
22
32
  ### scalr_use_role
23
33
  **Optional** Setting this option to an integer corresponding to a role id will trigger Role mode with the provided role identifier. If this option is not set, the driver will work in Image mode.
34
+
24
35
  ### scalr_server_image
25
36
  **Required in Image mode** This is a string corresponding to the image name used to instanciate the server.
37
+
26
38
  ### scalr_server_instanceType
27
39
  **Required** This is a string corresponding to the instance type of the VMs in the underlying cloud. Example: 'm3.medium'
40
+
28
41
  ### scalr_platform
29
42
  **Required in Role mode** This is the identifier of the underlying cloud platform. Examples: "ec2", "gce", "openstack".
43
+
30
44
  ### scalr_location
31
45
  **Required in Role mode** This is a string corresponding to the cloud location used to create the instance. Example: "us-east-1"
46
+
47
+ ### scalr_global_variables
48
+ **Optional** This is a dictionary of Scalr Global Variables to set or create. Global Variables in this dictionary are created if they don't exist in Scalr, otherwise their value is set. By default these global variables are set at the Farm Role scope, if you need to set one at the Farm scope, add `scope: Farm` to its description. Additional Global Variable settings corresponding to the definition of a [Global Variable object](https://api-explorer.scalr.com/definitions/G/GlobalVariable.html) in Scalr's APIv2 can be passed for each Global Variable. These settings are used only when the global variable is created, they are ignored if it is only set.
49
+
32
50
  ### scalr_permit_ssh_root_login
33
51
  **Optional** This is a boolean, default is 'false', that configures sshd to allow root logins and bounces the service during kitchen create. Useful if your base image does not allow ssh as root by default.
52
+
34
53
  ### scalr_base_farm_role
35
- **Optional** This is a yaml representation of a Farm Role Object as described in the APIv2 in Scalr. When kitchen-scalr creates a server, it merges this object with the previously-described parameters and creates the corresponding Farm Role. This section can be used to configure Security Groups, Networking etc... You can put the same parameters there as the ones you would get with a `scalr-ctl farm-roles get`.
54
+ **Optional** This is a yaml representation of a [Farm Role Object](https://api-explorer.scalr.com/definitions/F/FarmRole.html) as represented in the APIv2 in Scalr. When kitchen-scalr creates a server, it merges this object with the previously-described parameters and creates the corresponding Farm Role. This section can be used to configure Security Groups, Networking etc... You can put the same parameters there as the ones you would get with a `scalr-ctl farm-roles get`.
55
+
36
56
  ### scalr_use_private_ip
37
57
  **Optional** If set to true, kitchen will use Scalr private ips for the instances, otherwise it will use the public one.
58
+
38
59
  ## Configuration example
39
- ---
60
+
61
+ ```yaml
62
+ ---
63
+ driver:
64
+ name: scalr
65
+
66
+ provisioner:
67
+ name: chef_zero
68
+
69
+ verifier:
70
+ name: inspec
71
+
72
+ platforms:
73
+ - name: ubuntu-16.04
40
74
  driver:
41
- name: scalr
42
-
43
- provisioner:
44
- name: chef_zero
45
-
46
- verifier:
47
- name: inspec
48
-
49
- platforms:
50
- - name: ubuntu-14.04
51
- driver:
52
- scalr_api_url: 'http://my.scalr.com'
53
- scalr_env_id: '2'
54
- scalr_project_id: '30c59dba-fc9b-4d0f-83ec-4b5043b12f72'
55
- scalr_server_instanceType: 'm3.medium'
56
- scalr_use_role: 12345
57
- scalr_platform: 'ec2'
58
- scalr_location: 'us-east-1'
59
- scalr_base_farm_role:
60
- security:
61
- securityGroups:
62
- - id: 'sg-3b3d9153'
63
- - id: 'sg-349a765f'
64
- - id: 'sg-4a9a7621'
75
+ scalr_api_url: 'https://my.scalr.com'
76
+ scalr_env_id: '2'
77
+ scalr_project_id: '30c59dba-fc9b-4d0f-83ec-4b5043b12f72'
78
+ scalr_server_instanceType: 'm3.medium'
79
+ scalr_use_role: 12345
80
+ scalr_platform: 'ec2'
81
+ scalr_location: 'us-east-1'
82
+ scalr_base_farm_role: # Add platform-specific Farm Role settings
83
+ cloudFeatures:
84
+ type: AwsCloudFeatures
85
+ ebsOptimized: false
86
+ networking:
87
+ networks:
88
+ - id: vpc-xxxxxxxx
89
+ subnets:
90
+ - id: subnet-xxxxxxxx
91
+ security:
92
+ securityGroups:
93
+ - id: 'sg-3b3d9153'
94
+ - id: 'sg-349a765f'
95
+ - id: 'sg-4a9a7621'
96
+ scalr_global_variables:
97
+ My_Global_Variable: # Set or create a global variable named My_Global_Variable
98
+ value: Hello World
99
+ My_Secret_GV: # Create a Global Variable with additional settings
100
+ value: access-token
101
+ category: Monitoring
102
+ hidden: true
103
+ My_Farm_Scope_GV: # Set a Global Variable at the Farm scope
104
+ value: Farm name
105
+ scope: Farm
106
+ ```
65
107
 
66
108
  ## <a name="development"></a> Development
67
109
 
@@ -80,7 +122,8 @@ example:
80
122
 
81
123
  ## <a name="thanks"></a> Thanks
82
124
 
83
- - @daxgames for contributing the 'permit_ssh_root_login' setting.
125
+ - [@daxgames](https://github.com/daxgames) for contributing the `permit_ssh_root_login` setting.
126
+ - [@bpezan](https://github.com/bpezan) for contributing the `scalr_global_variables` setting.
84
127
 
85
128
  ## <a name="authors"></a> Authors
86
129
 
@@ -89,7 +132,7 @@ example:
89
132
 
90
133
  ## <a name="license"></a> License
91
134
 
92
- Apache 2.0 (see [LICENSE][license])
135
+ Apache 2.0 (see [LICENSE][license
93
136
 
94
137
 
95
138
  [author]: https://github.com/momohawari
@@ -74,10 +74,10 @@ class ScalrAPI
74
74
  :payload => body
75
75
  )
76
76
  rescue RestClient::ExceptionWithResponse => e
77
- puts "Scalr server returned an error: "
78
- puts e.response
79
- raise e
80
- end
77
+ puts "Scalr server returned an error: "
78
+ puts e.response
79
+ raise e
80
+ end
81
81
  if response == ""
82
82
  response = "{}"
83
83
  end
@@ -123,4 +123,10 @@ class ScalrAPI
123
123
  return response['data']
124
124
  end
125
125
 
126
- end
126
+ #Edit items in API via PATCH
127
+ def edit(url, data)
128
+ response = self.request('PATCH', url, data)
129
+ return response['data']
130
+ end
131
+
132
+ end
@@ -57,7 +57,7 @@ module Kitchen
57
57
 
58
58
  default_config :scalr_server_status_polling_period, 10
59
59
 
60
- default_config :scalr_server_status_polling_timeout, 600
60
+ default_config :scalr_server_status_polling_timeout, 1800
61
61
 
62
62
  default_config :scalr_server_image, ''
63
63
 
@@ -75,6 +75,8 @@ module Kitchen
75
75
 
76
76
  default_config :scalr_use_private_ip, false
77
77
 
78
+ default_config :scalr_global_variables, Hash.new
79
+
78
80
  def create(state)
79
81
  if config[:scalr_api_key_id]==''
80
82
  #We have to find some other way of getting the credentials
@@ -109,6 +111,10 @@ module Kitchen
109
111
  response = scalr_api.create('/api/v1beta0/user/%s/farms/%d/farm-roles/' % [config[:scalr_env_id], state[:farmId]], farmRoleObject)
110
112
  puts "Farm Role created"
111
113
  state[:farmRoleId] = response['id']
114
+ # Creating the configured global variables
115
+ if !config[:scalr_global_variables].empty?
116
+ setup_global_vars(config, state, scalr_api)
117
+ end
112
118
  #Start the farm now
113
119
  response = scalr_api.post('/api/v1beta0/user/%s/farms/%d/actions/launch/' % [config[:scalr_env_id], state[:farmId]], {})
114
120
  state[:farmLaunched] = 1
@@ -274,6 +280,50 @@ module Kitchen
274
280
  puts "RoleImage association created"
275
281
  end
276
282
 
283
+ def setup_global_vars(config, state, scalr_api)
284
+ puts 'Listing existing global variables'
285
+ # Start by listing the GVs at the Farm scope to know which GVs exist
286
+ gv_list = scalr_api.list('/api/v1beta0/user/%s/farms/%d/global-variables/' % [config[:scalr_env_id], state[:farmId]])
287
+ existing_gvs = {}
288
+ gv_list.each do |gv|
289
+ existing_gvs[gv['name']] = gv
290
+ end
291
+ config[:scalr_global_variables].each do |key, val|
292
+ if existing_gvs.has_key? key.to_s
293
+ puts 'Global variable "%s" exists, setting value "%s"...' % [key, val[:value]]
294
+ # set global var value
295
+ if val[:scope] and val[:scope].downcase == 'farm' then
296
+ gv_set_url = '/api/v1beta0/user/%s/farms/%d/global-variables/%s' % [config[:scalr_env_id], state[:farmId], key]
297
+ else
298
+ gv_set_url = '/api/v1beta0/user/%s/farm-roles/%d/global-variables/%s' % [config[:scalr_env_id], state[:farmRoleId], key]
299
+ end
300
+ globalVariableObjectEdit = {
301
+ 'value' => val[:value]
302
+ }
303
+ response = scalr_api.edit(gv_set_url, globalVariableObjectEdit)
304
+ else
305
+ puts 'Global variable "%s" not found, creating with value: "%s"...' % [key, val[:value]]
306
+ # create global var
307
+ if val[:scope] and val[:scope].downcase == 'farm' then
308
+ gv_create_url = '/api/v1beta0/user/%s/farms/%d/global-variables/' % [config[:scalr_env_id], state[:farmId], key]
309
+ else
310
+ gv_create_url = '/api/v1beta0/user/%s/farm-roles/%d/global-variables/' % [config[:scalr_env_id], state[:farmRoleId], key]
311
+ end
312
+ val.delete(:scope)
313
+ globalVariableDefaults = {
314
+ 'category' => '',
315
+ 'name' => key,
316
+ 'description' => '',
317
+ 'hidden' => false,
318
+ 'locked' => false
319
+ }
320
+ globalVariableObjectCreate = globalVariableDefaults.deep_merge(val)
321
+ response = scalr_api.create(gv_create_url, globalVariableObjectCreate)
322
+ end
323
+ end
324
+ puts 'Global variables created/updated'
325
+ end
326
+
277
327
  def setup_credentials(scalr_api,state)
278
328
  response = scalr_api.list('/api/v1beta0/user/%s/farms/%d/servers/' % [config[:scalr_env_id], state[:farmId]])
279
329
  state[:serverId] = response[0]['id']
@@ -311,9 +361,9 @@ module Kitchen
311
361
  puts "Script created with id %s" % [state[:scriptId]]
312
362
  #Now create a script version with the actual body
313
363
  puts "Creating a script version"
314
- puts "Script content:"
315
- puts scriptData
316
- puts "End of script content"
364
+ # puts "Script content:"
365
+ # puts scriptData
366
+ # puts "End of script content"
317
367
  response = scalr_api.create('/api/v1beta0/user/%s/scripts/%d/script-versions/' % [config[:scalr_env_id], state[:scriptId]],
318
368
  {
319
369
  'body' => scriptData,
@@ -21,6 +21,6 @@ module Kitchen
21
21
  module Driver
22
22
 
23
23
  # Version string for Scalr Kitchen driver
24
- SCALR_VERSION = "0.2.6"
24
+ SCALR_VERSION = "0.2.7"
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-scalr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mohammed HAWARI
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-02-08 00:00:00.000000000 Z
12
+ date: 2018-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: test-kitchen
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.6.14
186
+ rubygems_version: 2.7.6
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: A Test Kitchen Driver for Scalr