Class: Larrow::Runner::Service::Cloud
- Inherits:
-
Object
- Object
- Larrow::Runner::Service::Cloud
- Includes:
- Qingcloud
- Defined in:
- lib/larrow/runner/service/cloud.rb
Instance Method Summary collapse
- #check_available ⇒ Object
-
#create(image_id: nil, count: 1) ⇒ Object
return: Array< [ instance,eip ] > WARN: eips contains promise object, so it should be force.
-
#create_image(instance_id) ⇒ Object
return image future.
-
#destroy(*args) ⇒ Object
concurrent destroy(force).
- #image?(image_id) ⇒ Boolean
-
#initialize(args = {}) ⇒ Cloud
constructor
A new instance of Cloud.
- #ping(host, time, port = 22) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Cloud
8 9 10 11 12 13 14 15 |
# File 'lib/larrow/runner/service/cloud.rb', line 8 def initialize args={} Qingcloud.remove_connection access_id = args[:qy_access_key_id] secret_key = args[:qy_secret_access_key] zone_id = args[:zone_id] @keypair_id = args[:keypair_id] Qingcloud.establish_connection access_id,secret_key,zone_id end |
Instance Method Details
#check_available ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/larrow/runner/service/cloud.rb', line 52 def check_available KeyPair.list self rescue Qingcloud.remove_connection raise $! end |
#create(image_id: nil, count: 1) ⇒ Object
return: Array< [ instance,eip ] > WARN: eips contains promise object, so it should be force
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/larrow/runner/service/cloud.rb', line 19 def create image_id:nil,count:1 RunLogger.level(1).detail "assign node" instances = Instance.create(image_id: image_id||'trustysrvx64c', count:count, login_mode:'keypair', keypair_id: @keypair_id ) eips = Eip.create(count:count) (0...count).map do |i| RunLogger.level(1).detail "bind ip: #{eips[i].address}" eips[i] = eips[i].associate instances[i].id [ instances[i], eips[i] ] end.tap do |list| list.each{|instance,eip| ping eip.address,30} end end |
#create_image(instance_id) ⇒ Object
return image future
39 40 41 |
# File 'lib/larrow/runner/service/cloud.rb', line 39 def create_image instance_id Image.create instance_id end |
#destroy(*args) ⇒ Object
concurrent destroy(force)
48 49 50 |
# File 'lib/larrow/runner/service/cloud.rb', line 48 def destroy *args args.map(&:destroy).map(&:force) end |
#image?(image_id) ⇒ Boolean
43 44 45 |
# File 'lib/larrow/runner/service/cloud.rb', line 43 def image? image_id Image.list(:self, ids: [image_id]).size == 1 end |
#ping(host, time, port = 22) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/larrow/runner/service/cloud.rb', line 60 def ping host, time, port=22 Timeout::timeout(time) do loop do if system("nmap #{host} -p #{port} -Pn | grep -q open") return true end end end end |