knife-azure 1.9.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/azure/azure_interface.rb +2 -3
  3. data/lib/azure/custom_errors.rb +1 -1
  4. data/lib/azure/helpers.rb +1 -1
  5. data/lib/azure/resource_management/ARM_deployment_template.rb +157 -162
  6. data/lib/azure/resource_management/ARM_interface.rb +72 -73
  7. data/lib/azure/resource_management/vnet_config.rb +11 -10
  8. data/lib/azure/resource_management/windows_credentials.rb +19 -19
  9. data/lib/azure/service_management/ASM_interface.rb +6 -5
  10. data/lib/azure/service_management/ag.rb +11 -11
  11. data/lib/azure/service_management/certificate.rb +7 -5
  12. data/lib/azure/service_management/connection.rb +10 -10
  13. data/lib/azure/service_management/deploy.rb +12 -14
  14. data/lib/azure/service_management/disk.rb +4 -2
  15. data/lib/azure/service_management/host.rb +7 -4
  16. data/lib/azure/service_management/image.rb +4 -4
  17. data/lib/azure/service_management/loadbalancer.rb +2 -2
  18. data/lib/azure/service_management/rest.rb +9 -8
  19. data/lib/azure/service_management/role.rb +67 -70
  20. data/lib/azure/service_management/storageaccount.rb +5 -3
  21. data/lib/azure/service_management/utility.rb +1 -1
  22. data/lib/azure/service_management/vnet.rb +1 -1
  23. data/lib/chef/knife/azure_ag_create.rb +13 -13
  24. data/lib/chef/knife/azure_ag_list.rb +1 -1
  25. data/lib/chef/knife/azure_base.rb +49 -66
  26. data/lib/chef/knife/azure_image_list.rb +6 -6
  27. data/lib/chef/knife/azure_internal-lb_create.rb +14 -14
  28. data/lib/chef/knife/azure_internal-lb_list.rb +1 -1
  29. data/lib/chef/knife/azure_server_create.rb +233 -268
  30. data/lib/chef/knife/azure_server_delete.rb +31 -31
  31. data/lib/chef/knife/azure_server_list.rb +1 -1
  32. data/lib/chef/knife/azure_server_show.rb +1 -1
  33. data/lib/chef/knife/azure_vnet_create.rb +15 -19
  34. data/lib/chef/knife/azure_vnet_list.rb +1 -1
  35. data/lib/chef/knife/azurerm_base.rb +39 -28
  36. data/lib/chef/knife/azurerm_server_create.rb +112 -177
  37. data/lib/chef/knife/azurerm_server_delete.rb +13 -13
  38. data/lib/chef/knife/azurerm_server_list.rb +1 -1
  39. data/lib/chef/knife/azurerm_server_show.rb +1 -1
  40. data/lib/chef/knife/bootstrap/bootstrapper.rb +34 -238
  41. data/lib/chef/knife/bootstrap/common_bootstrap_options.rb +77 -76
  42. data/lib/chef/knife/bootstrap_azure.rb +56 -33
  43. data/lib/chef/knife/bootstrap_azurerm.rb +46 -29
  44. data/lib/knife-azure/version.rb +18 -1
  45. metadata +28 -16
  46. data/lib/chef/knife/bootstrap/bootstrap_options.rb +0 -105
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Adam Jacob (<adam@chef.io>)
4
4
  # Author:: Seth Chisamore (<schisamo@chef.io>)
5
- # Copyright:: Copyright 2009-2018 Chef Software, Inc.
5
+ # Copyright:: Copyright 2010-2019, 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");
@@ -33,50 +33,50 @@ class Chef
33
33
  banner "knife azure server delete SERVER [SERVER] (options)"
34
34
 
35
35
  option :preserve_azure_os_disk,
36
- :long => "--preserve-azure-os-disk",
37
- :boolean => true,
38
- :default => false,
39
- :description => "Preserve corresponding OS Disk"
36
+ long: "--preserve-azure-os-disk",
37
+ boolean: true,
38
+ default: false,
39
+ description: "Preserve corresponding OS Disk"
40
40
 
41
41
  option :preserve_azure_vhd,
42
- :long => "--preserve-azure-vhd",
43
- :boolean => true,
44
- :default => false,
45
- :description => "Preserve underlying VHD"
42
+ long: "--preserve-azure-vhd",
43
+ boolean: true,
44
+ default: false,
45
+ description: "Preserve underlying VHD"
46
46
 
47
47
  option :purge,
48
- :short => "-P",
49
- :long => "--purge",
50
- :boolean => true,
51
- :default => false,
52
- :description => "Destroy corresponding node and client on the Chef Server, in addition to destroying the Windows Azure node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
48
+ short: "-P",
49
+ long: "--purge",
50
+ boolean: true,
51
+ default: false,
52
+ description: "Destroy corresponding node and client on the Chef Server, in addition to destroying the Windows Azure node itself. Assumes node and client have the same name as the server (if not, add the '--node-name' option)."
53
53
 
54
54
  option :chef_node_name,
