Class: Blimpy::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/blimpy/cli.rb

Constant Summary collapse

BLIMPFILE =
File.join(Dir.pwd, 'Blimpfile')

Instance Method Summary collapse

Instance Method Details

#destroyObject



120
121
122
123
124
# File 'lib/blimpy/cli.rb', line 120

def destroy
  ensure_blimpfile
  fleet = Blimpy::Fleet.new
  fleet.destroy
end

#initObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/blimpy/cli.rb', line 134

def init
  File.open(File.join(Dir.pwd, 'Blimpfile'), 'w') do |f|
    f.write(
"""# vim: ft=ruby
# Blimpfile created on #{Time.now}

Blimpy.fleet do |fleet|
  fleet.add(:aws) do |ship|
ship.name = 'Excelsior'
ship.ports = [22, 8080]
  end
end
""")
  end
end

#provision(name = nil) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/blimpy/cli.rb', line 190

def provision(name=nil)
  ensure_blimpfile
  unless name.nil?
    box = box_by_name(name)
    if box.nil?
      puts "Could not find a blimp named \"#{name}\""
      exit 1
    end
    box.bootstrap
  else
    blimps = current_blimps
    unless blimps
      puts "No Blimps running!"
      exit 1
    end

    blimps.each do |blimp, data|
      next unless data[:name]
      box = box_by_name(data[:name])
      box.bootstrap
    end
  end
end

#scp(name, filename, *args) ⇒ Object



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/blimpy/cli.rb', line 177

def scp(name, filename, *args)
  ensure_blimpfile
  box = box_by_name(name)
  if box.nil?
    puts "Could not find a blimp named \"#{name}\""
    exit 1
  end
  box.wait_for_sshd
  # Pass any extra commands along to the `scp` invocation
  box.scp_file(filename, '', *ARGV[3..-1])
end

#showObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/blimpy/cli.rb', line 79

def show
  ensure_blimpfile
  blimps = current_blimps
  unless blimps
    puts 'No currently running VMs'
    exit 0
  end

  tags_option = options[:tags]
  blimps.each do |blimp, data|
    if tags_option
      tags = nil
      data[:tags].each do |k,v|
        if tags.nil?
          tags = "#{k}=#{v}"
        elsif
          tags = "#{tags},#{k}=#{v}"
        end
      end
      puts "#{data[:name]} #{data[:internal_dns]} #{tags}"
    end
  end
end

#ssh(name = nil, *args) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/blimpy/cli.rb', line 151

def ssh(name=nil, *args)
  ensure_blimpfile
  unless name.nil?
    box = box_by_name(name)
    if box.nil?
      puts "Could not find a blimp named \"#{name}\""
      exit 1
    end
  else
    blimps = current_blimps
    unless blimps
      puts "No Blimps running!"
      exit 1
    end

    blimps.each do |blimp, data|
      next unless data[:name]
      box = box_by_name(data[:name])
    end
  end

  box.wait_for_sshd
  box.ssh_into *args
end

#startObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/blimpy/cli.rb', line 59

def start
  ensure_blimpfile
  begin
    fleet = load_blimpfile
  rescue Blimpy::InvalidBlimpFileError => e
    puts "The Blimpfile is invalid!"
    puts e.to_s
    exit 1
  end

  if options[:'dry-run']
    puts 'skipping actually starting the fleet'
    exit 0
  end

  fleet.start
end

#statusObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/blimpy/cli.rb', line 104

def status
  ensure_blimpfile
  blimps = current_blimps
  unless blimps
    puts 'No currently running VMs'
    exit 0
  end

  blimps.each do |blimp, data|
    instance_id = File.basename(blimp)
    instance_id = instance_id.split('.blimp').first
    puts "#{data[:name]} (#{instance_id}) is: online at #{data[:dns]} (#{data[:internal_dns]} internally)"
  end
end

#stopObject



127
128
129
130
131
# File 'lib/blimpy/cli.rb', line 127

def stop
  ensure_blimpfile
  fleet = Blimpy::Fleet.new
  fleet.stop
end

#versionObject



215
216
217
# File 'lib/blimpy/cli.rb', line 215

def version
  puts Blimpy::VERSION
end