Skip to content

Commit 4341e6f

Browse files
committed
backport fixes to upstream
return public_url from config for discovery fix url creation for resources fix install script. add setting of public_url to install script. update sample config rework regions and remove public_url from config Change-Id: I1159f2ac8eeeb01433ec2373600475cd6b8a6688
1 parent cc0b9fb commit 4341e6f

File tree

8 files changed

+82
-63
lines changed

8 files changed

+82
-63
lines changed

etc/gceapi/gceapi.conf.sample

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@
5959
#gce_listen_port=8787
6060

6161

62-
#
63-
# Options defined in gceapi.api
64-
#
65-
66-
# Name of network API. neutron(quantum) or nova (string value)
67-
#network_api=neutron
68-
69-
# Keystone URL (string value)
70-
#keystone_gce_url=http://127.0.0.1:5000/v2.0
71-
72-
# name of public network (string value)
73-
#public_network=public
74-
75-
7662
#
7763
# Options defined in gceapi.wsgi
7864
#
@@ -102,6 +88,26 @@
10288
#tcp_keepidle=600
10389

10490

91+
#
92+
# Options defined in gceapi.api
93+
#
94+
95+
# Name of network API. neutron(quantum) or nova (string value)
96+
#network_api=neutron
97+
98+
# Keystone URL (string value)
99+
#keystone_gce_url=http://127.0.0.1:5000/v2.0
100+
101+
# name of public network (string value)
102+
#public_network=public
103+
104+
# Place of protocol files (string value)
105+
#protocol_dir=<None>
106+
107+
# Region of this service
108+
#region=RegionOne
109+
110+
105111
#
106112
# Options defined in gceapi.openstack.common.db.sqlalchemy.session
107113
#
@@ -181,7 +187,6 @@
181187
# configuration to any other existing logging options. Please
182188
# see the Python logging module documentation for details on
183189
# logging configuration files. (string value)
184-
# Deprecated group/name - [DEFAULT]/log_config
185190
#log_config_append=<None>
186191

187192
# DEPRECATED. A logging.Formatter log message format string
@@ -197,12 +202,10 @@
197202

198203
# (Optional) Name of log file to output to. If no default is
199204
# set, logging will go to stdout. (string value)
200-
# Deprecated group/name - [DEFAULT]/logfile
201205
#log_file=<None>
202206

203207
# (Optional) The base directory used for relative --log-file
204208
# paths (string value)
205-
# Deprecated group/name - [DEFAULT]/logdir
206209
#log_dir=<None>
207210

208211
# Use syslog for logging. Existing syslog format is DEPRECATED
@@ -227,7 +230,6 @@
227230
#
228231

229232
# The backend to use for db (string value)
230-
# Deprecated group/name - [DEFAULT]/db_backend
231233
#backend=sqlalchemy
232234

233235

@@ -237,9 +239,6 @@
237239

238240
# The SQLAlchemy connection string used to connect to the
239241
# database (string value)
240-
# Deprecated group/name - [DEFAULT]/sql_connection
241-
# Deprecated group/name - [DATABASE]/sql_connection
242-
# Deprecated group/name - [sql]/connection
243242
#connection=sqlite:////gceapi/openstack/common/db/$sqlite_db
244243

245244
# The SQLAlchemy connection string used to connect to the
@@ -248,53 +247,38 @@
248247

249248
# Timeout before idle sql connections are reaped (integer
250249
# value)
251-
# Deprecated group/name - [DEFAULT]/sql_idle_timeout
252-
# Deprecated group/name - [DATABASE]/sql_idle_timeout
253-
# Deprecated group/name - [sql]/idle_timeout
254250
#idle_timeout=3600
255251

256252
# Minimum number of SQL connections to keep open in a pool
257253
# (integer value)
258-
# Deprecated group/name - [DEFAULT]/sql_min_pool_size
259-
# Deprecated group/name - [DATABASE]/sql_min_pool_size
260254
#min_pool_size=1
261255

262256
# Maximum number of SQL connections to keep open in a pool
263257
# (integer value)
264-
# Deprecated group/name - [DEFAULT]/sql_max_pool_size
265-
# Deprecated group/name - [DATABASE]/sql_max_pool_size
266258
#max_pool_size=<None>
267259

268260
# Maximum db connection retries during startup. (setting -1
269261
# implies an infinite retry count) (integer value)
270-
# Deprecated group/name - [DEFAULT]/sql_max_retries
271-
# Deprecated group/name - [DATABASE]/sql_max_retries
272262
#max_retries=10
273263

274264
# Interval between retries of opening a sql connection
275265
# (integer value)
276-
# Deprecated group/name - [DEFAULT]/sql_retry_interval
277-
# Deprecated group/name - [DATABASE]/reconnect_interval
278266
#retry_interval=10
279267

280268
# If set, use this value for max_overflow with sqlalchemy
281269
# (integer value)
282-
# Deprecated group/name - [DEFAULT]/sql_max_overflow
283-
# Deprecated group/name - [DATABASE]/sqlalchemy_max_overflow
284270
#max_overflow=<None>
285271

