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 ###############################################################################
12 from hardware_adapter import HardwareAdapter
21 class IpmiAdapter(HardwareAdapter):
23 def __init__(self, yaml_path):
24 super(IpmiAdapter, self).__init__(yaml_path)
26 def get_access_info(self, node_id):
27 ip = self.get_node_property(node_id, 'ipmiIp')
28 username = self.get_node_property(node_id, 'ipmiUser')
29 password = self.get_node_property(node_id, 'ipmiPass')
30 return ip, username, password
32 def ipmi_cmd(self, node_id):
33 ip, username, password = self.get_access_info(node_id)
34 cmd = 'ipmitool -I lanplus -A password'
35 cmd += ' -H %s -U %s -P %s' % (ip, username, password)
38 def get_node_pxe_mac(self, node_id):
40 mac_list.append(self.get_node_property(node_id, 'pxeMac').lower())
43 def node_power_on(self, node_id):
46 log('Power ON Node %s' % node_id)
47 cmd_prefix = self.ipmi_cmd(node_id)
48 state = exec_cmd('%s chassis power status' % cmd_prefix)
49 if state == 'Chassis Power is off':
50 exec_cmd('%s chassis power on' % cmd_prefix)
52 for i in range(WAIT_LOOP):
53 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
55 if state == 'Chassis Power is on':
59 time.sleep(SLEEP_TIME)
61 err('Could Not Power ON Node %s' % node_id)
63 def node_power_off(self, node_id):
66 log('Power OFF Node %s' % node_id)
67 cmd_prefix = self.ipmi_cmd(node_id)
68 state = exec_cmd('%s chassis power status' % cmd_prefix)
69 if state == 'Chassis Power is on':
71 exec_cmd('%s chassis power off' % cmd_prefix)
72 for i in range(WAIT_LOOP):
73 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
75 if state == 'Chassis Power is off':
79 time.sleep(SLEEP_TIME)
81 err('Could Not Power OFF Node %s' % node_id)
83 def node_reset(self, node_id):
85 log('RESET Node %s' % node_id)
86 cmd_prefix = self.ipmi_cmd(node_id)
87 state = exec_cmd('%s chassis power status' % cmd_prefix)
88 if state == 'Chassis Power is on':
91 exec_cmd('%s chassis power reset' % cmd_prefix)
92 for i in range(WAIT_LOOP):
93 state, _ = exec_cmd('%s chassis power status' % cmd_prefix,
95 if state == 'Chassis Power is off':
97 elif state == 'Chassis Power is on' and was_shut_off:
102 err('Could Not RESET Node %s' % node_id)
104 err('Cannot RESET Node %s because it\'s not Active, state: %s'
107 def node_set_boot_order(self, node_id, boot_order_list):
108 log('Set boot order %s on Node %s' % (boot_order_list, node_id))
109 boot_order_list.reverse()
110 cmd_prefix = self.ipmi_cmd(node_id)
111 for dev in boot_order_list:
113 exec_cmd('%s chassis bootdev pxe options=persistent'
116 exec_cmd('%s chassis bootdev cdrom' % cmd_prefix)
118 exec_cmd('%s chassis bootdev disk options=persistent'