Class: Bosh::Bootstrap::Commander::RemoteScriptCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/bosh-bootstrap/commander/remote_script_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, description, script, full_present_tense = nil, full_past_tense = nil, options = {}) ⇒ RemoteScriptCommand

Returns a new instance of RemoteScriptCommand.



18
19
20
21
22
23
24
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 18

def initialize(command, description, script, full_present_tense=nil, full_past_tense=nil, options={})
  super(command, description, full_present_tense, full_past_tense)
  @script = script
  @specific_run_as_user = options[:user]
  @settings = options[:settings]
  @save_output_to_settings_key = options[:save_output_to_settings_key]
end

Instance Attribute Details

#commandObject (readonly)

verb e.g. “install”



6
7
8
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 6

def command
  @command
end

#descriptionObject (readonly)

noun phrase, e.g. “packages”



7
8
9
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 7

def description
  @description
end

#full_past_tenseObject (readonly)

e.g. “installed packages”



11
12
13
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 11

def full_past_tense
  @full_past_tense
end

#full_present_tenseObject (readonly)

e.g. “installing packages”



10
11
12
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 10

def full_present_tense
  @full_present_tense
end

#save_output_to_settings_keyObject (readonly)

e.g. bosh.salted_password



16
17
18
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 16

def save_output_to_settings_key
  @save_output_to_settings_key
end

#scriptObject (readonly)

Returns the value of attribute script.



8
9
10
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 8

def script
  @script
end

#settingsObject (readonly)

settings manifest (result of script might get stored back)



15
16
17
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 15

def settings
  @settings
end

#specific_run_as_userObject (readonly)

Optional:



14
15
16
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 14

def specific_run_as_user
  @specific_run_as_user
end

Instance Method Details

#as_file {|script_path| ... } ⇒ Object

Stores the script on the local filesystem in a temporary directory Returns path

Yields:

  • (script_path)


39
40
41
42
43
44
45
46
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 39

def as_file(&block)
  tmpdir = ENV['TMPDIR'] || "/tmp"
  script_path = File.join(tmpdir, to_filename)
  File.open(script_path, "w") do |f|
    f << @script
  end
  yield script_path
end

#perform(server) ⇒ Object

Invoke this command to call back upon server.run_script



27
28
29
30
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 27

def perform(server)
  server.run_script(self, script, :user => specific_run_as_user,
    :settings => settings, :save_output_to_settings_key => save_output_to_settings_key)
end

#to_filenameObject

Provide a filename that represents this Command



33
34
35
# File 'lib/bosh-bootstrap/commander/remote_script_command.rb', line 33

def to_filename
  @to_filename ||= "#{command} #{description}".gsub(/\W+/, '_')
end