Class: Vmpooler::PoolManager::Provider::Base
- Inherits:
-
Object
- Object
- Vmpooler::PoolManager::Provider::Base
- Defined in:
- lib/vmpooler/providers/base.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Helper Methods Global Logger object.
-
#metrics ⇒ Object
readonly
Global Metrics object.
-
#provider_options ⇒ Object
readonly
Provider options passed in during initialization.
Instance Method Summary collapse
-
#create_disk(_pool_name, _vm_name, _disk_size) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to create the disk on [Integer] disk_size : Size of the disk to create in Gigabytes (GB) returns [Boolean] : true if success, false if disk could not be created Raises RuntimeError if the Pool does not exist Raises RuntimeError if the VM does not exist.
-
#create_snapshot(_pool_name, _vm_name, _new_snapshot_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] new_vmname : Name of the VM to create the snapshot on [String] new_snapshot_name : Name of the new snapshot to create returns [Boolean] : true if success, false if snapshot could not be created Raises RuntimeError if the Pool does not exist Raises RuntimeError if the VM does not exist.
-
#create_template_delta_disks(pool) ⇒ Object
inputs [Hash] pool : Configuration for the pool returns nil when successful.
-
#create_vm(_pool_name, _new_vmname) ⇒ Object
inputs [String] pool : Name of the pool [String] new_vmname : Name to give the new VM returns [Hashtable] of the VM as per get_vm Raises RuntimeError if the pool_name is not supported by the Provider.
-
#destroy_vm(_pool_name, _vm_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to destroy returns [Boolean] : true if success, false on error.
-
#find_least_used_compatible_host(_pool_name, _vm_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM returns [String] : Name of the most appropriate host computer to run this VM.
-
#get_target_datacenter_from_config(provider_name) ⇒ Object
inputs [String] provider_name : Name of the provider returns Hash of folders.
-
#get_vm(_pool_name, _vm_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to find returns nil if VM doesn’t exist [Hastable] of the VM [String] name : Name of the VM [String] hostname : Name reported by Vmware tools (host.summary.guest.hostName) [String] template : This is the name of template exposed by the API.
-
#get_vm_host(_pool_name, _vm_name) ⇒ Object
inputs [String]pool_name : Name of the pool [String] vm_name : Name of the VM returns [String] : Name of the host computer running the vm.
-
#global_config ⇒ Object
returns [Hashtable] : The entire VMPooler configuration.
-
#initialize(config, logger, metrics, name, options) ⇒ Base
constructor
A new instance of Base.
-
#migrate_vm(_pool_name, _vm_name, _redis) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to migrate [Class] redis : Redis object.
-
#migrate_vm_to_host(_pool_name, _vm_name, _dest_host_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to migrate [String] dest_host_name : Name of the host to migrate ‘vm_name` to returns [Boolean] : true on success or false on failure.
-
#name ⇒ Object
returns [String] : Name of the provider service.
-
#pool_config(pool_name) ⇒ Object
inputs [String] pool_name : Name of the pool to get the configuration returns [Hashtable] : The pools configuration from the config file.
-
#provided_pools ⇒ Object
returns Array : Array of pool names this provider services.
-
#provider_config ⇒ Object
returns [Hashtable] : This provider’s configuration from the config file.
- #purge_unconfigured_folders(base_folders, configured_folders, whitelist) ⇒ Object
-
#revert_snapshot(_pool_name, _vm_name, _snapshot_name) ⇒ Object
inputs [String] pool_name : Name of the pool [String] new_vmname : Name of the VM to restore [String] snapshot_name : Name of the snapshot to restore to returns [Boolean] : true if success, false if snapshot could not be revertted Raises RuntimeError if the Pool does not exist Raises RuntimeError if the VM does not exist Raises RuntimeError if the snapshot does not exist.
-
#vm_exists?(pool_name, vm_name) ⇒ Boolean
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to check if it exists returns [Boolean] : true if it exists, false if not.
-
#vm_ready?(_pool_name, _vm_name) ⇒ Boolean
inputs [String] pool_name : Name of the pool [String] vm_name : Name of the VM to check if ready returns [Boolean] : true if ready, false if not.
-
#vms_in_pool(_pool_name) ⇒ Object
inputs [String] pool_name : Name of the pool returns Array Hash contains: ‘name’ => [String] Name of VM.
Constructor Details
#initialize(config, logger, metrics, name, options) ⇒ Base
Returns a new instance of Base.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vmpooler/providers/base.rb', line 15 def initialize(config, logger, metrics, name, ) @config = config @logger = logger @metrics = metrics @provider_name = name # Ensure that there is not a nil provider configuration @config[:providers] = {} if @config[:providers].nil? @config[:providers][@provider_name] = {} if provider_config.nil? # Ensure that there is not a nil pool configuration @config[:pools] = {} if @config[:pools].nil? @provider_options = logger.log('s', "[!] Creating provider '#{name}'") end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Helper Methods Global Logger object
9 10 11 |
# File 'lib/vmpooler/providers/base.rb', line 9 def logger @logger end |
#metrics ⇒ Object (readonly)
Global Metrics object
11 12 13 |
# File 'lib/vmpooler/providers/base.rb', line 11 def metrics @metrics end |
#provider_options ⇒ Object (readonly)
Provider options passed in during initialization
13 14 15 |
# File 'lib/vmpooler/providers/base.rb', line 13 def @provider_options end |
Instance Method Details
#create_disk(_pool_name, _vm_name, _disk_size) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to create the disk on
[Integer] disk_size : Size of the disk to create in Gigabytes (GB)
returns
[Boolean] : true if success, false if disk could not be created
Raises RuntimeError if the Pool does not exist
Raises RuntimeError if the VM does not exist
165 166 167 |
# File 'lib/vmpooler/providers/base.rb', line 165 def create_disk(_pool_name, _vm_name, _disk_size) raise("#{self.class.name} does not implement create_disk") end |
#create_snapshot(_pool_name, _vm_name, _new_snapshot_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] new_vmname : Name of the VM to create the snapshot on
[String] new_snapshot_name : Name of the new snapshot to create
returns
[Boolean] : true if success, false if snapshot could not be created
Raises RuntimeError if the Pool does not exist
Raises RuntimeError if the VM does not exist
177 178 179 |
# File 'lib/vmpooler/providers/base.rb', line 177 def create_snapshot(_pool_name, _vm_name, _new_snapshot_name) raise("#{self.class.name} does not implement create_snapshot") end |
#create_template_delta_disks(pool) ⇒ Object
inputs
[Hash] pool : Configuration for the pool
returns
nil when successful. Raises error when encountered
225 226 227 |
# File 'lib/vmpooler/providers/base.rb', line 225 def create_template_delta_disks(pool) raise("#{self.class.name} does not implement create_template_delta_disks") end |
#create_vm(_pool_name, _new_vmname) ⇒ Object
inputs
[String] pool : Name of the pool
[String] new_vmname : Name to give the new VM
returns
[Hashtable] of the VM as per get_vm
Raises RuntimeError if the pool_name is not supported by the Provider
153 154 155 |
# File 'lib/vmpooler/providers/base.rb', line 153 def create_vm(_pool_name, _new_vmname) raise("#{self.class.name} does not implement create_vm") end |
#destroy_vm(_pool_name, _vm_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to destroy
returns
[Boolean] : true if success, false on error. Should returns true if the VM is missing
199 200 201 |
# File 'lib/vmpooler/providers/base.rb', line 199 def destroy_vm(_pool_name, _vm_name) raise("#{self.class.name} does not implement destroy_vm") end |
#find_least_used_compatible_host(_pool_name, _vm_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM
returns
[String] : Name of the most appropriate host computer to run this VM. Useful for load balancing VMs in a cluster
If this is not a Virtual Machine, it returns the vm_name
108 109 110 |
# File 'lib/vmpooler/providers/base.rb', line 108 def find_least_used_compatible_host(_pool_name, _vm_name) raise("#{self.class.name} does not implement find_least_used_compatible_host") end |
#get_target_datacenter_from_config(provider_name) ⇒ Object
inputs
[String] provider_name : Name of the provider
returns
Hash of folders
233 234 235 |
# File 'lib/vmpooler/providers/base.rb', line 233 def get_target_datacenter_from_config(provider_name) raise("#{self.class.name} does not implement get_target_datacenter_from_config") end |
#get_vm(_pool_name, _vm_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to find
returns
nil if VM doesn't exist
[Hastable] of the VM
[String] name : Name of the VM
[String] hostname : Name reported by Vmware tools (host.summary.guest.hostName)
[String] template : This is the name of template exposed by the API. It must _match_ the poolname
[String] poolname : Name of the pool the VM is located
[Time] boottime : Time when the VM was created/booted
[String] powerstate : Current power state of a VM. Valid values (as per vCenter API)
- 'PoweredOn','PoweredOff'
143 144 145 |
# File 'lib/vmpooler/providers/base.rb', line 143 def get_vm(_pool_name, _vm_name) raise("#{self.class.name} does not implement get_vm") end |
#get_vm_host(_pool_name, _vm_name) ⇒ Object
inputs
[String]pool_name : Name of the pool
[String] vm_name : Name of the VM
returns
[String] : Name of the host computer running the vm. If this is not a Virtual Machine, it returns the vm_name
98 99 100 |
# File 'lib/vmpooler/providers/base.rb', line 98 def get_vm_host(_pool_name, _vm_name) raise("#{self.class.name} does not implement get_vm_host") end |
#global_config ⇒ Object
returns
[Hashtable] : The entire VMPooler configuration
60 61 62 63 |
# File 'lib/vmpooler/providers/base.rb', line 60 def global_config # This entire VM Pooler config @config end |
#migrate_vm(_pool_name, _vm_name, _redis) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to migrate
[Class] redis : Redis object
126 127 128 |
# File 'lib/vmpooler/providers/base.rb', line 126 def migrate_vm(_pool_name, _vm_name, _redis) raise("#{self.class.name} does not implement migrate_vm") end |
#migrate_vm_to_host(_pool_name, _vm_name, _dest_host_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to migrate
[String] dest_host_name : Name of the host to migrate `vm_name` to
returns
[Boolean] : true on success or false on failure
118 119 120 |
# File 'lib/vmpooler/providers/base.rb', line 118 def migrate_vm_to_host(_pool_name, _vm_name, _dest_host_name) raise("#{self.class.name} does not implement migrate_vm_to_host") end |
#name ⇒ Object
returns
[String] : Name of the provider service
67 68 69 |
# File 'lib/vmpooler/providers/base.rb', line 67 def name @provider_name end |
#pool_config(pool_name) ⇒ Object
inputs
[String] pool_name : Name of the pool to get the configuration
returns
[Hashtable] : The pools configuration from the config file. Returns nil if the pool does not exist
38 39 40 41 42 43 44 45 |
# File 'lib/vmpooler/providers/base.rb', line 38 def pool_config(pool_name) # Get the configuration of a specific pool @config[:pools].each do |pool| return pool if pool['name'] == pool_name end nil end |
#provided_pools ⇒ Object
returns
Array[String] : Array of pool names this provider services
73 74 75 76 77 78 79 |
# File 'lib/vmpooler/providers/base.rb', line 73 def provided_pools list = [] @config[:pools].each do |pool| list << pool['name'] if pool['provider'] == name end list end |
#provider_config ⇒ Object
returns
[Hashtable] : This provider's configuration from the config file. Returns nil if the provider does not exist
49 50 51 52 53 54 55 56 |
# File 'lib/vmpooler/providers/base.rb', line 49 def provider_config @config[:providers].each do |provider| # Convert the symbol from the config into a string for comparison return (provider[1].nil? ? {} : provider[1]) if provider[0].to_s == @provider_name end nil end |
#purge_unconfigured_folders(base_folders, configured_folders, whitelist) ⇒ Object
237 238 239 |
# File 'lib/vmpooler/providers/base.rb', line 237 def purge_unconfigured_folders(base_folders, configured_folders, whitelist) raise("#{self.class.name} does not implement purge_unconfigured_folders") end |
#revert_snapshot(_pool_name, _vm_name, _snapshot_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
[String] new_vmname : Name of the VM to restore
[String] snapshot_name : Name of the snapshot to restore to
returns
[Boolean] : true if success, false if snapshot could not be revertted
Raises RuntimeError if the Pool does not exist
Raises RuntimeError if the VM does not exist
Raises RuntimeError if the snapshot does not exist
190 191 192 |
# File 'lib/vmpooler/providers/base.rb', line 190 def revert_snapshot(_pool_name, _vm_name, _snapshot_name) raise("#{self.class.name} does not implement revert_snapshot") end |
#vm_exists?(pool_name, vm_name) ⇒ Boolean
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to check if it exists
returns
[Boolean] : true if it exists, false if not
217 218 219 |
# File 'lib/vmpooler/providers/base.rb', line 217 def vm_exists?(pool_name, vm_name) !get_vm(pool_name, vm_name).nil? end |
#vm_ready?(_pool_name, _vm_name) ⇒ Boolean
inputs
[String] pool_name : Name of the pool
[String] vm_name : Name of the VM to check if ready
returns
[Boolean] : true if ready, false if not
208 209 210 |
# File 'lib/vmpooler/providers/base.rb', line 208 def vm_ready?(_pool_name, _vm_name) raise("#{self.class.name} does not implement vm_ready?") end |
#vms_in_pool(_pool_name) ⇒ Object
inputs
[String] pool_name : Name of the pool
returns
Array[Hashtable]
Hash contains:
'name' => [String] Name of VM
89 90 91 |
# File 'lib/vmpooler/providers/base.rb', line 89 def vms_in_pool(_pool_name) raise("#{self.class.name} does not implement vms_in_pool") end |