class Chef::Knife::SakuraServerStart

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/sakura_server_start.rb, line 34
def run
  validate!

  options = {}
  options[:id] = locate_config_value( :id )

  if options[:id] == nil
    puts 'Error. Missing server id (-i) option.'
  else

    begin
      target = connection.servers.find { |server|
        server.id == options[:id]
      }
      if target == nil
        puts "Error. Not found server id #{options[:id]}."
      else
        response = target.start( options )
        if response
          puts "succeeded."
        else
          puts "failed."
        end
      end
    rescue Exception
      body = Fog::JSON.decode( $!.response.body )
      puts "#{body['status']}: #{body['error_msg']}"
    end
  end
end