knife-azure 1.8.0 → 1.8.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
3
  #
4
- # Copyright:: Copyright (c) 2016 Opscode, Inc.
4
+ # Copyright:: Copyright 2009-2018, Chef Software Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -192,7 +192,8 @@ class Chef
192
192
 
193
193
  def run
194
194
  $stdout.sync = true
195
-
195
+ # check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
196
+ get_azure_cli_version
196
197
  validate_arm_keys!(
197
198
  :azure_resource_group_name,
198
199
  :azure_vm_name,
@@ -201,11 +202,8 @@ class Chef
201
202
 
202
203
  begin
203
204
  validate_params!
204
-
205
205
  set_default_image_reference!
206
-
207
206
  ssh_override_winrm if !is_image_windows?
208
-
209
207
  vm_details = service.create_server(create_server_def)
210
208
  rescue => error
211
209
  service.common_arm_rescue_block(error)
@@ -319,61 +317,56 @@ class Chef
319
317
  def set_default_image_reference!
320
318
  begin
321
319
  if locate_config_value(:azure_image_os_type)
322
- if (locate_config_value(:azure_image_reference_publisher) || locate_config_value(:azure_image_reference_offer))
323
- # if azure_image_os_type is given and any of the other image reference parameters like publisher or offer are also given,
324
- # raise error
325
- raise ArgumentError, 'Please specify either --azure-image-os-type OR --azure-image-os-type with --azure-image-reference-sku or 4 image reference parameters i.e.
326
- --azure-image-reference-publisher, --azure-image-reference-offer, --azure-image-reference-sku, --azure-image-reference-version."'
320
+ validate_publisher_and_offer
321
+ ## if azure_image_os_type is given (with or without azure-image-reference-sku) and other image reference parameters are not given,
322
+ # set default image reference parameters
323
+ case locate_config_value(:azure_image_os_type)
324
+ when "ubuntu"
325
+ set_os_image("Canonical", "UbuntuServer", "14.04.2-LTS")
326
+ when "centos"
327
+ set_os_image("OpenLogic", "CentOS", "7.1")
328
+ when "rhel"
329
+ set_os_image("RedHat", "RHEL", "7.2")
330
+ when "debian"
331
+ set_os_image("credativ", "Debian", "7")
332
+ when "windows"
333
+ set_os_image("MicrosoftWindowsServer", "WindowsServer", "2012-R2-Datacenter")
327
334
  else
328
- ## if azure_image_os_type is given (with or without azure-image-reference-sku) and other image reference parameters are not given,
329
- # set default image reference parameters
330
- case locate_config_value(:azure_image_os_type)
331
- when "ubuntu"
332
- config[:azure_image_reference_publisher] = "Canonical"
333
- config[:azure_image_reference_offer] = "UbuntuServer"
334
- config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : "14.04.2-LTS"
335
- when "centos"
336
- config[:azure_image_reference_publisher] = "OpenLogic"
337
- config[:azure_image_reference_offer] = "CentOS"
338
- config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : "7.1"
339
- when "rhel"
340
- config[:azure_image_reference_publisher] = "RedHat"
341
- config[:azure_image_reference_offer] = "RHEL"
342
- config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : "7.2"
343
- when "debian"
344
- config[:azure_image_reference_publisher] = "credativ"
345
- config[:azure_image_reference_offer] = "Debian"
346
- config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : "7"
347
- when "windows"
348
- config[:azure_image_reference_publisher] = "MicrosoftWindowsServer"
349
- config[:azure_image_reference_offer] = "WindowsServer"
350
- config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : "2012-R2-Datacenter"
351
- else
352
- raise ArgumentError, 'Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|windows'
353
- end
335
+ raise ArgumentError, 'Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|windows'
354
336
  end
355
337
  else
356
- if (locate_config_value(:azure_image_reference_publisher) && locate_config_value(:azure_image_reference_offer) && locate_config_value(:azure_image_reference_sku) && locate_config_value(:azure_image_reference_version))
357
- # if azure_image_os_type is not given and other image reference parameters are given,
358
- # do nothing
359
- else
360
- # if azure_image_os_type is not given and other image reference parameters are also not given,
361
- # throw error for azure_image_os_type
362
- validate_arm_keys!(:azure_image_os_type)
363
- end
338
+ validate_arm_keys!(:azure_image_os_type) unless is_image_os_type?
364
339
  end
365
340
  rescue => error
366
341
  ui.error("#{error.message}")
367
342
  Chef::Log.debug("#{error.backtrace.join("\n")}")
368
343
  exit
369
344
  end
370
-
371
345
  # final verification for image reference parameters
372
346
  validate_arm_keys!(:azure_image_reference_publisher,
373
347
  :azure_image_reference_offer,
374
348
  :azure_image_reference_sku,
375
349
  :azure_image_reference_version)
376
350
  end
351
+
352
+ def set_os_image(publisher, img_offer, default_os_version)
353
+ config[:azure_image_reference_publisher] = publisher
354
+ config[:azure_image_reference_offer] = img_offer
355
+ config[:azure_image_reference_sku] = locate_config_value(:azure_image_reference_sku) ? locate_config_value(:azure_image_reference_sku) : default_os_version
356
+ end
357
+
358
+ def is_image_os_type?
359
+ locate_config_value(:azure_image_reference_publisher) && locate_config_value(:azure_image_reference_offer) && locate_config_value(:azure_image_reference_sku) && locate_config_value(:azure_image_reference_version)
360
+ end
361
+
362
+ def validate_publisher_and_offer
363
+ if (locate_config_value(:azure_image_reference_publisher) || locate_config_value(:azure_image_reference_offer))
364
+ # if azure_image_os_type is given and any of the other image reference parameters like publisher or offer are also given,
365
+ # raise error
366
+ raise ArgumentError, 'Please specify either --azure-image-os-type OR --azure-image-os-type with --azure-image-reference-sku or 4 image reference parameters i.e.
367
+ --azure-image-reference-publisher, --azure-image-reference-offer, --azure-image-reference-sku, --azure-image-reference-version."'
368
+ end
369
+ end
377
370
  end
378
371
  end
379
372
  end
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Adam Jacob (<adam@opscode.com>)
4
4
  # Author:: Seth Chisamore (<schisamo@opscode.com>)
5
- # Copyright:: Copyright (c) 2009-2011 Opscode, Inc.
5
+ # Copyright:: Copyright 2009-2018, Chef Software Inc.
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require File.expand_path('../azure_base', __FILE__)
21
+ require File.expand_path('../azurerm_base', __FILE__)
22
22
 
23
23
  # These two are needed for the '--purge' deletion case
24
24
  require 'chef/node'
@@ -69,44 +69,52 @@ class Chef
69
69
  def run
70
70
  begin
71
71
  $stdout.sync = true
72
+ # check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
73
+ get_azure_cli_version
72
74
  validate_arm_keys!(:azure_resource_group_name)
73
-
74
- vm_name = @name_args[0]
75
- resource_group_name = locate_config_value(:azure_resource_group_name)
75
+ @vm_name = @name_args[0]
76
76
 
77
77
  if locate_config_value(:delete_resource_group)
78
- ui.warn "Deleting resource group will delete all the virtual_machines inside it."
79
- begin
80
- ui.confirm('Do you really want to delete resource group')
81
- rescue SystemExit # Need to handle this as confirming with N/n raises SystemExit exception
82
- server = nil # Cleanup is implicitly performed in other cloud plugins
83
- ui.warn "Resource group not deleted. Proceeding for server delete ..."
84
- service.delete_server(locate_config_value(:azure_resource_group_name), vm_name)
85
- exit
86
- end
87
-
88
- ui.info 'Deleting Resource Group '+resource_group_name+' and Virtual Machine '+vm_name+' ..'
89
- service.delete_resource_group(locate_config_value(:azure_resource_group_name))
90
- ui.warn "Deleted resource_group_name #{resource_group_name} and #{vm_name}"
78
+ delete_resource_group
91
79
  else
92
- service.delete_server(locate_config_value(:azure_resource_group_name), vm_name)
80
+ service.delete_server(locate_config_value(:azure_resource_group_name), @vm_name)
93
81
  end
94
82
 
95
83
  if config[:purge]
96
- node_to_delete = config[:chef_node_name] || vm_name
97
- if node_to_delete
98
- destroy_item(Chef::Node, node_to_delete, 'node')
99
- destroy_item(Chef::ApiClient, node_to_delete, 'client')
100
- else
101
- ui.warn("Node name to purge not provided. Corresponding client node will remain on Chef Server.")
102
- end
84
+ purge_node
103
85
  else
104
- ui.warn("Corresponding node and client for the #{vm_name} server were not deleted and remain registered with the Chef Server")
86
+ ui.warn("Corresponding node and client for the #{@vm_name} server were not deleted and remain registered with the Chef Server")
105
87
  end
106
88
  rescue => error
107
89
  service.common_arm_rescue_block(error)
108
90
  end
109
91
  end
92
+
93
+ def delete_resource_group
94
+ resource_group_name = locate_config_value(:azure_resource_group_name)
95
+ ui.warn "Deleting resource group will delete all the virtual_machines inside it."
96
+ begin
97
+ ui.confirm('Do you really want to delete resource group')
98
+ rescue SystemExit # Need to handle this as confirming with N/n raises SystemExit exception
99
+ server = nil # Cleanup is implicitly performed in other cloud plugins
100
+ ui.warn "Resource group not deleted. Proceeding for server delete ..."
101
+ service.delete_server(locate_config_value(:azure_resource_group_name), @vm_name)
102
+ exit
103
+ end
104
+ ui.info 'Deleting Resource Group '+resource_group_name+' and Virtual Machine '+@vm_name+' ..'
105
+ service.delete_resource_group(locate_config_value(:azure_resource_group_name))
106
+ ui.warn "Deleted resource_group_name #{resource_group_name} and #{@vm_name}"
107
+ end
108
+
109
+ def purge_node
110
+ node_to_delete = config[:chef_node_name] || @vm_name
111
+ if node_to_delete
112
+ destroy_item(Chef::Node, node_to_delete, 'node')
113
+ destroy_item(Chef::ApiClient, node_to_delete, 'client')
114
+ else
115
+ ui.warn("Node name to purge not provided. Corresponding client node will remain on Chef Server.")
116
+ end
117
+ end
110
118
  end
111
119
  end
112
120
  end
@@ -1,3 +1,21 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@chef.io>)
3
+ # Copyright:: Copyright 2009-2018, Chef Software Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
1
19
  require File.expand_path('../azurerm_base', __FILE__)