55
- :short => "-N NAME",
56
- :long => "--node-name NAME",
57
- :description => "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
55
+ short: "-N NAME",
56
+ long: "--node-name NAME",
57
+ description: "The name of the node and client to delete, if it differs from the server name. Only has meaning when used with the '--purge' option."
58
58
 
59
59
  option :preserve_azure_dns_name,
60
- :long => "--preserve-azure-dns-name",
61
- :boolean => true,
62
- :default => false,
63
- :description => "Preserve corresponding cloud service (DNS). If the option is not set, it deletes the service not used by any VMs."
60
+ long: "--preserve-azure-dns-name",
61
+ boolean: true,
62
+ default: false,
63
+ description: "Preserve corresponding cloud service (DNS). If the option is not set, it deletes the service not used by any VMs."
64
64
 
65
65
  option :delete_azure_storage_account,
66
- :long => "--delete-azure-storage-account",
67
- :boolean => true,
68
- :default => false,
69
- :description => "Delete corresponding storage account. If the option is set, it deletes the storage account not used by any VMs."
66
+ long: "--delete-azure-storage-account",
67
+ boolean: true,
68
+ default: false,
69
+ description: "Delete corresponding storage account. If the option is set, it deletes the storage account not used by any VMs."
70
70
 
71
71
  option :azure_dns_name,
72
- :long => "--azure-dns-name NAME",
73
- :description => "specifies the DNS name (also known as hosted service name)"
72
+ long: "--azure-dns-name NAME",
73
+ description: "specifies the DNS name (also known as hosted service name)"
74
74
 
75
75
  option :wait,
76
- :long => "--wait",
77
- :boolean => true,
78
- :default => false,
79
- :description => "Wait for server deletion. Default is false"
76
+ long: "--wait",
77
+ boolean: true,
78
+ default: false,
79
+ description: "Wait for server deletion. Default is false"
80
80
 
81
81
  # Extracted from Chef::Knife.delete_object, because it has a
82
82
  # confirmation step built in... By specifying the '--purge'
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Seth Chisamore (<schisamo@chef.io>)
4
4
  # Author:: Adam Jacob (<adam@chef.io>)
5
- # Copyright:: Copyright 2010-2018 Chef Software, Inc.
5
+ # Copyright:: Copyright 2010-2019, 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");
@@ -2,7 +2,7 @@
2
2
  # Author:: Barry Davis (barryd@jetstreamsoftware.com)
3
3
  # Author:: Seth Chisamore (<schisamo@chef.io>)
4
4
  # Author:: Adam Jacob (<adam@chef.io>)
5
- # Copyright:: Copyright 2010-2018 Chef Software, Inc.
5
+ # Copyright:: Copyright 2010-2019, 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");
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2013-2018 Chef Software, Inc.
3
+ # Copyright:: Copyright 2010-2019, 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");
@@ -26,26 +26,22 @@ class Chef
26
26
  banner "knife azure vnet create (options)"
27
27
 
28
28
  option :azure_network_name,
29
- :short => "-n NETWORK_NAME",
30
- :long => "--azure-network-name NETWORK_NAME",
31
- :description =>
32
- "Specifies the name of the virtual network to create."
29
+ short: "-n NETWORK_NAME",
30
+ long: "--azure-network-name NETWORK_NAME",
31
+ description: "Specifies the name of the virtual network to create."
33
32
 
34
33
  option :azure_affinity_group,
35
- :short => "-a GROUP",
36
- :long => "--azure-affinity-group GROUP",
37
- :description =>
38
- "Specifies the affinity group to associate with the vnet."
34
+ short: "-a GROUP",
35
+ long: "--azure-affinity-group GROUP",
36
+ description: "Specifies the affinity group to associate with the vnet."
39
37
 
40
38
  option :azure_address_space,
41
- :long => "--azure-address-space CIDR",
42
- :description =>
43
- "Specifies the address space of the vnet using CIDR notation."
39
+ long: "--azure-address-space CIDR",
40
+ description: "Specifies the address space of the vnet using CIDR notation."
44
41
 
45
42
  option :azure_subnet_name,
46
- :long => "--azure-subnet-name CIDR",
47
- :description =>
48
- "Specifies the Subnet Name."
43
+ long: "--azure-subnet-name CIDR",
44
+ description: "Specifies the Subnet Name."
49
45
 
50
46
  def run
51
47
  $stdout.sync = true
@@ -57,7 +53,7 @@ class Chef
57
53
  azure_vnet_name: locate_config_value(:azure_network_name),
58
54
  azure_ag_name: locate_config_value(:azure_affinity_group),
59
55
  azure_address_space: locate_config_value(:azure_address_space),
60
- azure_subnet_name: locate_config_value(:azure_subnet_name) || "Subnet-#{Random.rand(10)}"
56
+ azure_subnet_name: locate_config_value(:azure_subnet_name) || "Subnet-#{Random.rand(10)}",
61
57
  }
62
58
 
63
59
  rsp = service.create_vnet(params)
@@ -66,11 +62,11 @@ class Chef
66
62
  if rsp.at_css("Code").nil? || rsp.at_css("Message").nil?
67
63
  puts "Unknown Error. try -VV"
68
64
  else
