class Chef::Knife::Cloud::GoogleServerCreate
Public Instance Methods
auto_migrate?()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 263 def auto_migrate? preemptible? ? false : config[:auto_migrate] end
auto_restart?()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 267 def auto_restart? preemptible? ? false : config[:auto_restart] end
before_bootstrap()
click to toggle source
Calls superclass method
# File lib/chef/knife/google_server_create.rb, line 225 def before_bootstrap super config[:chef_node_name] = config[:chef_node_name] || instance_name config[:bootstrap_ip_address] = ip_address_for_bootstrap if config[:image_os_type] == "windows" ui.msg("Resetting the Windows login password so the bootstrap can continue...") config[:connection_password] = reset_windows_password end end
before_exec_command()
click to toggle source
Calls superclass method
# File lib/chef/knife/google_server_create.rb, line 170 def before_exec_command super @create_options = { name: instance_name, image: config[:image], image_project: config[:image_project], network: config[:network], subnet: config[:subnet], public_ip: config[:public_ip], auto_migrate: auto_migrate?, auto_restart: auto_restart?, preemptible: preemptible?, boot_disk_autodelete: config[:boot_disk_autodelete], boot_disk_name: config[:boot_disk_name], boot_disk_size: boot_disk_size, boot_disk_ssd: config[:boot_disk_ssd], additional_disks: config[:additional_disks], local_ssd: config[:local_ssd], interface: config[:interface], number_of_local_ssd: number_of_local_ssd, can_ip_forward: config[:can_ip_forward], machine_type: config[:machine_type], service_account_scopes: config[:service_account_scopes], service_account_name: config[:service_account_name], metadata: metadata, tags: config[:tags], } end
boot_disk_size()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 290 def boot_disk_size config[:boot_disk_size].to_i end
email()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 255 def email config[:gce_email] end
gcewinpass_debug_mode()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 309 def gcewinpass_debug_mode Chef::Config[:log_level] == :debug end
get_node_name(_name, _prefix)
click to toggle source
overriding this from Chef::Knife::Cloud::ServerCreateCommand.
This gets called in validate_params! in that class before our before_bootstrap
is called, in which it randomly generates a node name, which means we never default to the instance name in our before_bootstrap
method. Instead, we'll just nil this and allow our class here to do The Right Thing.
# File lib/chef/knife/google_server_create.rb, line 243 def get_node_name(_name, _prefix) nil end
instance_name()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 279 def instance_name @name_args.first end
ip_address_for_bootstrap()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 271 def ip_address_for_bootstrap ip = config[:use_private_ip] ? private_ip_for(server) : public_ip_for(server) raise "Unable to determine instance IP address for bootstrapping" if ip == "unknown" ip end
metadata()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 283 def metadata config[:metadata].each_with_object({}) do |item, memo| key, value = item.split("=") memo[key] = value end end
number_of_local_ssd()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 294 def number_of_local_ssd config[:number_of_local_ssd].to_i end
preemptible?()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 259 def preemptible? config[:preemptible] end
project()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 247 def project config[:gce_project] end
reset_windows_password()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 298 def reset_windows_password GoogleComputeWindowsPassword.new( project: project, zone: zone, instance_name: instance_name, email: email, username: config[:connection_user], debug: gcewinpass_debug_mode ).new_password end
set_default_config()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 200 def set_default_config # dumb hack for knife-cloud, which expects the user to pass in the WinRM password to use when bootstrapping. # We won't know the password until the instance is created and we forcibly reset it. config[:connection_password] = "will_change_this_later" end
validate_params!()
click to toggle source
Calls superclass method
# File lib/chef/knife/google_server_create.rb, line 206 def validate_params! check_for_missing_config_values!(:gce_zone, :machine_type, :image, :boot_disk_size, :network) raise "You must supply an instance name." if @name_args.first.nil? raise "Boot disk size must be between 10 and 10,000" unless valid_disk_size?(boot_disk_size) if config[:connection_protocol] == "winrm" && config[:gce_email].nil? raise "Please provide your Google Cloud console email address via --gce-email. " \ "It is required when resetting passwords on Windows hosts." end raise "Please provide connection port via --connection-port." unless config[:connection_port] raise "Please provide image os type via --image-os-type." unless config[:image_os_type] ui.warn("Auto-migrate disabled for preemptible instance") if preemptible? && config[:auto_migrate] ui.warn("Auto-restart disabled for preemptible instance") if preemptible? && config[:auto_restart] super end
zone()
click to toggle source
# File lib/chef/knife/google_server_create.rb, line 251 def zone config[:gce_zone] end