286272
# Verbosity of SQL debugging information. 0=None,
287273
# 100=Everything (integer value)
288-
# Deprecated group/name - [DEFAULT]/sql_connection_debug
289274
#connection_debug=0
290275

291276
# Add python stack traces to SQL as comment strings (boolean
292277
# value)
293-
# Deprecated group/name - [DEFAULT]/sql_connection_trace
294278
#connection_trace=false
295279

296280
# If set, use this value for pool_timeout with sqlalchemy
297281
# (integer value)
298-
# Deprecated group/name - [DATABASE]/sqlalchemy_pool_timeout
299282
#pool_timeout=<None>
300283

284+

gceapi/api/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
cfg.StrOpt('protocol_dir',
5050
default=None,
5151
help='Place of protocol files'),
52-
cfg.StrOpt('region_list',
52+
cfg.StrOpt('region',
5353
default='RegionOne',
54-
help='list of regions separated by commas'),
54+
help='Region of this service'),
5555
]
5656

5757
CONF = cfg.CONF

gceapi/api/clients.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def nova(context, service_type='compute'):
5858

5959
client = novaclient.Client(1.1, **args)
6060

61-
management_url = _url_for(context, service_type=service_type)
61+
management_url = get_endpoint(context, service_type)
6262
client.client.auth_token = context.auth_token
6363
client.client.management_url = management_url
6464

@@ -73,7 +73,7 @@ def neutron(context):
7373
'auth_url': CONF.keystone_gce_url,
7474
'service_type': 'network',
7575
'token': context.auth_token,
76-
'endpoint_url': _url_for(context, service_type='network'),
76+
'endpoint_url': get_endpoint(context, 'network'),
7777
}
7878

7979
return neutronclient.Client(**args)
@@ -90,7 +90,7 @@ def glance(context):
9090
}
9191

9292
return glanceclient.Client(
93-
"1", endpoint=_url_for(context, service_type='image'), **args)
93+
"1", endpoint=get_endpoint(context, 'image'), **args)
9494

9595

9696
def cinder(context):
@@ -105,7 +105,7 @@ def cinder(context):
105105
}
106106

107107
_cinder = cinderclient.Client('1', **args)
108-
management_url = _url_for(context, service_type='volume')
108+
management_url = get_endpoint(context, 'volume')
109109
_cinder.client.auth_token = context.auth_token
110110
_cinder.client.management_url = management_url
111111

@@ -121,21 +121,25 @@ def keystone(context):
121121
return _keystone
122122

123123

124-
def _url_for(context, **kwargs):
125-
service_catalog = context.service_catalog
126-
if not service_catalog:
127-
catalog = keystone(context).service_catalog.catalog
128-
service_catalog = catalog["serviceCatalog"]
129-
context.service_catalog = service_catalog
130-
131-
service_type = kwargs["service_type"]
124+
def get_endpoint_from_catalog(service_catalog, service_type):
132125
for service in service_catalog:
133126
if service["type"] != service_type:
134127
continue
135128
for endpoint in service["endpoints"]:
136-
if "publicURL" in endpoint:
137-
return endpoint["publicURL"]
138-
else:
139-
return None
129+
if endpoint["region"] != CONF["region"]:
130+
continue
131+
return endpoint.get("publicURL")
132+
133+
return None
140134

141135
return None
136+
137+
138+
def get_endpoint(context, service_type):
139+
service_catalog = context.service_catalog
140+
if not service_catalog:
141+
catalog = keystone(context).service_catalog.catalog
142+
service_catalog = catalog["serviceCatalog"]
143+
context.service_catalog = service_catalog
144+
145+
return get_endpoint_from_catalog(service_catalog, service_type)

gceapi/api/common.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import re
1919
from webob import exc
2020

21+
from oslo.config import cfg
22+
23+
from gceapi.api import clients
2124
from gceapi.api import operation_api
2225
from gceapi.api import operation_util
2326
from gceapi.api import scopes
@@ -28,6 +31,7 @@
2831
from gceapi.openstack.common import timeutils
2932

3033
LOG = logging.getLogger(__name__)
34+
FLAGS = cfg.CONF
3135

3236