69
- puts "#{rsp.at_css('Code').content}: "\
70
- "#{rsp.at_css('Message').content}"
65
+ puts "#{rsp.at_css("Code").content}: "\
66
+ "#{rsp.at_css("Message").content}"
71
67
  end
72
68
  else
73
- puts "Creation status: #{rsp.at_css('Status').content}"
69
+ puts "Creation status: #{rsp.at_css("Status").content}"
74
70
  end
75
71
  end
76
72
  end
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Jeff Mendoza (jeffmendoza@live.com)
3
- # Copyright:: Copyright 2013-2018 Chef Software, Inc.
3
+ # Copyright:: Copyright 2010-2019, 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");
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
3
  #
4
- # Copyright:: Copyright 2009-2018, Chef Software Inc.
4
+ # Copyright:: Copyright 2010-2019, 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");
@@ -31,7 +31,7 @@ class Chef
31
31
 
32
32
  ## azure-xplat-cli versio that introduced deprecation of Windows Credentials
33
33
  ## Manager (WCM) usage for authentication credentials storage purpose ##
34
- XPLAT_VERSION_WITH_WCM_DEPRECATED ||= "0.10.5"
34
+ XPLAT_VERSION_WITH_WCM_DEPRECATED ||= "0.10.5".freeze
35
35
 
36
36
  if Chef::Platform.windows?
37
37
  require "azure/resource_management/windows_credentials"
@@ -46,15 +46,15 @@ class Chef
46
46
  end
47
47
 
48
48
  option :azure_resource_group_name,
49
- :short => "-r RESOURCE_GROUP_NAME",
50
- :long => "--azure-resource-group-name RESOURCE_GROUP_NAME",
51
- :description => "The Resource Group name."
49
+ short: "-r RESOURCE_GROUP_NAME",
50
+ long: "--azure-resource-group-name RESOURCE_GROUP_NAME",
51
+ description: "The Resource Group name."
52
52
  end
53
53
  end
54
54
 
55
55
  def service
56
56
  details = authentication_details
57
- details.update(:azure_subscription_id => locate_config_value(:azure_subscription_id))
57
+ details.update(azure_subscription_id: locate_config_value(:azure_subscription_id))
58
58
  @service ||= begin
59
59
  service = Azure::ResourceManagement::ARMInterface.new(details)
60
60
  end
@@ -64,7 +64,11 @@ class Chef
64
64
 
65
65
  def locate_config_value(key)
66
66
  key = key.to_sym
67
- config[key] || Chef::Config[:knife][key] || default_config[key]
67
+ if defined?(config_value) # Inherited by bootstrap
68
+ config_value(key) || default_config[key]
69
+ else
70
+ config[key] || Chef::Config[:knife][key] || default_config[key]
71
+ end
68
72
  end
69
73
 
70
74
  # validates ARM mandatory keys
@@ -75,7 +79,7 @@ class Chef
75
79
  if azure_cred?
76
80
  validate_azure_login
77
81
  else
78
- keys.concat([:azure_tenant_id, :azure_client_id, :azure_client_secret])
82
+ keys.concat(%i{azure_tenant_id azure_client_id azure_client_secret})
79
83
  end
80
84
 
81
85
  errors = []
@@ -91,12 +95,13 @@ class Chef
91
95
 
92
96
  def authentication_details
93
97
  if is_azure_cred?
94
- return { :azure_tenant_id => locate_config_value(:azure_tenant_id), :azure_client_id => locate_config_value(:azure_client_id), :azure_client_secret => locate_config_value(:azure_client_secret) }
98
+ return { azure_tenant_id: locate_config_value(:azure_tenant_id), azure_client_id: locate_config_value(:azure_client_id), azure_client_secret: locate_config_value(:azure_client_secret) }
95
99
  elsif Chef::Platform.windows?
96
- token_details = token_details_for_windows()
100
+ token_details = token_details_for_windows
97
101
  else
98
- token_details = token_details_for_linux()
102
+ token_details = token_details_for_linux
99
103
  end
104
+
100
105
  token_details = check_token_validity(token_details)
101
106
  token_details
102
107
  end
@@ -126,7 +131,7 @@ class Chef
126
131
  home_dir = File.expand_path("~")
127
132
  file = File.read(home_dir + "/.azure/accessTokens.json")
128
133
  file = JSON.parse(file)
129
- token_details = { :tokentype => file[-1]["tokenType"], :user => file[-1]["userId"], :token => file[-1]["accessToken"], :clientid => file[-1]["_clientId"], :expiry_time => file[-1]["expiresOn"], :refreshtoken => file[-1]["refreshToken"] }
134
+ token_details = { tokentype: file[-1]["tokenType"], user: file[-1]["userId"], token: file[-1]["accessToken"], clientid: file[-1]["_clientId"], expiry_time: file[-1]["expiresOn"], refreshtoken: file[-1]["refreshToken"] }
130
135
  token_details
131
136
  end
132
137
 
@@ -144,12 +149,12 @@ class Chef
144
149
 
145
150
  def refresh_token
146
151
  azure_authentication
147
- token_details = Chef::Platform.windows? ? token_details_for_windows() : token_details_for_linux()
152
+ token_details = Chef::Platform.windows? ? token_details_for_windows : token_details_for_linux
148
153
  end
