Skip to content

Commit

Permalink
netinterface: make linstorapi compatible with pre 1.0.7 API
Browse files Browse the repository at this point in the history
  • Loading branch information
rp- committed Jul 23, 2019
1 parent aa3e36e commit 5d2bad1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions linstor/linstorapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@ def disconnect(self):
if self._rest_conn:
self._rest_conn.close()

def _require_node_is_active(self, net_interface, value=True):
"""
Adds 'is_active' property if supported by controller.
:param dict[str, Any] net_interface:
:param bool value: Value for is_active
:return:
"""
# is_active is added with API 1.0.7, before active stlt conn was set via property
if self._ctrl_version and StrictVersion(self._ctrl_version.rest_api_version) >= StrictVersion("1.0.7"):
net_interface["is_active"] = value

def node_create(
self,
node_name,
Expand Down Expand Up @@ -529,12 +541,13 @@ def node_create(
"name": netif_name,
"address": ip,
"satellite_port": port,
"satellite_encryption_type": com_type,
"is_active": True
"satellite_encryption_type": com_type
}
]
}

self._require_node_is_active(body["net_interfaces"][0])

return self._rest_request(apiconsts.API_CRT_NODE, "POST", "/v1/nodes", body)

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

body["is_active"] = is_active
self._require_node_is_active(body, is_active)

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

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

body["is_active"] = is_active
self._require_node_is_active(body, is_active)

return self._rest_request(
apiconsts.API_CRT_NET_IF,
Expand Down

0 comments on commit 5d2bad1

Please sign in to comment.