Class: Chef::Knife::AzurermServerCreate

Inherits:
Bootstrap
  • Object
show all
Includes:
AzurermBase, Bootstrap::Bootstrapper, Bootstrap::CommonBootstrapOptions
Defined in:
lib/chef/knife/azurerm_server_create.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Bootstrap::Bootstrapper

#create_node_and_client_pem, #default_hint_options, #get_chef_extension_name, #get_chef_extension_private_params, #get_chef_extension_public_params, #get_chef_extension_publisher, #get_chef_extension_version, #load_correct_secret, #ohai_hints

Methods included from Bootstrap::CommonBootstrapOptions

included

Methods included from AzurermBase

#authentication_details, #azure_authentication, #check_token_validity, #find_file, #get_azure_cli_version, included, #is_token_valid?, #msg_server_summary, #parse_publish_settings_file, #refresh_token, #service, #token_details_for_linux, #token_details_for_windows, #token_details_from_accessToken_file, #validate_arm_keys!, #validate_azure_login, #validate_params!

Instance Attribute Details

#initial_sleep_delayObject

Returns the value of attribute initial_sleep_delay.



40
41
42
# File 'lib/chef/knife/azurerm_server_create.rb', line 40

def initial_sleep_delay
  @initial_sleep_delay
end

Instance Method Details

#connect!Object

Following methods are not required for ARM



145
# File 'lib/chef/knife/azurerm_server_create.rb', line 145

def connect!; end

#create_server_defObject

run() execution ends ####



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/chef/knife/azurerm_server_create.rb', line 157

