[vcloud|compute] Updates reference to service

This commit is contained in:
Paul Thornthwaite 2012-12-22 23:22:50 +00:00
parent a0a38fd8ca
commit e959078e89
18 changed files with 60 additions and 60 deletions

View File

@ -11,7 +11,7 @@ module Fog
end
def check_href!(opts = {})
self.href = connection.default_vdc_href unless href
self.href = service.default_vdc_href unless href
unless href
if opts.is_a?(String)
t = Hash.new
@ -61,7 +61,7 @@ module Fog
class_eval <<-EOS, __FILE__,__LINE__
def #{item}
load_unless_loaded!
connection.get_#{item}(link_up[:href])
service.get_#{item}(link_up[:href])
end
EOS
end
@ -356,9 +356,9 @@ module Fog
def get_#{type}(uri)
Fog::Vcloud::Compute::#{type.to_s.capitalize}.new(
self.request(basic_request_params(uri)).body.merge(
:connection => self,
:service => self,
:collection => Fog::Vcloud::Compute::#{type.to_s.capitalize}s.new(
:connection => self
:service => self
)
)
)

View File

@ -12,7 +12,7 @@ module Fog
def catalog_items
@catalog_items ||= Fog::Vcloud::Compute::CatalogItems.
new( :connection => connection,
new( :service => service,
:href => href )
end

View File

@ -15,7 +15,7 @@ module Fog
def customization_options
load_unless_loaded!
if data = connection.get_customization_options( link[:href] ).body
if data = service.get_customization_options( link[:href] ).body
data.delete_if { |key, value| [:xmlns_i, :xmlns].include?(key) }
data
else

View File

@ -10,8 +10,8 @@ module Fog
attribute :href, :aliases => :Href
def all
catalog_item_info = connection.get_catalog_item(self.href)
items = connection.get_catalog_item(self.href).body[:CatalogItems]
catalog_item_info = service.get_catalog_item(self.href)
items = service.get_catalog_item(self.href).body[:CatalogItems]
if items.size > 0
data = items[:CatalogItem]
load(data)
@ -19,7 +19,7 @@ module Fog
end
def get(uri)
if data = connection.get_catalog_item(uri)
if data = service.get_catalog_item(uri)
new(data.body)
end
rescue Fog::Errors::NotFound
@ -27,7 +27,7 @@ module Fog
end
def organization_uri
@organization_uri ||= connection.default_organization_uri
@organization_uri ||= service.default_organization_uri
end
end

View File

@ -10,13 +10,13 @@ module Fog
attribute :organization_uri
def all
org_uri = self.organization_uri || connection.default_organization_uri
data = connection.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.catalog+xml" }
org_uri = self.organization_uri || service.default_organization_uri
data = service.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.catalog+xml" }
load(data)
end
def get(uri)
connection.get_catalog(uri)
service.get_catalog(uri)
rescue Fog::Errors::NotFound
nil
end

View File

@ -14,7 +14,7 @@ module Fog
def save
if @changed
connection.configure_network_ip( href, _compose_network_ip_data )
service.configure_network_ip( href, _compose_network_ip_data )
end
true
end

View File

@ -12,15 +12,15 @@ module Fog
attribute :href
def all
self.href = connection.default_vdc_href unless self.href
self.href = service.default_vdc_href unless self.href
check_href!( :messages => "Ips href of a Network you want to enumerate" )
if data = connection.get_network_ips(href).body[:IpAddress]
if data = service.get_network_ips(href).body[:IpAddress]
load(data)
end
end
def get(uri)
if data = connection.get_network_ip(uri).body
if data = service.get_network_ip(uri).body
new(data)
end
rescue Fog::Errors::NotFound

View File

@ -15,7 +15,7 @@ module Fog
def parent_network
return nil if configuration[:ParentNetwork].nil?
@parent_network ||= connection.get_network(configuration[:ParentNetwork][:href])
@parent_network ||= service.get_network(configuration[:ParentNetwork][:href])
end
end
end

View File

@ -13,30 +13,30 @@ module Fog
attribute :href
def all
self.href = connection.default_vdc_href unless self.href
self.href = service.default_vdc_href unless self.href
data = nil
if self.href =~ /\/vdc\//
check_href!("Vdc")
data = [connection.get_vdc(self.href).available_networks].flatten.compact.reject{|n| n == '' }
data = [service.get_vdc(self.href).available_networks].flatten.compact.reject{|n| n == '' }
elsif self.href =~ /\/org\//
check_href!("Org")
data = connection.get_organization(self.href).links.select{|l| l[:type] == network_type_id }
data = service.get_organization(self.href).links.select{|l| l[:type] == network_type_id }
elsif self.href =~ /\/vApp\//
check_href!("Vapp")
data = [(connection.get_vapp(self.href).network_configs||{})[:NetworkConfig]].flatten.compact.collect{|n| n[:Configuration][:ParentNetwork] unless n[:Configuration].nil? }.compact
data = [(service.get_vapp(self.href).network_configs||{})[:NetworkConfig]].flatten.compact.collect{|n| n[:Configuration][:ParentNetwork] unless n[:Configuration].nil? }.compact
end
load([*data]) unless data.nil?
end
def get(uri)
connection.get_network(uri)
service.get_network(uri)
rescue Fog::Errors::NotFound
nil
end
private
def network_type_id
if connection.version == '1.0'
if service.version == '1.0'
'application/vnd.vmware.vcloud.network+xml'
else
'application/vnd.vmware.vcloud.orgNetwork+xml'

View File

@ -14,26 +14,26 @@ module Fog
def networks
@networks ||= Fog::Vcloud::Compute::Networks.
new( :connection => connection,
new( :service => service,
:href => href )
end
def tasks
load_unless_loaded!
@tasks ||= Fog::Vcloud::Compute::Tasks.
new( :connection => connection,
new( :service => service,
:href => other_links.find{|l| l[:type] == 'application/vnd.vmware.vcloud.tasksList+xml'}[:href] )
end
def vdcs
@vdcs ||= Fog::Vcloud::Compute::Vdcs.
new( :connection => connection,
new( :service => service,
:href => href )
end
def catalogs
@catalogs ||= Fog::Vcloud::Compute::Catalogs.
new( :connection => connection,
new( :service => service,
:href => href )
end

View File

@ -11,17 +11,17 @@ module Fog
undef_method :create
def all
raw_orgs = if connection.version == '1.0'
connection.login
raw_orgs = if service.version == '1.0'
service.login
else
connection.request(connection.basic_request_params("#{connection.base_path_url}/org/"))
service.request(service.basic_request_params("#{service.base_path_url}/org/"))
end
data = raw_orgs.body[:Org]
load(data)
end
def get(uri)
connection.get_organization(uri)
service.get_organization(uri)
rescue Fog::Errors::NotFound
nil
end

View File

@ -72,7 +72,7 @@ module Fog
# This is the real power-off operation
def undeploy
connection.undeploy href
service.undeploy href
end
def graceful_restart
@ -104,7 +104,7 @@ module Fog
def cpus=(qty)
return if qty.nil? or qty.size == 0
@changed = true
@update_cpu_value = qty
qty
@ -187,19 +187,19 @@ module Fog
if @update_password
guest_customization[:AdminPassword] = @update_password.to_s
connection.configure_vm_password(guest_customization)
service.configure_vm_password(guest_customization)
wait_for { ready? }
end
if @update_cpu_value
cpu_mess[:"rasd:VirtualQuantity"] = @update_cpu_value.to_s
connection.configure_vm_cpus(cpu_mess)
service.configure_vm_cpus(cpu_mess)
wait_for { ready? }
end
if @update_memory_value
memory_mess[:"rasd:VirtualQuantity"] = @update_memory_value.to_s
connection.configure_vm_memory(memory_mess)
service.configure_vm_memory(memory_mess)
wait_for { ready? }
end
@ -208,19 +208,19 @@ module Fog
vh[:'rasd:ResourceType'] == '17' &&
vh[:'rasd:AddressOnParent'].to_s == @remove_disk.to_s
end
connection.configure_vm_disks(self.href, data)
service.configure_vm_disks(self.href, data)
wait_for { ready? }
end
if @disk_change == :added
data = disk_mess
data << @add_disk
connection.configure_vm_disks(self.href, data)
service.configure_vm_disks(self.href, data)
wait_for { ready? }
end
if @name_changed || @description_changed
edit_uri = links.select {|i| i[:rel] == 'edit'}
edit_uri = edit_uri.kind_of?(Array) ? edit_uri.flatten[0][:href] : edit_uri[:href]
connection.configure_vm_name_description(edit_uri, self.name, self.description)
service.configure_vm_name_description(edit_uri, self.name, self.description)
wait_for { ready? }
end
end
@ -236,7 +236,7 @@ module Fog
wait_for { off? } # be sure..
wait_for { ready? } # be doubly sure..
sleep 2 # API lies. need to give it some time to be happy.
connection.delete_vapp(href).body[:status] == "running"
service.delete_vapp(href).body[:status] == "running"
end
alias :delete :destroy
@ -286,7 +286,7 @@ module Fog
def power_operation(op)
requires :href
begin
connection.send(op.keys.first, href + "/power/action/#{op.values.first}" )
service.send(op.keys.first, href + "/power/action/#{op.values.first}" )
rescue Excon::Errors::InternalServerError => e
#Frankly we shouldn't get here ...
raise e unless e.to_s =~ /because it is already powered o(n|ff)/
@ -295,7 +295,7 @@ module Fog
end
def reload_status
server = connection.get_server(href)
server = service.get_server(href)
self.status = server.status
self.tasks = server.tasks
end

View File

@ -19,7 +19,7 @@ module Fog
end
def get(uri)
connection.get_vapp(uri)
service.get_vapp(uri)
rescue Fog::Errors::NotFound
nil
end
@ -27,7 +27,7 @@ module Fog
def create options
check_href!
options[:vdc_uri] = href
data = connection.instantiate_vapp_template(options).body
data = service.instantiate_vapp_template(options).body
object = new(data)
object
end
@ -40,9 +40,9 @@ module Fog
def init_vapp
Fog::Vcloud::Compute::Vapp.new(
:connection => connection,
:service => service,
:href => self.href,
:collection => Fog::Vcloud::Compute::Vapps.new(:connection => connection)
:collection => Fog::Vcloud::Compute::Vapps.new(:service => service)
)
end

View File

@ -11,15 +11,15 @@ module Fog
attribute :href, :aliases => :Href
def all
self.href = connection.default_vdc_href unless self.href
self.href = service.default_vdc_href unless self.href
check_href!
if data = connection.get_task_list(href).body[:Task]
if data = service.get_task_list(href).body[:Task]
load(data)
end
end
def get(uri)
connection.get_task(uri)
service.get_task(uri)
rescue Fog::Errors::NotFound
nil
end

View File

@ -25,7 +25,7 @@ module Fog
def servers
@servers ||= Fog::Vcloud::Compute::Servers.
new( :connection => connection,
new( :service => service,
:href => href,
:vapp => self
)
@ -33,7 +33,7 @@ module Fog
def networks
@networks ||= Fog::Vcloud::Compute::Networks.
new( :connection => connection,
new( :service => service,
:href => href
)
end

View File

@ -13,11 +13,11 @@ module Fog
attribute :href
def all
load([connection.get_vdc(connection.default_vdc_href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" })
load([service.get_vdc(service.default_vdc_href).resource_entities].flatten.select { |re| re[:type] == "application/vnd.vmware.vcloud.vApp+xml" })
end
def get(uri)
connection.get_vapp(uri)
service.get_vapp(uri)
rescue Fog::Errors::NotFound
nil
end

View File

@ -24,13 +24,13 @@ module Fog
def networks
@networks ||= Fog::Vcloud::Compute::Networks.
new( :connection => connection,
new( :service => service,
:href => href )
end
def vapps
@vapps ||= Fog::Vcloud::Compute::Vapps.
new( :connection => connection,
new( :service => service,
:href => href
)
end

View File

@ -13,13 +13,13 @@ module Fog
attribute :href
def all
data = connection.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
data = service.get_organization(org_uri).links.select { |link| link[:type] == "application/vnd.vmware.vcloud.vdc+xml" }
data.each { |link| link.delete_if { |key, value| [:rel].include?(key) } }
load(data)
end
def get(uri)
connection.get_vdc(uri)
service.get_vdc(uri)
rescue Fog::Errors::NotFound
nil
end
@ -27,7 +27,7 @@ module Fog
private
def org_uri
self.href ||= connection.default_organization_uri
self.href ||= service.default_organization_uri
end
end
end