exe/conoharant in conoha-0.4.0 vs exe/conoharant in conoha-0.5.0

- old
+ new

@@ -58,27 +58,71 @@ case arg when 'status' puts status['status'] when 'up' - begin - server_id = Conoha.create config['os'], config['ram'] - rescue => e - STDERR.puts e.to_s + if status['status'] == 'running' + puts "# Nothing to do." + exit 0 + end + if status['id'].nil? + begin + server_id = Conoha.create config['os'], config['ram'] + rescue => e + STDERR.puts e.to_s + exit 1 + end + puts server_id + loop do + sleep 10 + result = Conoha.status_of server_id + break if result == "ACTIVE" + puts "# Current status is \"#{result}\", not \"ACTIVE\"." + puts "# Re-check after 10 seconds..." + end + puts "# OK!" + status['id'] = server_id + else + server_id = status['id'] + puts "conoha boot #{server_id}" + Conoha.boot server_id + end + status['status'] = 'running' + dump_conoharant_status status +when 'halt', 'shutdown' + if status['status'] != 'running' + STDERR.puts "A running VPS doesn't exist." exit 1 end - puts server_id - loop do + server_id = status['id'] + puts "conoha shutdown #{server_id}" + Conoha.shutdown server_id + status['status'] = 'shutdown' + dump_conoharant_status status +when 'destroy' + if status['status'] == 'nothing' + puts "# Nothing to do." + exit 0 + end + server_id = status['id'] + if status['status'] == 'running' + puts "conoha shutdown #{server_id}" + Conoha.shutdown server_id sleep 10 + end + loop do result = Conoha.status_of server_id - break if result == "ACTIVE" - puts "# Current status is \"#{result}\", not \"ACTIVE\"." + break if result == "SHUTOFF" + puts "# Current status is \"#{result}\", not \"SHUTOFF\"." puts "# Re-check after 10 seconds..." + sleep 10 end - puts "# OK!" - status['status'] = 'running' - status['id'] = server_id + puts "conoha delete #{server_id}" + Conoha.delete server_id + status['status'] = 'nothing' + status['id'] = nil dump_conoharant_status status + puts "# OK!" when 'ssh', 'mosh' connection = arg # 'ssh' or 'mosh' if status['status'] != 'running' STDERR.puts "VPS is not running." exit 1