def access_group_init_add(req, ag_name, init_id, init_type): if init_type != 'iscsi': raise TargetdError(TargetdError.NO_SUPPORT, "Only support iscsi") tpg = _get_iscsi_tpg() # Pre-check: # 1. Already in requested access group, return silently. # 2. Initiator does not exist. # 3. Initiator not used by other access group. if init_id in list(NodeACLGroup(tpg, ag_name).wwns): return for node_acl_group in tpg.node_acl_groups: if init_id in list(node_acl_group.wwns): raise TargetdError( TargetdError.EXISTS_INITIATOR, "Requested init_id is used by other access group") for node_acl in tpg.node_acls: if init_id == node_acl.node_wwn: raise TargetdError(TargetdError.EXISTS_INITIATOR, "Requested init_id is in use") NodeACLGroup(tpg, ag_name).add_acl(init_id) RTSRoot().save_to_file()
def access_group_create(req, ag_name, init_id, init_type): if init_type != 'iscsi': raise TargetdError( TargetdError.NO_SUPPORT, "Only support iscsi") name_check(ag_name) tpg = _get_iscsi_tpg() # Pre-check: # 1. Name conflict: requested name is in use # 2. Initiator conflict: request initiator is in use for node_acl_group in tpg.node_acl_groups: if node_acl_group.name == ag_name: raise TargetdError( TargetdError.NAME_CONFLICT, "Requested access group name is in use") if init_id in list(i.node_wwn for i in tpg.node_acls): raise TargetdError( TargetdError.EXISTS_INITIATOR, "Requested init_id is in use") node_acl_group = NodeACLGroup(tpg, ag_name) node_acl_group.add_acl(init_id) RTSRoot().save_to_file()
def access_group_init_del(req, ag_name, init_id, init_type): if init_type != 'iscsi': raise TargetdError(TargetdError.NO_SUPPORT, "Only support iscsi") tpg = _get_iscsi_tpg() # Pre-check: # 1. Initiator is not in requested access group, return silently. if init_id not in list(NodeACLGroup(tpg, ag_name).wwns): return NodeACLGroup(tpg, ag_name).remove_acl(init_id) RTSRoot().save_to_file()
def access_group_map_create(req, pool_name, vol_name, ag_name, h_lun_id=None): tpg = _get_iscsi_tpg() tpg.enable = True tpg.set_attribute("authentication", '0') NetworkPortal(tpg, "0.0.0.0") tpg_lun = _tpg_lun_of(tpg, pool_name, vol_name) # Pre-Check: # 1. Already mapped to requested access group, return None if any(tpg_lun.mapped_luns): tgt_map_list = access_group_map_list(req) for tgt_map in tgt_map_list: if tgt_map['ag_name'] == ag_name and \ tgt_map['pool_name'] == pool_name and \ tgt_map['vol_name'] == vol_name: # Already masked. return None node_acl_group = NodeACLGroup(tpg, ag_name) if not any(node_acl_group.wwns): # Non-existent access group means volume mapping status will not be # stored. This should be considered as an error instead of silently # returning. raise TargetdError( TargetdError.NOT_FOUND_ACCESS_GROUP, "Access group not found") if h_lun_id is None: # Find out next available host LUN ID # Assuming max host LUN ID is LUN.MAX_LUN free_h_lun_ids = set(range(LUN.MAX_LUN+1)) - \ set([int(x.mapped_lun) for x in tpg_lun.mapped_luns]) if len(free_h_lun_ids) == 0: raise TargetdError( TargetdError.NO_FREE_HOST_LUN_ID, "All host LUN ID 0 ~ %d is in use" % LUN.MAX_LUN) else: h_lun_id = free_h_lun_ids.pop() node_acl_group.mapped_lun_group(h_lun_id, tpg_lun) RTSRoot().save_to_file()
def access_group_map_create(req, pool_name, vol_name, ag_name, h_lun_id=None): tpg = _get_iscsi_tpg() tpg.enable = True tpg.set_attribute("authentication", '0') set_portal_addresses(tpg) tpg_lun = _tpg_lun_of(tpg, pool_name, vol_name) # Pre-Check: # 1. Already mapped to requested access group, return None if any(tpg_lun.mapped_luns): tgt_map_list = access_group_map_list(req) for tgt_map in tgt_map_list: if tgt_map['ag_name'] == ag_name and \ tgt_map['pool_name'] == pool_name and \ tgt_map['vol_name'] == vol_name: # Already masked. return None node_acl_group = NodeACLGroup(tpg, ag_name) if not any(node_acl_group.wwns): # Non-existent access group means volume mapping status will not be # stored. This should be considered as an error instead of silently # returning. raise TargetdError(TargetdError.NOT_FOUND_ACCESS_GROUP, "Access group not found") if h_lun_id is None: # Find out next available host LUN ID # Assuming max host LUN ID is MAX_LUN free_h_lun_ids = set(range(MAX_LUN + 1)) - \ set([int(x.mapped_lun) for x in tpg_lun.mapped_luns]) if len(free_h_lun_ids) == 0: raise TargetdError(TargetdError.NO_FREE_HOST_LUN_ID, "All host LUN ID 0 ~ %d is in use" % MAX_LUN) else: h_lun_id = free_h_lun_ids.pop() node_acl_group.mapped_lun_group(h_lun_id, tpg_lun) RTSRoot().save_to_file()
def access_group_create(req, ag_name, init_id, init_type): if init_type != 'iscsi': raise TargetdError(TargetdError.NO_SUPPORT, "Only support iscsi") name_check(ag_name) tpg = _get_iscsi_tpg() # Pre-check: # 1. Name conflict: requested name is in use # 2. Initiator conflict: request initiator is in use for node_acl_group in tpg.node_acl_groups: if node_acl_group.name == ag_name: raise TargetdError(TargetdError.NAME_CONFLICT, "Requested access group name is in use") if init_id in list(i.node_wwn for i in tpg.node_acls): raise TargetdError(TargetdError.EXISTS_INITIATOR, "Requested init_id is in use") node_acl_group = NodeACLGroup(tpg, ag_name) node_acl_group.add_acl(init_id) RTSRoot().save_to_file()
def access_group_map_destroy(req, pool_name, vol_name, ag_name): tpg = _get_iscsi_tpg() node_acl_group = NodeACLGroup(tpg, ag_name) tpg_lun = _tpg_lun_of(tpg, pool_name, vol_name) for map_group in node_acl_group.mapped_lun_groups: if map_group.tpg_lun == tpg_lun: map_group.delete() if not any(tpg_lun.mapped_luns): # If LUN is not masked to any access group or initiator # remove LUN instance. lun_so = tpg_lun.storage_object tpg_lun.delete() lun_so.delete() RTSRoot().save_to_file()
def access_group_destroy(req, ag_name): NodeACLGroup(_get_iscsi_tpg(), ag_name).delete() RTSRoot().save_to_file()