1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[xenserver|compute] Updates reference to service

This commit is contained in:
Paul Thornthwaite 2012-12-22 23:21:33 +00:00
parent e8630a0083
commit 0c674865d6
20 changed files with 162 additions and 162 deletions

View file

@ -24,15 +24,15 @@ module Fog
attribute :__resident_vms, :aliases => :resident_VMs
def pifs
__pifs.collect { |pif| connection.pifs.get pif }
__pifs.collect { |pif| service.pifs.get pif }
end
def pbds
__pbds.collect { |pbd| connection.pbds.get pbd }
__pbds.collect { |pbd| service.pbds.get pbd }
end
def resident_servers
__resident_vms.collect { |ref| connection.servers.get ref }
__resident_vms.collect { |ref| service.servers.get ref }
end
def resident_vms
@ -41,7 +41,7 @@ module Fog
def metrics
return nil unless __metrics
rec = connection.get_record(__metrics, 'host_metrics' )
rec = service.get_record(__metrics, 'host_metrics' )
Fog::Compute::XenServer::HostMetrics.new(rec)
end

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::XenServer::Host
def all(options={})
data = connection.get_records 'host'
data = service.get_records 'host'
load(data)
end
def get( host_ref )
if host_ref && host = connection.get_record( host_ref, 'host' )
if host_ref && host = service.get_record( host_ref, 'host' )
new(host)
else
nil

View file

@ -24,7 +24,7 @@ module Fog
attribute :blobs
def refresh
data = connection.get_record( reference, 'network' )
data = service.get_record( reference, 'network' )
merge_attributes( data )
true
end
@ -35,7 +35,7 @@ module Fog
def pifs
p = []
__pifs.each do |pif|
p << connection.pifs.get(pif)
p << service.pifs.get(pif)
end
p
end
@ -46,7 +46,7 @@ module Fog
def vifs
v = []
__vifs.each do |vif|
v << connection.vifs.get(vif)
v << service.vifs.get(vif)
end
v
end

View file

@ -14,12 +14,12 @@ module Fog
end
def all(options = {})
data = connection.get_records 'network'
data = service.get_records 'network'
load(data)
end
def get( ref )
if ref && obj = connection.get_record( ref, 'network' )
if ref && obj = service.get_record( ref, 'network' )
new(obj)
end
rescue Fog::XenServer::NotFound

View file

@ -16,7 +16,7 @@ module Fog
attribute :currently_attached
def sr
connection.storage_repositories.get __sr
service.storage_repositories.get __sr
end
def storage_repository
@ -24,7 +24,7 @@ module Fog
end
def host
connection.hosts.get __host
service.hosts.get __host
end
def unplug

View file

@ -14,12 +14,12 @@ module Fog
end
def all(options = {})
data = connection.get_records 'PBD'
data = service.get_records 'PBD'
load(data)
end
def get( ref )
if ref && obj = connection.get_record( ref, 'PBD' )
if ref && obj = service.get_record( ref, 'PBD' )
new(obj)
else
nil

View file

@ -32,11 +32,11 @@ module Fog
attribute :__host, :aliases => :host
def network
connection.networks.get __network
service.networks.get __network
end
def host
connection.hosts.get __host
service.hosts.get __host
end
end

View file

@ -14,12 +14,12 @@ module Fog
end
def all(options = {})
data = connection.get_records 'PIF'
data = service.get_records 'PIF'
load(data)
end
def get( ref )
if ref && obj = connection.get_record( ref, 'PIF' )
if ref && obj = service.get_record( ref, 'PIF' )
new(obj)
end
rescue Fog::XenServer::NotFound

View file

@ -23,7 +23,7 @@ module Fog
def default_sr
connection.storage_repositories.get __default_sr
service.storage_repositories.get __default_sr
end
def default_sr=(sr)
@ -44,7 +44,7 @@ module Fog
end
def master
connection.hosts.get __master
service.hosts.get __master
end
def set_attribute(name, *val)

View file

@ -14,12 +14,12 @@ module Fog
end
def all(options = {})
data = connection.get_records 'pool'
data = service.get_records 'pool'
load(data)
end
def get( pool_ref )
if pool_ref && pool = connection.get_record( pool_ref, 'pool' )
if pool_ref && pool = service.get_record( pool_ref, 'pool' )
new(pool)
else
nil

View file

