Skip to content

Commit 75b7fb4

Browse files
author
zhangdaolong
committed
Fix problem when api_host set in config.
1 parent 020682a commit 75b7fb4

File tree

10 files changed

+58
-28
lines changed

10 files changed

+58
-28
lines changed

ceph_iscsi_config/gateway_setting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ def normalize(self, raw_val):
171171
"pool": StrSetting("pool", "rbd"),
172172
"cluster_client_name": StrSetting("cluster_client_name", "client.admin"),
173173
"time_out": IntSetting("time_out", 1, 600, 30),
174-
"api_host": StrSetting("api_host", "::"),
174+
# if the api_host has a colon, you must wrap it with square brackets.
175+
# i.e:[::]
176+
"api_host": StrSetting("api_host", "localhost"),
175177
"api_port": IntSetting("api_port", 1, 65535, 5000),
176178
"api_secure": BoolSetting("api_secure", True),
177179
"api_ssl_verify": BoolSetting("api_ssl_verify", False),

ceph_iscsi_config/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def normalize_controls(raw_controls, settings_list):
4949
return controls
5050

5151
exclude_from_hash = ["cluster_client_name",
52-
"logger_level"
52+
"logger_level",
53+
"api_host"
5354
]
5455

5556
def __init__(self, conffile='/etc/ceph/iscsi-gateway.cfg'):

gwcli.8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Typically, the following options are regarded as site specific;
3131
.PP
3232
\fBapi_password = <password>\fR
3333
.PP
34+
\fBapi_host = <ip_address or hostname>\fR
35+
.PP
3436
\fBapi_port = <port_number>\fR
3537
.PP
3638
\fBapi_secure = <true or false>\fR

gwcli/client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ def ui_command_create(self, client_iqn):
7474
target_iqn = self.parent.name
7575

