fog-xenserver 0.0.1.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/CONTRIBUTING.md +18 -0
  6. data/CONTRIBUTORS.md +1 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.md +20 -0
  9. data/README.md +29 -0
  10. data/Rakefile +2 -0
  11. data/fog-xenserver.gemspec +26 -0
  12. data/lib/fog.rb +3 -0
  13. data/lib/fog/compute.rb +7 -0
  14. data/lib/fog/xenserver.rb +1 -0
  15. data/lib/fog/xenserver/compute.rb +176 -0
  16. data/lib/fog/xenserver/core.rb +84 -0
  17. data/lib/fog/xenserver/examples/README.md +11 -0
  18. data/lib/fog/xenserver/examples/chage_default_storage_repository.md +99 -0
  19. data/lib/fog/xenserver/examples/creating_servers.md +168 -0
  20. data/lib/fog/xenserver/examples/getting_started.md +163 -0
  21. data/lib/fog/xenserver/examples/networks-and-vlans.rb +45 -0
  22. data/lib/fog/xenserver/examples/storage_repositories.md +94 -0
  23. data/lib/fog/xenserver/models/compute/blob.rb +22 -0
  24. data/lib/fog/xenserver/models/compute/blobs.rb +25 -0
  25. data/lib/fog/xenserver/models/compute/bond.rb +23 -0
  26. data/lib/fog/xenserver/models/compute/bonds.rb +25 -0
  27. data/lib/fog/xenserver/models/compute/console.rb +29 -0
  28. data/lib/fog/xenserver/models/compute/consoles.rb +25 -0
  29. data/lib/fog/xenserver/models/compute/crash_dump.rb +19 -0
  30. data/lib/fog/xenserver/models/compute/crash_dumps.rb +25 -0
  31. data/lib/fog/xenserver/models/compute/dr_task.rb +17 -0
  32. data/lib/fog/xenserver/models/compute/dr_tasks.rb +25 -0
  33. data/lib/fog/xenserver/models/compute/gpu_group.rb +22 -0
  34. data/lib/fog/xenserver/models/compute/gpu_groups.rb +25 -0
  35. data/lib/fog/xenserver/models/compute/guest_metrics.rb +29 -0
  36. data/lib/fog/xenserver/models/compute/host.rb +159 -0
  37. data/lib/fog/xenserver/models/compute/host_cpu.rb +38 -0
  38. data/lib/fog/xenserver/models/compute/host_crash_dump.rb +20 -0
  39. data/lib/fog/xenserver/models/compute/host_crash_dumps.rb +25 -0
  40. data/lib/fog/xenserver/models/compute/host_metrics.rb +29 -0
  41. data/lib/fog/xenserver/models/compute/host_patch.rb +25 -0
  42. data/lib/fog/xenserver/models/compute/host_patchs.rb +25 -0
  43. data/lib/fog/xenserver/models/compute/hosts.rb +29 -0
  44. data/lib/fog/xenserver/models/compute/network.rb +92 -0
  45. data/lib/fog/xenserver/models/compute/networks.rb +33 -0
  46. data/lib/fog/xenserver/models/compute/pbd.rb +40 -0
  47. data/lib/fog/xenserver/models/compute/pbds.rb +33 -0
  48. data/lib/fog/xenserver/models/compute/pci.rb +22 -0
  49. data/lib/fog/xenserver/models/compute/pcis.rb +25 -0
  50. data/lib/fog/xenserver/models/compute/pgpu.rb +20 -0
  51. data/lib/fog/xenserver/models/compute/pgpus.rb +25 -0
  52. data/lib/fog/xenserver/models/compute/pif.rb +57 -0
  53. data/lib/fog/xenserver/models/compute/pif_metrics.rb +28 -0
  54. data/lib/fog/xenserver/models/compute/pifs.rb +33 -0
  55. data/lib/fog/xenserver/models/compute/pifs_metrics.rb +25 -0
  56. data/lib/fog/xenserver/models/compute/pool.rb +79 -0
  57. data/lib/fog/xenserver/models/compute/pool_patch.rb +24 -0
  58. data/lib/fog/xenserver/models/compute/pool_patchs.rb +25 -0
  59. data/lib/fog/xenserver/models/compute/pools.rb +33 -0
  60. data/lib/fog/xenserver/models/compute/role.rb +19 -0
  61. data/lib/fog/xenserver/models/compute/roles.rb +25 -0
  62. data/lib/fog/xenserver/models/compute/server.rb +250 -0
  63. data/lib/fog/xenserver/models/compute/server_appliance.rb +21 -0
  64. data/lib/fog/xenserver/models/compute/server_appliances.rb +25 -0
  65. data/lib/fog/xenserver/models/compute/servers.rb +68 -0
  66. data/lib/fog/xenserver/models/compute/storage_manager.rb +28 -0
  67. data/lib/fog/xenserver/models/compute/storage_managers.rb +25 -0
  68. data/lib/fog/xenserver/models/compute/storage_repositories.rb +31 -0
  69. data/lib/fog/xenserver/models/compute/storage_repository.rb +93 -0
  70. data/lib/fog/xenserver/models/compute/tunnel.rb +20 -0
  71. data/lib/fog/xenserver/models/compute/tunnels.rb +25 -0
  72. data/lib/fog/xenserver/models/compute/vbd.rb +91 -0
  73. data/lib/fog/xenserver/models/compute/vbd_metrics.rb +27 -0
  74. data/lib/fog/xenserver/models/compute/vbds.rb +33 -0
  75. data/lib/fog/xenserver/models/compute/vdi.rb +105 -0
  76. data/lib/fog/xenserver/models/compute/vdis.rb +29 -0
  77. data/lib/fog/xenserver/models/compute/vif.rb +60 -0
  78. data/lib/fog/xenserver/models/compute/vifs.rb +29 -0
  79. data/lib/fog/xenserver/models/compute/vlan.rb +81 -0
  80. data/lib/fog/xenserver/models/compute/vlans.rb +39 -0
  81. data/lib/fog/xenserver/models/compute/vmpp.rb +35 -0
  82. data/lib/fog/xenserver/models/compute/vmpps.rb +25 -0
  83. data/lib/fog/xenserver/models/compute/vtpm.rb +18 -0
  84. data/lib/fog/xenserver/models/compute/vtpms.rb +25 -0
  85. data/lib/fog/xenserver/parser.rb +36 -0
  86. data/lib/fog/xenserver/parsers/get_hosts.rb +19 -0
  87. data/lib/fog/xenserver/parsers/get_networks.rb +19 -0
  88. data/lib/fog/xenserver/parsers/get_pools.rb +19 -0
  89. data/lib/fog/xenserver/parsers/get_records.rb +19 -0
  90. data/lib/fog/xenserver/parsers/get_storage_repositories.rb +19 -0
  91. data/lib/fog/xenserver/parsers/get_vbds.rb +19 -0
  92. data/lib/fog/xenserver/parsers/get_vifs.rb +19 -0
  93. data/lib/fog/xenserver/parsers/get_vms.rb +20 -0
  94. data/lib/fog/xenserver/requests/compute/clone_server.rb +31 -0
  95. data/lib/fog/xenserver/requests/compute/create_network.rb +42 -0
  96. data/lib/fog/xenserver/requests/compute/create_server.rb +130 -0
  97. data/lib/fog/xenserver/requests/compute/create_sr.rb +72 -0
  98. data/lib/fog/xenserver/requests/compute/create_vbd.rb +40 -0
  99. data/lib/fog/xenserver/requests/compute/create_vdi.rb +33 -0
  100. data/lib/fog/xenserver/requests/compute/create_vif.rb +57 -0
  101. data/lib/fog/xenserver/requests/compute/create_vlan.rb +35 -0
  102. data/lib/fog/xenserver/requests/compute/destroy_network.rb +33 -0
  103. data/lib/fog/xenserver/requests/compute/destroy_server.rb +22 -0
  104. data/lib/fog/xenserver/requests/compute/destroy_sr.rb +30 -0
  105. data/lib/fog/xenserver/requests/compute/destroy_vdi.rb +22 -0
  106. data/lib/fog/xenserver/requests/compute/destroy_vif.rb +22 -0
  107. data/lib/fog/xenserver/requests/compute/destroy_vlan.rb +32 -0
  108. data/lib/fog/xenserver/requests/compute/disable_host.rb +29 -0
  109. data/lib/fog/xenserver/requests/compute/eject_vbd.rb +22 -0
  110. data/lib/fog/xenserver/requests/compute/enable_host.rb +28 -0
  111. data/lib/fog/xenserver/requests/compute/get_record.rb +29 -0
  112. data/lib/fog/xenserver/requests/compute/get_records.rb +30 -0
  113. data/lib/fog/xenserver/requests/compute/insert_vbd.rb +22 -0
  114. data/lib/fog/xenserver/requests/compute/provision_server.rb +21 -0
  115. data/lib/fog/xenserver/requests/compute/reboot_host.rb +23 -0
  116. data/lib/fog/xenserver/requests/compute/reboot_server.rb +23 -0
  117. data/lib/fog/xenserver/requests/compute/scan_sr.rb +22 -0
  118. data/lib/fog/xenserver/requests/compute/set_affinity.rb +25 -0
  119. data/lib/fog/xenserver/requests/compute/set_attribute.rb +25 -0
  120. data/lib/fog/xenserver/requests/compute/shutdown_host.rb +23 -0
  121. data/lib/fog/xenserver/requests/compute/shutdown_server.rb +23 -0
  122. data/lib/fog/xenserver/requests/compute/snapshot_revert.rb +22 -0
  123. data/lib/fog/xenserver/requests/compute/snapshot_server.rb +22 -0
  124. data/lib/fog/xenserver/requests/compute/start_server.rb +23 -0
  125. data/lib/fog/xenserver/requests/compute/start_vm.rb +25 -0
  126. data/lib/fog/xenserver/requests/compute/unplug_pbd.rb +25 -0
  127. data/lib/fog/xenserver/requests/compute/unplug_vbd.rb +30 -0
  128. data/lib/fog/xenserver/utilities.rb +8 -0
  129. data/lib/fog/xenserver/version.rb +5 -0
  130. metadata +228 -0