def create_server_def
  server_def = {
    azure_resource_group_name: config[:azure_resource_group_name],
    azure_storage_account: config[:azure_storage_account],
    azure_storage_account_type: config[:azure_storage_account_type],
    azure_vm_name: config[:azure_vm_name],
    azure_service_location: config[:azure_service_location],
    azure_os_disk_name: config[:azure_os_disk_name],
    azure_os_disk_caching: config[:azure_os_disk_caching],
    azure_os_disk_create_option: config[:azure_os_disk_create_option],
    azure_vm_size: config[:azure_vm_size],
    azure_image_reference_publisher: config[:azure_image_reference_publisher],
    azure_image_reference_offer: config[:azure_image_reference_offer],
    azure_image_reference_sku: config[:azure_image_reference_sku],
    azure_image_reference_version: config[:azure_image_reference_version],
    azure_availability_set: config[:azure_availability_set],
    azure_vnet_name: config[:azure_vnet_name],
    azure_vnet_subnet_name: config[:azure_vnet_subnet_name],
    ssl_cert_fingerprint: config[:thumbprint],
    cert_path: config[:cert_path],
    cert_password: config[:cert_passphrase],
    vnet_subnet_address_prefix: config[:vnet_subnet_address_prefix],
    server_count: config[:server_count],
  }

  server_def[:tcp_endpoints] = config[:tcp_endpoints] if config[:tcp_endpoints]

  # We assign azure_vm_name to chef_node_name If node name is nill because storage account name is combination of hash value and node name.
  config[:chef_node_name] ||= config[:azure_vm_name]

  server_def[:azure_storage_account] = config[:azure_vm_name] if server_def[:azure_storage_account].nil?
  server_def[:azure_storage_account] = server_def[:azure_storage_account].gsub(/[!@#$%^&*()_-]/, "")

  server_def[:azure_os_disk_name] = config[:azure_vm_name] if server_def[:azure_os_disk_name].nil?
  server_def[:azure_os_disk_name] = server_def[:azure_os_disk_name].gsub(/[!@#$%^&*()_-]/, "")

  server_def[:azure_vnet_name] = config[:azure_vm_name] if server_def[:azure_vnet_name].nil?
  server_def[:azure_vnet_subnet_name] = config[:azure_vm_name] if config[:azure_vnet_subnet_name].nil?

  server_def[:chef_extension] = get_chef_extension_name
  server_def[:chef_extension_publisher] = get_chef_extension_publisher
  server_def[:chef_extension_version] = config[:azure_chef_extension_version]
  server_def[:chef_extension_public_param] = get_chef_extension_public_params
  server_def[:chef_extension_private_param] = get_chef_extension_private_params
  server_def[:auto_upgrade_minor_version] = false
  server_def[:connection_user] = config[:connection_user]
  server_def[:disablePasswordAuthentication] = if config[:ssh_public_key]
                                                 server_def[:ssh_public_key] = File.read(config[:ssh_public_key])
                                                 "true"
                                               else
                                                 server_def[:connection_password] = config[:connection_password]
                                                 "false"
                                               end

  server_def
end

#format_ohai_hints(ohai_hints) ⇒ Object



222
223
224
225
# File 'lib/chef/knife/azurerm_server_create.rb', line 222

def format_ohai_hints(ohai_hints)
  ohai_hints = ohai_hints.split(",").each(&:strip!)
  ohai_hints.join(",")
end

#is_supported_ohai_hint?(hint) ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/chef/knife/azurerm_server_create.rb', line 227

def is_supported_ohai_hint?(hint)
  supported_ohai_hints.any? { |supported_ohai_hint| hint.eql? supported_ohai_hint }
end

#perform_bootstrap(bootstrap_path) ⇒ Object



153
# File 'lib/chef/knife/azurerm_server_create.rb', line 153

def perform_bootstrap(bootstrap_path); end

#plugin_create_instance!Object



133
134
135
136
137
138
139
# File 'lib/chef/knife/azurerm_server_create.rb', line 133

def plugin_create_instance!
  set_defaults
  vm_details = service.create_server(create_server_def)
rescue => error
  service.common_arm_rescue_block(error)
  exit
end

#plugin_finalizeObject



141
# File 'lib/chef/knife/azurerm_server_create.rb', line 141

def plugin_finalize; end

#plugin_setup!Object

run() would be executing from parent class Chef::Knife::Bootstrap, defined in core. Required methods have been overridden here run() execution begins ####



116
117
118
119
120
# File 'lib/chef/knife/azurerm_server_create.rb', line 116

def plugin_setup!
  # Check azure cli version due to azure changed `azure` to `az` in azure-cli2.0
  get_azure_cli_version
  set_default_image_reference!
end

#plugin_validate_options!Object



124
125
126
127
128
129
130
131
# File 'lib/chef/knife/azurerm_server_create.rb', line 124

def plugin_validate_options!
  validate_arm_keys!(
    :azure_resource_group_name,
    :azure_vm_name,
    :azure_service_location
  )
  validate_params!
end

#register_clientObject



147
# File 'lib/chef/knife/azurerm_server_create.rb', line 147

def register_client; end

#render_templateObject



149
# File 'lib/chef/knife/azurerm_server_create.rb', line 149

def render_template; end

#supported_ohai_hintsObject



214
215
216
217
218
219
220
# File 'lib/chef/knife/azurerm_server_create.rb', line 214

def supported_ohai_hints
  %w{
    vm_name
    public_fqdn
    platform
  }
end

#upload_bootstrap(content) ⇒ Object



151
# File 'lib/chef/knife/azurerm_server_create.rb', line 151

def upload_bootstrap(content); end

#validate_name_args!Object



122
# File 'lib/chef/knife/azurerm_server_create.rb', line 122

def validate_name_args!; end

#validate_ohai_hintsObject



231
232
233
234
235
236
237
238
# File 'lib/chef/knife/azurerm_server_create.rb', line 231

def validate_ohai_hints
  hint_values = config[:ohai_hints].split(",")
  hint_values.each do |hint|
    unless is_supported_ohai_hint?(hint)
      raise ArgumentError, "Ohai Hint name #{hint} passed is not supported. Please run the command help to see the list of supported values."
    end
  end
end