Class: Chef::Knife::HmcServerConfig

Inherits:
Chef::Knife show all
Includes:
HmcBase
Defined in:
lib/chef/knife/hmc_server_config.rb

Instance Method Summary collapse

Methods included from HmcBase

#get_config, included, #tcp_ssh_alive, #validate, #validate!

Instance Method Details

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/chef/knife/hmc_server_config.rb', line 35

def run
 Chef::Log.debug("Configuring server...")

  validate!
  validate!([:lpar,:frame, :attributes])
  hmc = Hmc.new(get_config(:hmc_host), get_config(:hmc_username) , {:password => get_config(:hmc_password)}) 
  hmc.connect

  options_hash = hmc.get_lpar_options(get_config(:frame),get_config(:lpar))
  lpar = Lpar.new(options_hash)

  puts "Configuring #{lpar.name}..."

  attrs = get_config(:attributes)
  attrs.each do |operation|
    key,value = operation.split('=')
    case key
    when "name"
      old_name = lpar.name
      lpar.rename(value)
      puts "Changed name from #{old_name} to #{lpar.name}"
    when "max_virtual_slots"
      old_max = lpar.max_virtual_slots
      lpar.max_virtual_slots = value.to_i
      puts "Changed max_virtual_slots from #{old_max} to #{lpar.max_virtual_slots}"
    when "uncap_weight"
      old_weight = lpar.uncap_weight
      unless (lpar.uncap_weight = value.to_i).nil?
        puts "Changed uncap_weight from #{old_weight} to #{lpar.uncap_weight}"
      end
    when "desired_proc_units"
      old_units = lpar.desired_proc_units
      lpar.desired_proc_units = value.to_f
      puts "Changed desired_proc_units from #{old_units} to #{lpar.desired_proc_units}"
    when "max_proc_units"
      old_units = lpar.max_proc_units
      lpar.max_proc_units = value.to_f
      puts "Changed max_proc_units from #{old_units} to #{lpar.max_proc_units}"
    when "min_proc_units"
      old_units = lpar.min_proc_units
      lpar.min_proc_units = value.to_f
      puts "Changed min_proc_units from #{old_units} to #{lpar.min_proc_units}"
    when "desired_vcpu"
      old_units = lpar.desired_vcpu
      lpar.desired_vcpu = value.to_i
      puts "Changed desired_vcpu from #{old_units} to #{lpar.desired_vcpu}"
    when "max_vcpu"
      old_units = lpar.max_vcpu
      lpar.max_vcpu = value.to_i
      puts "Changed max_vcpu from #{old_units} to #{lpar.max_vcpu}"
    when "min_vcpu"
      old_units = lpar.min_vcpu
      lpar.min_vcpu = value.to_i
      puts "Changed min_vcpu from #{old_units} to #{lpar.min_vcpu}"
    when "desired_memory"
      old_units = lpar.desired_memory
      lpar.desired_memory = value.to_i
      puts "Changed desired_memory from #{old_units} to #{lpar.desired_memory}"
    when "max_memory"
      old_units = lpar.max_memory
      lpar.max_memory = value.to_i
      puts "Changed max_memory from #{old_units} to #{lpar.max_memory}"
    when "min_memory"
      old_units = lpar.min_memory
      lpar.min_memory = value.to_i
      puts "Changed min_memory from #{old_units} to #{lpar.min_memory}"
    else
      puts "Unrecognized attribute #{key}, proceeding to next config change..."
    end
  end

  hmc.disconnect
end