@ -56,11 +56,11 @@ module Fog
end
def vbds
__vbds.collect {|vbd| connection.vbds.get vbd }
__vbds.collect {|vbd| service.vbds.get vbd }
end
def affinity
connection.hosts.get __affinity
service.hosts.get __affinity
end
def destroy
@ -74,12 +74,12 @@ module Fog
if vbd.vdi.allowed_operations.include?("destroy")
end
end
connection.destroy_server( reference )
service.destroy_server( reference )
true
end
def set_attribute(name, *val)
data = connection.set_attribute( 'VM', reference, name, *val )
data = service.set_attribute( 'VM', reference, name, *val )
# Do not reload automatically for performance reasons
# We can set multiple attributes at the same time and
# then reload manually
@ -87,13 +87,13 @@ module Fog
end
def refresh
data = connection.get_record( reference, 'VM' )
data = service.get_record( reference, 'VM' )
merge_attributes( data )
true
end
def vifs
__vifs.collect { |vif| connection.vifs.get vif }
__vifs.collect { |vif| service.vifs.get vif }
end
# associations
@ -102,7 +102,7 @@ module Fog
end
def resident_on
connection.hosts.get __resident_on
service.hosts.get __resident_on
end
#
@ -110,7 +110,7 @@ module Fog
# Guest needs XenTools installed to report this AFAIK
def guest_metrics
return nil unless __guest_metrics
rec = connection.get_record( __guest_metrics, 'VM_guest_metrics' )
rec = service.get_record( __guest_metrics, 'VM_guest_metrics' )
Fog::Compute::XenServer::GuestMetrics.new(rec)
end
@ -119,7 +119,7 @@ module Fog
end
def home_hypervisor
connection.hosts.first
service.hosts.first
end
def mac_address
@ -139,7 +139,7 @@ module Fog
# operations
def start
return false if running?
connection.start_server( reference )
service.start_server( reference )
true
end
@ -152,13 +152,13 @@ module Fog
auto_start = params[:auto_start]
end
if template_name
attr = connection.get_record(
connection.create_server( name, template_name, nets, :auto_start => auto_start),
attr = service.get_record(
service.create_server( name, template_name, nets, :auto_start => auto_start),
'VM'
)
else
attr = connection.get_record(
connection.create_server_raw(attributes),
attr = service.get_record(
service.create_server_raw(attributes),
'VM'
)
end
@ -167,7 +167,7 @@ module Fog
end
def reboot(stype = 'clean')
connection.reboot_server(reference, stype)
service.reboot_server(reference, stype)
true
end
@ -181,7 +181,7 @@ module Fog
def stop(stype = 'clean')
return false if !running?
connection.shutdown_server( reference, stype )
service.shutdown_server( reference, stype )
wait_for { power_state == 'Halted' }
true
end
@ -195,12 +195,12 @@ module Fog
end
def provision
connection.provision_server reference
service.provision_server reference
end
# def snapshot
# requires :reference, :name_label
# data = connection.snapshot_server(@reference, @name_label)
# data = service.snapshot_server(@reference, @name_label)
# merge_attributes(data.body)
# true
# end

View file

@ -10,7 +10,7 @@ module Fog
model Fog::Compute::XenServer::Server
def templates
data = connection.get_records 'VM'
data = service.get_records 'VM'
data.delete_if do |vm|
!vm[:is_a_template]
end
@ -18,7 +18,7 @@ module Fog
end
def custom_templates
data = connection.get_records 'VM'
data = service.get_records 'VM'
data.delete_if do |vm|
!vm[:is_a_template] or !vm[:other_config]['default_template'].nil?
end
@ -26,7 +26,7 @@ module Fog
end
def builtin_templates
data = connection.get_records 'VM'
data = service.get_records 'VM'
data.delete_if do |vm|
!vm[:is_a_template] or vm[:other_config]['default_template'].nil?
end
@ -34,7 +34,7 @@ module Fog
end
def all(options = {})
data = connection.get_records 'VM'
data = service.get_records 'VM'
# Exclude templates
data.delete_if { |vm| vm[:is_control_domain] or vm[:is_a_template] }
data.delete_if { |vm| vm[:is_a_snapshot] and !options[:include_snapshots] }
@ -44,12 +44,12 @@ module Fog
end
def get_by_name( name )
ref = connection.get_vm_by_name( name )
ref = service.get_vm_by_name( name )
get ref
end
def get( vm_ref )
if vm_ref && vm = connection.get_record( vm_ref, 'VM' )
if vm_ref && vm = service.get_record( vm_ref, 'VM' )
new(vm)
end
rescue Fog::XenServer::NotFound

View file

@ -10,14 +10,14 @@ module Fog
model Fog::Compute::XenServer::StorageRepository
def all
data = connection.get_records 'SR'
data = service.get_records 'SR'
#data.delete_if {|sr| sr[:shared].eql?(false)}
#data.delete_if {|sr| sr[:content_type].eql?('iso')}
load(data)
end
def get( sr_ref )
if sr_ref && sr = connection.get_record( sr_ref, 'SR' )
if sr_ref && sr = service.get_record( sr_ref, 'SR' )
new(sr)
else
nil

View file

@ -28,15 +28,15 @@ module Fog
attribute :virtual_allocation
def vdis
__vdis.collect { |vdi| connection.vdis.get vdi }
__vdis.collect { |vdi| service.vdis.get vdi }
end
def pbds
__pbds.collect { |pbd| connection.pbds.get pbd }
__pbds.collect { |pbd| service.pbds.get pbd }
end
def scan
connection.scan_sr reference
service.scan_sr reference
reload
end

View file

@ -38,36 +38,36 @@ module Fog
# May return nil
#
def vdi
connection.vdis.get __vdi
service.vdis.get __vdi
end
#
# TODO: May it return nil?
#
def server
connection.servers.get __vm
service.servers.get __vm
end
def save
requires :vdi, :server
ref = connection.create_vbd attributes[:server], attributes[:vdi], attributes
merge_attributes connection.vbds.get(ref).attributes
ref = service.create_vbd attributes[:server], attributes[:vdi], attributes
merge_attributes service.vbds.get(ref).attributes
end
def unplug
connection.unplug_vbd reference
service.unplug_vbd reference
end
def unplug_force
connection.unplug_force_vbd reference
service.unplug_force_vbd reference
end
def eject
connection.eject_vbd reference
service.eject_vbd reference
end
def insert(vdi)
connection.insert_vbd reference, vdi.reference
service.insert_vbd reference, vdi.reference
end
#
@ -79,7 +79,7 @@ module Fog
#
def metrics
return nil unless currently_attached
rec = connection.get_record( __metrics, 'VBD_metrics' )
rec = service.get_record( __metrics, 'VBD_metrics' )
Fog::Compute::XenServer::VbdMetrics.new(rec)
end

View file

@ -14,12 +14,12 @@ module Fog
end
def all(options = {})
data = connection.get_records 'VBD'
data = service.get_records 'VBD'
load(data)
end
def get( vbd_ref )
if vbd_ref && vbd = connection.get_record( vbd_ref, 'VBD' )
if vbd_ref && vbd = service.get_record( vbd_ref, 'VBD' )
new(vbd)
end
rescue Fog::XenServer::NotFound

View file

@ -54,41 +54,41 @@ module Fog
end
def set_attribute(name, *val)
data = connection.set_attribute( 'VDI', reference, name, *val )
data = service.set_attribute( 'VDI', reference, name, *val )
end
def snapshot_of
connection.vdis.get __sr
service.vdis.get __sr
end
def parent
connection.vdis.get __parent
service.vdis.get __parent
end
def snapshots
__snapshots.collect do |ref|
connection.vdis.get ref
service.vdis.get ref
end
end
def vbds
__vbds.collect do |ref|
connection.vbds.get ref
service.vbds.get ref
end
end
def save
requires :name, :storage_repository
ref = connection.create_vdi attributes
merge_attributes connection.vdis.get(ref).attributes
ref = service.create_vdi attributes
merge_attributes service.vdis.get(ref).attributes
end
def destroy
connection.destroy_vdi reference
service.destroy_vdi reference
end
def storage_repository
connection.storage_repositories.get __sr
service.storage_repositories.get __sr
end
def sr

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::XenServer::VDI
def all(options = {})
data = connection.get_records 'VDI'
data = service.get_records 'VDI'
load(data)
end
def get( vdi_ref )
if vdi_ref && vdi = connection.get_record( vdi_ref, 'VDI' )
if vdi_ref && vdi = service.get_record( vdi_ref, 'VDI' )
new(vdi)
end
rescue Fog::XenServer::NotFound

View file

@ -25,23 +25,23 @@ module Fog
def destroy
connection.destroy_vif reference
service.destroy_vif reference
end
def network
connection.networks.get __network
service.networks.get __network
end
def server
connection.servers.get __vm
service.servers.get __vm
end
def save
requires :server
raise ArgumentError.new('network is required for this operation') \
unless attributes[:__network]
ref = connection.create_vif attributes[:server], attributes[:__network]
merge_attributes connection.vifs.get(ref).attributes
ref = service.create_vif attributes[:server], attributes[:__network]
merge_attributes service.vifs.get(ref).attributes
end
end

View file

@ -10,12 +10,12 @@ module Fog
model Fog::Compute::XenServer::VIF
def all(options = {})
data = connection.get_records 'VIF'
data = service.get_records 'VIF'
load(data)
end
def get( ref )
if ref && obj = connection.get_record( ref, 'VIF' )
if ref && obj = service.get_record( ref, 'VIF' )
new(obj)
end
rescue Fog::XenServer::NotFound