3337
class Controller(object):
@@ -263,8 +267,16 @@ def _qualify(self, request, controller, identifier, scope):
263267
'zones/zone_id' prefix for zone(similar for regions) resources.
264268
"""
265269

270+
context = self._get_context(request)
271+
public_url = clients.get_endpoint(context, "gceapi")
272+
if public_url:
273+
public_url = public_url.rstrip("/") + "/"\
274+
+ request.script_name.lstrip("/")
275+
else:
276+
public_url = request.application_url
277+
266278
result = os.path.join(
267-
request.application_url, self._get_context(request).project_name)
279+
public_url, context.project_name)
268280
if controller:
269281
if scope:
270282
result = os.path.join(result, scope.get_path())

gceapi/api/discovery.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import threading
1818
import webob
1919

20+
from keystoneclient.v2_0 import client as keystone_client
2021
from oslo.config import cfg
2122

23+
from gceapi.api import clients
2224
from gceapi.openstack.common import log as logging
2325
from gceapi import wsgi_ext as openstack_wsgi
2426

@@ -34,17 +36,28 @@ class Controller(object):
3436
def discovery(self, req, version):
3537
"""Returns appropriate json by its version."""
3638

37-
key = version + req.host_url
39+
key = version
3840
if key in self._files:
3941
return self._files[key]
4042

43+
tenant = FLAGS.keystone_authtoken["admin_tenant_name"]
44+
user = FLAGS.keystone_authtoken["admin_user"]
45+
password = FLAGS.keystone_authtoken["admin_password"]
46+
keystone = keystone_client.Client(username=user, password=password,
47+
tenant_name=tenant, auth_url=FLAGS.keystone_gce_url)
48+
catalog = keystone.service_catalog.catalog["serviceCatalog"]
49+
public_url = clients.get_endpoint_from_catalog(catalog, "gceapi")
50+
if not public_url:
51+
public_url = req.host_url
52+
public_url = public_url.rstrip("/")
53+
4154
self._lock.acquire()
4255
try:
4356
if key in self._files:
4457
return self._files[key]
4558

4659
jfile = self._load_file(version)
47-
jfile = jfile.replace("{HOST_URL}", req.host_url)
60+
jfile = jfile.replace("{HOST_URL}", public_url)
4861
self._files[key] = jfile
4962
return jfile
5063
finally:

gceapi/api/oauth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333

3434
INTERNAL_GCUTIL_PROJECTS = ["debian-cloud", "centos-cloud", "suse-cloud",
35-
"rhel-cloud", "google"]
35+
"rhel-cloud", "windows-cloud", "google"]
3636

3737

3838
class OAuthFault(openstack_wsgi.Fault):

gceapi/api/region_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
class API(base_api.API):
2525
"""GCE Regions API
2626
27-
Stubbed now for support only one predefined region nova
27+
Stubbed now for support only one predefined region from config
28+
#TODO(apavlov): need to implement discovering or regions from keystone
2829
"""
2930

3031
KIND = "region"
3132
_REGIONS = []
3233

3334
def __init__(self, *args, **kwargs):
3435
super(API, self).__init__(*args, **kwargs)
35-
regions = CONF.get("region_list").split(",")
36-
self._REGIONS = [r.strip() for r in regions]
36+
self._REGIONS = [CONF.get("region").strip()]
3737

3838
def _get_type(self):
3939
return self.KIND

install.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ CONNECTION="mysql://root:[email protected]/gceapi?charset=utf8"
88
LOG_DIR=/var/log/gceapi
99
CONF_DIR=/etc/gceapi
1010
SIGNING_DIR=/var/cache/gceapi
11+
#this default values are for devstack. change it for real cloud (NETWORK_API=nova for example)
12+
NETWORK_API=quantum
13+
REGION=RegionOne
1114

1215
#Check for environment
1316
if [[ -z "$OS_AUTH_URL" || -z "$OS_USERNAME" || -z "$OS_PASSWORD" || -z "$OS_TENANT_NAME" ]]; then
@@ -200,7 +203,7 @@ APIPASTE_FILE=$CONF_DIR/api-paste.ini
200203
echo Creating configs
201204
sudo mkdir -p /etc/gceapi > /dev/null
202205
if [ ! -s $CONF_FILE ]; then
203-
sudo cp etc/gceapi/gceapi.conf $CONF_FILE
206+
sudo cp etc/gceapi/gceapi.conf.sample $CONF_FILE
204207
fi
205208
if [ ! -s $APIPASTE_FILE ]; then
206209
sudo cp etc/gceapi/api-paste.ini $APIPASTE_FILE
@@ -213,12 +216,15 @@ AUTH_PORT=`keystone catalog|grep -A 9 identity|grep adminURL|awk '{print $4}'`
213216
AUTH_PORT=${AUTH_PORT##*:}
214217
AUTH_PORT=${AUTH_PORT%%/*}
215218
AUTH_PROTO=${OS_AUTH_URL%%:*}
219+
PUBLIC_URL=${OS_AUTH_URL%:*}:8787/
216220

217221
#update default config with some values
218222
iniset $CONF_FILE DEFAULT api_paste_config $APIPASTE_FILE
219223
iniset $CONF_FILE DEFAULT logging_context_format_string "%(asctime)s.%(msecs)03d %(levelname)s %(name)s [%(request_id)s %(user_name)s %(project_name)s] %(instance)s%(message)s"
220224
iniset $CONF_FILE DEFAULT verbose True
221225
iniset $CONF_FILE DEFAULT keystone_gce_url "$OS_AUTH_URL"
226+
iniset $CONF_FILE DEFAULT network_api "$NETWORK_API"
227+
iniset $CONF_FILE DEFAULT region "$REGION"
222228
iniset $CONF_FILE database connection "$CONNECTION"
223229

224230
iniset $CONF_FILE keystone_authtoken signing_dir $SIGNING_DIR

0 commit comments

Comments
 (0)