Skip to content
This repository

New xenserver features and examples #1432

Merged
merged 16 commits into from over 1 year ago

2 participants

Sergio Rubio Wesley Beary
Sergio Rubio
Collaborator

Added new example and the required (missing) code to make it possible.

Wesley Beary
Owner

@rubiojr - looks good. Probably will want to add some tests around the new requests when you get a chance though.

Sergio Rubio
Collaborator

Sure @geemus, thanks!

And happy new year!

Wesley Beary
Owner

@rubiojr - happy new year!

Sergio Rubio
Collaborator

@geemus, I believe we're good to go now.

Wesley Beary
Owner

@rubiojr Cool, feel free to merge it when you are ready. Thanks!

Sergio Rubio rubiojr merged commit 9db7f34 into from January 04, 2013
Sergio Rubio rubiojr closed this January 04, 2013
Sergio Rubio
Collaborator

Great @geemus, thanks!

Sergio Rubio rubiojr deleted the branch January 04, 2013
Alan Ivey alanthing referenced this pull request from a commit February 21, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 16 unique commits by 1 author.

Dec 31, 2012
Sergio Rubio [xenserver] added create_sr request (create Storage Repository) c53f265
Sergio Rubio [xenserver] added destroy_sr request (destroy Storage Repository) bd16ffc
Sergio Rubio [xenserver] added unplug_pbd request 8570605
Sergio Rubio [xenserver] added new requests to compute service
- unplug_pbd
- destroy_sr
- create_sr
aba1506
Sergio Rubio [xenserver] added unplug method to PBD model 01c0669
Sergio Rubio [xenserver] missing Pool model attribute, new methods
- Added missing suspend_image_sr attribute
- added default_sr getter/setter
- added suspend_image_sr getter/setter
- added generic set_attribute method
6461286
Sergio Rubio [xenserver] added new methods to StorageRepository model
- destroy/save operations
- generic set_attribute method
e8594c4
Sergio Rubio [xenserver|docs] Added new example that covers a Citrix KB ctx116324 …
…article

Translated http://support.citrix.com/article/ctx116324 to fog/xenserver
72d4c6f
Jan 04, 2013
Sergio Rubio [xenserver] updated create_sr request documentation, fixed default va…
…lues
c7f75c8
Sergio Rubio [xenserver|tests] Added create_sr request tests 494ebe6
Sergio Rubio [xenserver|tests] Added destroy_sr request tests 9808b08
Sergio Rubio [xenserver] add missing PBD 'currently_attached' attribute 31f7883
Sergio Rubio [xenserver|tests] add unplug_pbd request tests 6d80fe5
Sergio Rubio [xenserver|tests] tests PBDs plug/unplug operation 4ddef41
Sergio Rubio [xenserver|tests] added more pool tests to cover the new functionality 09c8d80
Sergio Rubio [xenserver|tests] added missing SotorageRepository tests 731ba25
This page is out of date. Refresh to see the latest.
3  lib/fog/xenserver/compute.rb
@@ -60,6 +60,9 @@ class XenServer < Fog::Service
60 60
       request :reboot_server
61 61
       request :provision_server
62 62
       request :scan_sr
  63
+      request :unplug_pbd
  64
+      request :destroy_sr
  65
+      request :create_sr
63 66
     
64 67
       class Real
65 68
         
99  lib/fog/xenserver/examples/chage_default_storage_repository.md
Source Rendered
... ...
@@ -0,0 +1,99 @@
  1
+# How To Change the Default Storage Repository to File-based VHD-on-EXT3 
  2
+
  3
+**NOTE: Requires fog > 1.8 (currently in development as of this writing)**
  4
+
  5
+This tutorial explains how to convert a local Logical Volume Manager (LVM) 
  6
+based storage repository into a file-based (VHD) storage repository.
  7
+
  8
+It's the fog/xenserver version of the original Citrix KB article:
  9
+
  10
+http://support.citrix.com/article/ctx116324
  11
+
  12
+To create this tutorial, I've used a vanilla XCP 1.6 ISO install in VirtualBox.
  13
+
  14
+## Create the connection
  15
+
  16
+```ruby
  17
+require 'fog'
  18
+
  19
+conn = Fog::Compute.new({
  20
+  :provider => 'XenServer',
  21
+  :xenserver_url => '192.168.1.39',
  22
+  :xenserver_username => 'root',
  23
+  :xenserver_password => 'secret'
  24
+})
  25
+```
  26
