1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-24 02:03:52 +03:00

feature #2259: Add DescribeTags

This commit is contained in:
Daniel Molina 2013-08-16 09:37:24 +02:00
parent c2e4558040
commit aa71c45a0a
5 changed files with 79 additions and 1 deletions

View File

@ -1297,6 +1297,7 @@ ECO_LIB_VIEW_FILES="src/cloud/ec2/lib/views/describe_images.erb \
src/cloud/ec2/lib/views/describe_availability_zones.erb \
src/cloud/ec2/lib/views/create_tags.erb \
src/cloud/ec2/lib/views/delete_tags.erb \
src/cloud/ec2/lib/views/describe_tags.erb \
src/cloud/ec2/lib/views/create_volume.erb \
src/cloud/ec2/lib/views/create_snapshot.erb \
src/cloud/ec2/lib/views/delete_snapshot.erb \

View File

@ -389,6 +389,31 @@ class EC2QueryServer < CloudServer
return response.result(binding), 200
end
def describe_tags(params)
user_flag = OpenNebula::Pool::INFO_ALL
impool = ImageEC2Pool.new(@client, user_flag)
rc = impool.info
return rc if OpenNebula::is_error?(rc)
user_flag = OpenNebula::Pool::INFO_ALL
vmpool = VirtualMachinePool.new(@client, user_flag)
if include_terminated_instances?
rc = vmpool.info(user_flag, -1, -1,
OpenNebula::VirtualMachinePool::INFO_ALL_VM)
else
rc = vmpool.info
end
return rc if OpenNebula::is_error?(rc)
erb_version = params['Version']
response = ERB.new(File.read(@config[:views]+"/describe_tags.erb"))
return response.result(binding), 200
end
###########################################################################
# Helper functions
###########################################################################

View File

@ -100,10 +100,29 @@ class ImageEC2 < Image
def ec2_ami?
self["TEMPLATE/EC2_AMI"] == "YES"
true
end
def ebs_snapshot?
self["TEMPLATE/EBS_SNAPSHOT"] == "YES"
end
def ec2_id
if self.ebs_snapshot?
"snap-" + sprintf('%08i', self.id)
elsif self.ec2_ami?
"ami-" + sprintf('%08i', self.id)
elsif self.ebs_volume?
"vol-" + sprintf('%08i', self.id)
end
end
def resource_type
if self.ebs_snapshot?
"snapshot"
elsif self.ec2_ami?
"image"
elsif self.ebs_volume?
"volume"
end
end
end

View File

@ -144,6 +144,8 @@ class EC2Application
result,rc = econe_server.create_tags(params)
when 'DeleteTags'
result,rc = econe_server.delete_tags(params)
when 'DescribeTags'
result,rc = econe_server.describe_tags(params)
when 'CreateImage'
result,rc = econe_server.create_image(params)
when 'CreateVolume'

View File

@ -0,0 +1,31 @@
<DescribeTagsResponse xmlns="http://ec2.amazonaws.com/doc/2013-06-15/">
<requestId><%= @request_id %></requestId>
<tagSet>
<% impool.each do |im| %>
<% if (state_image = im.render_state) && im.has_elements?("TEMPLATE/EC2_TAGS") %>
<% image_hash = im.to_hash %>
<% image_hash["IMAGE"]["TEMPLATE"]["EC2_TAGS"].each do |key, value| %>
<item>
<resourceId><%= im.ec2_id %></resourceId>
<resourceType>image</resourceType>
<key><%= key %></key>
<value><%= value %></value>
</item>
<% end
end
end %>
<% vmpool.each do |vm| %>
<% if include_terminated_instance?(vm) && vm.has_elements?("USER_TEMPLATE/EC2_TAGS") %>
<% vm_hash = vm.to_hash %>
<% vm_hash["VM"]["USER_TEMPLATE"]["EC2_TAGS"].each do |key, value| %>
<item>
<resourceId>i-<%= sprintf('%08i', vm.id) %></resourceId>
<resourceType>instance</resourceType>
<key><%= key %></key>
<value><%= value %></value>
</item>
<% end
end
end %>
</tagSet>
</DescribeTagsResponse>