OpenStack Image Management (Glance)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.py 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. # Copyright 2011 OpenStack Foundation
  2. # All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. """
  16. Routines for configuring Glance
  17. """
  18. import logging
  19. import os
  20. from oslo_config import cfg
  21. from oslo_middleware import cors
  22. from oslo_policy import policy
  23. from paste import deploy
  24. from glance.i18n import _
  25. from glance.version import version_info as version
  26. paste_deploy_opts = [
  27. cfg.StrOpt('flavor',
  28. sample_default='keystone',
  29. help=_("""
  30. Deployment flavor to use in the server application pipeline.
  31. Provide a string value representing the appropriate deployment
  32. flavor used in the server application pipleline. This is typically
  33. the partial name of a pipeline in the paste configuration file with
  34. the service name removed.
  35. For example, if your paste section name in the paste configuration
  36. file is [pipeline:glance-api-keystone], set ``flavor`` to
  37. ``keystone``.
  38. Possible values:
  39. * String value representing a partial pipeline name.
  40. Related Options:
  41. * config_file
  42. """)),
  43. cfg.StrOpt('config_file',
  44. sample_default='glance-api-paste.ini',
  45. help=_("""
  46. Name of the paste configuration file.
  47. Provide a string value representing the name of the paste
  48. configuration file to use for configuring piplelines for
  49. server application deployments.
  50. NOTES:
  51. * Provide the name or the path relative to the glance directory
  52. for the paste configuration file and not the absolute path.
  53. * The sample paste configuration file shipped with Glance need
  54. not be edited in most cases as it comes with ready-made
  55. pipelines for all common deployment flavors.
  56. If no value is specified for this option, the ``paste.ini`` file
  57. with the prefix of the corresponding Glance service's configuration
  58. file name will be searched for in the known configuration
  59. directories. (For example, if this option is missing from or has no
  60. value set in ``glance-api.conf``, the service will look for a file
  61. named ``glance-api-paste.ini``.) If the paste configuration file is
  62. not found, the service will not start.
  63. Possible values:
  64. * A string value representing the name of the paste configuration
  65. file.
  66. Related Options:
  67. * flavor
  68. """)),
  69. ]
  70. image_format_opts = [
  71. cfg.ListOpt('container_formats',
  72. default=['ami', 'ari', 'aki', 'bare', 'ovf', 'ova', 'docker'],
  73. help=_("Supported values for the 'container_format' "
  74. "image attribute"),
  75. deprecated_opts=[cfg.DeprecatedOpt('container_formats',
  76. group='DEFAULT')]),
  77. cfg.ListOpt('disk_formats',
  78. default=['ami', 'ari', 'aki', 'vhd', 'vhdx', 'vmdk', 'raw',
  79. 'qcow2', 'vdi', 'iso', 'ploop'],
  80. help=_("Supported values for the 'disk_format' "
  81. "image attribute"),
  82. deprecated_opts=[cfg.DeprecatedOpt('disk_formats',
  83. group='DEFAULT')]),
  84. ]
  85. task_opts = [
  86. cfg.IntOpt('task_time_to_live',
  87. default=48,
  88. help=_("Time in hours for which a task lives after, either "
  89. "succeeding or failing"),
  90. deprecated_opts=[cfg.DeprecatedOpt('task_time_to_live',
  91. group='DEFAULT')]),
  92. cfg.StrOpt('task_executor',
  93. default='taskflow',
  94. help=_("""
  95. Task executor to be used to run task scripts.
  96. Provide a string value representing the executor to use for task
  97. executions. By default, ``TaskFlow`` executor is used.
  98. ``TaskFlow`` helps make task executions easy, consistent, scalable
  99. and reliable. It also enables creation of lightweight task objects
  100. and/or functions that are combined together into flows in a
  101. declarative manner.
  102. Possible values:
  103. * taskflow
  104. Related Options:
  105. * None
  106. """)),
  107. cfg.StrOpt('work_dir',
  108. sample_default='/work_dir',
  109. help=_("""
  110. Absolute path to the work directory to use for asynchronous
  111. task operations.
  112. The directory set here will be used to operate over images -
  113. normally before they are imported in the destination store.
  114. NOTE: When providing a value for ``work_dir``, please make sure
  115. that enough space is provided for concurrent tasks to run
  116. efficiently without running out of space.
  117. A rough estimation can be done by multiplying the number of
  118. ``max_workers`` with an average image size (e.g 500MB). The image
  119. size estimation should be done based on the average size in your
  120. deployment. Note that depending on the tasks running you may need
  121. to multiply this number by some factor depending on what the task
  122. does. For example, you may want to double the available size if
  123. image conversion is enabled. All this being said, remember these
  124. are just estimations and you should do them based on the worst
  125. case scenario and be prepared to act in case they were wrong.
  126. Possible values:
  127. * String value representing the absolute path to the working
  128. directory
  129. Related Options:
  130. * None
  131. """)),
  132. ]
  133. _DEPRECATE_GLANCE_V1_MSG = _('The Images (Glance) version 1 API has been '
  134. 'DEPRECATED in the Newton release and will be '
  135. 'removed on or after Pike release, following '
  136. 'the standard OpenStack deprecation policy. '
  137. 'Hence, the configuration options specific to '
  138. 'the Images (Glance) v1 API are hereby '
  139. 'deprecated and subject to removal. Operators '
  140. 'are advised to deploy the Images (Glance) v2 '
  141. 'API.')
  142. common_opts = [
  143. cfg.BoolOpt('allow_additional_image_properties', default=True,
  144. help=_("""
  145. Allow users to add additional/custom properties to images.
  146. Glance defines a standard set of properties (in its schema) that
  147. appear on every image. These properties are also known as
  148. ``base properties``. In addition to these properties, Glance
  149. allows users to add custom properties to images. These are known
  150. as ``additional properties``.
  151. By default, this configuration option is set to ``True`` and users
  152. are allowed to add additional properties. The number of additional
  153. properties that can be added to an image can be controlled via
  154. ``image_property_quota`` configuration option.
  155. Possible values:
  156. * True
  157. * False
  158. Related options:
  159. * image_property_quota
  160. """)),
  161. cfg.IntOpt('image_member_quota', default=128,
  162. help=_("""
  163. Maximum number of image members per image.
  164. This limits the maximum of users an image can be shared with. Any negative
  165. value is interpreted as unlimited.
  166. Related options:
  167. * None
  168. """)),
  169. cfg.IntOpt('image_property_quota', default=128,
  170. help=_("""
  171. Maximum number of properties allowed on an image.
  172. This enforces an upper limit on the number of additional properties an image
  173. can have. Any negative value is interpreted as unlimited.
  174. NOTE: This won't have any impact if additional properties are disabled. Please
  175. refer to ``allow_additional_image_properties``.
  176. Related options:
  177. * ``allow_additional_image_properties``
  178. """)),
  179. cfg.IntOpt('image_tag_quota', default=128,
  180. help=_("""
  181. Maximum number of tags allowed on an image.
  182. Any negative value is interpreted as unlimited.
  183. Related options:
  184. * None
  185. """)),
  186. cfg.IntOpt('image_location_quota', default=10,
  187. help=_("""
  188. Maximum number of locations allowed on an image.
  189. Any negative value is interpreted as unlimited.
  190. Related options:
  191. * None
  192. """)),
  193. # TODO(abashmak): Add choices parameter to this option:
  194. # choices('glance.db.sqlalchemy.api',
  195. # 'glance.db.registry.api',
  196. # 'glance.db.simple.api')
  197. # This will require a fix to the functional tests which
  198. # set this option to a test version of the registry api module:
  199. # (glance.tests.functional.v2.registry_data_api), in order to
  200. # bypass keystone authentication for the Registry service.
  201. # All such tests are contained in:
  202. # glance/tests/functional/v2/test_images.py
  203. cfg.StrOpt('data_api',
  204. default='glance.db.sqlalchemy.api',
  205. deprecated_for_removal=True,
  206. deprecated_since="Queens",
  207. deprecated_reason=_("""
  208. Glance registry service is deprecated for removal.
  209. More information can be found from the spec:
  210. http://specs.openstack.org/openstack/glance-specs/specs/queens/approved/glance/deprecate-registry.html
  211. """),
  212. help=_("""
  213. Python module path of data access API.
  214. Specifies the path to the API to use for accessing the data model.
  215. This option determines how the image catalog data will be accessed.
  216. Possible values:
  217. * glance.db.sqlalchemy.api
  218. * glance.db.registry.api
  219. * glance.db.simple.api
  220. If this option is set to ``glance.db.sqlalchemy.api`` then the image
  221. catalog data is stored in and read from the database via the
  222. SQLAlchemy Core and ORM APIs.
  223. Setting this option to ``glance.db.registry.api`` will force all
  224. database access requests to be routed through the Registry service.
  225. This avoids data access from the Glance API nodes for an added layer
  226. of security, scalability and manageability.
  227. NOTE: In v2 OpenStack Images API, the registry service is optional.
  228. In order to use the Registry API in v2, the option
  229. ``enable_v2_registry`` must be set to ``True``.
  230. Finally, when this configuration option is set to
  231. ``glance.db.simple.api``, image catalog data is stored in and read
  232. from an in-memory data structure. This is primarily used for testing.
  233. Related options:
  234. * enable_v2_api
  235. * enable_v2_registry
  236. """)),
  237. cfg.IntOpt('limit_param_default', default=25, min=1,
  238. help=_("""
  239. The default number of results to return for a request.
  240. Responses to certain API requests, like list images, may return
  241. multiple items. The number of results returned can be explicitly
  242. controlled by specifying the ``limit`` parameter in the API request.
  243. However, if a ``limit`` parameter is not specified, this
  244. configuration value will be used as the default number of results to
  245. be returned for any API request.
  246. NOTES:
  247. * The value of this configuration option may not be greater than
  248. the value specified by ``api_limit_max``.
  249. * Setting this to a very large value may slow down database
  250. queries and increase response times. Setting this to a
  251. very low value may result in poor user experience.
  252. Possible values:
  253. * Any positive integer
  254. Related options:
  255. * api_limit_max
  256. """)),
  257. cfg.IntOpt('api_limit_max', default=1000, min=1,
  258. help=_("""
  259. Maximum number of results that could be returned by a request.
  260. As described in the help text of ``limit_param_default``, some
  261. requests may return multiple results. The number of results to be
  262. returned are governed either by the ``limit`` parameter in the
  263. request or the ``limit_param_default`` configuration option.
  264. The value in either case, can't be greater than the absolute maximum
  265. defined by this configuration option. Anything greater than this
  266. value is trimmed down to the maximum value defined here.
  267. NOTE: Setting this to a very large value may slow down database
  268. queries and increase response times. Setting this to a
  269. very low value may result in poor user experience.
  270. Possible values:
  271. * Any positive integer
  272. Related options:
  273. * limit_param_default
  274. """)),
  275. cfg.BoolOpt('show_image_direct_url', default=False,
  276. help=_("""
  277. Show direct image location when returning an image.
  278. This configuration option indicates whether to show the direct image
  279. location when returning image details to the user. The direct image
  280. location is where the image data is stored in backend storage. This
  281. image location is shown under the image property ``direct_url``.
  282. When multiple image locations exist for an image, the best location
  283. is displayed based on the location strategy indicated by the
  284. configuration option ``location_strategy``.
  285. NOTES:
  286. * Revealing image locations can present a GRAVE SECURITY RISK as
  287. image locations can sometimes include credentials. Hence, this
  288. is set to ``False`` by default. Set this to ``True`` with
  289. EXTREME CAUTION and ONLY IF you know what you are doing!
  290. * If an operator wishes to avoid showing any image location(s)
  291. to the user, then both this option and
  292. ``show_multiple_locations`` MUST be set to ``False``.
  293. Possible values:
  294. * True
  295. * False
  296. Related options:
  297. * show_multiple_locations
  298. * location_strategy
  299. """)),
  300. # NOTE(flaper87): The policy.json file should be updated and the locaiton
  301. # related rules set to admin only once this option is finally removed.
  302. cfg.BoolOpt('show_multiple_locations', default=False,
  303. deprecated_for_removal=True,
  304. deprecated_reason=_('This option will be removed in the Pike '
  305. 'release or later because the same '
  306. 'functionality can be achieved with '
  307. 'greater granularity by using policies. '
  308. 'Please see the Newton '
  309. 'release notes for more information.'),
  310. deprecated_since='Newton',
  311. help=_("""
  312. Show all image locations when returning an image.
  313. This configuration option indicates whether to show all the image
  314. locations when returning image details to the user. When multiple
  315. image locations exist for an image, the locations are ordered based
  316. on the location strategy indicated by the configuration opt
  317. ``location_strategy``. The image locations are shown under the
  318. image property ``locations``.
  319. NOTES:
  320. * Revealing image locations can present a GRAVE SECURITY RISK as
  321. image locations can sometimes include credentials. Hence, this
  322. is set to ``False`` by default. Set this to ``True`` with
  323. EXTREME CAUTION and ONLY IF you know what you are doing!
  324. * If an operator wishes to avoid showing any image location(s)
  325. to the user, then both this option and
  326. ``show_image_direct_url`` MUST be set to ``False``.
  327. Possible values:
  328. * True
  329. * False
  330. Related options:
  331. * show_image_direct_url
  332. * location_strategy
  333. """)),
  334. cfg.IntOpt('image_size_cap', default=1099511627776, min=1,
  335. max=9223372036854775808,
  336. help=_("""
  337. Maximum size of image a user can upload in bytes.
  338. An image upload greater than the size mentioned here would result
  339. in an image creation failure. This configuration option defaults to
  340. 1099511627776 bytes (1 TiB).
  341. NOTES:
  342. * This value should only be increased after careful
  343. consideration and must be set less than or equal to
  344. 8 EiB (9223372036854775808).
  345. * This value must be set with careful consideration of the
  346. backend storage capacity. Setting this to a very low value
  347. may result in a large number of image failures. And, setting
  348. this to a very large value may result in faster consumption
  349. of storage. Hence, this must be set according to the nature of
  350. images created and storage capacity available.
  351. Possible values:
  352. * Any positive number less than or equal to 9223372036854775808
  353. """)),
  354. cfg.StrOpt('user_storage_quota', default='0',
  355. help=_("""
  356. Maximum amount of image storage per tenant.
  357. This enforces an upper limit on the cumulative storage consumed by all images
  358. of a tenant across all stores. This is a per-tenant limit.
  359. The default unit for this configuration option is Bytes. However, storage
  360. units can be specified using case-sensitive literals ``B``, ``KB``, ``MB``,
  361. ``GB`` and ``TB`` representing Bytes, KiloBytes, MegaBytes, GigaBytes and
  362. TeraBytes respectively. Note that there should not be any space between the
  363. value and unit. Value ``0`` signifies no quota enforcement. Negative values
  364. are invalid and result in errors.
  365. Possible values:
  366. * A string that is a valid concatenation of a non-negative integer
  367. representing the storage value and an optional string literal
  368. representing storage units as mentioned above.
  369. Related options:
  370. * None
  371. """)),
  372. cfg.BoolOpt('enable_v2_api',
  373. default=True,
  374. deprecated_reason=_('The Images (Glance) version 1 API has '
  375. 'been DEPRECATED in the Newton release. '
  376. 'It will be removed on or after Pike '
  377. 'release, following the standard '
  378. 'OpenStack deprecation policy. Once we '
  379. 'remove the Images (Glance) v1 API, only '
  380. 'the Images (Glance) v2 API can be '
  381. 'deployed and will be enabled by default '
  382. 'making this option redundant.'),
  383. deprecated_since='Newton',
  384. help=_("""
  385. Deploy the v2 OpenStack Images API.
  386. When this option is set to ``True``, Glance service will respond
  387. to requests on registered endpoints conforming to the v2 OpenStack
  388. Images API.
  389. NOTES:
  390. * If this option is disabled, then the ``enable_v2_registry``
  391. option, which is enabled by default, is also recommended
  392. to be disabled.
  393. Possible values:
  394. * True
  395. * False
  396. Related options:
  397. * enable_v2_registry
  398. """)),
  399. cfg.BoolOpt('enable_v1_registry',
  400. default=True,
  401. deprecated_reason=_DEPRECATE_GLANCE_V1_MSG,
  402. deprecated_since='Newton',
  403. help=_("""
  404. DEPRECATED FOR REMOVAL
  405. """)),
  406. cfg.BoolOpt('enable_v2_registry',
  407. default=True,
  408. deprecated_for_removal=True,
  409. deprecated_since="Queens",
  410. deprecated_reason=_("""
  411. Glance registry service is deprecated for removal.
  412. More information can be found from the spec:
  413. http://specs.openstack.org/openstack/glance-specs/specs/queens/approved/glance/deprecate-registry.html
  414. """),
  415. help=_("""
  416. Deploy the v2 API Registry service.
  417. When this option is set to ``True``, the Registry service
  418. will be enabled in Glance for v2 API requests.
  419. NOTES:
  420. * Use of Registry is optional in v2 API, so this option
  421. must only be enabled if both ``enable_v2_api`` is set to
  422. ``True`` and the ``data_api`` option is set to
  423. ``glance.db.registry.api``.
  424. * If deploying only the v1 OpenStack Images API, this option,
  425. which is enabled by default, should be disabled.
  426. Possible values:
  427. * True
  428. * False
  429. Related options:
  430. * enable_v2_api
  431. * data_api
  432. """)),
  433. cfg.HostAddressOpt('pydev_worker_debug_host',
  434. sample_default='localhost',
  435. help=_("""
  436. Host address of the pydev server.
  437. Provide a string value representing the hostname or IP of the
  438. pydev server to use for debugging. The pydev server listens for
  439. debug connections on this address, facilitating remote debugging
  440. in Glance.
  441. Possible values:
  442. * Valid hostname
  443. * Valid IP address
  444. Related options:
  445. * None
  446. """)),
  447. cfg.PortOpt('pydev_worker_debug_port',
  448. default=5678,
  449. help=_("""
  450. Port number that the pydev server will listen on.
  451. Provide a port number to bind the pydev server to. The pydev
  452. process accepts debug connections on this port and facilitates
  453. remote debugging in Glance.
  454. Possible values:
  455. * A valid port number
  456. Related options:
  457. * None
  458. """)),
  459. cfg.StrOpt('metadata_encryption_key',
  460. secret=True,
  461. help=_("""
  462. AES key for encrypting store location metadata.
  463. Provide a string value representing the AES cipher to use for
  464. encrypting Glance store metadata.
  465. NOTE: The AES key to use must be set to a random string of length
  466. 16, 24 or 32 bytes.
  467. Possible values:
  468. * String value representing a valid AES key
  469. Related options:
  470. * None
  471. """)),
  472. cfg.StrOpt('digest_algorithm',
  473. default='sha256',
  474. help=_("""
  475. Digest algorithm to use for digital signature.
  476. Provide a string value representing the digest algorithm to
  477. use for generating digital signatures. By default, ``sha256``
  478. is used.
  479. To get a list of the available algorithms supported by the version
  480. of OpenSSL on your platform, run the command:
  481. ``openssl list-message-digest-algorithms``.
  482. Examples are 'sha1', 'sha256', and 'sha512'.
  483. NOTE: ``digest_algorithm`` is not related to Glance's image signing
  484. and verification. It is only used to sign the universally unique
  485. identifier (UUID) as a part of the certificate file and key file
  486. validation.
  487. Possible values:
  488. * An OpenSSL message digest algorithm identifier
  489. Relation options:
  490. * None
  491. """)),
  492. cfg.StrOpt('node_staging_uri',
  493. default='file:///tmp/staging/',
  494. help=_("""
  495. The URL provides location where the temporary data will be stored
  496. This option is for Glance internal use only. Glance will save the
  497. image data uploaded by the user to 'staging' endpoint during the
  498. image import process.
  499. This option does not change the 'staging' API endpoint by any means.
  500. NOTE: It is discouraged to use same path as [task]/work_dir
  501. NOTE: 'file://<absolute-directory-path>' is the only option
  502. api_image_import flow will support for now.
  503. NOTE: The staging path must be on shared filesystem available to all
  504. Glance API nodes.
  505. Possible values:
  506. * String starting with 'file://' followed by absolute FS path
  507. Related options:
  508. * [task]/work_dir
  509. """)),
  510. cfg.ListOpt('enabled_import_methods',
  511. item_type=cfg.types.String(quotes=True),
  512. bounds=True,
  513. default=['glance-direct', 'web-download'],
  514. help=_("""
  515. List of enabled Image Import Methods
  516. Both 'glance-direct' and 'web-download' are enabled by default.
  517. Related options:
  518. * [DEFAULT]/node_staging_uri""")),
  519. ]
  520. CONF = cfg.CONF
  521. CONF.register_opts(paste_deploy_opts, group='paste_deploy')
  522. CONF.register_opts(image_format_opts, group='image_format')
  523. CONF.register_opts(task_opts, group='task')
  524. CONF.register_opts(common_opts)
  525. policy.Enforcer(CONF)
  526. def parse_args(args=None, usage=None, default_config_files=None):
  527. CONF(args=args,
  528. project='glance',
  529. version=version.cached_version_string(),
  530. usage=usage,
  531. default_config_files=default_config_files)
  532. def parse_cache_args(args=None):
  533. config_files = cfg.find_config_files(project='glance', prog='glance-cache')
  534. parse_args(args=args, default_config_files=config_files)
  535. def _get_deployment_flavor(flavor=None):
  536. """
  537. Retrieve the paste_deploy.flavor config item, formatted appropriately
  538. for appending to the application name.
  539. :param flavor: if specified, use this setting rather than the
  540. paste_deploy.flavor configuration setting
  541. """
  542. if not flavor:
  543. flavor = CONF.paste_deploy.flavor
  544. return '' if not flavor else ('-' + flavor)
  545. def _get_paste_config_path():
  546. paste_suffix = '-paste.ini'
  547. conf_suffix = '.conf'
  548. if CONF.config_file:
  549. # Assume paste config is in a paste.ini file corresponding
  550. # to the last config file
  551. path = CONF.config_file[-1].replace(conf_suffix, paste_suffix)
  552. else:
  553. path = CONF.prog + paste_suffix
  554. return CONF.find_file(os.path.basename(path))
  555. def _get_deployment_config_file():
  556. """
  557. Retrieve the deployment_config_file config item, formatted as an
  558. absolute pathname.
  559. """
  560. path = CONF.paste_deploy.config_file
  561. if not path:
  562. path = _get_paste_config_path()
  563. if not path or not (os.path.isfile(os.path.abspath(path))):
  564. msg = _("Unable to locate paste config file for %s.") % CONF.prog
  565. raise RuntimeError(msg)
  566. return os.path.abspath(path)
  567. def load_paste_app(app_name, flavor=None, conf_file=None):
  568. """
  569. Builds and returns a WSGI app from a paste config file.
  570. We assume the last config file specified in the supplied ConfigOpts
  571. object is the paste config file, if conf_file is None.
  572. :param app_name: name of the application to load
  573. :param flavor: name of the variant of the application to load
  574. :param conf_file: path to the paste config file
  575. :raises RuntimeError: when config file cannot be located or application
  576. cannot be loaded from config file
  577. """
  578. # append the deployment flavor to the application name,
  579. # in order to identify the appropriate paste pipeline
  580. app_name += _get_deployment_flavor(flavor)
  581. if not conf_file:
  582. conf_file = _get_deployment_config_file()
  583. try:
  584. logger = logging.getLogger(__name__)
  585. logger.debug("Loading %(app_name)s from %(conf_file)s",
  586. {'conf_file': conf_file, 'app_name': app_name})
  587. app = deploy.loadapp("config:%s" % conf_file, name=app_name)
  588. # Log the options used when starting if we're in debug mode...
  589. if CONF.debug:
  590. CONF.log_opt_values(logger, logging.DEBUG)
  591. return app
  592. except (LookupError, ImportError) as e:
  593. msg = (_("Unable to load %(app_name)s from "
  594. "configuration file %(conf_file)s."
  595. "\nGot: %(e)r") % {'app_name': app_name,
  596. 'conf_file': conf_file,
  597. 'e': e})
  598. logger.error(msg)
  599. raise RuntimeError(msg)
  600. def set_config_defaults():
  601. """This method updates all configuration default values."""
  602. set_cors_middleware_defaults()
  603. def set_cors_middleware_defaults():
  604. """Update default configuration options for oslo.middleware."""
  605. cors.set_defaults(
  606. allow_headers=['Content-MD5',
  607. 'X-Image-Meta-Checksum',
  608. 'X-Storage-Token',
  609. 'Accept-Encoding',
  610. 'X-Auth-Token',
  611. 'X-Identity-Status',
  612. 'X-Roles',
  613. 'X-Service-Catalog',
  614. 'X-User-Id',
  615. 'X-Tenant-Id',
  616. 'X-OpenStack-Request-ID'],
  617. expose_headers=['X-Image-Meta-Checksum',
  618. 'X-Auth-Token',
  619. 'X-Subject-Token',
  620. 'X-Service-Token',
  621. 'X-OpenStack-Request-ID'],
  622. allow_methods=['GET',
  623. 'PUT',
  624. 'POST',
  625. 'DELETE',
  626. 'PATCH']
  627. )