+
  27
+## Remove the LVM-backed storage repository (SR).
  28
+
  29
+Find the default LVM storage repository:
  30
+
  31
+```ruby
  32
+#
  33
+# Equivalent to:
  34
+# xe sr-list type=lvm
  35
+#
  36
+lvm_sr = nil 
  37
+conn.storage_repositories.each do |sr|
  38
+  lvm_sr = sr if sr.type == 'lvm'
  39
+end
  40
+```
  41
+
  42
+Determine the UUID for your default SR's physical block device:
  43
+
  44
+```ruby
  45
+#
  46
+# Equivalent to:
  47
+# xe pbd-list sr-uuid=your SR UUID
  48
+#
  49
+if lvm_sr
  50
+  conn.pbds.each do |pbd|
  51
+    # Unplug it if found
  52
+    # Equivalent to:
  53
+    # xe pbd-unplug uuid=your PBD UUID
  54
+    #
  55
+    pbd.unplug if pbd.storage_repository.uuid == lvm_sr.uuid
  56
+  end
  57
+  # Destroy the SR
  58
+  lvm_sr.destroy 
  59
+end
  60
+```
  61
+
  62
+Create a new VHD-backed SR:
  63
+
  64
+```ruby
  65
+#
  66
+# Equivalent to:
  67
+#
  68
+# xe sr-create content-type="local SR" \
  69
+#              host-uuid=5d189b7a-cd5e-4029-9940-d4daaa34633d \ 
  70
+#              type=ext device-config-device=/dev/sda3 shared=false \
  71
+#              name-label="Local File SR"
  72
+#
  73
+sr = conn.storage_repositories.create :name => 'Local File SR',
  74
+                                      :host => conn.hosts.first,
  75
+                                      :type => 'ext',
  76
+                                      :content_type => 'local SR',
  77
+                                      :device_config => { :device => '/dev/sda3' },
  78
+                                      :shared => false
  79
+```
  80
+
  81
+Set your SR as the default SR on the system:
  82
+
  83
+```ruby
  84
+#
  85
+# Equivalent command:
  86
+# xe pool-param-set suspend-image-SR='YOUR NEW SR UUID' uuid=bleh
  87
+#
  88
+conn.pools.first.default_storage_repository = sr
  89
+```
  90
+
  91
+Set your SR as the default location for suspended VM images:
  92
+
  93
+```ruby
  94
+#
  95
+# Equivalent command:
  96
+# xe pool-param-set suspend-image-SR= YOUR NEW SR UUID  uuid=bleh
  97
+#
  98
+conn.pools.first.suspend_image_sr = sr
  99
+```
5  lib/fog/xenserver/models/compute/pbd.rb
@@ -13,6 +13,7 @@ class PBD < Fog::Model
13 13
         attribute :uuid
14 14
         attribute :__host,             :aliases => :host
15 15
         attribute :__sr,               :aliases => :SR
  16
+        attribute :currently_attached
16 17
 
17 18
         def sr
18 19
           connection.storage_repositories.get __sr
@@ -25,6 +26,10 @@ def storage_repository
25 26
         def host
26 27
           connection.hosts.get __host
27 28
         end
  29
+        
  30
+        def unplug
  31
+          connection.unplug_pbd reference
  32
+        end
28 33
 
29 34
       end
30 35
       
22  lib/fog/xenserver/models/compute/pool.rb
@@ -19,19 +19,41 @@ class Pool < Fog::Model
19 19
         attribute :restrictions
20 20
         attribute :ha_enabled
21 21
         attribute :vswitch_controller
  22
+        attribute :__suspend_image_sr,     :aliases => :suspend_image_SR
22 23
 
23 24
         
24 25
         def default_sr
25 26
           connection.storage_repositories.get __default_sr
26 27
         end
27 28
 
  29
+        def default_sr=(sr)
  30
+          connection.set_attribute( 'pool', reference, 'default_SR', sr.reference )
  31
+        end
  32
+        alias :default_storage_repository= :default_sr=
  33
+
28 34
         def default_storage_repository
29 35
           default_sr
30 36
         end
31 37
 
  38
+        def suspend_image_sr=(sr)
  39
+          connection.set_attribute( 'pool', reference, 'suspend_image_SR', sr.reference )
  40
+        end
  41
+
  42
+        def suspend_image_sr
  43
+          connection.storage_repositories.get __suspend_image_sr
  44
