Skip to content

Commit cd73d61

Browse files
NambrokWescoeur
authored andcommitted
linstor: add network path api in linstor-manager
Add getNetworkPath, setNetworkPath and destroyNetworkPath to the linstor-manager plugin. Signed-off-by: Damien Thenot <damien.thenot@vates.tech>
1 parent 0722952 commit cd73d61

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

drivers/linstor-manager

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,77 @@ def set_node_preferred_interface(session, args):
11831183
raise XenAPIPlugin.Failure('-1', [str(e)])
11841184
return str(True)
11851185

1186+
def list_network_path(session, args):
1187+
group_name = args["groupName"]
1188+
1189+
linstor = LinstorVolumeManager(
1190+
get_controller_uri(),
1191+
group_name,
1192+
logger=util.SMlog
1193+
)
1194+
try:
1195+
return str(linstor.list_node_path())
1196+
except Exception as e:
1197+
raise XenAPIPlugin.Failure('-1', [str(e)])
1198+
1199+
def get_network_path(session, args):
1200+
group_name = args["groupName"]
1201+
node1 = args["node1"]
1202+
node2 = args["node2"]
1203+
1204+
linstor = LinstorVolumeManager(
1205+
get_controller_uri(),
1206+
group_name,
1207+
logger=util.SMlog
1208+
)
1209+
try:
1210+
return str(linstor.get_node_path(node1, node2))
1211+
except Exception as e:
1212+
raise XenAPIPlugin.Failure('-1', [str(e)])
1213+
1214+
def set_network_path(session, args):
1215+
group_name = args["groupName"]
1216+
hostname1 = args["node1"]
1217+
hostname2 = args["node2"]
1218+
network_name = args["network"]
1219+
1220+
linstor = LinstorVolumeManager(
1221+
get_controller_uri(),
1222+
group_name,
1223+
logger=util.SMlog
1224+
)
1225+
ret_list = []
1226+
try:
1227+
list_resp = linstor.set_node_path(hostname1, hostname2, network_name)
1228+
for resp in list_resp:
1229+
if(resp.is_error()):
1230+
raise XenAPIPlugin.Failure('-1', [str(resp)])
1231+
ret_list.append(str(resp))
1232+
1233+
except Exception as e:
1234+
raise XenAPIPlugin.Failure('-1', [str(e)])
1235+
return str(ret_list)
1236+
1237+
def destroy_network_path(session, args):
1238+
group_name = args["groupName"]
1239+
hostname1 = args["node1"]
1240+
hostname2 = args["node2"]
1241+
1242+
linstor = LinstorVolumeManager(
1243+
get_controller_uri(),
1244+
group_name,
1245+
logger=util.SMlog
1246+
)
1247+
ret_list = []
1248+
try:
1249+
list_resp = linstor.destroy_node_path(hostname1, hostname2)
1250+
for resp in list_resp:
1251+
if(resp.is_error()):
1252+
raise XenAPIPlugin.Failure('-1', [str(resp)])
1253+
ret_list.append(str(resp))
1254+
except Exception as e:
1255+
raise XenAPIPlugin.Failure('-1', [str(e)])
1256+
return str(ret_list)
11861257

11871258
if __name__ == '__main__':
11881259
XenAPIPlugin.dispatch({
@@ -1238,5 +1309,10 @@ if __name__ == '__main__':
12381309
'modifyNodeInterface': modify_node_interface,
12391310
'listNodeInterfaces': list_node_interfaces,
12401311
'getNodePreferredInterface': get_node_preferred_interface,
1241-
'setNodePreferredInterface': set_node_preferred_interface
1312+
'setNodePreferredInterface': set_node_preferred_interface,
1313+
1314+
'listNetworkPath': list_network_path,
1315+
'getNetworkPath': get_network_path,
1316+
'setNetworkPath': set_network_path,
1317+
'destroyNetworkPath': destroy_network_path
12421318
})

drivers/linstorvolumemanager.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
PLUGIN = 'linstor-manager'
4747

4848

49+
PATH_NAME = "xostor"
50+
4951
# ==============================================================================
5052

5153
def get_local_volume_openers(resource_name, volume):
@@ -1620,6 +1622,50 @@ def set_node_preferred_interface(self, node_name, name):
16201622
'Failed to set preferred node interface on `{}`: {}'.format(node_name, error_str)
16211623
)
16221624

1625+
def list_node_path(self):
1626+
result = self._linstor.node_conn_list()
1627+
errors = self._filter_errors(result)
1628+
if errors:
1629+
error_str = self._get_error_str(errors)
1630+
raise LinstorVolumeManagerError(
1631+
'Failed to list node connection: {}'.format(error_str)
1632+
)
1633+
return result
1634+
1635+
def get_node_path(self, hostname1, hostname2):
1636+
result = self._linstor.node_conn_list_specific_pair(node_a=hostname1, node_b=hostname2)
1637+
errors = self._filter_errors(result)
1638+
if errors:
1639+
error_str = self._get_error_str(errors)
1640+
raise LinstorVolumeManagerError(
1641+
'Failed to get node connection for `{}` <-> `{}`: {}'.format(hostname1, hostname2, error_str)
1642+
)
1643+
return result
1644+
1645+
def set_node_path(self, hostname1, hostname2, network_name):
1646+
property_name1 = "Paths/{netname}/{node_name}".format(netname=PATH_NAME, node_name=hostname1)
1647+
property_name2 = "Paths/{netname}/{node_name}".format(netname=PATH_NAME, node_name=hostname2)
1648+
result = self._linstor.node_conn_modify(hostname1, hostname2, property_dict={property_name1: network_name, property_name2: network_name}, delete_props=None)
1649+
errors = self._filter_errors(result)
1650+
if errors:
1651+
error_str = self._get_error_str(errors)
1652+
raise LinstorVolumeManagerError(
1653+
'Failed to set node connection `{}` <-> `{}`: {}'.format(hostname1, hostname2, error_str)
1654+
)
1655+
return result
1656+
1657+
def destroy_node_path(self, hostname1, hostname2):
1658+
property_name1 = "Paths/{netname}/{node_name}".format(netname=PATH_NAME, node_name=hostname1)
1659+
property_name2 = "Paths/{netname}/{node_name}".format(netname=PATH_NAME, node_name=hostname2)
1660+
result = self._linstor.node_conn_modify(hostname1, hostname2, property_dict=None, delete_props=[property_name1, property_name2])
1661+
errors = self._filter_errors(result)
1662+
if errors:
1663+
error_str = self._get_error_str(errors)
1664+
raise LinstorVolumeManagerError(
1665+
'Failed to destroy node connection `{}` <-> `{}`: {}'.format(hostname1, hostname2, error_str)
1666+
)
1667+
return result
1668+
16231669
def get_nodes_info(self):
16241670
"""
16251671
Get all nodes + statuses, used or not by the pool.

0 commit comments

Comments
 (0)