class Vanagon::Engine::Hardware
Class to use when building on a hardware device (e.g. AIX, Switch, etc)
Public Class Methods
new(platform, target, **opts)
click to toggle source
Calls superclass method
Vanagon::Engine::Base::new
# File lib/vanagon/engine/hardware.rb, line 53 def initialize(platform, target, **opts) super Vanagon::Driver.logger.debug "Hardware engine invoked." @build_hosts = platform.build_hosts # Redis is the only backend supported in lock_manager currently @lockman = LockManager.new(type: 'redis', server: LOCK_MANAGER_HOST) @required_attributes << "build_hosts" end
Public Instance Methods
build_host_name()
click to toggle source
Get the first build host name to build on
# File lib/vanagon/engine/hardware.rb, line 69 def build_host_name if @build_host_name.nil? validate_platform # For now, get the first build host. In the future, lock management # will be pushed into the pooler (or something that wraps it), and # the hardware engine can go away. @build_host_name = @build_hosts.first end @build_host_name end
name()
click to toggle source
Get the engine name
# File lib/vanagon/engine/hardware.rb, line 64 def name 'hardware' end
node_lock(hosts)
click to toggle source
Iterate over the options and find a node open to lock.
# File lib/vanagon/engine/hardware.rb, line 32 def node_lock(hosts) hosts.each do |h| Vanagon::Driver.logger.info "Attempting to lock #{h}." if @lockman.lock(h, VANAGON_LOCK_USER, "Vanagon automated lock") Vanagon::Driver.logger.info "Lock acquired on #{h}." VanagonLogger.info "Lock acquired on #{h} for #{VANAGON_LOCK_USER}." return h end end # If they are all locked, fall back to a polling lock on last item polling_lock(hosts.pop) end
polling_lock(host)
click to toggle source
Poll for a lock
# File lib/vanagon/engine/hardware.rb, line 23 def polling_lock(host) Vanagon::Driver.logger.info "Polling for a lock on #{host}." @lockman.polling_lock(host, VANAGON_LOCK_USER, "Vanagon automated lock") Vanagon::Driver.logger.info "Lock acquired on #{host}." VanagonLogger.info "Lock acquired on #{host} for #{VANAGON_LOCK_USER}." host end
select_target()
click to toggle source
This method is used to obtain a vm to build upon For the base class we just return the target that was passed in
# File lib/vanagon/engine/hardware.rb, line 18 def select_target @target = node_lock(@build_hosts) end
teardown()
click to toggle source
Steps needed to tear down or clean up the system after the build is complete. In this case, we’ll attempt to unlock the hardware
# File lib/vanagon/engine/hardware.rb, line 47 def teardown Vanagon::Driver.logger.info "Removing lock on #{@target}." VanagonLogger.info "Removing lock on #{@target}." @lockman.unlock(@target, VANAGON_LOCK_USER) end