Class: Caterer::Provisioner::Shell

Inherits:
Base
  • Object
show all
Defined in:
lib/caterer/provisioner/shell.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#image

Instance Method Summary collapse

Methods inherited from Base

#cleanup, #install, #installed?, #uninstall

Constructor Details

#initialize(image, opts = {}) ⇒ Shell

Returns a new instance of Shell.



12
13
14
15
16
17
# File 'lib/caterer/provisioner/shell.rb', line 12

def initialize(image, opts={})
  @image  = image
  @path   = opts[:path] if opts[:path]
  @inline = opts[:inline] if opts[:inline]
  @args   = opts[:args] if opts[:args]
end

Instance Attribute Details

#args(args) ⇒ Object

Returns the value of attribute args.



10
11
12
# File 'lib/caterer/provisioner/shell.rb', line 10

def args
  @args
end

#inline(inline) ⇒ Object

Returns the value of attribute inline.



10
11
12
# File 'lib/caterer/provisioner/shell.rb', line 10

def inline
  @inline
end

#path(path) ⇒ Object

config dsl



21
22
23
# File 'lib/caterer/provisioner/shell.rb', line 21

def path
  @path
end

Instance Method Details

#dest_lib_dirObject



61
62
63
# File 'lib/caterer/provisioner/shell.rb', line 61

def dest_lib_dir
  "#{image.lib_dir}/shell"
end

#dest_script_pathObject



65
66
67
# File 'lib/caterer/provisioner/shell.rb', line 65

def dest_script_path
  "#{dest_lib_dir}/#{uuid}"
end

#errorsObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/caterer/provisioner/shell.rb', line 33

def errors
  errors = {}
  
  if not @path and not @inline
    errors[:action] = "cannot be determined. Please set 'inline' or 'script'"
  end

  if errors.length > 0
    errors
  end

end

#prepare(server) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/caterer/provisioner/shell.rb', line 46

def prepare(server)
  # create lib dir
  server.ssh.sudo "mkdir -p #{dest_lib_dir}", :stream => true
  server.ssh.sudo "chown -R #{server.username} #{dest_lib_dir}", :stream => true

  # create script
  server.ui.info "Generating shell script..."
  server.ssh.upload(StringIO.new(script_content), dest_script_path)
  server.ssh.sudo "chmod +x #{dest_script_path}", :stream => true
end

#provision_cmdObject



57
58
59
# File 'lib/caterer/provisioner/shell.rb', line 57

def provision_cmd
  "#{dest_script_path} #{@args}"
end

#script_contentObject



73
74
75
76
77
78
79
# File 'lib/caterer/provisioner/shell.rb', line 73

def script_content
  if @inline
    Tilt.new(File.expand_path('../../../templates/provisioner/shell/script.erb', __FILE__)).render(self)          
  else
    File.read @path
  end
end

#uuidObject



69
70
71
# File 'lib/caterer/provisioner/shell.rb', line 69

def uuid
  @uuid ||= ::Digest::MD5.hexdigest((@inline or @path))
end