+        end
  45
+
32 46
         def master
33 47
           connection.hosts.get __master
34 48
         end
  49
+        
  50
+        def set_attribute(name, *val)
  51
+          data = connection.set_attribute( 'pool', reference, name, *val )
  52
+          # Do not reload automatically for performance reasons
  53
+          # We can set multiple attributes at the same time and
  54
+          # then reload manually
  55
+          #reload
  56
+        end
35 57
 
36 58
       end
37 59
       
43  lib/fog/xenserver/models/compute/storage_repository.rb
@@ -40,6 +40,49 @@ def scan
40 40
           reload
41 41
         end
42 42
 
  43
+        def destroy
  44
+          connection.destroy_sr reference
  45
+        end
  46
+        
  47
+        def save
  48
+          requires :name
  49
+          requires :type
  50
+
  51
+          # host is not a model attribute (not in XAPI at least), 
  52
+          # but we need it here
  53
+          host = attributes[:host]
  54
+          raise ArgumentError.new('host is required for this operation') unless
  55
+            host
  56
+
  57
+          # Not sure if this is always required, so not raising exception if nil
  58
+          device_config = attributes[:device_config]
  59
+
  60
+          # create_sr request provides sane defaults if some attributes are
  61
+          # missing
  62
+          attr = connection.get_record(
  63
+            connection.create_sr( host.reference, 
  64
+                                  name,
  65
+                                  type,
  66
+                                  description,
  67
+                                  device_config,
  68
+                                  physical_size,
  69
+                                  content_type,
  70
+                                  shared || false,
  71
+                                  sm_config),
  72
+            'SR'
  73
+          )
  74
+          merge_attributes attr 
  75
+          true
  76
+        end
  77
+        
  78
+        def set_attribute(name, *val)
  79
+          data = connection.set_attribute( 'SR', reference, name, *val )
  80
+          # Do not reload automatically for performance reasons
  81
+          # We can set multiple attributes at the same time and
  82
+          # then reload manually
  83
+          #reload
  84
+        end
  85
+
43 86
       end
44 87
       
45 88
     end
72  lib/fog/xenserver/requests/compute/create_sr.rb
... ...
@@ -0,0 +1,72 @@
  1
+module Fog
  2
+  module Compute
  3
+    class XenServer
  4
+
  5
+      class Real
  6
+        
  7
+        #
  8
+        # Create a storage repository (SR)
  9
+        #
  10
+        # @see http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=SR
  11
+        #
  12
+        # @param [String] host_ref host reference
  13
+        # @param [String] name_label repository label
  14
+        # @param [String] type storage repository type
  15
+        # @param [String] name_description storage repository description
  16
+        # @param [Hash]   device_config used to specify block device path, like
  17
+        # { :device => /dev/sdb } for example
  18
+        # @param [String] physical_size '0' will use the whole device (FIXME
  19
+        # needs confirmation)
  20
+        # @param [String] content_type the type of the SR's content. 
  21
+        # According to Citrix documentation, used only to distinguish ISO         
  22
+        # libraries from other SRs. Set it to 'iso' for storage repositories 
  23
+        # that store a library of ISOs, 'user' or '' (empty) otherwise.
  24
+        # @see http://docs.vmd.citrix.com/XenServer/6.1.0/1.0/en_gb/reference.html#cli-xe-commands_sr
  25
+        # @param [String] shared
  26
+        #
  27
+        # @return [String] an OpaqueRef to the storage repository
  28
+        def create_sr( host_ref,
  29
+                       name_label, 
  30
+                       type,
  31
+                       name_description = '',
  32
+                       device_config    = {}, 
  33
+                       physical_size    = '0',
  34
+                       content_type     = 'user', 
  35
+                       shared           = false, 
  36
+                       sm_config        = {} )
  37
+
  38
