From 9ef0aa59ca5e64d85444464795b6d768bea5dc3e Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Thu, 12 Apr 2012 14:16:14 +0200 Subject: [PATCH] * Added create_vbd and provision_server requests * Do not provision server when :auto_start is false * Add Server.provisio method * Add VBD.save method --- lib/fog/xenserver/compute.rb | 2 + lib/fog/xenserver/models/compute/server.rb | 4 ++ lib/fog/xenserver/models/compute/vbd.rb | 11 ++++- .../requests/compute/create_server.rb | 6 ++- .../xenserver/requests/compute/create_vbd.rb | 40 +++++++++++++++++++ .../requests/compute/provision_server.rb | 21 ++++++++++ 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 lib/fog/xenserver/requests/compute/create_vbd.rb create mode 100644 lib/fog/xenserver/requests/compute/provision_server.rb diff --git a/lib/fog/xenserver/compute.rb b/lib/fog/xenserver/compute.rb index a5f71e6f0..d00c333e1 100644 --- a/lib/fog/xenserver/compute.rb +++ b/lib/fog/xenserver/compute.rb @@ -41,6 +41,7 @@ module Fog request :create_server request :create_vif request :create_vdi + request :create_vbd request :destroy_vif request :clone_server request :destroy_server @@ -56,6 +57,7 @@ module Fog request :set_affinity request :set_attribute request :reboot_server + request :provision_server class Real diff --git a/lib/fog/xenserver/models/compute/server.rb b/lib/fog/xenserver/models/compute/server.rb index 3cf0f04c3..92e855666 100644 --- a/lib/fog/xenserver/models/compute/server.rb +++ b/lib/fog/xenserver/models/compute/server.rb @@ -177,6 +177,10 @@ module Fog stop 'clean' end + def provision + connection.provision_server reference + end + # def snapshot # requires :reference, :name_label # data = connection.snapshot_server(@reference, @name_label) diff --git a/lib/fog/xenserver/models/compute/vbd.rb b/lib/fog/xenserver/models/compute/vbd.rb index 2ba2f4151..ee76dc27e 100644 --- a/lib/fog/xenserver/models/compute/vbd.rb +++ b/lib/fog/xenserver/models/compute/vbd.rb @@ -28,6 +28,9 @@ module Fog attribute :runtime_properties attribute :unpluggable attribute :bootable + attribute :qos_supported_algorithms + attribute :qos_algorithm_params + attribute :qos_algorithm_type attribute :empty attribute :__metrics, :aliases => :metrics @@ -37,7 +40,7 @@ module Fog def vdi connection.vdis.get __vdi end - + # # TODO: May it return nil? # @@ -45,6 +48,12 @@ module Fog connection.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 + end + def unplug connection.unplug_vbd reference end diff --git a/lib/fog/xenserver/requests/compute/create_server.rb b/lib/fog/xenserver/requests/compute/create_server.rb index 0f686cc9d..25c4e3071 100644 --- a/lib/fog/xenserver/requests/compute/create_server.rb +++ b/lib/fog/xenserver/requests/compute/create_server.rb @@ -35,8 +35,10 @@ module Fog networks.each do |n| create_vif ref, n.reference end - @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, ref) - start_vm( ref ) unless extra_args[:auto_start] == false + if !extra_args[:auto_start] == false + @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, ref) + start_vm( ref ) + end ref end diff --git a/lib/fog/xenserver/requests/compute/create_vbd.rb b/lib/fog/xenserver/requests/compute/create_vbd.rb new file mode 100644 index 000000000..a6c27c4c1 --- /dev/null +++ b/lib/fog/xenserver/requests/compute/create_vbd.rb @@ -0,0 +1,40 @@ +module Fog + module Compute + class XenServer + + class Real + + def create_vbd( vm_ref, vdi_ref, config = {} ) + raise ArgumentError.new('Invalid config') if config.nil? + vm_ref = vm_ref.reference if vm_ref.kind_of? Fog::Compute::XenServer::Server + vdi_ref = vdi_ref.reference if vdi_ref.kind_of? Fog::Compute::XenServer::VDI + config.reject! { |k,v| (k == :server) or (k == :vdi) } + default_config = { + :VM => vm_ref, + :VDI => vdi_ref, + :empty => false, + :other_config => {'owner' => ''}, + :userdevice => "0", + :bootable => true, + :mode => 'RW', + :qos_algorithm_type=> '', + :qos_algorithm_params=> {}, + :qos_supported_algorithms=> [], + :type => 'Disk' + }.merge config + + @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VBD.create'}, default_config ) + end + end + + class Mock + + def create_vbd( config ) + Fog::Mock.not_implemented + end + + end + + end + end +end diff --git a/lib/fog/xenserver/requests/compute/provision_server.rb b/lib/fog/xenserver/requests/compute/provision_server.rb new file mode 100644 index 000000000..ca68b30ea --- /dev/null +++ b/lib/fog/xenserver/requests/compute/provision_server.rb @@ -0,0 +1,21 @@ +module Fog + module Compute + class XenServer + class Real + + def provision_server( ref ) + @connection.request({:parser => Fog::Parsers::XenServer::Base.new, :method => 'VM.provision'}, ref) + end + + end + + class Mock + + def provision_server( ref ) + Fog::Mock.not_implemented + end + end + + end + end +end