The 'standalone_only' parameter is optional. Default is False which means all initiators will be included in results. When standalone_only is True, only return initiator which is not in any NodeACLGroup.
Return a list of initiator in the format of
[ { 'init_id': str, 'init_type': str, }, ]
The 'init_id' of result is the iSCSI IQN/NAA/EUI address of initiator. Example: 'iqn.2000-04.com.example:someone-01' The 'init_type' is reserved for future use, currently, it is 'iscsi'.
Signed-off-by: Gris Ge fge@redhat.com --- API.md | 23 ++++++++++++++++++++++- targetd/block.py | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/API.md b/API.md index c33625e..9db742a 100644 --- a/API.md +++ b/API.md @@ -101,6 +101,27 @@ direction. Calling this method is not required for exports to work. If it is not called, exports require no authentication.
+### initiator_list(standalone_only=False) +List all initiators. +Parameters: + standalone_only(bool, optional): + If 'standalone_only' is True, only return initiator which is not in any + NodeACLGroup. + By default, all initiators will be included in result. +Returns: + [ + { + 'init_id': str, + 'init_type': str, + }, + ] + The 'init_id' of result is the iSCSI IQN/NAA/EUI address of initiator. + Example: 'iqn.2000-04.com.example:someone-01' + The 'init_type' is reserved for future use, currently, it is 'iscsi'. + +Errors: + N/A + File system operations ---------------------- Ability to create different file systems and perform operation on them. The @@ -147,7 +168,7 @@ Returns an array of export objects. Each export object contains: `host`, `path`
### nfs_export_add(host, path, options) Adds a NFS export given a `host`, and an export `path` to export and a list of `options` -Options is a list of NFS export options. Each option can be either a single value +Options is a list of NFS export options. Each option can be either a single value eg. no_root_squash or can be a `key=value` like `sec=sys`. See `man 5 exports` for all available supported options and the formats supported for `host`.
diff --git a/targetd/block.py b/targetd/block.py index e8206b2..b17c58a 100644 --- a/targetd/block.py +++ b/targetd/block.py @@ -105,6 +105,7 @@ def initialize(config_dict): export_create=export_create, export_destroy=export_destroy, initiator_set_auth=initiator_set_auth, + initiator_list=initiator_list, )
@@ -326,3 +327,43 @@ def block_pools(req): type='block', uuid=thinp.getUuid()))
return results + + +def _get_iscsi_tpg(): + fabric_module = FabricModule('iscsi') + target = Target(fabric_module, target_name) + return TPG(target, 1) + + +def initiator_list(req, standalone_only=False): + """Return a list of initiator + + Iterate all iSCSI rtslib-fb.NodeACL via rtslib-fb.TPG.node_acls(). + Args: + req (TargetHandler): Reserved for future use. + standalone_only (bool): + When standalone_only is True, only return initiator which is not + in any NodeACLGroup (NodeACL.tag is None). + Returns: + [ + { + 'init_id': NodeACL.node_wwn, + 'init_type': 'iscsi', + }, + ] + + Currently, targetd only support iscsi which means 'init_type' is + always 'iscsi'. + Raises: + N/A + """ + def _condition(node_acl, standalone_only): + if standalone_only and node_acl.tag is not None: + return False + else: + return True + + return list( + {'init_id': node_acl.node_wwn, 'init_type': 'iscsi'} + for node_acl in _get_iscsi_tpg().node_acls + if _condition(node_acl, standalone_only))