/nova/openstack/common/db/options.py

https://github.com/markmc/nova
Python | 171 lines | 134 code | 9 blank | 28 comment | 3 complexity | 0f397a502647857c0fcdac85a141ce70 MD5 | raw file
  1. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  2. # not use this file except in compliance with the License. You may obtain
  3. # a copy of the License at
  4. #
  5. # http://www.apache.org/licenses/LICENSE-2.0
  6. #
  7. # Unless required by applicable law or agreed to in writing, software
  8. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  9. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  10. # License for the specific language governing permissions and limitations
  11. # under the License.
  12. import copy
  13. from oslo.config import cfg
  14. database_opts = [
  15. cfg.StrOpt('sqlite_db',
  16. deprecated_group='DEFAULT',
  17. default='nova.sqlite',
  18. help='The file name to use with SQLite'),
  19. cfg.BoolOpt('sqlite_synchronous',
  20. deprecated_group='DEFAULT',
  21. default=True,
  22. help='If True, SQLite uses synchronous mode'),
  23. cfg.StrOpt('backend',
  24. default='sqlalchemy',
  25. deprecated_name='db_backend',
  26. deprecated_group='DEFAULT',
  27. help='The backend to use for db'),
  28. cfg.StrOpt('connection',
  29. help='The SQLAlchemy connection string used to connect to the '
  30. 'database',
  31. secret=True,
  32. deprecated_opts=[cfg.DeprecatedOpt('sql_connection',
  33. group='DEFAULT'),
  34. cfg.DeprecatedOpt('sql_connection',
  35. group='DATABASE'),
  36. cfg.DeprecatedOpt('connection',
  37. group='sql'), ]),
  38. cfg.StrOpt('mysql_sql_mode',
  39. default='TRADITIONAL',
  40. help='The SQL mode to be used for MySQL sessions. '
  41. 'This option, including the default, overrides any '
  42. 'server-set SQL mode. To use whatever SQL mode '
  43. 'is set by the server configuration, '
  44. 'set this to no value. Example: mysql_sql_mode='),
  45. cfg.IntOpt('idle_timeout',
  46. default=3600,
  47. deprecated_opts=[cfg.DeprecatedOpt('sql_idle_timeout',
  48. group='DEFAULT'),
  49. cfg.DeprecatedOpt('sql_idle_timeout',
  50. group='DATABASE'),
  51. cfg.DeprecatedOpt('idle_timeout',
  52. group='sql')],
  53. help='Timeout before idle sql connections are reaped'),
  54. cfg.IntOpt('min_pool_size',
  55. default=1,
  56. deprecated_opts=[cfg.DeprecatedOpt('sql_min_pool_size',
  57. group='DEFAULT'),
  58. cfg.DeprecatedOpt('sql_min_pool_size',
  59. group='DATABASE')],
  60. help='Minimum number of SQL connections to keep open in a '
  61. 'pool'),
  62. cfg.IntOpt('max_pool_size',
  63. default=None,
  64. deprecated_opts=[cfg.DeprecatedOpt('sql_max_pool_size',
  65. group='DEFAULT'),
  66. cfg.DeprecatedOpt('sql_max_pool_size',
  67. group='DATABASE')],
  68. help='Maximum number of SQL connections to keep open in a '
  69. 'pool'),
  70. cfg.IntOpt('max_retries',
  71. default=10,
  72. deprecated_opts=[cfg.DeprecatedOpt('sql_max_retries',
  73. group='DEFAULT'),
  74. cfg.DeprecatedOpt('sql_max_retries',
  75. group='DATABASE')],
  76. help='Maximum db connection retries during startup. '
  77. '(setting -1 implies an infinite retry count)'),
  78. cfg.IntOpt('retry_interval',
  79. default=10,
  80. deprecated_opts=[cfg.DeprecatedOpt('sql_retry_interval',
  81. group='DEFAULT'),
  82. cfg.DeprecatedOpt('reconnect_interval',
  83. group='DATABASE')],
  84. help='Interval between retries of opening a sql connection'),
  85. cfg.IntOpt('max_overflow',
  86. default=None,
  87. deprecated_opts=[cfg.DeprecatedOpt('sql_max_overflow',
  88. group='DEFAULT'),
  89. cfg.DeprecatedOpt('sqlalchemy_max_overflow',
  90. group='DATABASE')],
  91. help='If set, use this value for max_overflow with sqlalchemy'),
  92. cfg.IntOpt('connection_debug',
  93. default=0,
  94. deprecated_opts=[cfg.DeprecatedOpt('sql_connection_debug',
  95. group='DEFAULT')],
  96. help='Verbosity of SQL debugging information. 0=None, '
  97. '100=Everything'),
  98. cfg.BoolOpt('connection_trace',
  99. default=False,
  100. deprecated_opts=[cfg.DeprecatedOpt('sql_connection_trace',
  101. group='DEFAULT')],
  102. help='Add python stack traces to SQL as comment strings'),
  103. cfg.IntOpt('pool_timeout',
  104. default=None,
  105. deprecated_opts=[cfg.DeprecatedOpt('sqlalchemy_pool_timeout',
  106. group='DATABASE')],
  107. help='If set, use this value for pool_timeout with sqlalchemy'),
  108. cfg.BoolOpt('use_db_reconnect',
  109. default=False,
  110. help='Enable the experimental use of database reconnect '
  111. 'on connection lost'),
  112. cfg.IntOpt('db_retry_interval',
  113. default=1,
  114. help='seconds between db connection retries'),
  115. cfg.BoolOpt('db_inc_retry_interval',
  116. default=True,
  117. help='Whether to increase interval between db connection '
  118. 'retries, up to db_max_retry_interval'),
  119. cfg.IntOpt('db_max_retry_interval',
  120. default=10,
  121. help='max seconds between db connection retries, if '
  122. 'db_inc_retry_interval is enabled'),
  123. cfg.IntOpt('db_max_retries',
  124. default=20,
  125. help='maximum db connection retries before error is raised. '
  126. '(setting -1 implies an infinite retry count)'),
  127. ]
  128. CONF = cfg.CONF
  129. CONF.register_opts(database_opts, 'database')
  130. def set_defaults(sql_connection, sqlite_db, max_pool_size=None,
  131. max_overflow=None, pool_timeout=None):
  132. """Set defaults for configuration variables."""
  133. cfg.set_defaults(database_opts,
  134. connection=sql_connection,
  135. sqlite_db=sqlite_db)
  136. # Update the QueuePool defaults
  137. if max_pool_size is not None:
  138. cfg.set_defaults(database_opts,
  139. max_pool_size=max_pool_size)
  140. if max_overflow is not None:
  141. cfg.set_defaults(database_opts,
  142. max_overflow=max_overflow)
  143. if pool_timeout is not None:
  144. cfg.set_defaults(database_opts,
  145. pool_timeout=pool_timeout)
  146. def list_opts():
  147. """Returns a list of oslo.config options available in the library.
  148. The returned list includes all oslo.config options which may be registered
  149. at runtime by the library.
  150. Each element of the list is a tuple. The first element is the name of the
  151. group under which the list of elements in the second element will be
  152. registered. A group name of None corresponds to the [DEFAULT] group in
  153. config files.
  154. The purpose of this is to allow tools like the Oslo sample config file
  155. generator to discover the options exposed to users by this library.
  156. :returns: a list of (group_name, opts) tuples
  157. """
  158. return [('database', copy.deepcopy(database_opts))]