2
20
 
3
21
  class Chef
@@ -10,6 +28,8 @@ class Chef
10
28
 
11
29
  def run
12
30
  $stdout.sync = true
31
+ # check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
32
+ get_azure_cli_version
13
33
  validate_arm_keys!
14
34
  begin
15
35
  service.list_servers(locate_config_value(:azure_resource_group_name))
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Meera Navale (meera.navale@msystechnologies.com)
3
- # Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
3
+ # Copyright:: Copyright 2010-2018, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,8 @@ class Chef
28
28
 
29
29
  def run
30
30
  $stdout.sync = true
31
+ # check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
32
+ get_azure_cli_version
31
33
  validate_arm_keys!(:azure_resource_group_name)
32
34
  begin
33
35
  service.show_server(@name_args[0], locate_config_value(:azure_resource_group_name))
@@ -275,7 +275,7 @@ class Chef
275
275
  def get_chef_extension_public_params
276
276
  pub_config = Hash.new
277
277
  if(locate_config_value(:azure_extension_client_config))
278
- pub_config[:client_rb] = File.read(locate_config_value(:azure_extension_client_config))
278
+ pub_config[:client_rb] = File.read(File.expand_path(locate_config_value(:azure_extension_client_config)))
279
279
  else
280
280
  pub_config[:client_rb] = "chef_server_url \t #{Chef::Config[:chef_server_url].to_json}\nvalidation_client_name\t#{Chef::Config[:validation_client_name].to_json}"