149
154
 
150
155
  def azure_authentication
151
156
  ui.log("Authenticating...")
152
- Mixlib::ShellOut.new("#{@azure_prefix} vm show 'knifetest@resourcegroup' testvm", :timeout => 30).run_command
157
+ Mixlib::ShellOut.new("#{@azure_prefix} vm show 'knifetest@resourcegroup' testvm", timeout: 30).run_command
153
158
  rescue Mixlib::ShellOut::CommandTimeout
154
159
  rescue Exception
155
160
  raise_azure_status
@@ -158,9 +163,7 @@ class Chef
158
163
  def check_token_validity(token_details)
159
164
  unless is_token_valid?(token_details)
160
165
  token_details = refresh_token
161
- unless is_token_valid?(token_details)
162
- raise_azure_status
163
- end
166
+ raise_azure_status unless is_token_valid?(token_details)
164
167
  end
165
168
  token_details
166
169
  end
@@ -170,11 +173,10 @@ class Chef
170
173
  # cmdkey command is used for accessing windows credential manager
171
174
  xplat_creds_cmd = Mixlib::ShellOut.new("cmdkey /list | findstr AzureXplatCli")
172
175
  result = xplat_creds_cmd.run_command
173
- if result.stdout.nil? || result.stdout.empty?
174
- raise login_message
175
- end
176
+ raise login_message if result.stdout.nil? || result.stdout.empty?
176
177
  else
177
178
  home_dir = File.expand_path("~")
179
+ puts "File.exist? = #{File.exist?("a")}"
178
180
  if !File.exist?(home_dir + "/.azure/accessTokens.json") || File.size?(home_dir + "/.azure/accessTokens.json") <= 2
179
181
  raise login_message
180
182
  end
@@ -190,7 +192,7 @@ class Chef
190
192
  doc = Nokogiri::XML(File.open(find_file(filename)))
191
193
  profile = doc.at_css("PublishProfile")
192
194
  subscription = profile.at_css("Subscription")
193
- #check given PublishSettings XML file format.Currently PublishSettings file have two different XML format
195
+ # check given PublishSettings XML file format.Currently PublishSettings file have two different XML format
194
196
  if profile.attribute("SchemaVersion").nil?
195
197
  management_cert = OpenSSL::PKCS12.new(Base64.decode64(profile.attribute("ManagementCertificate").value))
196
198
  Chef::Config[:knife][:azure_api_host_name] = URI(profile.attribute("Url").value).host
@@ -264,6 +266,14 @@ class Chef
264
266
  end
265
267
 
266
268
  def validate_params!
269
+ if locate_config_value(:connection_user).nil?
270
+ raise ArgumentError, "Please provide --connection-user option for authentication."
271
+ end
272
+
273
+ unless locate_config_value(:connection_password).nil? ^ locate_config_value(:ssh_public_key).nil?
274
+ raise ArgumentError, "Please specify either --connection-password or --ssh-public-key option for authentication."
275
+ end
276
+
267
277
  if locate_config_value(:azure_vnet_subnet_name) && !locate_config_value(:azure_vnet_name)
268
278
  raise ArgumentError, "When --azure-vnet-subnet-name is specified, the --azure-vnet-name must also be specified."
269
279
  end
@@ -276,12 +286,6 @@ class Chef
276
286
  raise ArgumentError, "Invalid value '#{locate_config_value(:node_ssl_verify_mode)}' for --node-ssl-verify-mode. Use Valid values i.e 'none', 'peer'."
277
287
  end
278
288
 
279
- if is_image_windows?
280
- if locate_config_value(:winrm_user).nil? || locate_config_value(:winrm_password).nil?
281
- raise ArgumentError, "Please provide --winrm-user and --winrm-password options for Windows option."
282
- end
283
- end
284
-
285
289
  if !is_image_windows?
286
290
  if (locate_config_value(:azure_vm_name).match /^(?=.*[a-zA-Z-])([a-zA-z0-9-]{1,64})$/).nil?
287
291
  raise ArgumentError, "VM name can only contain alphanumeric and hyphen(-) characters and maximun length cannot exceed 64 charachters."
@@ -304,8 +308,14 @@ class Chef
304
308
  end
305
309
  end
306
310
 
311
+ if locate_config_value(:azure_image_os_type)
312
+ unless %w{ubuntu centos rhel debian windows}.include?(locate_config_value(:azure_image_os_type))
313
+ raise ArgumentError, "Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|rhel|debian|windows"
314
+ end
315
+ end
316
+
307
317
  config[:ohai_hints] = format_ohai_hints(locate_config_value(:ohai_hints))
308
- validate_ohai_hints if ! locate_config_value(:ohai_hints).casecmp("default").zero?
318
+ validate_ohai_hints unless locate_config_value(:ohai_hints).casecmp("default").zero?
309
319
  end
310
320
 
311
321
  private
@@ -334,6 +344,7 @@ class Chef
334
344
 
335
345
  def is_old_xplat?
336
346
  return true unless @azure_version
