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, BMCException
20 def __init__(self, host, user, passwd, priv_level='ADMINISTRATOR', log_path=None):
21 super(HW17, self).__init__(host, user, passwd, priv_level, log_path)
23 def attach_virtual_cd(self, nfs_host, nfs_mount, boot_iso_filename):
25 self._setup_bmc_nfs_service(nfs_host, nfs_mount, boot_iso_filename)
26 success = self._wait_for_bmc_nfs_service(90, 'mounted')
30 logging.debug('BMC NFS server did not start yet')
33 raise BMCException('NFS service setup failed')
35 def _detach_virtual_media(self):
36 logging.debug('Detach virtual media')
38 comp_code = self._run_ipmitool_raw_command('0x3c 0x00')
39 if comp_code[0] == '80':
40 raise BMCException('BMC NFS service reset failed, cannot get configuration')
41 elif comp_code[0] == '81':
42 raise BMCException('BMC NFS service reset failed, cannot set configuration')
44 BMCException('BMC NFS service reset failed (rc={})'.format(comp_code))
46 def _set_boot_from_virtual_media(self):
47 logging.debug('Set boot from cd (%s), and boot after that', self._host)
48 self._run_ipmitool_command('chassis bootdev floppy options=persistent')
50 def _get_bmc_nfs_service_status(self):
51 logging.debug('Get BMC NFS service status')
53 status_code = self._run_ipmitool_raw_command('0x3c 0x03')
54 if status_code[0] == '00':
56 elif status_code[0] == '64':
58 elif status_code[0] == 'ff':
60 elif status_code[0] == '20':
63 raise BMCException('Could not get BMC NFS service status (rc={})'.format(status_code))
65 logging.debug('Returned status: %s', status)
68 def _set_bmc_nfs_configuration(self, nfs_host, mount_path, image_name):
69 logging.debug('Set BMC NFS configuration')
71 nfs_host_hex = self._convert_to_hex(nfs_host)
72 mount_path_hex = self._convert_to_hex(mount_path)
73 image_name_hex = self._convert_to_hex(image_name)
75 logging.debug('Set the IP address of the BMC NFS service (%s)', self._host)
76 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x00 {} 0x00'.format(nfs_host_hex))
77 if comp_code[0] != '':
78 raise BMCException('Failed to set BMC NFS service IP address (rc={})'.format(comp_code))
80 logging.debug('Set the path of the BMC NFS service (%s)', mount_path)
81 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x01 {} 0x00'.format(mount_path_hex))
82 if comp_code[0] != '':
83 raise BMCException('Failed to set BMC NFS service path (rc={})'.format(comp_code))
85 logging.debug('Set the ISO image name of the BMC NFS service (%s)', image_name)
86 comp_code = self._run_ipmitool_raw_command('0x3c 0x01 0x02 {} 0x00'.format(image_name_hex))
87 if comp_code[0] != '':
88 raise BMCException('Failed to set BMC NFS service iso image name (rc={})'.format(comp_code))
90 def _setup_bmc_nfs_service(self, nfs_host, mount_path, image_name):
91 logging.debug('Setup BMC NFS service')
93 self._detach_virtual_media()
94 self._set_bmc_nfs_configuration(nfs_host, mount_path, image_name)
96 logging.debug('Start the BMC NFS service')
97 comp_code = self._run_ipmitool_raw_command('0x3c 0x02 0x01')
98 if comp_code[0] != '':
99 raise BMCException('Failed to start the BMC NFS service (rc={})'.format(comp_code))