3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from .bmctools import BMC
19 class BMCException(Exception):
23 def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
24 super(HW17, self).__init__(host, user, passwd, priv_level, log_path)
26 def attach_virtual_cd(self, nfs_host, nfs_mount, boot_iso_filename):
28 self._setup_bmc_nfs_service(nfs_host, nfs_mount, boot_iso_filename)
29 success = self._wait_for_bmc_nfs_service(90, 'mounted')
33 logging.debug('BMC NFS server did not start yet')
36 raise BMCException('NFS service setup failed')
38 def _detach_virtual_media(self):
39 logging.debug('Detach virtual media')
41 comp_code = self._run_ipmitool_raw_command('0x3c 0x00')
42 if comp_code[0] == '80':
43 raise BMCException('BMC NFS service reset failed, cannot get configuration')
44 elif comp_code[0] == '81':
45 raise BMCException('BMC NFS service reset failed, cannot set configuration')
47 BMCException('BMC NFS service reset failed (rc={})'.format(comp_code))
49 def _set_boot_from_virtual_media(self):
50 logging.debug('Set boot from cd (%s), and boot after that', self._host)
51 self._run_ipmitool_command('chassis bootdev floppy options=persistent')
53 def _get_bmc_nfs_service_status(self):
54 logging.debug('Get BMC NFS service status')
56 status_code = self._run_ipmitool_raw_command('0x3c 0x03')
57 if status_code[0] == '00':
59 elif status_code[0] == '64':
61 elif status_code[0] == 'ff':
63 elif status_code[0] == '20':
66 raise BMCException('Could not get BMC NFS service status (rc={})'.format(status_code))
68 logging.debug('Returned status: %s', status)
71 def _set_bmc_nfs_configuration(self, nfs_host, mount_path, image_name):
72 logging.debug('Set BMC NFS configuration')
74 nfs_host_hex = self._convert_to_hex(nfs_host)
75 mount_path_hex = self._convert_to_hex(mount_path)
76 image_name_hex = self._convert_to_hex(image_name)
78 logging.debug('Set the IP address of the BMC NFS service (%s)', self._host)
79 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x00 {} 0x00'.format(nfs_host_hex))
80 if comp_code[0] != '':
81 raise BMCException('Failed to set BMC NFS service IP address (rc={})'.format(comp_code))
83 logging.debug('Set the path of the BMC NFS service (%s)', mount_path)
84 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x01 {} 0x00'.format(mount_path_hex))
85 if comp_code[0] != '':
86 raise BMCException('Failed to set BMC NFS service path (rc={})'.format(comp_code))
88 logging.debug('Set the ISO image name of the BMC NFS service (%s)', image_name)
89 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x02 {} 0x00'.format(image_name_hex))
90 if comp_code[0] != '':
91 raise BMCException('Failed to set BMC NFS service iso image name (rc={})'.format(comp_code))
93 def _setup_bmc_nfs_service(self, nfs_host, mount_path, image_name):
94 logging.debug('Setup BMC NFS service')
96 self._detach_virtual_media()
97 self._set_bmc_nfs_configuration(nfs_host, mount_path, image_name)
99 logging.debug('Start the BMC NFS service')
100 comp_code = self._run_ipmitool_raw_command('0x3c 0x02 0x01')
101 if comp_code[0] != '':
102 raise BMCException('Failed to start the BMC NFS service (rc={})'.format(comp_code))