2012-12-16 16:23:44 -05:00
|
|
|
# Storage Repositories
|
|
|
|
|
|
|
|
Official storage repository Citrix API documentation:
|
|
|
|
|
|
|
|
http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=SR
|
|
|
|
|
|
|
|
Create the XenServer connection first, as usual:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
require 'fog'
|
|
|
|
require 'net/scp'
|
|
|
|
require 'pp'
|
2012-12-16 16:23:44 -05:00
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
xenserver = Fog::Compute.new({
|
|
|
|
:provider => 'XenServer',
|
|
|
|
:xenserver_url => 'xenserver-test',
|
|
|
|
:xenserver_username => 'root',
|
|
|
|
:xenserver_password => 'secret',
|
|
|
|
})
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
Listing the available storage repositories:
|
2012-12-16 16:23:44 -05:00
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
xenserver.storage_repositories
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
Filter storage repositories by content type:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
xenserver.storage_repositories.select { |sr| sr.content_type == 'iso' }
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
|
|
|
Filter storage repositories by allowed operations:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
rw_srs = xenserver.storage_repositories.select do |sr|
|
|
|
|
# Are we allowed to create a VDI here?
|
|
|
|
sr.allowed_operations.include? 'vdi_create'
|
|
|
|
end
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
|
|
|
Print some attributes of the first SR found:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
sr = rw_srs.first
|
|
|
|
puts sr.name
|
|
|
|
puts sr.description
|
|
|
|
puts sr.type
|
|
|
|
puts sr.tags
|
|
|
|
# in bytes
|
|
|
|
puts sr.physical_size
|
|
|
|
puts sr.physical_utilisation
|
|
|
|
# sum of virtual_sizes of all VDIs in this storage repository (in bytes)
|
|
|
|
puts sr.virtual_allocation
|
|
|
|
```
|
|
|
|
|
2012-12-16 16:23:44 -05:00
|
|
|
List virtual disk images available and print some VDI's attributes:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
sr.vdis.each do |vdi|
|
|
|
|
# http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=VDI
|
|
|
|
puts vdi.uuid
|
|
|
|
puts vdi.is_a_snapshot
|
|
|
|
puts vdi.name
|
|
|
|
# in bytes
|
|
|
|
puts vdi.physical_utilisation
|
|
|
|
puts vdi.virtual_size
|
|
|
|
puts vdi.read_only
|
|
|
|
# ["update", "resize", "destroy", "clone", "copy", "snapshot"],
|
|
|
|
puts vdi.allowed_operations
|
|
|
|
end
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
|
|
|
Create a new VDI in this storage repository:
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
vdi = xenserver.vdis.create :name => 'super-vdi',
|
|
|
|
:storage_repository => sr,
|
|
|
|
:description => 'my super-vdi',
|
|
|
|
:virtual_size => '1073741824' # 1 GB
|
|
|
|
```
|
2012-12-16 16:23:44 -05:00
|
|
|
|
|
|
|
I have an ext3 storage repository and this creates a 1GB VHD file there:
|
|
|
|
|
|
|
|
[root@xenserver ~]# vhd-util query -v -n /var/run/sr-mount/6edd263a-2da1-7533-840c-768417b5be25/4050057d-a3a8-4c00-8f2e-cf5531232921.vhd
|
|
|
|
1024
|
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
Destroy the VDI:
|
2012-12-16 16:23:44 -05:00
|
|
|
|
2012-12-16 16:35:51 -05:00
|
|
|
```ruby
|
|
|
|
vdi.destroy
|
|
|
|
```
|