347
+
337
348
  Gem::Version.new(@azure_version) < Gem::Version.new(XPLAT_VERSION_WITH_WCM_DEPRECATED)
338
349
  end
339
350
 
@@ -1,7 +1,6 @@
1
1
  #
2
2
  # Author:: Aliasgar Batterywala (aliasgar.batterywala@clogeny.com)
3
- #
4
- # Copyright:: Copyright 2009-2018, Chef Software Inc.
3
+ # Copyright:: Copyright 2010-2019, Chef Software Inc.
5
4
  # License:: Apache License, Version 2.0
6
5
  #
7
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,12 +18,14 @@
19
18
 
20
19
  require "chef/knife/azurerm_base"
21
20
  require "securerandom"
21
+ require "chef/knife/bootstrap"
22
+ require "chef/knife/bootstrap/client_builder"
22
23
  require "chef/knife/bootstrap/common_bootstrap_options"
23
24
  require "chef/knife/bootstrap/bootstrapper"
24
25
 
25
26
  class Chef
26
27
  class Knife
27
- class AzurermServerCreate < Knife
28
+ class AzurermServerCreate < Knife::Bootstrap
28
29
 
29
30
  include Knife::AzurermBase
30
31
  include Knife::Bootstrap::CommonBootstrapOptions
@@ -34,122 +35,51 @@ class Chef
34
35
 
35
36
  attr_accessor :initial_sleep_delay
36
37
 
37
- option :ssh_user,
38
- :short => "-x USERNAME",
39
- :long => "--ssh-user USERNAME",
40
- :description => "The ssh username",
41
- :default => "root"
42
-
43
- option :ssh_password,
44
- :short => "-P PASSWORD",
45
- :long => "--ssh-password PASSWORD",
46
- :description => "The ssh password"
47
-
48
- option :ssh_port,
49
- :long => "--ssh-port PORT",
50
- :description => "The ssh port. Default is 22."
51
-
52
- option :node_ssl_verify_mode,
53
- :long => "--node-ssl-verify-mode [peer|none]",
54
- :description => "Whether or not to verify the SSL cert for all HTTPS requests."
55
-
56
- option :winrm_user,
57
- :short => "-x USERNAME",
58
- :long => "--winrm-user USERNAME",
59
- :description => "The WinRM username",
60
- :default => "Administrator",
61
- :proc => Proc.new { |key| Chef::Config[:knife][:winrm_user] = key }
62
-
63
- option :winrm_password,
64
- :short => "-P PASSWORD",
65
- :long => "--winrm-password PASSWORD",
66
- :description => "The WinRM password",
67
- :proc => Proc.new { |key| Chef::Config[:knife][:winrm_password] = key }
68
-
69
- option :azure_storage_account,
70
- :short => "-a NAME",
71
- :long => "--azure-storage-account NAME",
72
- :description => "Required for advanced server-create option.
73
- A name for the storage account that is unique within Windows Azure. Storage account names must be
74
- between 3 and 24 characters in length and use numbers and lower-case letters only.
75
- This name is the DNS prefix name and can be used to access blobs, queues, and tables in the storage account.
76
- For example: http://ServiceName.blob.core.windows.net/mycontainer/"
77
-
78
38
  option :azure_storage_account_type,
79
- :long => "--azure-storage-account-type TYPE",
80
- :description => "Optional. One of the following account types (case-sensitive):
39
+ long: "--azure-storage-account-type TYPE",
40
+ description: "Optional. One of the following account types (case-sensitive):
81
41
  Standard_LRS (Standard Locally-redundant storage)
82
42
  Standard_ZRS (Standard Zone-redundant storage)
83
43
  Standard_GRS (Standard Geo-redundant storage)
84
44
  Standard_RAGRS (Standard Read access geo-redundant storage)
85
45
  Premium_LRS (Premium Locally-redundant storage)",
86
- :default => "Standard_GRS"
87
-
88
- option :azure_vm_name,
89
- :long => "--azure-vm-name NAME",
90
- :description => "Required. Specifies the name for the virtual machine.
91
- The name must be unique within the ResourceGroup.
92
- The azure vm name cannot be more than 15 characters long"
93
-
94
- option :azure_service_location,
95
- :short => "-m LOCATION",
96
- :long => "--azure-service-location LOCATION",
97
- :description => "Required if not using an Affinity Group. Specifies the geographic location - the name of the data center location that is valid for your subscription.
98
- Eg: westus, eastus, eastasia, southeastasia, northeurope, westeurope",
99
- :proc => Proc.new { |lo| Chef::Config[:knife][:azure_service_location] = lo }
100
-
101
- option :azure_os_disk_name,
102
- :short => "-o DISKNAME",
103
- :long => "--azure-os-disk-name DISKNAME",
104
- :description => "Optional. Specifies the friendly name of the disk containing the guest OS image in the image repository."
46
+ default: "Standard_GRS"
105
47
 
106
48
  option :azure_image_reference_publisher,
107
- :long => "--azure-image-reference-publisher PUBLISHER_NAME",
108
- :description => "Optional. Specifies the publisher of the image used to create the virtual machine.
49
+ long: "--azure-image-reference-publisher PUBLISHER_NAME",
50
+ description: "Optional. Specifies the publisher of the image used to create the virtual machine.
109
51
  eg. OpenLogic, Canonical, MicrosoftWindowsServer"
