此操作用来创建iSCSI Target。
说明
HBlock上target IQN的数量最多32766个。一个target最多可以关联256个卷,但是一个卷只能被一个target关联。
请求语法
单机版
POST /rest/v1/block/target HTTP/1.1
Date: date
Content-Type: application/json; charset=utf-8
Content-Length: length
Host: ip:port
Authorization: authorization
{
"targetName": targetName,
"maxSessions": value,
"reclaimPolicy": reclaimPolicy,
"chap":{
"name": name,
"password": password,
"status": status
},
"allowlist": {
"initiator": [
{
"IPs": [ip,ip,...],
"names": [name,name,...]
},
{
"IPs": [ip,ip,...],
"names": [name,name,...]
},
......
],
"target": [
{
"IPs": [ip,ip,...],
"NICs": [NIC,NIC,...]
},
{
"IPs": [ip,ip,...],
"NICs": [NIC,NIC,...]
},
......
]
}
}
集群版
POST /rest/v1/block/target HTTP/1.1
Date: date
Content-Type: application/json; charset=utf-8
Content-Length: length
Host: ip:port
Authorization: authorization
{
"targetName": targetName,
"maxSessions": value,
"reclaimPolicy": reclaimPolicy,
"chap":{
"name": name,
"password": password,
"status": status
},
"serverNumbers": value,
"server":["server_ID",…],
"allowlist": {
"initiator": [
{
"IPs": [ip,ip,...],
"names": [name,name,...]
},
{
"IPs": [ip,ip,...],
"names": [name,name,...]
},
......
],
"target": [
{
"IPs": [ip,ip,...],
"NICs": [NIC,NIC,...]
},
{
"IPs": [ip,ip,...],
"NICs": [NIC,NIC,...]
},
......
]
}
}
请求参数
参数 | 类型 | 描述 | 是否必须 |
---|---|---|---|
targetName | String | iSCSI target名称。 取值:长度范围是1~16,可以由小写字母、数字、句点(.)和短横线(-)组成,且仅支持以字母或数字开头。 | 是 |
maxSessions | Integer | iSCSI target下每个IQN允许建立的最大会话数。 取值:取值范围是[0, 1024],默认值为1。0表示客户端无法发现该target。 注意 如果多个客户端连接同一target IQN,客户端可以同时读,但不能同时写。 | 否 |
reclaimPolicy | String | 指定iSCSI target的回收策略。 取值:
默认值为Retain。 说明 如果创建卷时指定不存在的iSCSI target,那么同时创建iSCSI target,新创建iSCSI target的回收策略默认为Delete。 | 否 |
chap.name | String | CHAP名称。 取值:长度范围是3~64,可以由字母、数字、句点(.)、短横线(-)、下划线(_)和冒号(:)组成,字母区分大小写,且仅支持以字母或数字开头。 | 否 |
chap.password | String | CHAP密码。 取值:长度范围是12~16,必须包含大写字母、小写字母、数字、下划线(_)中的至少两种字符,字母区分大小写。 | 否 |
chap.status | String | 是否启用CHAP认证。 取值:
注意 如果启用CHAP认证,name和password必须设置。 | 是 |
serverNumbers | Integer | target所在的服务器数量(仅集群版支持)。 取值:[2, n],n为集群内服务器的数量。默认值是2。 | 否 |
server | Array of string | 指定iSCSI target对应的服务器ID(仅集群版支持)。 最多可以指定n个服务器ID,以英文逗号隔开。n为集群内服务器的数量。 | 否 |
allowlist.initiator | Array of initiator | 对target下所有IQN指定iSCSI发起方(initiator)允许访问列表。可以设置多组initiator允许访问列表,各组允许访问列表之间为“或”的关系。每组允许访问列表可以同时指定IP和initiator名称,二者为“与”的关系。详见“表1 参数initiator说明”。 说明 如果不设置,则表示允许所有访问。 | 否 |
allowlist.target | Array of target | 对target下所有IQN指定目标端(target)的允许访问列表。可以设置多组target允许访问列表,各组允许访问列表之间为“或”的关系。每组允许访问列表可以同时指定IP和NIC名称,二者为“与”的关系。详见“表2 参数target说明”。 说明 如果不设置,则表示允许所有访问。 | 否 |
表1 参数initiator说明
参数 | 类型 | 描述 | 是否必须 |
---|---|---|---|
IPs | Array of ip | 根据initiator IP地址设置iSCSI发起方的允许访问列表。 取值:IPv4、IPv6、CIDR子网,可以设置多个,以英文逗号分隔。如果设置"IPs":[],表示禁止所有发起端进行访问。 注意 IP不能为localhost。 | 否 |
names | Array of name | 根据initiator名称设置iSCSI发起方的允许访问列表。 取值:字符串形式,长度范围是1~223,只能由字母、数字、句点( . )、短横线( - )、冒号( : )组成,字母区分大小写。支持通配符*和?。可以设置多个,以英文逗号分隔。如果设置"names":[],表示禁止所有发起端进行访问。 | 否 |
表2 参数target说明
参数 | 类型 | 描述 | 是否必须 |
---|---|---|---|
IPs | Array of ip | 通过target端IP进行设置target允许访问列表,表示只允许通过target端的指定IP访问target。 取值:IPv4、IPv6、CIDR子网,可以设置多个,以英文逗号分隔。如果设置"IPs":[],表示禁止通过target端进行访问。 注意 IP不能为localhost。 | 否 |
NICs | Array of NIC | 通过target端的网卡名称设置target允许访问列表,表示只允许通过target端的指定网卡访问target。 取值:target端的网卡名称,可包含字母、数字、句点(.)、短横线(-)和下划线(_),最多100个字符。支持通配符*和?。可以设置多个,以英文逗号分隔。如果设置"NICs":[],表示禁止通过target端进行访问。 | 否 |
响应结果
名称 | 类型 | 描述 |
---|---|---|
iSCSITargets | Array of iSCSITarget | iSCSI target属性集合,详见“表3 响应参数iSCSITarget说明”。 |
表3 响应参数iSCSITarget说明
名称 | 类型 | 名称 |
---|---|---|
iqn | String | iSCSI target IQN。 |
ips | Array of ip | iSCSI target的IP属性集合,详见“表4 响应参数ip说明”。 |
allowlist.initiator | Array of initiator | iSCSI发起方(initiator)允许访问列表。详见“表5 响应参数initiator说明”。 |
allowlist.target | Array of target | 目标端(target)的允许访问列表。详见“表6 响应参数target说明”。 |
表4 响应参数ip说明
名称 | 类型 | 名称 |
---|---|---|
ip | String | iSCSI target的IP。 |
port | Integer | iSCSI target的端口号。 |
表5 响应参数initiator说明
名称 | 类型 | 描述 |
---|---|---|
IPs | Array of ip | 根据initiator IP地址设置的iSCSI发起方允许访问列表。 |
names | Array of name | 根据initiator名称设置的iSCSI发起方允许访问列表。 |
表6 响应参数target说明
名称 | 类型 | 描述 |
---|---|---|
IPs | Array of ip | 通过target端IP进行设置的target允许访问列表,表示只允许通过target端的指定IP访问target。 |
NICs | Array of NIC | 通过target端的网卡名称设置的target允许访问列表,表示只允许通过target端的指定网卡访问target。 |
请求示例1
单机版:创建一个名称为targete的target。
POST /rest/v1/block/target HTTP/1.1
Date: Tue, 14 Feb 2023 07: 58: 44 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 155
Host: 192.168.0.32: 1443
{
"targetName": "targete",
"chap": {
"name": "test",
"password": "12345678901a",
"status": "Enabled"
}
}
响应示例1
HTTP/1.1 200 OK
x-hblock-request-id: 8c2a6566e6d84b5e82ac26387c6a50ac
Connection: keep-alive
Content-Length: 217
Date: Tue, 14 Feb 2023 07: 58: 44 GMT
Content-Type: application/json;charset=utf-8
Server: HBlock
{
"data": {
"iSCSITargets": [
{
"iqn": "iqn.2012-08.cn.ctyunapi.oos:targete.6",
"ips": [
{
"ip": "192.168.0.32",
"port": 3260
}
]
}
]
}
}
请求示例2
单机版:创建一个名称为targetf的target。
POST /rest/v1/block/target HTTP/1.1
Date: Mon, 18 Aug 2025 02:25:34 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 571
Host: 192.168.0.66:1443
{
"targetName": "targetf",
"allowlist": {
"initiator": [
{
"IPs": [
"192.168.0.70"
],
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
]
},
{
"IPs": [
"192.168.0.67"
]
}
],
"target": [
{
"IPs": [
"192.168.0.66"
]
}
]
}
}
响应示例2
HTTP/1.1 200 OK
x-hblock-request-id: ca3aa28f0807489fa4af85833c4de8a7
Connection: keep-alive
Content-Length: 280
Date: Mon, 18 Aug 2025 02:25:34 GMT
Content-Type: application/json;charset=utf-8
Server: HBlock
{
"data": {
"iSCSITargets": [
{
"iqn": "iqn.2012-08.cn.ctyunapi.oos:targetf.4",
"ips": [
{
"ip": "192.168.0.66",
"port": 3260
}
],
"allowlist": {
"initiator": [
{
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
],
"IPs": [
"192.168.0.70"
]
},
{
"IPs": [
"192.168.0.67"
]
}
],
"target": [
{
"IPs": [
"192.168.0.66"
]
}
]
}
}
]
}
}
请求示例3
集群版:创建一个名称为target09的target。
POST /rest/v1/block/target HTTP/1.1
Date: Mon, 18 Aug 2025 02:19:06 GMT
Content-Type: application/json; charset=utf-8
Authorization: HBlock userName:signature
Content-Length: 910
Host: 192.168.0.64:1443
{
"targetName": "target09",
"maxSessions": 6,
"serverNumbers": 3,
"server": [
"hblock_1",
"hblock_3"
],
"allowlist": {
"initiator": [
{
"IPs": [
"192.168.0.70"
],
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
]
},
{
"IPs": [
"192.168.0.66"
]
}
],
"target": [
{
"IPs": [
"192.168.0.64",
"192.168.0.67"
]
},
{
"IPs": [
"192.168.0.65"
],
"NICs": [
"eth0"
]
}
]
}
}
响应示例3
HTTP/1.1 200 OK
x-hblock-request-id: 1f7fe9f8cd054d629a88f618fac0a878
Connection: keep-alive
Content-Length: 960
Date: Mon, 18 Aug 2025 02:19:06 GMT
Content-Type: application/json;charset=utf-8
Server: HBlock
{
"data": {
"iSCSITargets": [
{
"iqn": "iqn.2012-08.cn.ctyunapi.oos:target09.17",
"ips": [
{
"ip": "192.168.0.64",
"port": 3260
}
],
"allowlist": {
"initiator": [
{
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
],
"IPs": [
"192.168.0.70"
]
},
{
"IPs": [
"192.168.0.66"
]
}
],
"target": [
{
"IPs": [
"192.168.0.64",
"192.168.0.67"
]
},
{
"IPs": [
"192.168.0.65"
],
"NICs": [
"eth0"
]
}
]
}
},
{
"iqn": "iqn.2012-08.cn.ctyunapi.oos:target09.18",
"ips": [
{
"ip": "192.168.0.65",
"port": 3260
}
],
"allowlist": {
"initiator": [
{
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
],
"IPs": [
"192.168.0.70"
]
},
{
"IPs": [
"192.168.0.66"
]
}
],
"target": [
{
"IPs": [
"192.168.0.64",
"192.168.0.67"
]
},
{
"IPs": [
"192.168.0.65"
],
"NICs": [
"eth0"
]
}
]
}
},
{
"iqn": "iqn.2012-08.cn.ctyunapi.oos:target09.19",
"ips": [
{
"ip": "192.168.0.67",
"port": 3260
}
],
"allowlist": {
"initiator": [
{
"names": [
"iqn.1991-05.com.microsoft:songt-0001"
],
"IPs": [
"192.168.0.70"
]
},
{
"IPs": [
"192.168.0.66"
]
}
],
"target": [
{
"IPs": [
"192.168.0.64",
"192.168.0.67"
]
},
{
"IPs": [
"192.168.0.65"
],
"NICs": [
"eth0"
]
}
]
}
}
]
}
}