Class: OsCtl::Image::Operations::Builder::RunscriptFromString

Inherits:
OsCtl::Image::Operations::Base show all
Defined in:
lib/osctl/image/operations/builder/runscript_from_string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OsCtl::Image::Operations::Base

run

Constructor Details

#initialize(builder, script, name: nil, client: nil) ⇒ RunscriptFromString

Returns a new instance of RunscriptFromString.

Parameters:

  • builder (Builder)
  • script (Script)
  • name (nil, String) (defaults to: nil)
  • client (nil, OsCtldClient) (defaults to: nil)


16
17
18
19
20
21
22
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 16

def initialize(builder, script, name: nil, client: nil)
  super()
  @builder = builder
  @script = script
  @name = name || 'osctl-image-runscript'
  @client = client || OsCtldClient.new
end

Instance Attribute Details

#builderBuilder (readonly)

Returns:



7
8
9
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 7

def builder
  @builder
end

#clientObject (readonly, protected)

Returns the value of attribute client.



40
41
42
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 40

def client
  @client
end

#nameObject (readonly, protected)

Returns the value of attribute name.



40
41
42
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 40

def name
  @name
end

#scriptString (readonly)

Returns:

  • (String)


10
11
12
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 10

def script
  @script
end

Instance Method Details

#executeInteger

Returns exit status.

Returns:

  • (Integer)

    exit status



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/osctl/image/operations/builder/runscript_from_string.rb', line 25

def execute
  tmp = Tempfile.new(name, '/tmp')
  File.chmod(0o755, tmp.path)
  tmp.write(script)
  tmp.close

  begin
    OsCtldClient.new.runscript(builder.ctid, tmp.path)
  ensure
    tmp.unlink
  end
end