110
52
 
111
53
  option :azure_image_reference_offer,
112
- :long => "--azure-image-reference-offer OFFER",
113
- :description => "Optional. Specifies the offer of the image used to create the virtual machine.
54
+ long: "--azure-image-reference-offer OFFER",
55
+ description: "Optional. Specifies the offer of the image used to create the virtual machine.
114
56
  eg. CentOS, UbuntuServer, WindowsServer"
115
57
 
116
58
  option :azure_image_reference_sku,
117
- :long => "--azure-image-reference-sku SKU",
118
- :description => "Optional. Specifies the SKU of the image used to create the virtual machine."
59
+ long: "--azure-image-reference-sku SKU",
60
+ description: "Optional. Specifies the SKU of the image used to create the virtual machine."
119
61
 
120
62
  option :azure_image_reference_version,
121
- :long => "--azure-image-reference-version VERSION",
122
- :description => "Optional. Specifies the version of the image used to create the virtual machine.
63
+ long: "--azure-image-reference-version VERSION",
64
+ description: "Optional. Specifies the version of the image used to create the virtual machine.
123
65
  Default value is 'latest'",
124
- :default => "latest"
66
+ default: "latest"
125
67
 
126
68
  option :azure_image_os_type,
127
- :long => "--azure-image-os-type OSTYPE",
128
- :description => "Optional. Specifies the image OS Type for which server needs to be created. Accepted values ubuntu|centos|rhel|debian|windows"
129
-
130
- option :azure_vm_size,
131
- :short => "-z SIZE",
132
- :long => "--azure-vm-size SIZE",
133
- :description => "Optional. Size of virtual machine. Default is Standard_A1_v2.
134
- Eg: Standard_A2, Standard_F2, Standard_G1 etc.",
135
- :default => "Standard_A1_v2",
136
- :proc => Proc.new { |si| Chef::Config[:knife][:azure_vm_size] = si }
137
-
138
- option :azure_availability_set,
139
- :long => "--azure-availability-set NAME",
140
- :description => "Optional. Name of availability set to add virtual machine into."
69
+ long: "--azure-image-os-type OSTYPE",
70
+ description: "Optional. Specifies the image OS Type for which server needs to be created. Accepted values ubuntu|centos|rhel|debian|windows"
141
71
 
142
72
  option :azure_vnet_name,
143
- :long => "--azure-vnet-name VNET_NAME",
144
- :description => "Optional. Specifies the virtual network name.
73
+ long: "--azure-vnet-name VNET_NAME",
74
+ description: "Optional. Specifies the virtual network name.
145
75
  This may be the name of an existing vnet present under the given resource group
146
76
  or this may be the name of a new vnet to be added in the given resource group.
147
77
  If not specified then azure-vm-name will be taken as the default name for vnet name as well.
148
78
  Along with this option azure-vnet-subnet-name option can also be specified or it can also be skipped."
149
79
 
150
80
  option :azure_vnet_subnet_name,
151
- :long => "--azure-vnet-subnet-name VNET_SUBNET_NAME",
152
- :description => "Optional. Specifies the virtual network subnet name.
81
+ long: "--azure-vnet-subnet-name VNET_SUBNET_NAME",
82
+ description: "Optional. Specifies the virtual network subnet name.
153
83
  Must be specified only with azure-vnet-name option.
154
84
  This may be the name of an existing subnet present under the given virtual network
155
85
  or this may be the name of a new subnet to be added in the given virtual network.
@@ -157,85 +87,92 @@ class Chef
157
87
  Value as 'GatewaySubnet' cannot be used as the name for the --azure-vnet-subnet-name option."
158
88
 
159
89
  option :ssh_public_key,
160
- :long => "--ssh-public-key FILENAME",
161
- :description => "It is the ssh-rsa public key path. Specify either ssh-password or ssh-public-key"
162
-
163
- option :thumbprint,
164
- :long => "--thumbprint THUMBPRINT",
165
- :description => "The thumprint of the ssl certificate"
166
-
167
- option :cert_passphrase,
168
- :long => "--cert-passphrase PASSWORD",
169
- :description => "SSL Certificate Password"
170
-
171
- option :cert_path,
172
- :long => "--cert-path PATH",
173
- :description => "SSL Certificate Path"
174
-
175
- option :tcp_endpoints,
176
- :short => "-t PORT_LIST",
177
- :long => "--tcp-endpoints PORT_LIST",
178
- :description => "Comma-separated list of TCP ports to open e.g. '80,433'"
90
+ long: "--ssh-public-key FILENAME",
91
+ description: "It is the ssh-rsa public key path. Specify either connection-password or ssh-public-key"
179
92
 
180
93
  option :server_count,
181
- :long => "--server-count COUNT",
182
- :description => "Number of servers to create with same configuration.
94
+ long: "--server-count COUNT",
95
+ description: "Number of servers to create with same configuration.
183
96
  Maximum count is 5. Default value is 1.",
184
- :default => 1
97
+ default: 1
185
98
 