+          @connection.request(
  39
+            {:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.create'}, 
  40
+            host_ref, 
  41
+            device_config || {}, 
  42
+            physical_size || '0', 
  43
+            name_label, 
  44
+            name_description || '',
  45
+            type,
  46
+            content_type, 
  47
+            shared || false,
  48
+            sm_config || {}
  49
+          )
  50
+        end
  51
+
  52
+      end
  53
+
  54
+      class Mock
  55
+        
  56
+        def create_sr( host_ref,
  57
+                       name_label, 
  58
+                       type,
  59
+                       name_description = nil,
  60
+                       device_config    = {}, 
  61
+                       physical_size    = '0',
  62
+                       content_type     = nil, 
  63
+                       shared           = false, 
  64
+                       sm_config        = {} )
  65
+          Fog::Mock.not_implemented
  66
+        end
  67
+        
  68
+      end
  69
+
  70
+    end
  71
+  end
  72
+end
30  lib/fog/xenserver/requests/compute/destroy_sr.rb
... ...
@@ -0,0 +1,30 @@
  1
+module Fog
  2
+  module Compute
  3
+    class XenServer
  4
+
  5
+      class Real
  6
+
  7
+        # 
  8
+        # Destroy a Storage Repository
  9
+        #
  10
+        # http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=SR
  11
+        #
  12
+        def destroy_sr( sr_ref )
  13
+          @connection.request(
  14
+            {:parser => Fog::Parsers::XenServer::Base.new, :method => 'SR.destroy'}, 
  15
+            sr_ref
  16
+          )
  17
+        end
  18
+
  19
+      end
  20
+
  21
+      class Mock
  22
+
  23
+        def destroy_sr( sr_ref )
  24
+          Fog::Mock.not_implemented
  25
+        end
  26
+
  27
+      end
  28
+    end
  29
+  end
  30
+end
25  lib/fog/xenserver/requests/compute/unplug_pbd.rb
... ...
@@ -0,0 +1,25 @@
  1
+module Fog
  2
+  module Compute
  3
+    class XenServer
  4
+
  5
+      class Real
  6
+
  7
+        def unplug_pbd( ref )
  8
+          @connection.request(
  9
+            {:parser => Fog::Parsers::XenServer::Base.new, :method => 'PBD.unplug'}, 
  10
+            ref
  11
+          )
  12
+        end
  13
+
  14
+      end
  15
+
  16
+      class Mock
  17
+
  18
+        def unplug_pbd( ref )
  19
+          Fog::Mock.not_implemented
  20
+        end
  21
+
  22
+      end
  23
+    end
  24
+  end
  25
+end
34  tests/xenserver/models/compute/pbd_tests.rb
@@ -6,6 +6,7 @@
6 6
   tests('The PBD model should') do
7 7
     tests('have the action') do
8 8
       test('reload') { pbd.respond_to? 'reload' }
  9
+      test('unplug') { pbd.respond_to? 'reload' }
9 10
     end
10 11
     tests('have attributes') do
11 12
       model_attribute_hash = pbd.attributes
@@ -13,7 +14,8 @@
13 14
         :reference,
14 15
         :uuid,
15 16
         :__host,
16  
-        :__sr
  17
+        :__sr,
  18
+        :currently_attached
17 19
       ]
18 20
       tests("The PBD model should respond to") do
19 21
         attributes.each do |attribute|
@@ -38,6 +40,36 @@
38 40
     tests("return valid storage repository") do
39 41
       test("should be a Fog::Compute::XenServer::StorageRepository") { pbd.storage_repository.kind_of? Fog::Compute::XenServer::StorageRepository }
40 42
     end
  43
+    # FIXME: find a better way (faster, lighter) to tests this
  44
+    tests("be plugged or unplugged") do
  45
+      compute = Fog::Compute[:xenserver]
  46
+      # Create a storage repository only to tests PBD.unplug
  47
+      ref = compute.create_sr compute.hosts.first.reference,
  48
+                              'FOG TEST SR',
  49
+                              'ext',
  50
+                              '',
  51
+                              { :device => '/dev/sdb' },
  52
+                              '0',
  53
+                              'user',
  54
+                              false,
  55
+                              {}
  56
+      sr = compute.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }
  57
+      pbd = sr.pbds.first
  58
+      test('plugged') do
  59
+        pbd.currently_attached == true
  60
+      end
  61
+      pbd.unplug
  62
+      pbd.reload
  63
+      test('unplugged') do
  64
+        pbd.currently_attached == false
  65
+      end
  66
+      # Clean-up
  67
+      compute.storage_repositories.each do |sr|
  68
+        next unless sr.name == 'FOG TEST SR'
  69
+        sr.pbds.each { |pbd| pbd.unplug }
  70
+        sr.destroy
  71
+      end
  72
+    end
41 73
 
42 74
   end
43 75
 
8  tests/xenserver/models/compute/pool_tests.rb
@@ -19,7 +19,8 @@
19 19
         :tags,
20 20
         :restrictions,
