1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
13 from hardware_adapter import HardwareAdapter
16 exec_cmd = common.exec_cmd
20 class IpmiAdapter(HardwareAdapter):
22 def __init__(self, yaml_path):
23 super(IpmiAdapter, self).__init__(yaml_path)
25 def get_access_info(self, node_id):
26 ip = self.get_node_property(node_id, 'ipmiIp')
27 username = self.get_node_property(node_id, 'ipmiUser')
28 password = self.get_node_property(node_id, 'ipmiPass')
29 return ip, username, password
31 def ipmi_cmd(self, node_id):
32 ip, username, password = self.get_access_info(node_id)
33 cmd = 'ipmitool -I lanplus -A password'
34 cmd += ' -H %s -U %s -P %s' % (ip, username, password)
37 def get_node_pxe_mac(self, node_id):
39 mac_list.append(self.get_node_property(node_id, 'pxeMac').lower())
42 def node_power_on(self, node_id):
45 log('Power ON Node %s' % node_id)
46 cmd_prefix = self.ipmi_cmd(node_id)
47 state = exec_cmd('%s chassis power status' % cmd_prefix)
48 if state == 'Chassis Power is off':
49 exec_cmd('%s chassis power on' % cmd_prefix)
51 for i in range(WAIT_LOOP):
52 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
54 if state == 'Chassis Power is on':
58 time.sleep(SLEEP_TIME)
60 err('Could Not Power ON Node %s' % node_id)
62 def node_power_off(self, node_id):
65 log('Power OFF Node %s' % node_id)
66 cmd_prefix = self.ipmi_cmd(node_id)
67 state = exec_cmd('%s chassis power status' % cmd_prefix)
68 if state == 'Chassis Power is on':
70 exec_cmd('%s chassis power off' % cmd_prefix)
71 for i in range(WAIT_LOOP):
72 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
74 if state == 'Chassis Power is off':
78 time.sleep(SLEEP_TIME)
80 err('Could Not Power OFF Node %s' % node_id)
82 def node_reset(self, node_id):
84 log('RESET Node %s' % node_id)
85 cmd_prefix = self.ipmi_cmd(node_id)
86 state = exec_cmd('%s chassis power status' % cmd_prefix)
87 if state == 'Chassis Power is on':
90 exec_cmd('%s chassis power reset' % cmd_prefix)
91 for i in range(WAIT_LOOP):
92 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
94 if state == 'Chassis Power is off':
96 elif state == 'Chassis Power is on' and was_shut_off:
101 err('Could Not RESET Node %s' % node_id)
103 err('Cannot RESET Node %s because it\'s not Active, state: %s'
106 def node_set_boot_order(self, node_id, boot_order_list):
107 log('Set boot order %s on Node %s' % (boot_order_list, node_id))
108 boot_order_list.reverse()
109 cmd_prefix = self.ipmi_cmd(node_id)
110 for dev in boot_order_list:
112 exec_cmd('%s chassis bootdev pxe options=persistent'
115 exec_cmd('%s chassis bootdev cdrom' % cmd_prefix)
117 exec_cmd('%s chassis bootdev disk options=persistent'