Introduce ipmi device emulations via qemu/virsh cmd line for the power management of the hypervisor

Introduce ipmi device emulations for the power management of the hypervisor

I. IPMI (intelligent platform maintenance interface)

II. Use the qemu & virsh command line as the "startcmd" parameter for IPMI emulations
1. for qemu command line
- Supported qemu version: at least from qemu v2.2
- How to define:
   #1 Create a BMC, normally done from ipmi_sim
   #1.1 for internal: basic BMC inside qemu, like watchdog timer.
   -device ipmi-bmc-sim,id=bmc0
   #or 1.2 for external: connects to an external BMC over a chardev, like power
   #management, watchdog timer, set sensor value.
   #(need to install OpenIPMI in the hypervisor)
   -chardev socket,id=ipmi0,host=localhost,port=9002,reconnect=10 \
   -device ipmi-bmc-extern,id=bmc1,chardev=ipmi0 \
   #2 Attach the BMC to an interface
   -device isa-ipmi-kcs,bmc=bmc1 \
   #or -device isa-ipmi-bt,bmc=bmc1 \
2. for virsh command line
- startcmd = 'virsh start/destroy/restart vm-name'
- For the guest vm, should add the ipmi simulator in its xml, like:
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
<name>vm-name</name>
...
<qemu:commandline>
<qemu:arg value='-chardev'/>
<qemu:arg value='socket,id=ipmi0,host=0.0.0.0,port=9002,reconnect=10'/>
<qemu:arg value='-device'/>
<qemu:arg value='ipmi-bmc-extern,chardev=ipmi0,id=bmc0'/>
<qemu:arg value='-device'/>
<qemu:arg value='isa-ipmi-bt,bmc=bmc0'/>
</qemu:commandline>
...
</domain>


III. Examples for external power status/on simulation
1. in the hypervisor
1.1 install OpenIPMI
$ zypper in OpenIPMI
1.2 use the default /etc/ipmi/lan.conf or config it as the following:
$ cat /etc/ipmi/lan.conf
name "ipmisim1"
set_working_mc 0x20
  startlan 1
    addr 192.168.27.126 9001
    priv_limit admin
    allowed_auths_callback none md2 md5 straight
    allowed_auths_user none md2 md5 straight
    allowed_auths_operator none md2 md5 straight
    allowed_auths_admin none md2 md5 straight
    guid a123456789abcdefa123456789abcdef
    lan_config_program "/etc/ipmi/ipmi_sim_lancontrol eth1"
  endlan
  serial 15 0.0.0.0 9002 codec VM
  startcmd "virsh start opensuse-42.3"

  startnow false

  user 1 true  ""        "test" user     10       none md2 md5 straight
  user 2 true  "ipmiusr" "test" admin    10       none md2 md5 straight

Tips:
* addr: the IP/port where the base system is listening for the ipmi client connections.
* serial: the connection to the VM ipmi device.
* startcmd: the command to run the a "power on" is issued. Either qemu command
            line or virsh command line (examples are in II.) can be used.
* user: the credentials to be used by the ipmi client.
        e.g. "ipmiusr" is the username and "test" is the password.

$ cat /etc/ipmi/imisim1.emu
# The BMC is the MC at address 20
mc_setbmc 0x20
# Now add the BMC
mc_add 0x20 0 no-device-sdrs 0x23 9 8 0x9f 0x1291 0xf02 persist_sdr
sel_enable 0x20 1000 0x0a
# Watchdog sensor.  This must be sensor zero.
sensor_add 0x20 0 0 35 0x6f event-only
sensor_set_event_support 0x20 0 0 enable scanning per-state \
        000000000001111 000000000000000 \
        000000000001111 000000000000000
# Add a temperature sensor and its SDR.  Note that sensor 0 is already
# taken as the watchdog sensor.
sensor_add 0x20 0 1 0x01 0x01
# Start with the value set to 0x60
sensor_set_value 0x20 0 1 0x60 0
# Set just the upper thresholds with the values 0x70, 0x90, and 0xa0
sensor_set_threshold 0x20 0 1 settable 111000 0xa0 0x90 0x70 00 00 00
# Enable all upper threshold events events
sensor_set_event_support 0x20 0 1 enable scanning per-state \
        000111111000000 000111111000000 \
        000111111000000 000111111000000
mc_enable 0x20

1.3 run ipmi_sim command:
$ ipmi_sim -c /etc/ipmi/lan.conf
IPMI Simulator version 1.0.13
# This is an example simulation setup for ipmi_sim.  It creates a single
# management controller as a BMC.  That will have the standard watchdog
# sensor and we add a temperature sensor.
...<snip>...
# Turn on the BMC
mc_enable 0x20
>

2. in the ipmi client
2.1 install ipmitool
$ zypper in ipmitool
2.2 test the ipmi device whether can power status/on/off the vm using ipmitool
$ ipmitool -I lanplus -H 192.168.27.126 -U ipmiusr -p 9001 power status
Password:
Chassis Power is off
$ ipmitool -I lanplus -H 192.168.27.126 -U ipmiusr -p 9001 power on
Password:
Chassis Power Control: Up/On
$ ipmitool -I lanplus -H 192.168.27.126 -U ipmiusr -P test -p 9001 power status
Chassis Power is on
$ ipmitool -I lanplus -H 192.168.27.126 -U ipmiusr -P test -p 9001 power off
Chassis Power Control: Down/off
$ ipmitool -I lanplus -H 192.168.27.126 -U ipmiusr -p 9001 power status
Password:
Chassis Power is off

Referenced link:
http://apahim.livejournal.com/2395.html
http://www.linux-kvm.org/images/7/76/03x08-Juniper-Corey_Minyard-UsingIPMIinQEMU.ods.pdf


猜你喜欢

转载自blog.csdn.net/Shirleylinyuer/article/details/79495203