Class: Larrow::Qingcloud::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/larrow/qingcloud/image.rb

Constant Summary

Constants inherited from Base

Base::DESTROY_STATUSES

Instance Attribute Summary collapse

Attributes inherited from Base

#delegator, #id, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

conn, #conn, describe, destroy_action, #initialize, #method_missing, #model_name, model_name, #param_by, param_by, plural_name, #show, singular_name

Methods included from Logger

#debug, #err, included, #info

Constructor Details

This class inherits a constructor from Larrow::Qingcloud::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Larrow::Qingcloud::Base

Instance Attribute Details

#platformObject

Returns the value of attribute platform.



4
5
6
# File 'lib/larrow/qingcloud/image.rb', line 4

def platform
  @platform
end

#providerObject

Returns the value of attribute provider.



4
5
6
# File 'lib/larrow/qingcloud/image.rb', line 4

def provider
  @provider
end

Class Method Details

.create(instance_id) ⇒ Object



14
15
16
17
18
19
# File 'lib/larrow/qingcloud/image.rb', line 14

def self.create instance_id
  result = conn.get 'CaptureInstance', instance: instance_id
  info "image created(instance: #{instance_id}): #{result}"
  image = new result['image_id']
  promise(timeout:90){ image.wait_for :available }
end

.create_from_snapshot(snapshot_id) ⇒ Object



21
22
23
24
25
26
# File 'lib/larrow/qingcloud/image.rb', line 21

def self.create_from_snapshot snapshot_id
  result = conn.get 'CaptureInstanceFromSnapshot', snapshot: snapshot_id
  info "image created(snapshot: #{snapshot_id}): #{result}"
  image = new result['image_id']
  promise(timeout:90){ image.wait_for :available }
end

.list(provider = :system, ids: []) ⇒ Object



7
8
9
10
11
12
# File 'lib/larrow/qingcloud/image.rb', line 7

def self.list(provider=:system,ids:[])
  describe(ids,{:provider => provider,:'status.1' => :available}) do |hash|
    new hash['image_id'],
      hash.slice('status','platform','provider')
  end
end

Instance Method Details

#wait_for(status) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/larrow/qingcloud/image.rb', line 28

def wait_for status
  super do |data|
    self.status = status
    self.platform = data['platform']
    self.provider = data['provider']
  end
end