Seed code for ironic_virtmedia_driver
[ta/ironic-virtmedia-driver.git] / src / ironic_virtmedia_driver / vendors / nokia / hw17.py
1 # Copyright 2019 Nokia
2 #
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
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14 #
15
16 import time
17
18 from ironic.drivers.modules import ipmitool
19 from ironic.conductor import utils as manager_utils
20 from ironic.common import exception
21 from ironic.common import boot_devices
22
23 from .nokia_hw import NokiaIronicVirtMediaHW
24
25 class HW17(NokiaIronicVirtMediaHW):
26     def __init__(self, log):
27         super(HW17, self).__init__(log)
28
29     def get_disk_attachment_status(self, task):
30         # Check NFS Service Status
31         (out, err) = ipmitool.send_raw(task, '0x3c 0x03')
32         self.log.debug("get_disk_attachment_status: NFS service status: error:%r, output:%r" %(err, out))
33         if out == ' 00\n':
34             return 'mounted'
35         elif out == ' 64\n':
36             return 'mounting'
37         elif out == ' 20\n':
38             return 'nfserror'
39         else:
40             return 'dismounted'
41
42     def attach_virtual_cd(self, image_filename, driver_info, task):
43
44         # Stop virtual device and Clear NFS configuration
45         ipmitool.send_raw(task, '0x3c 0x0')
46         # Set NFS Configurations
47         # NFS server IP
48         ipmitool.send_raw(task, '0x3c 0x01 0x00 %s 0x00' %(self.hex_convert(driver_info['provisioning_server'])))
49         # Set NFS Mount Root path
50         ipmitool.send_raw(task, '0x3c 0x01 0x01 %s 0x00' %(self.hex_convert(self.remote_share)))
51         # Set Image Name
52         ipmitool.send_raw(task, '0x3c 0x01 0x02 %s 0x00' %(self.hex_convert(image_filename)))
53         # Start NFS Service
54         ipmitool.send_raw(task, '0x3c 0x02 0x01')
55
56         time.sleep(1)
57
58         return self.check_and_wait_for_cd_mounting(image_filename, task, driver_info)
59
60     def detach_virtual_cd(self, driver_info, task):
61         """Detaches virtual cdrom on the node.
62
63         :param task: an ironic task object.
64         """
65         # Stop virtual device and Clear NFS configuration
66         self.log.debug("detach_virtual_cd")
67         ipmitool.send_raw(task, '0x3c 0x00')
68
69     def set_boot_device(self, task):
70         manager_utils.node_set_boot_device(task, boot_devices.FLOPPY, persistent=True)