Class: Chef::Knife::BootstrapAzurerm

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

Instance Method Summary collapse

Methods included from Chef::Knife::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 Chef::Knife::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 Method Details

#connect!Object

Following methods are not required



77
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 77

def connect!; end

#perform_bootstrap(bootstrap_path) ⇒ Object



85
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 85

def perform_bootstrap(bootstrap_path); end

#plugin_create_instance!Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 52

def plugin_create_instance!
  if @name_args.length == 1
    ui.log("Creating VirtualMachineExtension....")
    ext_params = set_ext_params
    vm_extension = service.create_vm_extension(ext_params)
    if vm_extension
      if ext_params[:chef_extension_public_param][:extendedLogs] == "true"
        service.fetch_chef_client_logs(ext_params[:azure_resource_group_name], ext_params[:azure_vm_name], ext_params[:chef_extension], Time.now)
      end
      ui.log("VirtualMachineExtension creation successfull.")
      ui.log("Virtual Machine Extension name is: #{vm_extension.name}")
      ui.log("Virtual Machine Extension ID is: #{vm_extension.id}")
    end
  else
    raise ArgumentError, "Please specify the SERVER name which needs to be bootstrapped via the Chef Extension." if @name_args.empty?
    raise ArgumentError, "Please specify only one SERVER name which needs to be bootstrapped via the Chef Extension." if @name_args.length > 1
  end
rescue StandardError => error
  service.common_arm_rescue_block(error)
end

#plugin_finalizeObject



73
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 73

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



43
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 43

def plugin_setup!; end

#plugin_validate_options!Object



47
48
49
50
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 47

def plugin_validate_options!
  ui.log("Validating...")
  validate_arm_keys!(:azure_resource_group_name, :azure_service_location)
end

#register_clientObject



79
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 79

def register_client; end

#render_templateObject



81
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 81

def render_template; end

#set_ext_paramsObject

run() execution ends ####



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 89

def set_ext_params
  server = service.find_server(config[:azure_resource_group_name], name_args[0])

  if server
    if service.extension_already_installed?(server)
      raise "Virtual machine #{server.name} already has Chef extension installed on it."
    else
      ext_params = {}
      case server.storage_profile.os_disk.os_type.downcase
      when "windows"
        ext_params[:chef_extension] = "ChefClient"
      when "linux"
        if %w{ubuntu debian rhel centos}.any? { |platform| server.storage_profile.image_reference.offer.downcase.include? platform }
          ext_params[:chef_extension] = "LinuxChefClient"
        else
          raise "Offer #{server.storage_profile.image_reference.offer} is not supported in the extension."
        end
      else
        raise "OS type #{server.storage_profile.os_disk.os_type} is not supported."
      end

      ext_params[:azure_resource_group_name] = config[:azure_resource_group_name]
      ext_params[:azure_vm_name] = @name_args[0]
      ext_params[:azure_service_location] = config[:azure_service_location]
      ext_params[:chef_extension_publisher] = get_chef_extension_publisher
      ext_params[:chef_extension_version] = get_chef_extension_version(ext_params[:chef_extension])
      ext_params[:chef_extension_public_param] = get_chef_extension_public_params
      ext_params[:chef_extension_private_param] = get_chef_extension_private_params
    end
  else
    raise "The given server '#{@name_args[0]}' does not exist under resource group '#{config[:azure_resource_group_name]}'"
  end

  ext_params
end

#upload_bootstrap(content) ⇒ Object



83
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 83

def upload_bootstrap(content); end

#validate_name_args!Object



45
# File 'lib/chef/knife/bootstrap_azurerm.rb', line 45

def validate_name_args!; end