Class: Vanagon::Engine::Hardware

Inherits:
Base
  • Object
show all
Defined in:
lib/vanagon/engine/hardware.rb

Overview

Class to use when building on a hardware device (e.g. AIX, Switch, etc)

Instance Attribute Summary

Attributes inherited from Base

#remote_workdir, #target

Instance Method Summary collapse

Methods inherited from Base

#dispatch, #get_remote_workdir, #retrieve_built_artifact, #setup, #ship_workdir, #startup, #validate_platform

Constructor Details

#initialize(platform, target, **opts) ⇒ Hardware

Returns a new instance of Hardware.



53
54
55
56
57
58
59
60
61
# 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

Instance Method Details

#build_host_nameObject

Get the first build host name to build on



69
70
71
72
73
74
75
76
77
78
79
# 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

#nameObject

Get the engine name



64
65
66
# File 'lib/vanagon/engine/hardware.rb', line 64

def name
  'hardware'
end

#node_lock(hosts) ⇒ Object

Iterate over the options and find a node open to lock.



32
33
34
35
36
37
38
39
40
41
42
43
# 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) ⇒ Object

Poll for a lock



23
24
25
26
27
28
29
# 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_targetObject

This method is used to obtain a vm to build upon For the base class we just return the target that was passed in



18
19
20
# File 'lib/vanagon/engine/hardware.rb', line 18

def select_target
  @target = node_lock(@build_hosts)
end

#teardownObject

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



47
48
49
50
51
# 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