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

[xenserver|docs] added some color!, minor format fixes

This commit is contained in:
Sergio Rubio 2012-12-16 22:35:51 +01:00
parent 592dc03ea0
commit 5152fd273b

View file

@ -6,75 +6,89 @@ http://docs.vmd.citrix.com/XenServer/6.0.0/1.0/en_gb/api/?c=SR
Create the XenServer connection first, as usual:
require 'fog'
require 'net/scp'
require 'pp'
xenserver = Fog::Compute.new({
:provider => 'XenServer',
:xenserver_url => 'xenserver-test',
:xenserver_username => 'root',
:xenserver_password => 'secret',
})
```ruby
require 'fog'
require 'net/scp'
require 'pp'
xenserver = Fog::Compute.new({
:provider => 'XenServer',
:xenserver_url => 'xenserver-test',
:xenserver_username => 'root',
:xenserver_password => 'secret',
})
```
Listing the available storage repositories
Listing the available storage repositories:
xenserver.storage_repositories
```ruby
xenserver.storage_repositories
```
Filter storage repositories by content type:
xenserver.storage_repositories.select { |sr| sr.content_type == 'iso' }
```ruby
xenserver.storage_repositories.select { |sr| sr.content_type == 'iso' }
```
Filter storage repositories by allowed operations:
rw_srs = xenserver.storage_repositories.select do |sr|
# Are we allowed to create a VDI here?
sr.allowed_operations.include? 'vdi_create'
end
```ruby
rw_srs = xenserver.storage_repositories.select do |sr|
# Are we allowed to create a VDI here?
sr.allowed_operations.include? 'vdi_create'
end
```
Print some attributes of the first SR found:
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
```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
```
List virtual disk images available and print some VDI's attributes:
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
```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
```
Create a new VDI in this storage repository:
vdi = xenserver.vdis.create :name => 'super-vdi',
:storage_repository => sr,
:description => 'my super-vdi',
:virtual_size => '1073741824' # 1 GB
```ruby
vdi = xenserver.vdis.create :name => 'super-vdi',
:storage_repository => sr,
:description => 'my super-vdi',
:virtual_size => '1073741824' # 1 GB
```
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
Destroy it
Destroy the VDI:
vdi.destroy
```ruby
vdi.destroy
```