Method: Deltacloud::Drivers::Openstack::OpenstackDriver#instances

Defined in:
lib/deltacloud/drivers/openstack/openstack_driver.rb

#instances(credentials, opts = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/deltacloud/drivers/openstack/openstack_driver.rb', line 158

def instances(credentials, opts={})
  os = new_client(credentials)
  insts = attachments = []
  safely do
    if opts[:id]
      begin
        server = os.get_server(opts[:id])
        insts << convert_from_server(server, os.connection.authuser, get_attachments(opts[:id], os))
      rescue => e
        raise e unless e.message =~ /The resource could not be found/
        insts = []
      end
    else
      insts = os.list_servers_detail.collect do |s|
        convert_from_server(s, os.connection.authuser,get_attachments(s[:id], os))
      end
    end
  end
  insts = filter_on( insts, :state, opts )
  insts
end