Class: Kytoon::ThorTasks

Inherits:
Thor
  • Object
show all
Defined in:
lib/kytoon/thor_tasks.rb

Instance Method Summary collapse

Instance Method Details

#create(options = (options or {})) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/kytoon/thor_tasks.rb', line 10

def create(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    sg = ServerGroup.create(options[:group_config])
    puts "Server group ID #{sg.id} created."
  rescue KytoonException => ke
    puts ke.message
  end
end

#delete(options = (options or {})) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/kytoon/thor_tasks.rb', line 47

def delete(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    sg = ServerGroup.get(options[:group_id])
    sg.delete
    SshUtil.remove_known_hosts_ip(sg.gateway_ip)
  rescue KytoonException => ke
    puts ke.message
  end
end

#ip(options = (options or {})) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/kytoon/thor_tasks.rb', line 61

def ip(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    sg = ServerGroup.get(options[:group_id])
    puts sg.gateway_ip
  rescue KytoonException => ke
    puts ke.message
  end
end

#list(options = (options or {})) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/kytoon/thor_tasks.rb', line 22

def list(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    ServerGroup.index()
  rescue KytoonException => ke
    puts ke.message
  end
end

#show(options = (options or {})) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/kytoon/thor_tasks.rb', line 34

def show(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    sg = ServerGroup.get(options[:group_id])
    sg.pretty_print
  rescue KytoonException => ke
    puts ke.message
  end
end

#ssh(options = (options or {})) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kytoon/thor_tasks.rb', line 74

def ssh(options=(options or {}))
  begin
    ServerGroup.init(options[:group_type])
    args=ARGV[1, ARGV.length].join(" ")
    sg = ServerGroup.get(options[:group_id])
    if (ARGV[1] and ARGV[1] =~ /^--group_id.*/) and (ARGV[2] and ARGV[2] =~ /^--group_id.*/)
      args=ARGV[3, ARGV.length].join(" ")
    elsif ARGV[1] and ARGV[1] =~ /^--group_id.*/
      args=ARGV[2, ARGV.length].join(" ")
    end
    exec("ssh -o \"StrictHostKeyChecking no\" root@#{sg.gateway_ip} #{args}")
  rescue KytoonException => ke
    puts ke.message
  end
end