def instances(credentials, opts=nil)
instances = []
if opts and opts[:id]
begin
client = new_client(credentials)
instance = client.request('grid/server/get', { 'name' => opts[:id] })['list'].first
login_data = get_login_data(client, instance['id'])
if login_data['username'] and login_data['password']
instance['username'] = login_data['username']
instance['password'] = login_data['password']
inst = convert_instance(instance, credentials.user)
else
inst = convert_instance(instance, credentials.user)
inst.authn_error = "Unable to fetch password"
end
instances = [inst]
rescue Exception => e
if e.message == "400 Bad Request"
instances = list_instances(credentials, opts[:id])
end
end
else
instances = list_instances(credentials, nil)
end
instances = filter_on( instances, :state, opts )
instances
end