Skip to content

Instantly share code, notes, and snippets.

@dmamolina
Created February 8, 2012 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmamolina/aee5654cbe0b44bbbd51 to your computer and use it in GitHub Desktop.
Save dmamolina/aee5654cbe0b44bbbd51 to your computer and use it in GitHub Desktop.
diff --git a/src/cloud/ec2/lib/EC2QueryServer.rb b/src/cloud/ec2/lib/EC2QueryServer.rb
index cfcac7c..7269506 100644
--- a/src/cloud/ec2/lib/EC2QueryServer.rb
+++ b/src/cloud/ec2/lib/EC2QueryServer.rb
@@ -174,6 +174,8 @@ class EC2QueryServer < CloudServer
vmpool = VirtualMachinePool.new(@client, user_flag)
vmpool.info
+ vmhash = vmpool.to_hash
+
erb_version = params['Version']
erb_user_name = params['AWSAccessKeyId']
@@ -211,12 +213,33 @@ class EC2QueryServer < CloudServer
# Helper functions
###########################################################################
def render_state(vm)
- ec2_state = EC2_STATES[ONE_STATES[vm.status]]
+ state_str=VirtualMachine::VM_STATE[vm['STATE'].to_i]
+ short_state_str=VirtualMachine::SHORT_VM_STATES[state_str]
+
+ if short_state_str=="actv"
+ lcm_state_str= VirtualMachine::LCM_STATE[vm['LCM_STATE'].to_i]
+ short_state_str=VirtualMachine::SHORT_LCM_STATES[lcm_state_str]
+ end
+
+ short_state_str ||= 'pend'
+
+ one_state = ONE_STATES[short_state_str]
+ ec2_state = EC2_STATES[one_state]
return "<code>#{ec2_state[:code]}</code>
<name>#{ec2_state[:name]}</name>"
end
+ def render_ip(vm)
+ if vm['TEMPLATE']['NIC']
+ if vm['TEMPLATE']['NIC'].instance_of?(Array)
+ vm['TEMPLATE']['NIC'].first['IP']
+ else
+ vm['TEMPLATE']['NIC']['IP']
+ end
+ end
+ end
+
def render_launch_time(vm)
return "<launchTime>#{Time.at(vm["STIME"].to_i).xmlschema}</launchTime>"
end
diff --git a/src/cloud/ec2/lib/views/describe_instances.erb b/src/cloud/ec2/lib/views/describe_instances.erb
index e07e4e7..494b711 100644
--- a/src/cloud/ec2/lib/views/describe_instances.erb
+++ b/src/cloud/ec2/lib/views/describe_instances.erb
@@ -11,20 +11,19 @@
</item>
</groupSet>
<instancesSet>
- <% vmpool.each do |vm| %>
- <% vm.info %>
+ <% vmhash['VM_POOL']['VM'].each do |vm| %>
<item>
- <instanceId>i-<%= vm.id %></instanceId>
- <imageId><%= vm['TEMPLATE/IMAGE_ID'] %></imageId>
+ <instanceId>i-<%= vm['ID'] %></instanceId>
+ <imageId><%= vm['TEMPLATE']['IMAGE_ID'] %></imageId>
<instanceState>
<%= render_state(vm) %>
</instanceState>
- <privateDnsName><%= vm["TEMPLATE/NIC/IP"] %></privateDnsName>
- <dnsName><%= vm["TEMPLATE/NIC/IP"] %></dnsName>
+ <privateDnsName><%= render_ip(vm) %></privateDnsName>
+ <dnsName><%= render_ip(vm) %></dnsName>
<keyName>default</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
<productCodes/>
- <instanceType><%= vm['TEMPLATE/INSTANCE_TYPE'] %></instanceType>
+ <instanceType><%= vm['TEMPLATE']['INSTANCE_TYPE'] %></instanceType>
<%= render_launch_time(vm) %>
<placement>
<availabilityZone>default</availabilityZone>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment