Class: Staypuft::Fencing

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
app/models/staypuft/fencing.rb

Constant Summary collapse

FENCING_ATTRS =
{
  'general' => ['fencing_enabled',
                'fencing_type'],
  'fence_ipmilan' => ['fence_ipmilan_address',
                      'fence_ipmilan_username',
                      'fence_ipmilan_password',
                      'fence_ipmilan_expose_lanplus',
                      'fence_ipmilan_lanplus_options']
}

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ Fencing

Returns a new instance of Fencing.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/staypuft/fencing.rb', line 20

def initialize(host)
  @host = host
  FENCING_ATTRS.each do |key, attrs|
    attrs.each do |name|
      instance_var_name  = :"@#{name}"
      value = host.bmc_nic.attrs[name] if host.bmc_nic && host.bmc_nic.attrs.has_key?(name)
      self.class.send(:define_method, name) do
        instance_variable_get(instance_var_name) or
          instance_variable_set(instance_var_name, value)
      end
    end
  end
end

Instance Method Details

#marked_for_destruction?Boolean

compatibility with validates_associated

Returns:

  • (Boolean)


49
50
51
# File 'app/models/staypuft/fencing.rb', line 49

def marked_for_destruction?
  false
end

#update(values) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/staypuft/fencing.rb', line 34

def update(values)
  values.each do |key, value|
    instance_var_name  = :"@#{key}"
    instance_variable_set(instance_var_name, value)
  end

  bmc_nics = @host.interfaces.select{ |interface| interface.type == "Nic::BMC" }
  return if bmc_nics.empty?

  bmc_nic = bmc_nics[0]
  bmc_nic.attrs.merge!(values)
  bmc_nic.save
end