281
281
  end
@@ -331,7 +331,9 @@ class Chef
331
331
  pri_config = Hash.new
332
332
 
333
333
  # validator less bootstrap support for bootstrap protocol cloud-api
334
- if (Chef::Config[:validation_key] && !File.exist?(File.expand_path(Chef::Config[:validation_key])))
334
+ if Chef::Config[:validation_key] && File.exist?(File.expand_path(Chef::Config[:validation_key]))
335
+ pri_config[:validation_key] = File.read(File.expand_path(Chef::Config[:validation_key]))
336
+ else
335
337
  if Chef::VERSION.split('.').first.to_i == 11
336
338
  ui.error('Unable to find validation key. Please verify your configuration file for validation_key config value.')
337
339
  exit 1
@@ -346,16 +348,19 @@ class Chef
346
348
  config[:chef_node_name] = node_name
347
349
  else
348
350
  key_path = create_node_and_client_pem
349
- pri_config[:client_pem] = File.read(key_path)
351
+ if File.exist?(key_path)
352
+ pri_config[:client_pem] = File.read(key_path)
353
+ else
354
+ ui.error('Unable to find client.pem at given path #{key_path}')
355
+ exit 1
356
+ end
350
357
  end
351
- else
352
- pri_config[:validation_key] = File.read(Chef::Config[:validation_key])
353
358
  end
354
359
 
355
360
  # SSL cert bootstrap support
356
361
  if locate_config_value(:cert_path)
357
362
  if File.exist?(File.expand_path(locate_config_value(:cert_path)))
358
- pri_config[:chef_server_crt] = File.read(locate_config_value(:cert_path))
363
+ pri_config[:chef_server_crt] = File.read(File.expand_path(locate_config_value(:cert_path)))
359
364
  else
360
365
  ui.error('Specified SSL certificate does not exist.')
361
366
  exit 1
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Azure
3
- VERSION = "1.8.0"
3
+ VERSION = "1.8.6"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-azure
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barry Davis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-09-28 00:00:00.000000000 Z
12
+ date: 2018-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -151,20 +151,6 @@ dependencies:
151
151
  - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: 12.2.1
154
- - !ruby/object:Gem::Dependency
155
- name: github_changelog_generator
156
- requirement: !ruby/object:Gem::Requirement
157
- requirements:
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: '0'
161
- type: :development
162
- prerelease: false
163
- version_requirements: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - ">="
166
- - !ruby/object:Gem::Version
167
- version: '0'
168
154
  - !ruby/object:Gem::Dependency
169
155
  name: mixlib-config
170
156
  requirement: !ruby/object:Gem::Requirement
@@ -282,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
282
268
  version: '0'
283
269
  requirements: []
284
270
  rubyforge_project:
285
- rubygems_version: 2.6.10
271
+ rubygems_version: 2.7.6
286
272
  signing_key:
287
273
  specification_version: 4
288
274
  summary: A plugin to the Chef knife tool for creating instances on the Microsoft Azure