Class: Pairhost::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/pairhost.rb

Instance Method Summary collapse

Instance Method Details

#attach(instance_id) ⇒ Object



199
200
201
202
203
# File 'lib/pairhost.rb', line 199

def attach(instance_id)
  invoke :verify, []
  Pairhost.write_instance_id(instance_id)
  invoke :status, []
end

#create(name = nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pairhost.rb', line 108

def create(name=nil)
  invoke :verify, []

  if name == nil
    initials = `git config user.initials`.chomp.split("/").map(&:upcase).join(" ")
    name = "Pairhost (#{initials})"
  end

  puts "Provisioning \"#{name}\"..."
  server = Pairhost.create(name)
  puts "provisioned!"
  invoke :status, []
end

#destroyObject



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/pairhost.rb', line 179

def destroy
  invoke :verify
  server = Pairhost.fetch!
  confirm = ask("Type 'yes' to confirm deleting '#{server.tags['Name']}'.\n>")
  return unless confirm == "yes"

  puts "Destroying..."
  server.destroy
  server.wait_for { state == "terminated" }
  puts "destroyed!"
end

#detachObject



206
207
208
209
210
# File 'lib/pairhost.rb', line 206

def detach
  invoke :verify
  # TODO implement
  puts "Coming soon..."
end

#initObject



98
99
100
101
102
103
104
105
# File 'lib/pairhost.rb', line 98

def init
  if File.exists?(Pairhost.config_file)
    STDERR.puts "pairhost: Already initialized."
  else
    FileUtils.mkdir_p File.dirname(Pairhost.config_file)
    FileUtils.cp(File.dirname(__FILE__) + '/../config.example.yml', Pairhost.config_file)
  end
end

#provisionObject



192
193
194
195
196
# File 'lib/pairhost.rb', line 192

def provision
  invoke :verify
  # TODO implement
  puts "Coming soon..."
end

#resumeObject



125
126
127
128
129
130
131
132
133
# File 'lib/pairhost.rb', line 125

def resume
  invoke :verify
  server = Pairhost.fetch!
  puts "Starting..."
  Pairhost.start(server.reload)
  puts "started!"

  invoke :status
end

#sshObject



157
158
159
160
161
# File 'lib/pairhost.rb', line 157

def ssh
  invoke :verify
  server = Pairhost.fetch!
  exec "ssh -A -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=QUIET pair@#{server.dns_name}"
end

#statusObject



148
149
150
151
152
153
154
# File 'lib/pairhost.rb', line 148

def status
  invoke :verify
  server = Pairhost.fetch!
  puts "#{server.id}: #{server.tags['Name']}"
  puts "State: #{server.state}"
  puts server.dns_name if server.dns_name
end

#stopObject



168
169
170
171
172
173
174
# File 'lib/pairhost.rb', line 168

def stop
  invoke :verify
  server = Pairhost.fetch!
  puts "Shutting down..."
  Pairhost.stop(server)
  puts "shutdown!"
end

#upObject



136
137
138
139
140
141
142
143
144
145
# File 'lib/pairhost.rb', line 136

def up
  invoke :verify
  server = Pairhost.fetch

  if server
    invoke :resume
  else
    invoke :create
  end
end

#verifyObject



93
94
95
# File 'lib/pairhost.rb', line 93

def verify
  Pairhost.config
end