summaryrefslogtreecommitdiffstats
path: root/cyborg_enhancement/mitaka_version/cyborg/cyborg/accelerator/drivers/spdk/vhost/vhost.py
blob: b7aef33591c61c5cc6d7ad1e8479c6716ae3fece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
"""
SPDK VHOSTDRIVER module implementation.
"""

from cyborg.accelerator.drivers.spdk.util.pyspdk.vhost_client import VhostTgt
from oslo_log import log as logging
from cyborg.accelerator.drivers.spdk.util import common_fun
from cyborg.accelerator.drivers.spdk.spdk import SPDKDRIVER
from cyborg.accelerator.drivers.spdk.util.pyspdk.py_spdk import PySPDK

LOG = logging.getLogger(__name__)


class VHOSTDRIVER(SPDKDRIVER):
    """VHOSTDRIVER class.
       vhost server app should be able to implement this driver.
    """

    SERVER = 'vhost'

    def __init__(self, *args, **kwargs):
        super(VHOSTDRIVER, self).__init__(*args, **kwargs)
        self.servers = common_fun.discover_servers()
        self.py = common_fun.get_py_client(self.SERVER)

    def discover_accelerator(self):
        if common_fun.check_for_setup_error(self.py, self.SERVER):
            return self.get_one_accelerator()

    def get_one_accelerator(self):
        acc_client = VhostTgt(self.py)
        bdevs = acc_client.get_bdevs()
        # Display current blockdev list
        scsi_devices = acc_client.get_scsi_devices()
        # Display SCSI devices
        luns = acc_client.get_luns()
        # Display active LUNs
        interfaces = acc_client.get_interfaces()
        # Display current interface list
        accelerator_obj = {
            'server': self.SERVER,
            'bdevs': bdevs,
            'scsi_devices': scsi_devices,
            'luns': luns,
            'interfaces': interfaces
        }
        return accelerator_obj

    def install_accelerator(self, driver_id, driver_type):
        pass

    def uninstall_accelerator(self, driver_id, driver_type):
        pass

    def accelerator_list(self):
        return self.get_all_accelerators()

    def get_all_accelerators(self):
        accelerators = []
        for accelerator_i in range(len(self.servers)):
            accelerator = self.servers[accelerator_i]
            py_tmp = PySPDK(accelerator)
            if py_tmp.is_alive():
                accelerators.append(self.get_one_accelerator())
        return accelerators

    def update(self, driver_type, **kwargs):
        pass

    def attach_instance(self, instance_id):
        pass

    def detach_instance(self, instance_id):
        pass

    def add_ip_address(self, ifc_index, ip_addr):
        """Add IP address
        :param ifc_index: ifc index of the nic device.
        :param ip_addr: ip address will be added.
        :return: ip_address
        """
        acc_client = VhostTgt(self.py)
        return acc_client.add_ip_address(ifc_index, ip_addr)

    def delete_ip_address(self, ifc_index, ip_addr):
        """Delete IP address
        :param ifc_index: ifc index of the nic device.
        :param ip_addr: ip address will be added.
        :return: ip_address
        """
        acc_client = VhostTgt(self.py)
        return acc_client.delete_ip_address(ifc_index, ip_addr)