2018-03-23 11:40:31 +01:00
|
|
|
from .ui_node import UINode, UIBdevs, UILvolStores
|
|
|
|
import rpc.client
|
|
|
|
import rpc
|
|
|
|
|
|
|
|
|
|
|
|
class UIRoot(UINode):
|
|
|
|
"""
|
|
|
|
Root node for CLI menu tree structure. Refreshes running config on startup.
|
|
|
|
"""
|
|
|
|
def __init__(self, s, shell):
|
|
|
|
UINode.__init__(self, "/", shell=shell)
|
|
|
|
self.current_bdevs = []
|
|
|
|
self.current_lvol_stores = []
|
|
|
|
self.set_rpc_target(s)
|
|
|
|
|
|
|
|
def refresh(self):
|
|
|
|
self._children = set([])
|
|
|
|
UIBdevs(self)
|
|
|
|
UILvolStores(self)
|
|
|
|
|
|
|
|
def set_rpc_target(self, s):
|
|
|
|
self.client = rpc.client.JSONRPCClient(s)
|
|
|
|
|
|
|
|
def print_array(self, a):
|
|
|
|
return " ".join(a)
|
|
|
|
|
|
|
|
def get_bdevs(self, bdev_type):
|
2018-05-21 13:28:21 -07:00
|
|
|
self.current_bdevs = rpc.bdev.get_bdevs(self.client)
|
2018-03-23 11:40:31 +01:00
|
|
|
# Following replace needs to be done in order for some of the bdev
|
2018-06-13 10:29:22 +02:00
|
|
|
# listings to work: logical volumes, split disk.
|
2018-03-23 11:40:31 +01:00
|
|
|
# For example logical volumes: listing in menu is "Logical_Volume"
|
|
|
|
# (cannot have space), but the product name in SPDK is "Logical Volume"
|
|
|
|
bdev_type = bdev_type.replace("_", " ")
|
|
|
|
for bdev in filter(lambda x: bdev_type in x["product_name"],
|
|
|
|
self.current_bdevs):
|
|
|
|
test = Bdev(bdev)
|
|
|
|
yield test
|
|
|
|
|
2018-06-13 11:35:46 +02:00
|
|
|
def get_bdevs_iostat(self, **kwargs):
|
|
|
|
return rpc.bdev.get_bdevs_iostat(self.client, **kwargs)
|
|
|
|
|
2018-06-13 10:29:22 +02:00
|
|
|
def split_bdev(self, **kwargs):
|
|
|
|
response = rpc.bdev.construct_split_vbdev(self.client, **kwargs)
|
|
|
|
return self.print_array(response)
|
|
|
|
|
|
|
|
def destruct_split_bdev(self, **kwargs):
|
|
|
|
rpc.bdev.destruct_split_vbdev(self.client, **kwargs)
|
|
|
|
|
2018-03-23 11:40:31 +01:00
|
|
|
def delete_bdev(self, name):
|
2018-05-21 13:28:21 -07:00
|
|
|
rpc.bdev.delete_bdev(self.client, bdev_name=name)
|
2018-03-23 11:40:31 +01:00
|
|
|
|
|
|
|
def create_malloc_bdev(self, **kwargs):
|
2018-05-21 13:28:21 -07:00
|
|
|
response = rpc.bdev.construct_malloc_bdev(self.client, **kwargs)
|
2018-03-23 11:40:31 +01:00
|
|
|
return self.print_array(response)
|
|
|
|
|
2018-06-15 03:58:57 -04:00
|
|
|
def delete_malloc_bdev(self, **kwargs):
|
|
|
|
rpc.bdev.delete_malloc_bdev(self.client, **kwargs)
|
|
|
|
|
2018-03-23 11:40:31 +01:00
|
|
|
def create_aio_bdev(self, **kwargs):
|
2018-05-21 13:28:21 -07:00
|
|
|
response = rpc.bdev.construct_aio_bdev(self.client, **kwargs)
|
2018-03-23 11:40:31 +01:00
|
|
|
return self.print_array(response)
|
|
|
|
|
2018-06-14 10:15:36 -04:00
|
|
|
def delete_aio_bdev(self, **kwargs):
|
|
|
|
rpc.bdev.delete_aio_bdev(self.client, **kwargs)
|
|
|
|
|
2018-03-23 11:40:31 +01:00
|
|
|
def create_lvol_bdev(self, **kwargs):
|
|
|
|
response = rpc.lvol.construct_lvol_bdev(self.client, **kwargs)
|
|
|
|
return self.print_array(response)
|
|
|
|
|
|
|
|
def create_nvme_bdev(self, **kwargs):
|
2018-05-21 13:28:21 -07:00
|
|
|
response = rpc.bdev.construct_nvme_bdev(self.client, **kwargs)
|
2018-03-23 11:40:31 +01:00
|
|
|
return self.print_array(response)
|
|
|
|
|
2018-06-13 11:38:39 +02:00
|
|
|
def create_null_bdev(self, **kwargs):
|
|
|
|
response = rpc.bdev.construct_null_bdev(self.client, **kwargs)
|
|
|
|
return self.print_array(response)
|
|
|
|
|
2018-06-13 11:39:36 +02:00
|
|
|
def create_error_bdev(self, **kwargs):
|
|
|
|
response = rpc.bdev.construct_error_bdev(self.client, **kwargs)
|
|
|
|
|
2018-03-23 11:40:31 +01:00
|
|
|
def get_lvol_stores(self):
|
|
|
|
self.current_lvol_stores = rpc.lvol.get_lvol_stores(self.client)
|
|
|
|
for lvs in self.current_lvol_stores:
|
|
|
|
yield LvolStore(lvs)
|
|
|
|
|
|
|
|
def create_lvol_store(self, **kwargs):
|
|
|
|
response = rpc.lvol.construct_lvol_store(self.client, **kwargs)
|
|
|
|
new_lvs = rpc.lvol.get_lvol_stores(self.client,
|
|
|
|
self.print_array(response),
|
|
|
|
lvs_name=None)
|
|
|
|
return new_lvs[0]["name"]
|
|
|
|
|
|
|
|
def delete_lvol_store(self, **kwargs):
|
|
|
|
rpc.lvol.destroy_lvol_store(self.client, **kwargs)
|
|
|
|
|
2018-06-18 14:41:55 +02:00
|
|
|
def create_pmem_pool(self, **kwargs):
|
|
|
|
response = rpc.pmem.create_pmem_pool(self.client, **kwargs)
|
|
|
|
return response
|
|
|
|
|
|
|
|
def delete_pmem_pool(self, **kwargs):
|
|
|
|
rpc.pmem.delete_pmem_pool(self.client, **kwargs)
|
|
|
|
|
|
|
|
def create_pmem_bdev(self, **kwargs):
|
|
|
|
response = rpc.bdev.construct_pmem_bdev(self.client, **kwargs)
|
|
|
|
return response
|
|
|
|
|
2018-03-23 11:40:31 +01:00
|
|
|
|
|
|
|
class Bdev(object):
|
|
|
|
def __init__(self, bdev_info):
|
|
|
|
"""
|
|
|
|
All class attributes are set based on what information is received
|
|
|
|
from get_bdevs RPC call.
|
|
|
|
# TODO: Document in docstring parameters which describe bdevs.
|
|
|
|
# TODO: Possible improvement: JSON schema might be used here in future
|
|
|
|
"""
|
|
|
|
for i in bdev_info.keys():
|
|
|
|
setattr(self, i, bdev_info[i])
|
|
|
|
|
|
|
|
|
|
|
|
class LvolStore(object):
|
|
|
|
def __init__(self, lvs_info):
|
|
|
|
"""
|
|
|
|
All class attributes are set based on what information is received
|
|
|
|
from get_bdevs RPC call.
|
|
|
|
# TODO: Document in docstring parameters which describe bdevs.
|
|
|
|
# TODO: Possible improvement: JSON schema might be used here in future
|
|
|
|
"""
|
|
|
|
for i in lvs_info.keys():
|
|
|
|
setattr(self, i, lvs_info[i])
|