Class: Yun::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/yun/model/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Connection

Returns a new instance of Connection.



5
6
7
# File 'lib/yun/model/connection.rb', line 5

def initialize options
  @servers = Fog::Compute.new(options).servers
end

Instance Method Details

#create(attributes = {}, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/yun/model/connection.rb', line 9

def create attributes={}, &block
  fog_attributes = FogAttributes.new attributes
  server = @servers.create fog_attributes
  server.wait_for do
    instance_eval(&block) if block_given?
    ready?
  end
  Node.new server
end

#find(node_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/yun/model/connection.rb', line 25

def find node_name
  node = list.find do |node|
    node.name == node_name and not node.is_destroyed?
  end
  if node == nil
    puts "Error: Cannot find node #{node_name}"
    exit 1
  end
  node
end

#listObject



19
20
21
22
23
# File 'lib/yun/model/connection.rb', line 19

def list
  @servers.map do |server|
    Node.new server
  end
end