Class: Stackato::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/conan/stackato.rb

Constant Summary collapse

@@executable =
"stackato-3.1.1"
@@token_file =
File.join(Dir.tmpdir(), "token_#{Time.now.to_i}")

Instance Method Summary collapse

Constructor Details

#initialize(target, dry_run = false) ⇒ Commands

Returns a new instance of Commands.



11
12
13
14
15
16
17
# File 'lib/conan/stackato.rb', line 11

def initialize(target, dry_run=false)
  @target = target
  @dry_run = dry_run
  v = get_version
  puts(v)
  raise "Stackato 3.1.* required. Found #{v}" unless v =~ /\(3\.1\.[0-9]+\)/
end

Instance Method Details

#delete(app_name) ⇒ Object



62
63
64
65
# File 'lib/conan/stackato.rb', line 62

def delete(app_name)
  shell_cmd("delete", "--no-prompt #{app_name}", true)  #instead of ignore error- look for Found a problem with input "application": An application "tentacles-integ-sea2" does not exist in space 'MTN::kraken'. Please use a different value.

end

#get_versionObject



43
44
45
46
47
48
49
50
51
# File 'lib/conan/stackato.rb', line 43

def get_version    
  begin
    v, err, status = Open3.capture3("#{@@executable} version")
    abort "Stackato error: #{err}" unless status.success?        
    v
  rescue Exception => e
    abort "Failed to invoke Stackato client: #{e}"
  end    
end

#login(username, password, space) ⇒ Object



53
54
55
# File 'lib/conan/stackato.rb', line 53

def (username, password, space)
  shell_cmd("login", "--space #{space} --password '#{password}' #{username}")
end

#map(app_name, url) ⇒ Object



67
68
69
# File 'lib/conan/stackato.rb', line 67

def map(app_name, url)
  shell_cmd("map", "#{app_name} #{url}")
end

#push(manifest) ⇒ Object



57
58
59
60
# File 'lib/conan/stackato.rb', line 57

def push(manifest)
  shell_cmd("push", "--manifest #{manifest} --no-prompt --reset --force-start --timeout 5m")
  puts(">> push complete")
end

#shell_cmd(stackato_cmd, args, ignoreErrs = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/conan/stackato.rb', line 19

def shell_cmd(stackato_cmd, args, ignoreErrs=false)
  base_args = "--target #{@target} --token-file #{@@token_file}"

  cmd = "#{@@executable} #{stackato_cmd} #{base_args} #{args}"
  puts(">>> #{cmd}")
  if @dry_run
    puts "Dry-run, skipping execution of command: #{cmd}"
  else
    # output, err, status = Open3.capture3(cmd)
    #  raise "Stackato error: #{err}" unless (ignoreErrs||status.success?)
    #  output
    Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr|
      Thread.new do
        stdout_stderr.each {|l| puts l }
      end
      stdin.close
      exit_status = wait_thr.value          
      unless ignoreErrs || exit_status.success?
        abort "Stackato #{stackato_cmd} failed"
      end
    end
  end
end