7676
# Issue the API call to create the client
77-
client_api = ('{}://localhost:{}/api/'
77+
client_api = ('{}://{}:{}/api/'
7878
'client/{}/{}'.format(self.http_mode,
79+
settings.config.api_host,
7980
settings.config.api_port,
8081
target_iqn,
8182
client_iqn))
@@ -126,7 +127,7 @@ def ui_command_delete(self, client_iqn):
126127

127128
client_api = ('{}://{}:{}/api/'
128129
'client/{}/{}'.format(self.http_mode,
129-
"localhost",
130+
settings.config.api_host,
130131
settings.config.api_port,
131132
target_iqn,
132133
client_iqn))
@@ -217,8 +218,9 @@ def ui_command_auth(self, action=None):
217218
else:
218219
target_iqn = self.parent.name
219220
api_vars = {'action': action}
220-
targetauth_api = ('{}://localhost:{}/api/'
221+
targetauth_api = ('{}://{}:{}/api/'
221222
'targetauth/{}'.format(self.http_mode,
223+
settings.config.api_host,
222224
settings.config.api_port,
223225
target_iqn))
224226
api = APIRequest(targetauth_api, data=api_vars)
@@ -399,8 +401,9 @@ def set_auth(self, username=None, password=None, mutual_username=None, mutual_pa
399401
"mutual_password": mutual_password
400402
}
401403

402-
clientauth_api = ('{}://localhost:{}/api/'
404+
clientauth_api = ('{}://{}:{}/api/'
403405
'clientauth/{}/{}'.format(self.http_mode,
406+
settings.config.api_host,
404407
settings.config.api_port,
405408
target_iqn,
406409
self.client_iqn))
@@ -582,8 +585,9 @@ def ui_command_disk(self, action='add', disk=None, size=None):
582585

583586
api_vars = {"disk": disk}
584587

585-
clientlun_api = ('{}://localhost:{}/api/'
588+
clientlun_api = ('{}://{}:{}/api/'
586589
'clientlun/{}/{}'.format(self.http_mode,
590+
settings.config.api_host.
587591
settings.config.api_port,
588592
target_iqn,
589593
self.client_iqn))

gwcli/gateway.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ def __init__(self, shell, scan_threads=1, endpoint=None):
4444

4545
if endpoint is None:
4646

47-
self.local_api = ('{}://localhost:{}/'
47+
self.local_api = ('{}://{}:{}/'
4848
'api'.format(self.http_mode,
49+
settings.config.api_host,
4950
settings.config.api_port))
5051

5152
else:
@@ -184,8 +185,9 @@ def ui_command_create(self, target_iqn):
184185
# 'safe' to continue with the definition
185186
self.logger.debug("Create an iscsi target definition in the UI")
186187

187-
local_api = ('{}://localhost:{}/api/'
188+
local_api = ('{}://{}:{}/api/'
188189
'target/{}'.format(self.http_mode,
190+
settings.config.api_host,
189191
settings.config.api_port,
190192
target_iqn))
191193

@@ -220,8 +222,9 @@ def ui_command_delete(self, target_iqn):
220222
"iSCSI".format(target_iqn))
221223
return
222224

223-
gw_api = ('{}://localhost:{}/api/'
225+
gw_api = ('{}://{}:{}/api/'
224226
'target/{}'.format(self.http_mode,
227+
settings.config.api_host,
225228
settings.config.api_port,
226229
target_iqn))
227230

@@ -352,8 +355,9 @@ def ui_command_discovery_auth(self, username=None, password=None, mutual_usernam
352355
"mutual_username": mutual_username,
353356
"mutual_password": mutual_password
354357
}
355-
discoveryauth_api = ('{}://localhost:{}/api/'
358+
discoveryauth_api = ('{}://{}:{}/api/'
356359
'discoveryauth'.format(self.http_mode,
360+
settings.config.api_host,
357361
settings.config.api_port))
358362
api = APIRequest(discoveryauth_api, data=api_vars)
359363
api.put()
@@ -499,8 +503,9 @@ def ui_command_reconfigure(self, attribute, value):
499503
return
500504

501505
# Issue the api request for the reconfigure
502-
gateways_api = ('{}://localhost:{}/api/'
506+
gateways_api = ('{}://{}:{}/api/'
503507
'target/{}'.format(self.http_mode,
508+
settings.config.api_host,
504509
settings.config.api_port,
505510
self.target_iqn))
506511

@@ -572,8 +577,9 @@ def ui_command_auth(self, username=None, password=None, mutual_username=None,
572577
"mutual_password": mutual_password
573578
}
574579

575-
targetauth_api = ('{}://localhost:{}/api/'
580+
targetauth_api = ('{}://{}:{}/api/'
576581
'targetauth/{}'.format(self.http_mode,
582+
settings.config.api_host,
577583
settings.config.api_port,
578584
target_iqn))
579585
api = APIRequest(targetauth_api, data=api_vars)
@@ -722,7 +728,8 @@ def ui_command_delete(self, gateway_name, confirm=None):
722728
"objects on this target. Use confirm=true")
723729
return
724730

725-
gw_api = '{}://{}:{}/api'.format(self.http_mode, "localhost",
731+
gw_api = '{}://{}:{}/api'.format(self.http_mode,
732+
settings.config.api_host,
726733
settings.config.api_port)
727734
gw_rqst = gw_api + '/gateway/{}/{}'.format(target_iqn, gateway_name)
728735
if confirm:
@@ -836,7 +843,7 @@ def ui_command_create(self, gateway_name, ip_addresses, nosync=False,
836843
self.logger.info("Adding gateway, {}".format(sync_text))
837844

838845
gw_api = '{}://{}:{}/api'.format(self.http_mode,
839-
"localhost",
846+
settings.config.api_host,
840847
settings.config.api_port)
841848
gw_rqst = gw_api + '/gateway/{}/{}'.format(target_iqn, gateway_name)
842849
gw_vars = {"nosync": nosync,

gwcli/hostgroup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def ui_command_create(self, group_name):
9090
# this is a new group
9191
group_api = ('{}://{}:{}/api/hostgroup/'
9292
'{}/{}'.format(self.http_mode,
93-
"localhost",
93+
settings.config.api_host,
9494
settings.config.api_port,
9595
target_iqn,
9696
group_name))
@@ -132,7 +132,7 @@ def ui_command_delete(self, group_name):
132132
# OK, so the group exists...
133133
group_api = ('{}://{}:{}/api/hostgroup/'
134134
'{}/{}'.format(self.http_mode,
135-
"localhost",
135+
settings.config.api_host,
136136
settings.config.api_port,
137137
target_iqn,
138138
group_name))
@@ -238,7 +238,7 @@ def ui_command_host(self, action, client_iqn):
238238
# Basic checks passed, hand-off to the API now
239239
group_api = ('{}://{}:{}/api/hostgroup/'
240240
'{}/{}'.format(self.http_mode,
241-
"localhost",
241+
settings.config.api_host,
242242
settings.config.api_port,
243243
target_iqn,
244244
self.name))
@@ -337,7 +337,7 @@ def ui_command_disk(self, action, disk_name):
337337
# Basic checks passed, hand-off to the API
338338
group_api = ('{}://{}:{}/api/hostgroup/'
339339
'{}/{}'.format(self.http_mode,
340-
"localhost",
340+
settings.config.api_host,
341341
settings.config.api_port,
342342
target_iqn,
343343
self.name))

gwcli/storage.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def create_disk(self, pool=None, image=None, size=None, count=1,
304304
image))
305305

306306
# make call to local api server's disk endpoint
307-
disk_api = '{}://localhost:{}/api/disk/{}'.format(self.http_mode,
307+
disk_api = '{}://{}:{}/api/disk/{}'.format(self.http_mode,
308+
settings.config.api_host,
308309
settings.config.api_port,
309310
disk_key)
310311
api_vars = {'pool': pool, 'owner': local_gw,
@@ -333,8 +334,9 @@ def create_disk(self, pool=None, image=None, size=None, count=1,
333334
else:
334335
disk_key = "{}/{}".format(pool, image)
335336

336-
disk_api = ('{}://localhost:{}/api/disk/'
337+
disk_api = ('{}://{}:{}/api/disk/'
337338
'{}'.format(self.http_mode,
339+
settings.config.api_host,
338340
settings.config.api_port,
339341
disk_key))
340342

@@ -808,8 +810,9 @@ def reconfigure(self, attribute, value):
808810
local_gw = this_host()
809811

810812
# Issue the api request for reconfigure
811-
disk_api = ('{}://localhost:{}/api/'
813+
disk_api = ('{}://{}:{}/api/'
812814
'disk/{}'.format(self.http_mode,
815+
settings.config.api_host,
813816
settings.config.api_port,
814817
self.image_id))
815818

@@ -851,8 +854,9 @@ def resize(self, size):
851854
local_gw = this_host()
852855

853856
# Issue the api request for the resize
854-
disk_api = ('{}://localhost:{}/api/'
857+
disk_api = ('{}://{}:{}/api/'
855858
'disk/{}'.format(self.http_mode,
859+
settings.config.api_host,
856860
settings.config.api_port,
857861
self.image_id))
858862

@@ -903,8 +907,9 @@ def snapshot(self, action, name):
903907
self.logger.warning("Please be patient, rollback might take time")
904908

905909
self.logger.debug("Issuing snapshot {} request".format(action))
906-
disk_api = ('{}://localhost:{}/api/'
910+
disk_api = ('{}://{}:{}/api/'
907911
'disksnap/{}/{}/{}'.format(self.http_mode,
912+
settings.config.api_host,
908913
settings.config.api_port,
909914
self.pool,
910915
self.rbd_image,
@@ -1015,8 +1020,9 @@ def ui_command_add(self, disk, lun_id=None):
10151020
def add_disk(self, disk, lun_id, success_msg='ok'):
10161021
rc = 0
10171022
api_vars = {"disk": disk, "lun_id": lun_id}
1018-
targetdisk_api = ('{}://localhost:{}/api/'
1023+
targetdisk_api = ('{}://{}:{}/api/'
10191024
'targetlun/{}'.format(self.http_mode,
1025+
settings.config.api_host,
10201026
settings.config.api_port,
10211027
self.target_iqn))
10221028
api = APIRequest(targetdisk_api, data=api_vars)
@@ -1047,8 +1053,9 @@ def ui_command_delete(self, disk):
10471053
def delete_disk(self, disk):
10481054
rc = 0
10491055
api_vars = {"disk": disk}
1050-
targetdisk_api = ('{}://localhost:{}/api/'
1056+
targetdisk_api = ('{}://{}:{}/api/'
10511057
'targetlun/{}'.format(self.http_mode,
1058+
settings.config.api_host,
10521059
settings.config.api_port,
10531060
self.target_iqn))
10541061
api = APIRequest(targetdisk_api, data=api_vars)

gwcli/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def get_config():
3737
"""
3838

3939
http_mode = "https" if settings.config.api_secure else "http"
40-
api_rqst = "{}://localhost:{}/api/config".format(http_mode,
40+
api_rqst = "{}://{}:{}/api/config".format(http_mode,
41+
settings.config.api_host,
4142
settings.config.api_port)
4243
api = APIRequest(api_rqst)
4344
api.get()

iscsi-gateway.cfg_sample

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ api_secure = false
2525
# api_user = admin
2626
# api_password = admin
2727
# api_port = 5000
28+
# api_host = localhost
2829
# trusted_ip_list = IP,IP
2930

3031
# Refer to the ceph-iscsi-config/settings module for more options

rbd-target-api.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ def hostgroup(target_iqn, group_name):
24392439
# At this point the group name is valid, so go ahead and remove it
24402440
api_endpoint = ("{}://{}:{}/api/"
24412441
"_hostgroup/{}/{}".format(http_mode,
2442-
'localhost',
2442+
settings.config.api_host,
24432443
settings.config.api_port,
24442444
target_iqn,
24452445
group_name
@@ -2621,6 +2621,8 @@ def target_ready(gateway_list):
26212621
"summary": ''}
26222622

26232623
for gw in gateway_list:
2624+
if gw == "localhost":
2625+
gw = settings.config.api_host
26242626
api_endpoint = ("{}://{}:{}/api/_ping".format(http_mode,
26252627
normalize_ip_literal(gw),
26262628
settings.config.api_port))
@@ -2673,6 +2675,9 @@ def call_api(gateway_list, endpoint, element, http_method='put', api_vars=None):
26732675
logger.debug("gateway update order is {}".format(','.join(gateway_list)))
26742676

26752677
for gw in gateway_list:
2678+
if gw == "localhost":
2679+
gw = settings.config.api_host
2680+
26762681
logger.debug("processing GW '{}'".format(gw))
26772682
api_endpoint = ("{}://{}:{}/api/"
26782683
"{}/{}".format(http_mode,

0 commit comments

Comments
 (0)