class Chef::Knife::IonoscloudServerStart

Attributes

description[R]
required_options[R]

Public Class Methods

new(args = []) click to toggle source
Calls superclass method
# File lib/chef/knife/ionoscloud_server_start.rb, line 17
def initialize(args = [])
  super(args)
  @description =
  'This will start a server. If the server\'s public IP was deallocated then a new IP will be assigned.'
  @required_options = [:datacenter_id, :ionoscloud_username, :ionoscloud_password]
end

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/ionoscloud_server_start.rb, line 24
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_start_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.info("Server #{server_id} is starting. Request ID: #{get_request_id headers}")
  end
end