118: def list_as_hash(state=nil, vol_id=[], &each_vol)
119: state &&= state.to_sym
120: state = nil if state == :any
121:
122: raise UnknownState, state if state && !Volumes.known_state?(state)
123:
124: opts = {
125: :volume_id => vol_id ? [vol_id].flatten : []
126: }
127:
128: vlist = Rudy::AWS::EC2.execute_request({}) {
129: @@ec2.describe_volumes(opts)
130: }
131:
132: volumes = {}
133: return volumes unless vlist['volumeSet'].is_a?(Hash)
134: vlist['volumeSet']['item'].each do |vol|
135: v = Volumes.from_hash(vol)
136: next if state && v.state != state.to_s
137: volumes[v.awsid] = v
138: end
139: volumes.values.each { |v| each_vol.call(v) } if each_vol
140: volumes = nil if volumes.empty?
141: volumes
142: end