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)


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

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:



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

def builder
  @builder
end

#clientObject (readonly, protected)

Returns the value of attribute client.



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

def client
  @client
end

#nameObject (readonly, protected)

Returns the value of attribute name.



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

def name
  @name
end

#scriptString (readonly)

Returns:

  • (String)


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

def script
  @script
end

Instance Method Details

#executeInteger

Returns exit status.

Returns:

  • (Integer)

    exit status



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

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

  begin
    client.runscript(builder.ctid, tmp.path)
  ensure
    tmp&.unlink
  end
end