Class: Fog::Compute::Ecloud::Servers

Inherits:
Ecloud::Collection show all
Defined in:
lib/fog/ecloud/models/compute/servers.rb

Instance Attribute Summary

Attributes inherited from Fog::Collection

#service

Instance Method Summary collapse

Methods inherited from Ecloud::Collection

#check_href!, #load

Methods inherited from Fog::Collection

#clear, #destroy, #initialize, #inspect, #load, model, #model, #new, #reload, #table, #to_json

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

This class inherits a constructor from Fog::Collection

Instance Method Details

#allObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/ecloud/models/compute/servers.rb', line 12

def all
  data = service.get_servers(href).body
  if data.keys.include?(:VirtualMachines)
    data = data[:VirtualMachines][:VirtualMachine]
  elsif data[:VirtualMachine]
    data = data[:VirtualMachine]
  else
    data = []
  end
  load(data)
end

#create(template_uri, options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fog/ecloud/models/compute/servers.rb', line 35

def create( template_uri, options )
  options[:cpus]        ||= 1
  options[:memory]      ||= 512
  options[:description] ||= ""
  options[:tags]        ||= []

  if template_uri =~ /\/templates\/\d+/
    options[:uri] = href + "/action/createVirtualMachine"
    options[:customization] ||= :linux
    options[:powered_on] ||= false
    if options[:ips]
      options[:ips] = [*options[:ips]]
    else
      [*options[:network_uri]].each do |uri|
        index = options[:network_uri].index(uri)
        ip = self.service.ip_addresses(:href => uri).detect { |i| i.host == nil && i.detected_on.nil? }.name
        options[:ips] ||= []
        options[:ips][index] = ip
      end
    end
    data = service.virtual_machine_create_from_template( template_uri, options ).body
  else
    options[:uri] = href + "/action/importVirtualMachine"
    data = service.virtual_machine_import( template_uri, options ).body
  end
  object = self.service.servers.new(data)
  object
end

#from_data(data) ⇒ Object



31
32
33
# File 'lib/fog/ecloud/models/compute/servers.rb', line 31

def from_data(data)
  new(data)
end

#get(uri) ⇒ Object



24
25
26
27
28
29
# File 'lib/fog/ecloud/models/compute/servers.rb', line 24

def get(uri)
  data = service.get_server(uri).body
  new(data)
rescue Fog::Errors::NotFound
  nil
end