mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
feature #3242: Implement client token for econe server, to support idempotent calls
This commit is contained in:
parent
6f05fa78ac
commit
b11dd2268d
@ -26,4 +26,4 @@ CONTEXT = [ EC2_USER_DATA="<%= erb_vm_info[:user_data] %>" ]
|
||||
<% elsif erb_vm_info[:public_key] %>
|
||||
CONTEXT = [ EC2_PUBLIC_KEY="<%= erb_vm_info[:public_key] %>", EC2_KEYNAME ="<%= erb_vm_info[:key_name] %>" ]
|
||||
<% end %>
|
||||
|
||||
|
||||
|
@ -61,6 +61,33 @@ module Instance
|
||||
TERMINATED_INSTANCES_EXPIRATION_TIME = 900
|
||||
|
||||
def run_instances(params)
|
||||
erb_user_name = params['AWSAccessKeyId']
|
||||
erb_version = params['Version']
|
||||
erb_vms = Array.new
|
||||
|
||||
if params['ClientToken']
|
||||
user_flag = OpenNebula::Pool::INFO_ALL
|
||||
vm_pool = VirtualMachinePool.new(@client, user_flag)
|
||||
rc = vm_pool.info
|
||||
if OpenNebula::is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
vm_id = vm_pool["VM/USER_TEMPLATE[EC2_CLIENT_TOKEN=\'#{params['ClientToken']}\']/../ID"]
|
||||
if vm_id
|
||||
instance = VirtualMachine.new(VirtualMachine.build_xml(vm_id), @client)
|
||||
rc = instance.info
|
||||
if OpenNebula::is_error?(rc)
|
||||
return rc
|
||||
end
|
||||
|
||||
erb_vms << instance
|
||||
|
||||
response = ERB.new(File.read(@config[:views]+"/run_instances.erb"))
|
||||
return response.result(binding), 200
|
||||
end
|
||||
end
|
||||
|
||||
# Get the image
|
||||
img = nil
|
||||
if params['ImageId'] =~ /ami\-(.+)/
|
||||
@ -82,11 +109,13 @@ module Instance
|
||||
# Get the instance type and path
|
||||
if params['InstanceType'] != nil
|
||||
instance_type_name = params['InstanceType']
|
||||
instance_type = @config[:instance_types][instance_type_name.to_sym]
|
||||
else
|
||||
instance_type_name = "m1.small"
|
||||
end
|
||||
|
||||
if instance_type != nil
|
||||
path = @config[:template_location] + "/#{instance_type[:template]}"
|
||||
end
|
||||
instance_type = @config[:instance_types][instance_type_name.to_sym]
|
||||
if instance_type != nil
|
||||
path = @config[:template_location] + "/#{instance_type[:template]}"
|
||||
end
|
||||
|
||||
# Build the VM
|
||||
@ -102,8 +131,9 @@ module Instance
|
||||
|
||||
template = ERB.new(File.read(erb_vm_info[:template]))
|
||||
template_text = template.result(binding)
|
||||
|
||||
erb_vms = Array.new
|
||||
if params["ClientToken"]
|
||||
template_text += "\nEC2_CLIENT_TOKEN=\"#{params['ClientToken']}\""
|
||||
end
|
||||
|
||||
min_count = params['MinCount'] || 1
|
||||
max_count = params['MaxCount'] || min_count
|
||||
@ -174,10 +204,11 @@ module Instance
|
||||
merge_info.delete("CONTEXT")
|
||||
end
|
||||
|
||||
template_str = template_to_str(merge_info)
|
||||
vm_id =
|
||||
if params['ClientToken']
|
||||
merge_info['EC2_CLIENT_TOKEN'] = params['ClientToken']
|
||||
end
|
||||
|
||||
erb_vms = Array.new
|
||||
template_str = template_to_str(merge_info)
|
||||
|
||||
min_count = params['MinCount'] || 1
|
||||
max_count = params['MaxCount'] || min_count
|
||||
@ -202,9 +233,6 @@ module Instance
|
||||
}
|
||||
end
|
||||
|
||||
erb_user_name = params['AWSAccessKeyId']
|
||||
erb_version = params['Version']
|
||||
|
||||
response = ERB.new(File.read(@config[:views]+"/run_instances.erb"))
|
||||
return response.result(binding), 200
|
||||
end
|
||||
|
@ -37,13 +37,12 @@
|
||||
<availabilityZone>default</availabilityZone>
|
||||
</placement>
|
||||
<amiLaunchIndex><%= vm.id %></amiLaunchIndex>
|
||||
|
||||
<kernelId>eki-EA801065</kernelId>
|
||||
<ramdiskId>eri-1FEE1144</ramdiskId>
|
||||
<monitoring>
|
||||
<state>false</state>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
|
||||
<clientToken><%= vm['USER_TEMPLATE/EC2_CLIENT_TOKEN'] %></clientToken>
|
||||
</item>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/<%= erb_version %>/">
|
||||
<requestId><%= @request_id %></requestId>
|
||||
<reservationId></reservationId>
|
||||
<reservationId>default</reservationId>
|
||||
<ownerId><%= erb_user_name %></ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
@ -11,7 +11,7 @@
|
||||
<% erb_vms.each { |vm| %>
|
||||
<item>
|
||||
<%= render_instance_id(vm) %>
|
||||
<imageId><%= params['ImageId'] %></imageId>
|
||||
<imageId><%= vm['USER_TEMPLATE/IMAGE_ID'] %></imageId>
|
||||
<instanceState><%= render_state(vm) %></instanceState>
|
||||
<% if vm.has_elements?("TEMPLATE/NIC/IP") %>
|
||||
<% ips_str = vm.retrieve_elements("TEMPLATE/NIC/IP").join(', ') %>
|
||||
@ -24,15 +24,18 @@
|
||||
<% else %>
|
||||
<keyName><%= vm['TEMPLATE/CONTEXT/EC2_KEYNAME'] %></keyName>
|
||||
<% end %>
|
||||
<amiLaunchIndex><%= vm.id %></amiLaunchIndex>
|
||||
<instanceType><%= params['InstanceType'] %></instanceType>
|
||||
<instanceType><%= vm['USER_TEMPLATE/INSTANCE_TYPE'] %></instanceType>
|
||||
<%= render_launch_time(vm) %>
|
||||
<placement>
|
||||
<availabilityZone>default</availabilityZone>
|
||||
</placement>
|
||||
<amiLaunchIndex><%= vm.id %></amiLaunchIndex>
|
||||
<kernelId>eki-EA801065</kernelId>
|
||||
<ramdiskId>eri-1FEE1144</ramdiskId>
|
||||
<monitoring>
|
||||
<enabled>true</enabled>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
<clientToken><%= vm['USER_TEMPLATE/EC2_CLIENT_TOKEN'] %></clientToken>
|
||||
</item>
|
||||
<% } %>
|
||||
</instancesSet>
|
||||
|
Loading…
x
Reference in New Issue
Block a user