Skip to content

Commit

Permalink
Fix problem when api_host set in config.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangdaolong committed Apr 3, 2020
1 parent 020682a commit 75b7fb4
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 28 deletions.
4 changes: 3 additions & 1 deletion ceph_iscsi_config/gateway_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ def normalize(self, raw_val):
"pool": StrSetting("pool", "rbd"),
"cluster_client_name": StrSetting("cluster_client_name", "client.admin"),
"time_out": IntSetting("time_out", 1, 600, 30),
"api_host": StrSetting("api_host", "::"),
# if the api_host has a colon, you must wrap it with square brackets.
# i.e:[::]
"api_host": StrSetting("api_host", "localhost"),
"api_port": IntSetting("api_port", 1, 65535, 5000),
"api_secure": BoolSetting("api_secure", True),
"api_ssl_verify": BoolSetting("api_ssl_verify", False),
Expand Down
3 changes: 2 additions & 1 deletion ceph_iscsi_config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def normalize_controls(raw_controls, settings_list):
return controls

exclude_from_hash = ["cluster_client_name",
"logger_level"
"logger_level",
"api_host"
]

def __init__(self, conffile='/etc/ceph/iscsi-gateway.cfg'):
Expand Down
2 changes: 2 additions & 0 deletions gwcli.8
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Typically, the following options are regarded as site specific;
.PP
\fBapi_password = <password>\fR
.PP
\fBapi_host = <ip_address or hostname>\fR
.PP
\fBapi_port = <port_number>\fR
.PP
\fBapi_secure = <true or false>\fR
Expand Down
14 changes: 9 additions & 5 deletions gwcli/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ def ui_command_create(self, client_iqn):
target_iqn = self.parent.name

# Issue the API call to create the client
client_api = ('{}://localhost:{}/api/'
client_api = ('{}://{}:{}/api/'
'client/{}/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn,
client_iqn))
Expand Down Expand Up @@ -126,7 +127,7 @@ def ui_command_delete(self, client_iqn):

