Sha256: 7892d047b21254a17a137e88fe9b00e0945725d68049471470ae215a9d92cb00

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

#!/usr/bin/env ruby
# vim: filetype=ruby

require 'conoha'
require 'conoha/util'
require 'pp'

subcommand = ARGV.shift

Conoha.init!

def server_id(server_id_or_index)
  if server_id_or_index.length == '01234567-89ab-cdef-0123-456789abcdef'.length
    server_id_or_index
  else
    Conoha.vps_list[server_id_or_index.to_i]
  end
end

case subcommand
when 'authenticate'
  Conoha.authenticate!
  puts 'Succeeded!'
when 'vpslist'
  pp Conoha.vps_list
when 'ipaddress'
  exit 1 if ARGV.size != 1
  pp Conoha.ip_address_of server_id(ARGV.first)
when 'create'
  pp Conoha.create *ARGV
when 'delete'
  exit 1 if ARGV.size != 1
  puts Conoha.delete server_id(ARGV.first)
when 'boot'
  exit 1 if ARGV.size != 1
  puts Conoha.boot server_id(ARGV.first)
when 'shutdown'
  exit 1 if ARGV.size != 1
  puts Conoha.shutdown server_id(ARGV.first)
when 'imagelist'
  pp Conoha.images
when 'imagecreate'
  exit 1 if ARGV.size != 2
  name = ARGV[1]
  puts Conoha.create_image server_id(ARGV[0]), name
when 'imagedelete'
  exit 1 if ARGV.size != 1
  image_ref = ARGV.first
  puts Conoha.delete_image image_ref
when 'createfromimage'
  exit 1 if ARGV.size != 2
  image_ref = ARGV[0]
  ram = ARGV[1]
  puts Conoha.create_from_image image_ref, ram
when 'ssh'
  exit 1 if ARGV.size < 1 || 2 < ARGV.size
  ipaddress = ipv4(Conoha.ip_address_of(server_id(ARGV.first)))
  user = ARGV[1].nil? ? '' : "#{ARGV[1]}@"
  command = "ssh -oStrictHostKeyChecking=no #{user}#{ipaddress}"
  puts command
  system command
when 'mosh'
  exit 1 if ARGV.size != 1
  ipaddress = ipv4(Conoha.ip_address_of(server_id(ARGV.first)))
  command = "mosh #{ipaddress}"
  puts command
  system command
when 'browse'
  exit 1 if ARGV.size < 1 || 2 < ARGV.size
  ipaddress = ipv4(Conoha.ip_address_of(server_id(ARGV.first)))
  port = ARGV[1].nil? ? '' : ":#{ARGV[1]}"
  command = "xdg-open http://#{ipaddress}#{port}"
  puts command
  system command
else
  STDERR.puts 'Error'
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conoha-0.0.5 exe/conoha
conoha-0.0.4 exe/conoha