From: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
Here we call libvirt findStoragePoolSources to get the iSCSI targets.
Zhou Zheng Sheng aslo provides a method to get the iSCSI targets in
commit f163d22e.
Test this patch by:
$ curl -k -u <user>:<password> -H "Content-Type: application/json"
\
[
{
"host":"127.0.0.1",
"target":"iqn.2003-01.org.linux-iscsi.localhost.x8664:sn.edb1a004dc57",
"target_type":"iscsi"
}
]
Signed-off-by: ShaoHe Feng <shaohef(a)linux.vnet.ibm.com>
---
docs/API.md | 5 ++++-
src/kimchi/API.json | 7 ++++++-
src/kimchi/model/storagetargets.py | 28 ++++++++++++++++++++--------
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/docs/API.md b/docs/API.md
index 1c7d9e2..4f51dd0 100644
--- a/docs/API.md
+++ b/docs/API.md
@@ -653,7 +653,10 @@ creation.
* **GET**: Retrieve a list of available storage targets.
* Parameters:
- * _target_type: Filter target list with given type, currently support
'netfs'.
+ * _target_type: Filter target list with given type, currently support
+ 'netfs' and 'iscsi'.
+ * _server_port: Filter target list with given server port,
+ currently support 'iscsi'.
* Response: A list with storage targets information.
* host: IP or host name of storage server of this target.
* target_type: Type of storage target, supported: 'nfs'.
diff --git a/src/kimchi/API.json b/src/kimchi/API.json
index b0df606..6d1324c 100644
--- a/src/kimchi/API.json
+++ b/src/kimchi/API.json
@@ -428,7 +428,12 @@
"_target_type": {
"description": "List storage servers of given
type",
"type": "string",
- "pattern": "^netfs$"
+ "pattern": "^netfs|iscsi$"
+ },
+ "_server_port": {
+ "description": "the port of iscsi storage
servers",
+ "type": "string",
+ "pattern": "^[0-9]{1,5}$"
}
},
"additionalProperties": false,
diff --git a/src/kimchi/model/storagetargets.py b/src/kimchi/model/storagetargets.py
index caa8dbe..971bfca 100644
--- a/src/kimchi/model/storagetargets.py
+++ b/src/kimchi/model/storagetargets.py
@@ -32,9 +32,8 @@ def __init__(self, **kargs):
self.conn = kargs['conn']
self.caps = CapabilitiesModel()
- def get_list(self, storage_server, _target_type=None):
+ def get_list(self, storage_server, _target_type=None, _server_port=None):
target_list = list()
-
if not _target_type:
target_types = STORAGE_SERVERS
else:
@@ -45,7 +44,8 @@ def get_list(self, storage_server, _target_type=None):
targets = patch_find_nfs_target(storage_server)
else:
xml = self._get_storage_server_spec(server=storage_server,
- target_type=target_type)
+ target_type=target_type,
+ server_port=_server_port)
conn = self.conn.get()
try:
ret = conn.findStoragePoolSources(target_type, xml, 0)
@@ -64,9 +64,18 @@ def _get_storage_server_spec(self, **kwargs):
# server:
# target_type:
extra_args = []
- if kwargs['target_type'] == 'netfs':
+ server_type = kwargs['target_type']
+ if server_type == 'netfs':
extra_args.append(E.format(type='nfs'))
- obj = E.source(E.host(name=kwargs['server']), *extra_args)
+ else:
+ extra_args.append(E.format(type=server_type))
+
+ host_attr = {"name": kwargs['server']}
+ server_port = kwargs.get("server_port")
+ if server_port is not None:
+ host_attr['port'] = server_port
+
+ obj = E.source(E.host(host_attr), *extra_args)
xml = ET.tostring(obj)
return xml
@@ -75,9 +84,12 @@ def _parse_target_source_result(self, target_type, xml_str):
ret = []
for source in root.getchildren():
if target_type == 'netfs':
- host_name = source.host.get('name')
target_path = source.dir.get('path')
type = source.format.get('type')
- ret.append(dict(host=host_name, target_type=type,
- target=target_path))
+ if target_type == 'iscsi':
+ target_path = source.device.get('path')
+ type = target_type
+ host_name = source.host.get('name')
+ ret.append(dict(host=host_name, target_type=type,
+ target=target_path))
return ret
--
1.9.3