Skip to content

Commit

Permalink
Parse the name of EBS volume or snapshot
Browse files Browse the repository at this point in the history
Name is defined as a tag and can be optional. Patch uses the id of
the volume/snapshot if name is not given.

Signed-off-by: Gregor Berginc <[email protected]>
  • Loading branch information
gberginc committed Jan 30, 2017
1 parent 6358226 commit 774e479
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def parse_volume(volume)
new_result = {
:type => self.class.volume_type,
:ems_ref => uid,
:name => uid,
:name => get_from_tags(volume, :name) || uid,
:status => volume.state,
:creation_time => volume.create_time,
:volume_type => volume.volume_type,
Expand All @@ -58,7 +58,7 @@ def parse_snapshot(snap)
new_result = {
:ems_ref => uid,
:type => self.class.volume_snapshot_type,
:name => snap.snapshot_id,
:name => get_from_tags(snap, :name) || uid,
:status => snap.state,
:creation_time => snap.start_time,
:description => snap.description,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def parse_volume(volume)
:type => self.class.volume_type,
:ext_management_system => ems,
:ems_ref => uid,
:name => uid,
:name => get_from_tags(volume, :name) || uid,
:status => volume['state'],
:creation_time => volume['create_time'],
:volume_type => volume['volume_type'],
Expand All @@ -50,7 +50,7 @@ def parse_snapshot(snap)
:type => self.class.volume_snapshot_type,
:ext_management_system => ems,
:ems_ref => uid,
:name => snap['snapshot_id'],
:name => get_from_tags(snap, :name) || uid,
:status => snap['state'],
:creation_time => snap['start_time'],
:description => snap['description'],
Expand All @@ -59,6 +59,11 @@ def parse_snapshot(snap)
}
end

# Overridden helper methods, we should put them in helper once we get rid of old refresh
def get_from_tags(resource, item)
(resource['tags'] || []).detect { |tag, _| tag['key'].downcase == item.to_s.downcase }.try(:[], 'value')
end

class << self
def volume_type
"ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume"
Expand Down
4 changes: 3 additions & 1 deletion spec/models/manageiq/providers/amazon/aws_stubs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ def mocked_cloud_volumes
:state => "in-use",
:volume_id => "volume_id_#{i}",
:volume_type => "standard",
:snapshot_id => "snapshot_id_#{i}"
:snapshot_id => "snapshot_id_#{i}",
:tags => [{ :key => "name", :value => "volume_#{i}" }]
}
end

Expand All @@ -398,6 +399,7 @@ def mocked_cloud_volume_snapshots
:volume_size => i,
:state => "completed",
:volume_id => "volume_id_#{i}",
:tags => [{ :key => "name", :value => "snapshot_#{i}" }]
}
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def assert_specific_snapshot
expect(@snapshot).not_to be_nil
expect(@snapshot).to have_attributes(
:ems_ref => "snapshot_id_1",
:name => "snapshot_id_1",
:name => "snapshot_1",
:description => "snapshot_desc_1",
:status => "completed",
:size => 1.gigabyte
Expand All @@ -212,7 +212,7 @@ def assert_specific_volume
expect(@volume).not_to be_nil
expect(@volume).to have_attributes(
:ems_ref => "volume_id_1",
:name => "volume_id_1",
:name => "volume_1",
:status => "in-use",
:volume_type => "standard",
:size => 1.gigabyte
Expand Down

0 comments on commit 774e479

Please sign in to comment.