@@ -0,0 +1,20 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+ class Pgpu < Fog::Model
7
+ # API Reference here:
8
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=PGPU
9
+
10
+ identity :reference
11
+
12
+ attribute :__gpu_group, :aliases => :GPU_group
13
+ attribute :__host, :aliases => :host
14
+ attribute :other_config
15
+ attribute :__pci, :aliases => :PCI
16
+ attribute :uuid
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/pgpu'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+ class Pgpus < Fog::Collection
8
+ model Fog::Compute::XenServer::Pgpu
9
+
10
+ def all(options={})
11
+ data = service.get_records 'PGPU'
12
+ load(data)
13
+ end
14
+
15
+ def get( pgpu_ref )
16
+ if pgpu_ref && pgpu = service.get_record( pgpu_ref, 'PGPU' )
17
+ new(pgpu)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,57 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+
7
+ class PIF < Fog::Model
8
+ # API Reference here:
9
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=PIF
10
+
11
+ identity :reference
12
+
13
+ attribute :uuid
14
+ attribute :__bond_master_of, :aliases => :bond_master_of
15
+ attribute :__bond_slave_of, :aliases => :bond_slave_of
16
+ attribute :disallow_unplug
17
+ attribute :physical
18
+ attribute :mac, :aliases => :MAC
19
+ attribute :currently_attached
20
+ attribute :device
21
+ attribute :device_name
22
+ attribute :metrics
23
+ attribute :dns, :aliases => :DNS
24
+ attribute :gateway
25
+ attribute :ip, :aliases => :IP
26
+ attribute :ip_configuration_mode
27
+ attribute :ipv6, :aliases => :IPv6
28
+ attribute :ipv6_configuration_mode
29
+ attribute :ipv6_gateway
30
+ attribute :mtu, :aliases => :MTU
31
+ attribute :__network, :aliases => :network
32
+ attribute :netmask
33
+ attribute :status_code
34
+ attribute :status_detail
35
+ attribute :management
36
+ attribute :primary_address_type
37
+ attribute :__tunnel_access_pif_of, :aliases => :tunnel_access_PIF_of
38
+ attribute :__tunnel_transport_pif_of, :aliases => :tunnel_transport_PIF_of
39
+ attribute :vlan, :aliases => :VLAN
40
+ attribute :vlan_master_of, :aliases => :VLAN_master_of
41
+ attribute :vlan_slave_of, :aliases => :VLAN_slave_of
42
+ attribute :other_config
43
+ attribute :__host, :aliases => :host
44
+
45
+ def network
46
+ service.networks.get __network
47
+ end
48
+
49
+ def host
50
+ service.hosts.get __host
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+ class PifMetrics < Fog::Model
7
+ # API Reference here:
8
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=PIF_metrics
9
+
10
+ identity :reference
11
+
12
+ attribute :carrier
13
+ attribute :device_id
14
+ attribute :device_name
15
+ attribute :duplex
16
+ attribute :io_read_kbs
17
+ attribute :io_write_kbs
18
+ attribute :last_updated
19
+ attribute :other_config
20
+ attribute :pci_bus_path
21
+ attribute :speed
22
+ attribute :uuid
23
+ attribute :vendor_id
24
+ attribute :vendor_name
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/pif'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+
8
+ class Pifs < Fog::Collection
9
+
10
+ model Fog::Compute::XenServer::PIF
11
+
12
+ def initialize(attributes)
13
+ super
14
+ end
15
+
16
+ def all(options = {})
17
+ data = service.get_records 'PIF'
18
+ load(data)
19
+ end
20
+
21
+ def get( ref )
22
+ if ref && obj = service.get_record( ref, 'PIF' )
23
+ new(obj)
24
+ end
25
+ rescue Fog::XenServer::NotFound
26
+ nil
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/pif_metrics'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+ class PifsMetrics < Fog::Collection
8
+ model Fog::Compute::XenServer::PifMetrics
9
+
10
+ def all(options={})
11
+ data = service.get_records 'PIF_metrics'
12
+ load(data)
13
+ end
14
+
15
+ def get( pif_metrics_ref )
16
+ if pif_metrics_ref && pif_metrics = service.get_record( pif_metrics_ref, 'PIF_metrics' )
17
+ new(pif_metrics)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,79 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+
7
+ class Pool < Fog::Model
8
+ # API Reference here:
9
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=pool
10
+
11
+ identity :reference
12
+
13
+ attribute :uuid
14
+ attribute :blobs
15
+ attribute :__crash_dump_sr, :aliases => :crash_dump_SR
16
+ attribute :name, :aliases => :name_label
17
+ attribute :description, :aliases => :name_description
18
+ attribute :__default_sr, :aliases => :default_SR
19
+ attribute :gui_config
20
+ attribute :ha_allow_overcommit
21
+ attribute :ha_configuration
22
+ attribute :__master, :aliases => :master
23
+ attribute :tags
24
+ attribute :restrictions
25
+ attribute :ha_enabled
26
+ attribute :ha_host_failures_to_tolerate
27
+ attribute :ha_overcommitted
28
+ attribute :ha_plan_exists_for
29
+ attribute :ha_statefiles
30
+ attribute :__metadata_vdis, :aliases => :metadata_VDIs
31
+ attribute :other_config
32
+ attribute :redo_log_enabled
33
+ attribute :redo_log_vdi
34
+ attribute :vswitch_controller
35
+ attribute :__suspend_image_sr, :aliases => :suspend_image_SR
36
+ attribute :wlb_enabled
37
+ attribute :wlb_url
38
+ attribute :wlb_username
39
+ attribute :wlb_verify_cert
40
+
41
+
42
+ def default_sr
43
+ service.storage_repositories.get __default_sr
44
+ end
45
+
46
+ def default_sr=(sr)
47
+ service.set_attribute( 'pool', reference, 'default_SR', sr.reference )
48
+ end
49
+ alias :default_storage_repository= :default_sr=
50
+
51
+ def default_storage_repository
52
+ default_sr
53
+ end
54
+
55
+ def suspend_image_sr=(sr)
56
+ service.set_attribute( 'pool', reference, 'suspend_image_SR', sr.reference )
57
+ end
58
+
59
+ def suspend_image_sr
60
+ service.storage_repositories.get __suspend_image_sr
61
+ end
62
+
63
+ def master
64
+ service.hosts.get __master
65
+ end
66
+
67
+ def set_attribute(name, *val)
68
+ data = service.set_attribute( 'pool', reference, name, *val )
69
+ # Do not reload automatically for performance reasons
70
+ # We can set multiple attributes at the same time and
71
+ # then reload manually
72
+ #reload
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,24 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+ class PoolPatch < Fog::Model
7
+ # API Reference here:
8
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=pool_patch
9
+
10
+ identity :reference
11
+
12
+ attribute :after_apply_guidance
13
+ attribute :__host_patches, :aliases => :host_patches
14
+ attribute :description, :aliases => :name_description
15
+ attribute :name, :aliases => :name_label
16
+ attribute :other_config
17
+ attribute :pool_applied
18
+ attribute :size
19
+ attribute :uuid
20
+ attribute :version
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/pool_patch'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+ class PoolPatchs < Fog::Collection
8
+ model Fog::Compute::XenServer::PoolPatch
9
+
10
+ def all(options={})
11
+ data = service.get_records 'pool_patch'
12
+ load(data)
13
+ end
14
+
15
+ def get( pool_patch_ref )
16
+ if pool_patch_ref && pool_patch = service.get_record( pool_patch_ref, 'pool_patch' )
17
+ new(pool_patch)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/pool'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+
8
+ class Pools < Fog::Collection
9
+
10
+ model Fog::Compute::XenServer::Pool
11
+
12
+ def initialize(attributes)
13
+ super
14
+ end
15
+
16
+ def all(options = {})
17
+ data = service.get_records 'pool'
18
+ load(data)
19
+ end
20
+
21
+ def get( pool_ref )
22
+ if pool_ref && pool = service.get_record( pool_ref, 'pool' )
23
+ new(pool)
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+ class Role < Fog::Model
7
+ # API Reference here:
8
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=role
9
+
10
+ identity :reference
11
+
12
+ attribute :description, :aliases => :name_description
13
+ attribute :name, :aliases => :name_label
14
+ attribute :__subroles, :aliases => :subroles
15
+ attribute :uuid
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ require 'fog/core/collection'
2
+ require 'fog/xenserver/models/compute/role'
3
+
4
+ module Fog
5
+ module Compute
6
+ class XenServer
7
+ class Roles < Fog::Collection
8
+ model Fog::Compute::XenServer::Role
9
+
10
+ def all(options={})
11
+ data = service.get_records 'role'
12
+ load(data)
13
+ end
14
+
15
+ def get( role_ref )
16
+ if role_ref && role = service.get_record( role_ref, 'role' )
17
+ new(role)
18
+ else
19
+ nil
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,250 @@
1
+ require 'fog/compute/models/server'
2
+
3
+ module Fog
4
+ module Compute
5
+ class XenServer
6
+
7
+ class Server < Fog::Compute::Server
8
+ # API Reference here:
9
+ # http://docs.vmd.citrix.com/XenServer/6.2.0/1.0/en_gb/api/?c=VM
10
+
11
+ identity :reference
12
+
13
+ attribute :uuid
14
+ attribute :name, :aliases => :name_label
15
+ attribute :description, :aliases => :name_description
16
+ attribute :__affinity, :aliases => :affinity
17
+ attribute :actions_after_crash
18
+ attribute :actions_after_reboot
19
+ attribute :actions_after_shutdown
20
+ attribute :allowed_operations
21
+ attribute :__consoles, :aliases => :consoles
22
+ attribute :__attached_pcis, :aliases => :attached_PCIs
23
+ attribute :bios_strings
24
+ attribute :blobs
25
+ attribute :blocked_operations
26
+ attribute :__children, :aliases => :children
27
+ attribute :__crash_dumps, :aliases => :crash_dumps
28
+ attribute :current_operations
29
+ attribute :domarch
30
+ attribute :domid
31
+ attribute :generation_id
32
+ attribute :tags
33
+ attribute :__guest_metrics, :aliases => :guest_metrics
34
+ attribute :ha_always_run
35
+ attribute :ha_restart_priority
36
+ attribute :is_a_snapshot
37
+ attribute :is_a_template
38
+ attribute :is_control_domain
39
+ attribute :is_snapshot_from_vmpp
40
+ attribute :last_boot_cpu_flags, :aliases => :last_boot_CPU_flags
41
+ attribute :last_booted_record
42
+ attribute :memory_dynamic_max
43
+ attribute :memory_dynamic_min
44
+ attribute :memory_overhead
45
+ attribute :memory_static_max
46
+ attribute :memory_static_min
47
+ attribute :memory_target
48
+ attribute :__metrics, :aliases => :metrics
49
+ attribute :order
50
+ attribute :other_config
51
+ attribute :__parent, :aliases => :parent
52
+ attribute :platform
53
+ attribute :power_state
54
+ attribute :protection_policy
55
+ attribute :pv_args, :aliases => :PV_args
56
+ attribute :pv_bootloader, :aliases => :PV_bootloader
57
+ attribute :pv_bootloader_args, :aliases => :PV_bootloader_args
58
+ attribute :pv_kernel, :aliases => :PV_kernel
59
+ attribute :pv_ramdisk, :aliases => :PV_ramdisk
60
+ attribute :pv_legacy_args, :aliases => :PV_legacy_args
61
+ attribute :recommendations
62
+ attribute :__resident_on, :aliases => :resident_on
63
+ attribute :shutdown_delay
64
+ attribute :snapshot_info
65
+ attribute :snapshot_metadata
66
+ attribute :__snapshot_of, :aliases => :snapshot_of
67
+ attribute :snapshot_time
68
+ attribute :start_delay
69
+ attribute :__suspend_sr, :aliases => :suspend_sr
70
+ attribute :__suspend_vdi, :aliases => :suspend_VDI
71
+ attribute :transportable_snapshot_id
72
+ attribute :user_version
73
+ attribute :version
74
+ attribute :__vgpus, :aliases => :VGPUs
75
+ attribute :__vtpms, :aliases => :VTPMs
76
+ attribute :xenstore_data
77
+ # Virtual Block Devices
78
+ attribute :__vbds, :aliases => :VBDs
79
+ # Virtual CPUs
80
+ attribute :vcpus_at_startup, :aliases => :VCPUs_at_startup
81
+ attribute :vcpus_max, :aliases => :VCPUs_max
82
+ attribute :vcpus_params, :aliases => :VCPUs_params
83
+ # Virtual Interfaces (NIC)
84
+ attribute :__vifs, :aliases => :VIFs
85
+ attribute :template_name
86
+ attribute :hvm_boot_policy, :aliases => :HVM_boot_policy
87
+ attribute :hvm_boot_params, :aliases => :HVM_boot_params
88
+ attribute :hvm_shadow_multiplier, :aliases => :HVM_shadow_multiplier
89
+ attribute :pci_bus, :aliases => :PCI_bus
90
+ attribute :snapshots
91
+
92
+ def vbds
93
+ __vbds.collect {|vbd| service.vbds.get vbd }
94
+ end
95
+
96
+ def affinity
97
+ service.hosts.get __affinity
98
+ end
99
+
100
+ def consoles
101
+ __consoles.collect {|console| service.consoles.get console }
102
+ end
103
+
104
+ def destroy
105
+ # Make sure it's halted
106
+ stop('hard')
107
+ vbds.each do |vbd|
108
+ if vbd.type == "Disk"
109
+ vbd.unplug \
110
+ if vbd.allowed_operations.include?("unplug")
111
+ vbd.vdi.destroy \
112
+ if vbd.vdi.allowed_operations.include?("destroy")
113
+ end
114
+ end
115
+ service.destroy_server( reference )
116
+ true
117
+ end
118
+
119
+ def set_attribute(name, *val)
120
+ data = service.set_attribute( 'VM', reference, name, *val )
121
+ # Do not reload automatically for performance reasons
122
+ # We can set multiple attributes at the same time and
123
+ # then reload manually
124
+ #reload
125
+ end
126
+
127
+ def refresh
128
+ data = service.get_record( reference, 'VM' )
129
+ merge_attributes( data )
130
+ true
131
+ end
132
+
133
+ def vifs
134
+ __vifs.collect { |vif| service.vifs.get vif }
135
+ end
136
+
137
+ # associations
138
+ def networks
139
+ vifs.collect { |v| v.network }
140
+ end
141
+
142
+ def resident_on
143
+ service.hosts.get __resident_on
144
+ end
145
+
146
+ #
147
+ # This is not always present in XenServer VMs
148
+ # Guest needs XenTools installed to report this AFAIK
149
+ def guest_metrics
150
+ return nil unless __guest_metrics
151
+ rec = service.get_record( __guest_metrics, 'VM_guest_metrics' )
152
+ Fog::Compute::XenServer::GuestMetrics.new(rec)
153
+ end
154
+
155
+ def tools_installed?
156
+ !guest_metrics.nil?
157
+ end
158
+
159
+ def home_hypervisor
160
+ service.hosts.first
161
+ end
162
+
163
+ def mac_address
164
+ networks.first.MAC
165
+ end
166
+
167
+ def running?
168
+ reload
169
+ power_state == "Running"
170
+ end
171
+
172
+ def halted?
173
+ reload
174
+ power_state == "Halted"
175
+ end
176
+
177
+ # operations
178
+ def start
179
+ return false if running?
180
+ service.start_server( reference )
181
+ true
182
+ end
183
+
184
+ def save(params = {})
185
+ requires :name
186
+ nets = attributes[:networks] || []
187
+ if params[:auto_start].nil?
188
+ auto_start = true
189
+ else
190
+ auto_start = params[:auto_start]
191
+ end
192
+ if template_name
193
+ attr = service.get_record(
194
+ service.create_server( name, template_name, nets, :auto_start => auto_start),
195
+ 'VM'
196
+ )
197
+ else
198
+ attr = service.get_record(
199
+ service.create_server_raw(attributes),
200
+ 'VM'
201
+ )
202
+ end
203
+ merge_attributes attr
204
+ true
205
+ end
206
+
207
+ def reboot(stype = 'clean')
208
+ service.reboot_server(reference, stype)
209
+ true
210
+ end
211
+
212
+ def hard_reboot
213
+ reboot 'hard'
214
+ end
215
+
216
+ def clean_reboot
217
+ reboot 'clean'
218
+ end
219
+
220
+ def stop(stype = 'clean')
221
+ return false if !running?
222
+ service.shutdown_server( reference, stype )
223
+ wait_for { power_state == 'Halted' }
224
+ true
225
+ end
226
+
227
+ def hard_shutdown
228
+ stop 'hard'
229
+ end
230
+
231
+ def clean_shutdown
232
+ stop 'clean'
233
+ end
234
+
235
+ def provision
236
+ service.provision_server reference
237
+ end
238
+
239
+ def snapshot(name)
240
+ service.snapshot_server(reference, name)
241
+ end
242
+
243
+ def revert(snapshot_ref)
244
+ service.snapshot_revert(snapshot_ref)
245
+ end
246
+ end
247
+
248
+ end
249
+ end
250
+ end