186
99
  option :ohai_hints,
187
- :long => "--ohai-hints HINT_OPTIONS",
188
- :description => "Hint option names to be set in Ohai configuration of the target node.
100
+ long: "--ohai-hints HINT_OPTIONS",
101
+ description: "Hint option names to be set in Ohai configuration of the target node.
189
102
  Supported values are: vm_name, public_fqdn and platform.
190
103
  User can pass any comma separated combination of these values like 'vm_name,public_fqdn'.
191
104
  Default value is 'default' which corresponds to the supported values list mentioned here.",
192
- :default => "default"
105
+ default: "default"
193
106
 
194
- def run
195
- $stdout.sync = true
196
- # check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
107
+ # run() would be executing from parent class
108
+ # Chef::Knife::Bootstrap, defined in core.
109
+ # Required methods have been overridden here
110
+ #### run() execution begins ####
111
+
112
+ def plugin_setup!
113
+ # Check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
197
114
  get_azure_cli_version
115
+ set_default_image_reference!
116
+ end
117
+
118
+ def validate_name_args!; end
119
+
120
+ def plugin_validate_options!
198
121
  validate_arm_keys!(
199
122
  :azure_resource_group_name,
200
123
  :azure_vm_name,
201
124
  :azure_service_location
202
125
  )
126
+ validate_params!
127
+ end
203
128
 
204
- begin
205
- validate_params!
206
- set_default_image_reference!
207
- ssh_override_winrm if !is_image_windows?
208
- vm_details = service.create_server(create_server_def)
209
- rescue => error
210
- service.common_arm_rescue_block(error)
211
- exit
212
- end
129
+ def plugin_create_instance!
130
+ set_defaults
131
+ vm_details = service.create_server(create_server_def)
132
+ rescue => error
133
+ service.common_arm_rescue_block(error)
134
+ exit
213
135
  end
214
136
 
137
+ def plugin_finalize; end
138
+
139
+ # Following methods are not required for ARM
140
+ #
141
+ def connect!; end
142
+
143
+ def register_client; end
144
+
145
+ def render_template; end
146
+
147
+ def upload_bootstrap(content); end
148
+
149
+ def perform_bootstrap(bootstrap_path); end
150
+
151
+ #### run() execution ends ####
152
+
215
153
  def create_server_def
216
154
  server_def = {
217
- :azure_resource_group_name => locate_config_value(:azure_resource_group_name),
218
- :azure_storage_account => locate_config_value(:azure_storage_account),
219
- :azure_storage_account_type => locate_config_value(:azure_storage_account_type),
220
- :azure_vm_name => locate_config_value(:azure_vm_name),
221
- :azure_service_location => locate_config_value(:azure_service_location),
222
- :azure_os_disk_name => locate_config_value(:azure_os_disk_name),
223
- :azure_os_disk_caching => locate_config_value(:azure_os_disk_caching),
224
- :azure_os_disk_create_option => locate_config_value(:azure_os_disk_create_option),
225
- :azure_vm_size => locate_config_value(:azure_vm_size),
226
- :azure_image_reference_publisher => locate_config_value(:azure_image_reference_publisher),
227
- :azure_image_reference_offer => locate_config_value(:azure_image_reference_offer),
228
- :azure_image_reference_sku => locate_config_value(:azure_image_reference_sku),
229
- :azure_image_reference_version => locate_config_value(:azure_image_reference_version),
230
- :winrm_user => locate_config_value(:winrm_user),
231
- :azure_availability_set => locate_config_value(:azure_availability_set),
232
- :azure_vnet_name => locate_config_value(:azure_vnet_name),
233
- :azure_vnet_subnet_name => locate_config_value(:azure_vnet_subnet_name),
234
- :ssl_cert_fingerprint => locate_config_value(:thumbprint),
235
- :cert_path => locate_config_value(:cert_path),
236
- :cert_password => locate_config_value(:cert_passphrase),
237
- :vnet_subnet_address_prefix => locate_config_value(:vnet_subnet_address_prefix),
238
- :server_count => locate_config_value(:server_count)
155
+ azure_resource_group_name: locate_config_value(:azure_resource_group_name),
156
+ azure_storage_account: locate_config_value(:azure_storage_account),
157
+ azure_storage_account_type: locate_config_value(:azure_storage_account_type),
158
+ azure_vm_name: locate_config_value(:azure_vm_name),
159
+ azure_service_location: locate_config_value(:azure_service_location),
160
+ azure_os_disk_name: locate_config_value(:azure_os_disk_name),
161
+ azure_os_disk_caching: locate_config_value(:azure_os_disk_caching),
162
+ azure_os_disk_create_option: locate_config_value(:azure_os_disk_create_option),
163
+ azure_vm_size: locate_config_value(:azure_vm_size),
164
+ azure_image_reference_publisher: locate_config_value(:azure_image_reference_publisher),
165
+ azure_image_reference_offer: locate_config_value(:azure_image_reference_offer),
166
+ azure_image_reference_sku: locate_config_value(:azure_image_reference_sku),
167
+ azure_image_reference_version: locate_config_value(:azure_image_reference_version),
168
+ azure_availability_set: locate_config_value(:azure_availability_set),
169
+ azure_vnet_name: locate_config_value(:azure_vnet_name),
170
+ azure_vnet_subnet_name: locate_config_value(:azure_vnet_subnet_name),
171
+ ssl_cert_fingerprint: locate_config_value(:thumbprint),
172
+ cert_path: locate_config_value(:cert_path),
173
+ cert_password: locate_config_value(:cert_passphrase),
174
+ vnet_subnet_address_prefix: locate_config_value(:vnet_subnet_address_prefix),
175
+ server_count: locate_config_value(:server_count),
239
176
  }