21 21
         :ha_enabled,
22  
-        :vswitch_controller
  22
+        :vswitch_controller,
  23
+        :__suspend_image_sr
23 24
       ]
24 25
       tests("The Pool model should respond to") do
25 26
         attributes.each do |attribute|
@@ -44,6 +45,11 @@
44 45
     tests("return valid Host as the master") do
45 46
       test("should be a Fog::Compute::XenServer::Host") { pool.master.kind_of? Fog::Compute::XenServer::Host }
46 47
     end
  48
+    test("be able to be configured as a valid suspend_image_sr") do
  49
+      pool.suspend_image_sr = pool.default_storage_repository
  50
+      pool.reload
  51
+      pool.suspend_image_sr.reference == pool.default_storage_repository.reference
  52
+    end
47 53
 
48 54
   end
49 55
 
26  tests/xenserver/models/compute/storage_repository_tests.rb
@@ -6,6 +6,9 @@
6 6
   tests('The StorageRepository model should') do
7 7
     tests('have the action') do
8 8
       test('reload') { storage_repository.respond_to? 'reload' }
  9
+      test('destroy') { storage_repository.respond_to? 'destroy' }
  10
+      test('scan') { storage_repository.respond_to? 'scan' }
  11
+      test('save') { storage_repository.respond_to? 'save' }
9 12
     end
10 13
     tests('have attributes') do
11 14
       model_attribute_hash = storage_repository.attributes
@@ -25,7 +28,9 @@
25 28
         :tags,
26 29
         :__vdis,
27 30
         :physical_size,
28  
-        :physical_utilisation
  31
+        :physical_utilisation,
  32
+        :virtual_allocation,
  33
+        :sm_config
29 34
       ]
30 35
       tests("The StorageRepository model should respond to") do
31 36
         attributes.each do |attribute|
@@ -60,4 +65,23 @@
60 65
     end
61 66
   end
62 67
 
  68
+  test('#save') do
  69
+    conn = Fog::Compute[:xenserver]
  70
+    sr = conn.storage_repositories.create :name => 'FOG TEST SR',
  71
+                                          :host => conn.hosts.first,
  72
+                                          :type => 'ext',
  73
+                                          :content_type => 'local SR',
  74
+                                          :device_config => { :device => '/dev/sdb' },
  75
+                                          :shared => false
  76
