class Chef::Knife::HmcServerState

Public Instance Methods

run() click to toggle source
# File lib/chef/knife/hmc_server_state.rb, line 46
        def run
        Chef::Log.debug("Changing State...")

                validate!([:frame_name,:lpar_name])

                hmc = Hmc.new(get_config(:hmc_host), get_config(:hmc_username) , {:password => get_config(:hmc_password)}) 
        hmc.connect

        #Populate hash to make LPAR object
        lpar_hash = hmc.get_lpar_options(get_config(:frame_name),get_config(:lpar_name))
        #Create LPAR object based on hash, and VIO objects
        lpar = Lpar.new(lpar_hash)

        if validate([:power_on])
                if lpar.is_running?
                        puts "#{get_config(:lpar_name)} is already running, exiting"   
                        return true                  
                else
                        lpar.activate
                        puts "Powering on #{get_config(:lpar_name)}."
                end
        end

        if validate([:power_off_soft])
                lpar.soft_shutdown
                puts "Shutting down #{get_config(:lpar_name)}."
        end

        if validate([:power_off_quick])
                lpar.hard_shutdown
                puts "Performing hard power off of #{get_config(:lpar_name)}."
        end
        hmc.disconnect
end