240
177
 
241
178
  server_def[:tcp_endpoints] = locate_config_value(:tcp_endpoints) if locate_config_value(:tcp_endpoints)
@@ -258,18 +195,14 @@ class Chef
258
195
  server_def[:chef_extension_public_param] = get_chef_extension_public_params
259
196
  server_def[:chef_extension_private_param] = get_chef_extension_private_params
260
197
  server_def[:auto_upgrade_minor_version] = false
261
-
262
- if is_image_windows?
263
- server_def[:admin_password] = locate_config_value(:winrm_password)
264
- else
265
- server_def[:ssh_user] = locate_config_value(:ssh_user)
266
- server_def[:ssh_password] = locate_config_value(:ssh_password)
267
- server_def[:disablePasswordAuthentication] = "false"
268
- if locate_config_value(:ssh_public_key)
269
- server_def[:disablePasswordAuthentication] = "true"
270
- server_def[:ssh_key] = File.read(locate_config_value(:ssh_public_key))
271
- end
272
- end
198
+ server_def[:connection_user] = locate_config_value(:connection_user)
199
+ server_def[:disablePasswordAuthentication] = if locate_config_value(:ssh_public_key)
200
+ server_def[:ssh_public_key] = File.read(locate_config_value(:ssh_public_key))
201
+ "true"
202
+ else
203
+ server_def[:connection_password] = locate_config_value(:connection_password)
204
+ "false"
205
+ end
273
206
 
274
207
  server_def
275
208
  end
@@ -283,7 +216,7 @@ class Chef
283
216
  end
284
217
 
285
218
  def format_ohai_hints(ohai_hints)
286
- ohai_hints = ohai_hints.split(",").each { |hint| hint.strip! }
219
+ ohai_hints = ohai_hints.split(",").each(&:strip!)
287
220
  ohai_hints.join(",")
288
221
  end
289
222
 
@@ -294,7 +227,7 @@ class Chef
294
227
  def validate_ohai_hints
295
228
  hint_values = locate_config_value(:ohai_hints).split(",")
296
229
  hint_values.each do |hint|
297
- if ! is_supported_ohai_hint?(hint)
230
+ unless is_supported_ohai_hint?(hint)
298
231
  raise ArgumentError, "Ohai Hint name #{hint} passed is not supported. Please run the command help to see the list of supported values."
299
232
  end
300
233
  end
@@ -302,16 +235,18 @@ class Chef
302
235
 
303
236
  private
304
237
 
305
- def ssh_override_winrm
306
- # unchanged ssh_user and changed winrm_user, override ssh_user
307
- if locate_config_value(:ssh_user).eql?(options[:ssh_user][:default]) &&
308
- !locate_config_value(:winrm_user).eql?(options[:winrm_user][:default])
309
- config[:ssh_user] = locate_config_value(:winrm_user)
238
+ def set_defaults
239
+ # set_default_image_reference!
240
+ set_configs
241
+ end
242
+
243
+ def set_configs
244
+ unless locate_config_value(:connection_user).nil?
245
+ config[:connection_user] = locate_config_value(:connection_user)
310
246
  end
311
247
 
312
- if locate_config_value(:ssh_password).nil? &&
313
- !locate_config_value(:winrm_password).nil?
314
- config[:ssh_password] = locate_config_value(:winrm_password)
248
+ unless locate_config_value(:connection_password).nil?
249
+ config[:connection_password] = locate_config_value(:connection_password)
315
250
  end
316
251
  end
317
252
 
@@ -333,7 +268,7 @@ class Chef
333
268
  when "windows"
334
269
  set_os_image("MicrosoftWindowsServer", "WindowsServer", "2012-R2-Datacenter")
335
270
  else
336
- raise ArgumentError, "Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|windows"
271
+ raise ArgumentError, "Invalid value of --azure-image-os-type. Accepted values ubuntu|centos|rhel|debian|windows"
337
272
  end
338
273
  else
339
274
  validate_arm_keys!(:azure_image_os_type) unless is_image_os_type?
@@ -345,9 +280,9 @@ class Chef
345
280
  end
346
281
  # final verification for image reference parameters
347
282
  validate_arm_keys!(:azure_image_reference_publisher,
348
- :azure_image_reference_offer,
349
- :azure_image_reference_sku,
350
- :azure_image_reference_version)
283
+ :azure_image_reference_offer,
284
+ :azure_image_reference_sku,
285
+ :azure_image_reference_version)
351
286
  end
352
287
 
353
288
  def set_os_image(publisher, img_offer, default_os_version)