+    !(conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
  77
+  end
  78
+
  79
+  test('#destroy') do
  80
+    conn = Fog::Compute[:xenserver]
  81
+    sr = (conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' })
  82
+    sr.pbds.each { |pbd| pbd.unplug }
  83
+    sr.destroy
  84
+    (conn.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
  85
+  end
  86
+
63 87
 end
54  tests/xenserver/requests/compute/create_sr_tests.rb
... ...
@@ -0,0 +1,54 @@
  1
+#
  2
+# @rubiojr
  3
+#
  4
+# Testing this requires a very specific setup:
  5
+#
  6
+# I use VirtualBox to virtualize XenServer/XCP and create the XenServer VM using
  7
+# two virtual disks under the same SATA controller. One of the virtual disks
  8
+# will be /dev/sdb, used to perform the tests.
  9
+#
  10
+
  11
+Shindo.tests('Fog::Compute[:xenserver] | create_sr request', ['xenserver']) do
  12
+
  13
+  compute = Fog::Compute[:xenserver]
  14
+  
  15
+  tests('#create_sr "FOG TEST SR" with device /dev/sdb') do
  16
+    test('create an EXT SR') do
  17
+      ref = compute.create_sr compute.hosts.first.reference,
  18
+                             'FOG TEST SR',
  19
+                             'ext',
  20
+                             '',
  21
+                             { :device => '/dev/sdb' },
  22
+                             '0',
  23
+                             'user',
  24
+                             false,
  25
+                             {}
  26
+      valid_ref? ref
  27
+    end
  28
+
  29
+    raises(Fog::XenServer::RequestFailed, 'raise when device in use') do
  30
+      ref = compute.create_sr compute.hosts.first.reference,
  31
+                             'FOG TEST SR',
  32
+                             'ext',
  33
+                             '',
  34
+                             { :device => '/dev/sdb' },
  35
+                             '0',
  36
+                             'user',
  37
+                             false,
  38
+                             {}
  39
+      valid_ref? ref
  40
+    end
  41
+  end
  42
+
  43
+  tests('The expected options') do
  44
+    raises(ArgumentError, 'raises ArgumentError when arguments missing') { compute.create_sr }
  45
+  end
  46
+
  47
+  # Clean-up
  48
+  compute.storage_repositories.each do |sr|
  49
+    next unless sr.name == 'FOG TEST SR'
  50
+    sr.pbds.each { |pbd| pbd.unplug }
  51
+    sr.destroy
  52
+  end
  53
+
  54
+end
46  tests/xenserver/requests/compute/destroy_sr_tests.rb
... ...
@@ -0,0 +1,46 @@
  1
+#
  2
+# @rubiojr
  3
+#
  4
+# Testing this requires a very specific setup:
  5
+#
  6
+# I use VirtualBox to virtualize XenServer/XCP and create the XenServer VM using
  7
+# two virtual disks under the same SATA controller. One of the virtual disks
  8
+# will be /dev/sdb, used to perform the tests.
  9
+#
  10
+
  11
+Shindo.tests('Fog::Compute[:xenserver] | destroy_sr request', ['xenserver']) do
  12
+
  13
+  compute = Fog::Compute[:xenserver]
  14
+  # We need the SR available for this to work, so create it first
  15
+  ref = compute.create_sr compute.hosts.first.reference,
  16
+                         'FOG TEST SR',
  17
+                         'ext',
  18
+                         '',
  19
+                         { :device => '/dev/sdb' },
  20
+                         '0',
  21
+                         'user',
  22
+                         false,
  23
+                         {}
  24
+  
  25
+  tests('#destroy_sr') do
  26
+    test('destroyed "FOG TEST SR"') do
  27
+      compute.storage_repositories.each do |sr|
  28
+        next unless sr.name == 'FOG TEST SR'
  29
+        sr.pbds.each { |pbd| pbd.unplug }
  30
+      end
  31
+      compute.destroy_sr ref
  32
+      (compute.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }).nil?
  33
+    end
  34
+
  35
+    raises(Fog::XenServer::RequestFailed, 
  36
+           'raises HandleInvalid trying to destroy it twice') do
  37
+      compute.destroy_sr ref
  38
+    end
  39
+  end
  40
+
  41
+  tests('The expected options') do
  42
+    raises(ArgumentError, 'raises ArgumentError when arguments missing') \
  43
+      { compute.destroy_sr }
  44
+  end
  45
+
  46
+end
48  tests/xenserver/requests/compute/unplug_pbd_tests.rb
... ...
@@ -0,0 +1,48 @@
  1
+#
  2
+# @rubiojr
  3
+#
  4
+# Testing this requires a very specific setup:
  5
+#
  6
+# I use VirtualBox to virtualize XenServer/XCP and create the XenServer VM using
  7
+# two virtual disks under the same SATA controller. One of the virtual disks
  8
+# will be /dev/sdb, used to perform the tests.
  9
+#
  10
+
  11
+Shindo.tests('Fog::Compute[:xenserver] | unplug_pbd request', ['xenserver']) do
  12
+
  13
+  compute = Fog::Compute[:xenserver]
  14
+  # Creating a new SR automatically plugs the PBD
  15
+  # We need the SR available for this to work, so create it first
  16
+  ref = compute.create_sr compute.hosts.first.reference,
  17
+                         'FOG TEST SR',
  18
+                         'ext',
  19
+                         '',
  20
+                         { :device => '/dev/sdb' },
  21
+                         '0',
  22
+                         'user',
  23
+                         false,
  24
+                         {}
  25
+  
  26
+  tests('#unplug_pbd') do
  27
+    test('unplugged') do
  28
+      sr = compute.storage_repositories.find { |sr| sr.name == 'FOG TEST SR' }
  29
+      pbd = sr.pbds.first
  30
+      compute.unplug_pbd pbd.reference
  31
+      pbd.reload
  32
+      pbd.currently_attached == false
  33
+    end
  34
+  end
  35
+
  36
+  tests('The expected options') do
  37
+    raises(ArgumentError, 'raises ArgumentError when arguments missing') \
  38
+      { compute.unplug_pbd }
  39
+  end
  40
+  
  41
+  # Clean-up
  42
+  compute.storage_repositories.each do |sr|
  43
+    next unless sr.name == 'FOG TEST SR'
  44
+    sr.pbds.each { |pbd| pbd.unplug }
  45
+    sr.destroy
  46
+  end
  47
+
  48
+end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.