Skip to content

Commit 5d2bad1

Browse files
committed
netinterface: make linstorapi compatible with pre 1.0.7 API
1 parent aa3e36e commit 5d2bad1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

linstor/linstorapi.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,18 @@ def disconnect(self):
483483
if self._rest_conn:
484484
self._rest_conn.close()
485485

486+
def _require_node_is_active(self, net_interface, value=True):
487+
"""
488+
Adds 'is_active' property if supported by controller.
489+
490+
:param dict[str, Any] net_interface:
491+
:param bool value: Value for is_active
492+
:return:
493+
"""
494+
# is_active is added with API 1.0.7, before active stlt conn was set via property
495+
if self._ctrl_version and StrictVersion(self._ctrl_version.rest_api_version) >= StrictVersion("1.0.7"):
496+
net_interface["is_active"] = value
497+
486498
def node_create(
487499
self,
488500
node_name,
@@ -529,12 +541,13 @@ def node_create(
529541
"name": netif_name,
530542
"address": ip,
531543
"satellite_port": port,
532-
"satellite_encryption_type": com_type,
533-
"is_active": True
544+
"satellite_encryption_type": com_type
534545
}
535546
]
536547
}
537548

549+
self._require_node_is_active(body["net_interfaces"][0])
550+
538551
return self._rest_request(apiconsts.API_CRT_NODE, "POST", "/v1/nodes", body)
539552

540553
def node_create_swordfish_target(self, node_name, storage_service):
@@ -620,7 +633,7 @@ def netinterface_create(self, node_name, interface_name, ip, port=None, com_type
620633
body["satellite_port"] = port
621634
body["satellite_encryption_type"] = com_type
622635

623-
body["is_active"] = is_active
636+
self._require_node_is_active(body, is_active)
624637

625638
return self._rest_request(apiconsts.API_CRT_NET_IF, "POST", "/v1/nodes/" + node_name + "/net-interfaces", body)
626639

@@ -646,7 +659,7 @@ def netinterface_modify(self, node_name, interface_name, ip=None, port=None, com
646659
body["satellite_port"] = port
647660
body["satellite_encryption_type"] = com_type
648661

649-
body["is_active"] = is_active
662+
self._require_node_is_active(body, is_active)
650663

651664
return self._rest_request(
652665
apiconsts.API_CRT_NET_IF,

0 commit comments

Comments
 (0)