class Chef::Knife::OneandoneServerModify

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/oneandone_server_modify.rb, line 35
def run
  $stdout.sync = true

  init_client

  name_args.each do |server_id|
    server = OneAndOne::Server.new

    begin
      server.get(server_id: server_id)
    rescue StandardError => e
      if e.message.include? 'NOT_FOUND'
        ui.error("Server ID #{server_id} not found. Skipping.")
      else
        ui.error(e.message)
      end
      next
    end

    server.modify_hardware(
      fixed_instance_id: config[:fixed_size_id],
      vcore: config[:cpu],
      cores_per_processor: config[:cores],
      ram: config[:ram]
    )

    if config[:wait]
      puts ui.color('Reconfiguring, wait for the operation to complete...', :cyan).to_s
      server.wait_for

      puts "\t#{ui.color('ID', :cyan)}: #{server.id}"
      puts "\t#{ui.color('Name', :cyan)}: #{server.specs['name']}"
      puts "\t#{ui.color('Fixed Size ID', :cyan)}: #{server.specs['hardware']['fixed_instance_size_id']}"
      puts "\t#{ui.color('Processors', :cyan)}: #{server.specs['hardware']['vcore']}"
      puts "\t#{ui.color('Cores per Processor', :cyan)}: #{server.specs['hardware']['cores_per_processor']}"
      puts "\t#{ui.color('RAM (GB)', :cyan)}: #{server.specs['hardware']['ram']}\n"

      puts "Server's hardware is #{ui.color('modified', :bold)}"
    else
      puts "Server's hardware is #{ui.color('being modified', :bold)}"
    end
  end
end