Class: OsCtl::Image::Operations::Image::Instantiate
- Includes:
- Lib::Utils::Log, Lib::Utils::System
- Defined in:
- lib/osctl/image/operations/image/instantiate.rb
Instance Attribute Summary collapse
- #base_dir ⇒ String readonly
-
#client ⇒ Object
readonly
protected
Returns the value of attribute client.
-
#ctid ⇒ Object
readonly
protected
Returns the value of attribute ctid.
- #image ⇒ Image readonly
-
#opts ⇒ Object
readonly
protected
Returns the value of attribute opts.
-
#reinstall ⇒ Object
readonly
protected
Returns the value of attribute reinstall.
Instance Method Summary collapse
- #create_container(image_path) ⇒ Object protected
-
#execute ⇒ String
Ctid.
- #gen_ctid ⇒ Object protected
-
#initialize(base_dir, image, opts) ⇒ Instantiate
constructor
A new instance of Instantiate.
- #instantiate(build) ⇒ Object protected
Methods inherited from Base
Constructor Details
#initialize(base_dir, image, opts) ⇒ Instantiate
Returns a new instance of Instantiate.
24 25 26 27 28 29 30 31 32 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 24 def initialize(base_dir, image, opts) super() @base_dir = base_dir @image = image @opts = opts @client = OsCtldClient.new @ctid = opts[:ctid] || gen_ctid @reinstall = opts[:ctid] ? true : false end |
Instance Attribute Details
#base_dir ⇒ String (readonly)
11 12 13 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 11 def base_dir @base_dir end |
#client ⇒ Object (readonly, protected)
Returns the value of attribute client.
50 51 52 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 50 def client @client end |
#ctid ⇒ Object (readonly, protected)
Returns the value of attribute ctid.
50 51 52 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 50 def ctid @ctid end |
#image ⇒ Image (readonly)
14 15 16 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 14 def image @image end |
#opts ⇒ Object (readonly, protected)
Returns the value of attribute opts.
50 51 52 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 50 def opts @opts end |
#reinstall ⇒ Object (readonly, protected)
Returns the value of attribute reinstall.
50 51 52 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 50 def reinstall @reinstall end |
Instance Method Details
#create_container(image_path) ⇒ Object (protected)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 63 def create_container(image_path) if reinstall client.stop_container(ctid) client.reinstall_container_from_image( ctid, image_path, remove_snapshots: true ) else client.create_container_from_file(ctid, image_path) sleep(3) # FIXME: wait for osctld... client.set_container_attr( ctid, 'org.vpsadminos.osctl-image:type', 'instance' ) end end |
#execute ⇒ String
Returns ctid.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 35 def execute build = Operations::Image::Build.new(base_dir, image, opts) build.execute if opts[:rebuild] if (!File.exist?(build.output_stream) && !File.exist?(build.output_tar)) \ || opts[:rebuild] build.execute end instantiate(build) ctid end |
#gen_ctid ⇒ Object (protected)
82 83 84 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 82 def gen_ctid "instance-#{SecureRandom.hex(4)}" end |
#instantiate(build) ⇒ Object (protected)
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/osctl/image/operations/image/instantiate.rb', line 52 def instantiate(build) if File.exist?(build.output_stream) create_container(build.output_stream) elsif File.exist?(build.output_tar) create_container(build.output_tar) else raise OperationError, "no image file for '#{build.image}' found in output directory" end end |