class Chef::Knife::IonoscloudServerReboot

Attributes

description[R]
required_options[R]

Public Class Methods

new(args = []) click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_server_reboot.rb, line 17
def initialize(args = [])
  super(args)
  @description =
  'This will force a hard reboot of the server. Do not use this method '\
  'if you want to gracefully reboot the machine. This is the equivalent '\
  'of powering off the machine and turning it back on.'
  @required_options = [:datacenter_id, :ionoscloud_username, :ionoscloud_password]
end

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/ionoscloud_server_reboot.rb, line 26
def run
  $stdout.sync = true
  handle_extra_config
  validate_required_params(@required_options, config)

  server_api = Ionoscloud::ServerApi.new(api_client)

  @name_args.each do |server_id|
    begin
      _, _, headers = server_api.datacenters_servers_reboot_post_with_http_info(config[:datacenter_id], server_id)
    rescue Ionoscloud::ApiError => err
      raise err unless err.code == 404
      ui.error("Server ID #{server_id} not found. Skipping.")
      next
    end
    ui.warn("Server #{server_id} is rebooting. Request ID: #{get_request_id headers}")
  end
end