client_api = ('{}://{}:{}/api/'
'client/{}/{}'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port,
target_iqn,
client_iqn))
Expand Down Expand Up @@ -217,8 +218,9 @@ def ui_command_auth(self, action=None):
else:
target_iqn = self.parent.name
api_vars = {'action': action}
targetauth_api = ('{}://localhost:{}/api/'
targetauth_api = ('{}://{}:{}/api/'
'targetauth/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn))
api = APIRequest(targetauth_api, data=api_vars)
Expand Down Expand Up @@ -399,8 +401,9 @@ def set_auth(self, username=None, password=None, mutual_username=None, mutual_pa
"mutual_password": mutual_password
}

clientauth_api = ('{}://localhost:{}/api/'
clientauth_api = ('{}://{}:{}/api/'
'clientauth/{}/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn,
self.client_iqn))
Expand Down Expand Up @@ -582,8 +585,9 @@ def ui_command_disk(self, action='add', disk=None, size=None):

api_vars = {"disk": disk}

clientlun_api = ('{}://localhost:{}/api/'
clientlun_api = ('{}://{}:{}/api/'
'clientlun/{}/{}'.format(self.http_mode,
settings.config.api_host.
settings.config.api_port,
target_iqn,
self.client_iqn))
Expand Down
23 changes: 15 additions & 8 deletions gwcli/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ def __init__(self, shell, scan_threads=1, endpoint=None):

if endpoint is None:

self.local_api = ('{}://localhost:{}/'
self.local_api = ('{}://{}:{}/'
'api'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port))

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

local_api = ('{}://localhost:{}/api/'
local_api = ('{}://{}:{}/api/'
'target/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn))

Expand Down Expand Up @@ -220,8 +222,9 @@ def ui_command_delete(self, target_iqn):
"iSCSI".format(target_iqn))
return

gw_api = ('{}://localhost:{}/api/'
gw_api = ('{}://{}:{}/api/'
'target/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn))

Expand Down Expand Up @@ -352,8 +355,9 @@ def ui_command_discovery_auth(self, username=None, password=None, mutual_usernam
"mutual_username": mutual_username,
"mutual_password": mutual_password
}
discoveryauth_api = ('{}://localhost:{}/api/'
discoveryauth_api = ('{}://{}:{}/api/'
'discoveryauth'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port))
api = APIRequest(discoveryauth_api, data=api_vars)
api.put()
Expand Down Expand Up @@ -499,8 +503,9 @@ def ui_command_reconfigure(self, attribute, value):
return

# Issue the api request for the reconfigure
gateways_api = ('{}://localhost:{}/api/'
gateways_api = ('{}://{}:{}/api/'
'target/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.target_iqn))

Expand Down Expand Up @@ -572,8 +577,9 @@ def ui_command_auth(self, username=None, password=None, mutual_username=None,
"mutual_password": mutual_password
}

targetauth_api = ('{}://localhost:{}/api/'
targetauth_api = ('{}://{}:{}/api/'
'targetauth/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
target_iqn))
api = APIRequest(targetauth_api, data=api_vars)
Expand Down Expand Up @@ -722,7 +728,8 @@ def ui_command_delete(self, gateway_name, confirm=None):
"objects on this target. Use confirm=true")
return

gw_api = '{}://{}:{}/api'.format(self.http_mode, "localhost",
gw_api = '{}://{}:{}/api'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port)
gw_rqst = gw_api + '/gateway/{}/{}'.format(target_iqn, gateway_name)
if confirm:
Expand Down Expand Up @@ -836,7 +843,7 @@ def ui_command_create(self, gateway_name, ip_addresses, nosync=False,
self.logger.info("Adding gateway, {}".format(sync_text))

gw_api = '{}://{}:{}/api'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port)
gw_rqst = gw_api + '/gateway/{}/{}'.format(target_iqn, gateway_name)
gw_vars = {"nosync": nosync,
Expand Down
8 changes: 4 additions & 4 deletions gwcli/hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def ui_command_create(self, group_name):
# this is a new group
group_api = ('{}://{}:{}/api/hostgroup/'
'{}/{}'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port,
target_iqn,
group_name))
Expand Down Expand Up @@ -132,7 +132,7 @@ def ui_command_delete(self, group_name):
# OK, so the group exists...
group_api = ('{}://{}:{}/api/hostgroup/'
'{}/{}'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port,
target_iqn,
group_name))
Expand Down Expand Up @@ -238,7 +238,7 @@ def ui_command_host(self, action, client_iqn):
# Basic checks passed, hand-off to the API now
group_api = ('{}://{}:{}/api/hostgroup/'
'{}/{}'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port,
target_iqn,
self.name))
Expand Down Expand Up @@ -337,7 +337,7 @@ def ui_command_disk(self, action, disk_name):
# Basic checks passed, hand-off to the API
group_api = ('{}://{}:{}/api/hostgroup/'
'{}/{}'.format(self.http_mode,
"localhost",
settings.config.api_host,
settings.config.api_port,
target_iqn,
self.name))
Expand Down
21 changes: 14 additions & 7 deletions gwcli/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ def create_disk(self, pool=None, image=None, size=None, count=1,
image))

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

disk_api = ('{}://localhost:{}/api/disk/'
disk_api = ('{}://{}:{}/api/disk/'
'{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
disk_key))

Expand Down Expand Up @@ -808,8 +810,9 @@ def reconfigure(self, attribute, value):
local_gw = this_host()

# Issue the api request for reconfigure
disk_api = ('{}://localhost:{}/api/'
disk_api = ('{}://{}:{}/api/'
'disk/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.image_id))

Expand Down Expand Up @@ -851,8 +854,9 @@ def resize(self, size):
local_gw = this_host()

# Issue the api request for the resize
disk_api = ('{}://localhost:{}/api/'
disk_api = ('{}://{}:{}/api/'
'disk/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.image_id))

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

self.logger.debug("Issuing snapshot {} request".format(action))
disk_api = ('{}://localhost:{}/api/'
disk_api = ('{}://{}:{}/api/'
'disksnap/{}/{}/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.pool,
self.rbd_image,
Expand Down Expand Up @@ -1015,8 +1020,9 @@ def ui_command_add(self, disk, lun_id=None):
def add_disk(self, disk, lun_id, success_msg='ok'):
rc = 0
api_vars = {"disk": disk, "lun_id": lun_id}
targetdisk_api = ('{}://localhost:{}/api/'
targetdisk_api = ('{}://{}:{}/api/'
'targetlun/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.target_iqn))
api = APIRequest(targetdisk_api, data=api_vars)
Expand Down Expand Up @@ -1047,8 +1053,9 @@ def ui_command_delete(self, disk):
def delete_disk(self, disk):
rc = 0
api_vars = {"disk": disk}
targetdisk_api = ('{}://localhost:{}/api/'
targetdisk_api = ('{}://{}:{}/api/'
'targetlun/{}'.format(self.http_mode,
settings.config.api_host,
settings.config.api_port,
self.target_iqn))
api = APIRequest(targetdisk_api, data=api_vars)
Expand Down
3 changes: 2 additions & 1 deletion gwcli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def get_config():
"""

http_mode = "https" if settings.config.api_secure else "http"
api_rqst = "{}://localhost:{}/api/config".format(http_mode,
api_rqst = "{}://{}:{}/api/config".format(http_mode,
settings.config.api_host,
settings.config.api_port)
api = APIRequest(api_rqst)
api.get()
Expand Down
1 change: 1 addition & 0 deletions iscsi-gateway.cfg_sample
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ api_secure = false
# api_user = admin
# api_password = admin
# api_port = 5000
# api_host = localhost
# trusted_ip_list = IP,IP

# Refer to the ceph-iscsi-config/settings module for more options
7 changes: 6 additions & 1 deletion rbd-target-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2439,7 +2439,7 @@ def hostgroup(target_iqn, group_name):
# At this point the group name is valid, so go ahead and remove it
api_endpoint = ("{}://{}:{}/api/"
"_hostgroup/{}/{}".format(http_mode,
'localhost',
settings.config.api_host,
settings.config.api_port,
target_iqn,
group_name
Expand Down Expand Up @@ -2621,6 +2621,8 @@ def target_ready(gateway_list):
"summary": ''}

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

for gw in gateway_list:
if gw == "localhost":
gw = settings.config.api_host

logger.debug("processing GW '{}'".format(gw))
api_endpoint = ("{}://{}:{}/api/"
"{}/{}".format(http_mode,
Expand Down

0 comments on commit 75b7fb4

Please sign in to comment.