Class: Chef::Knife::AzurermServerCreate

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

Constant Summary

Constants included from Azure::ARM::ReadCred

Azure::ARM::ReadCred::CRED_TYPE_DOMAIN_CERTIFICATE, Azure::ARM::ReadCred::CRED_TYPE_DOMAIN_PASSWORD, Azure::ARM::ReadCred::CRED_TYPE_DOMAIN_VISIBLE_PASSWORD, Azure::ARM::ReadCred::CRED_TYPE_GENERIC

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?, #locate_config_value, #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!

Methods included from Azure::ARM::WindowsCredentials

#latest_credential_target, #target_name, #token_details_from_WCM

Instance Attribute Details

#initial_sleep_delayObject

Returns the value of attribute initial_sleep_delay.



36
37
38
# File 'lib/chef/knife/azurerm_server_create.rb', line 36

def initial_sleep_delay
  @initial_sleep_delay
end

Instance Method Details

#connect!Object

Following methods are not required for ARM



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

def connect!; end

#create_server_defObject

run() execution ends ####



153
154
155
156
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
# File 'lib/chef/knife/azurerm_server_create.rb', line 153

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

  server_def[:tcp_endpoints] = locate_config_value(:tcp_endpoints) if locate_config_value(: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] ||= locate_config_value(:azure_vm_name)

  server_def[:azure_storage_account] = locate_config_value(: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] = locate_config_value(: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] = locate_config_value(:azure_vm_name) if server_def[:azure_vnet_name].nil?
  server_def[:azure_vnet_subnet_name] = locate_config_value(:azure_vm_name) if locate_config_value(: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] = locate_config_value(: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] = locate_config_value(:connection_user)
  server_def[:disablePasswordAuthentication] = if locate_config_value(:ssh_public_key)
                                                 server_def[:ssh_public_key] = File.read(locate_config_value(:ssh_public_key))
                                                 "true"
                                               else
                                                 server_def[:connection_password] = locate_config_value(:connection_password)
                                                 "false"
                                               end

  server_def
end

#format_ohai_hints(ohai_hints) ⇒ Object



218
219
220
221
# File 'lib/chef/knife/azurerm_server_create.rb', line 218

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)


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

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

#perform_bootstrap(bootstrap_path) ⇒ Object



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

def perform_bootstrap(bootstrap_path); end

#plugin_create_instance!Object



129
130
131
132
133
134
135
# File 'lib/chef/knife/azurerm_server_create.rb', line 129

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



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

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 ####



112
113
114
115
116
# File 'lib/chef/knife/azurerm_server_create.rb', line 112

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



120
121
122
123
124
125
126
127
# File 'lib/chef/knife/azurerm_server_create.rb', line 120

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

#register_clientObject



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

def register_client; end

#render_templateObject



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

def render_template; end

#supported_ohai_hintsObject



210
211
212
213
214
215
216
# File 'lib/chef/knife/azurerm_server_create.rb', line 210

def supported_ohai_hints
  %w{
    vm_name
    public_fqdn
    platform
  }
end

#upload_bootstrap(content) ⇒ Object



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

def upload_bootstrap(content); end

#validate_name_args!Object



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

def validate_name_args!; end

#validate_ohai_hintsObject



227
228
229
230
231
232
233
234
# File 'lib/chef/knife/azurerm_server_create.rb', line 227

def validate_ohai_hints
  hint_values = locate_config_value(: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