mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
experiment with dynamic requests based on links
This commit is contained in:
parent
346fe644bb
commit
28eb4db402
4 changed files with 58 additions and 1 deletions
|
@ -19,6 +19,21 @@ class VcloudngParser < Fog::Parsers::Base
|
||||||
end
|
end
|
||||||
attributes
|
attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract_link(attributes_xml)
|
||||||
|
response = {}
|
||||||
|
link_attrs = extract_attributes(attributes_xml)
|
||||||
|
puts link_attrs["type"]
|
||||||
|
response[:type] = link_attrs["type"]
|
||||||
|
response[:rel] = link_attrs["rel"]
|
||||||
|
response[:href] = link_attrs["href"]
|
||||||
|
if response[:type] && response[:rel]
|
||||||
|
short_type = response[:type].scan(/.*\.(.*)\+/).first.first
|
||||||
|
snake_case_short_type = short_type.gsub(/([A-Z])/) { '_' + $1.downcase }
|
||||||
|
response[:method_name] = response[:rel] + '_' + snake_case_short_type
|
||||||
|
end
|
||||||
|
response
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,11 +94,12 @@ module Fog
|
||||||
request :put_vm_cpu
|
request :put_vm_cpu
|
||||||
request :get_vm_memory
|
request :get_vm_memory
|
||||||
request :put_vm_memory
|
request :put_vm_memory
|
||||||
request :get_request
|
|
||||||
request :get_vm_disks
|
request :get_vm_disks
|
||||||
request :put_vm_disks
|
request :put_vm_disks
|
||||||
request :get_vm_network
|
request :get_vm_network
|
||||||
request :put_vm_network
|
request :put_vm_network
|
||||||
|
request :get_request
|
||||||
|
request :get_href
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,22 @@ module Fog
|
||||||
attribute :cpu, :type => :integer
|
attribute :cpu, :type => :integer
|
||||||
attribute :memory
|
attribute :memory
|
||||||
attribute :hard_disks, :aliases => 'disks'
|
attribute :hard_disks, :aliases => 'disks'
|
||||||
|
|
||||||
|
def links
|
||||||
|
attributes["links"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_methods
|
||||||
|
attributes["links"].each do |link|
|
||||||
|
next unless link[:method_name]
|
||||||
|
self.class.instance_eval do
|
||||||
|
define_method(link[:method_name]) do
|
||||||
|
puts link[:href]
|
||||||
|
service.get_href(link[:href])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def customization
|
def customization
|
||||||
data = service.get_vm_customization(id).body
|
data = service.get_vm_customization(id).body
|
||||||
|
|
|
@ -13,6 +13,7 @@ module Fog
|
||||||
@in_children = false
|
@in_children = false
|
||||||
@resource_type = nil
|
@resource_type = nil
|
||||||
@response = { 'vms' => [] }
|
@response = { 'vms' => [] }
|
||||||
|
@links = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_element(name, attributes)
|
def start_element(name, attributes)
|
||||||
|
@ -34,6 +35,8 @@ module Fog
|
||||||
@in_children = true
|
@in_children = true
|
||||||
when 'HostResource'
|
when 'HostResource'
|
||||||
@current_host_resource = extract_attributes(attributes)
|
@current_host_resource = extract_attributes(attributes)
|
||||||
|
when 'Link'
|
||||||
|
@links << extract_link(attributes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,6 +66,8 @@ module Fog
|
||||||
@vm['disks'] ||= []
|
@vm['disks'] ||= []
|
||||||
@vm['disks'] << { @element_name => @current_host_resource["capacity"].to_i }
|
@vm['disks'] << { @element_name => @current_host_resource["capacity"].to_i }
|
||||||
end
|
end
|
||||||
|
when 'Link'
|
||||||
|
@vm['links'] = @links
|
||||||
when 'Vm'
|
when 'Vm'
|
||||||
@response['vms'] << @vm
|
@response['vms'] << @vm
|
||||||
@vm = {}
|
@vm = {}
|
||||||
|
|
20
lib/fog/vcloudng/requests/compute/get_href.rb
Normal file
20
lib/fog/vcloudng/requests/compute/get_href.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
module Fog
|
||||||
|
module Compute
|
||||||
|
class Vcloudng
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def get_href(href)
|
||||||
|
request(
|
||||||
|
:expects => 200,
|
||||||
|
:headers => { 'Accept' => 'application/*+xml;version=1.5' },
|
||||||
|
:method => 'GET',
|
||||||
|
:parser => Fog::ToHashDocument.new,
|
||||||
|
:override_path => true,
|
||||||
|
:path => URI.parse(href).path
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue