Networking サービスのデータベースのアップグレードは、一連の Alembic の移行ルールとして実装されています。 alembic/versions
の移行ルール (migration) には、Networking サービスの古いリリースから新しいリリースへの移行に必要な変更が入っています。
Liberty 以降、 Networking サービスでは 2 つの独立した Alembic の移行ブランチを持っています。
1 つめのブランチは expand (拡張) と呼ばれ、拡張のみの移行ルールを格納するのに使用されます。これらのルールは追加処理のみであり、Neutron サーバーの実行中に適用できます。
2 つめのブランチは contract (縮小) と呼ばれ、 Neutron サーバーの実行中には安全に適用できない移行ルールが格納されます。
別々のブランチを持つ理由は、 Neutron サーバーの実行中に expand ブランチの安全な移行ルールを適用し、サービスのアップグレードに必要な停止時間を減らすことにあります。
データベース移行コマンドラインツールは、Alembic ライブラリーを使って移行ルールを管理しています。
The database management command-line tool is called
neutron-db-manage. Pass the --help
option to the tool for
usage information.
このツールでは、オプションの後にコマンドが続きます。
$ neutron-db-manage <options> <commands>
このツールでは、 OpenStack 環境の設定ファイル neutron.conf
で指定されるデータベース接続の文字列オプションが必要です。 /etc/neutron/neutron.conf
が存在する場合は、自動的にこのファイルから設定を読み込みます。設定ファイルが別の場所にある場合は、以下のコマンドを使用します。
$ neutron-db-manage --config-file /path/to/neutron.conf <commands>
Multiple --config-file
options can be passed if needed.
Instead of reading the DB connection from the configuration file(s), you can
use the --database-connection
option:
$ neutron-db-manage --database-connection
mysql+pymysql://root:secret@127.0.0.1/neutron?charset=utf8 <commands>
The branches, current, and history commands all accept a
--verbose
option, which, when passed, will instruct
neutron-db-manage to display more verbose output for the specified
command:
$ neutron-db-manage current --verbose
注釈
以下のツールの実行例ではオプションは記載していません。必要な場合はオプションを指定してください。
新規のデプロイメントでは、空のデータベースから始め、以下のコマンドを使って最新のデータベースバージョンまでアップグレードします。
$ neutron-db-manage upgrade heads
新しいバージョンの neutron サーバーのインストール後は、以下のコマンドを使ってデータベースをアップグレードします。
$ neutron-db-manage upgrade heads
既存のデプロイメントでは、以下のコマンドを使って現在のデータベースのバージョンを確認します。
$ neutron-db-manage current
拡張の移行ルールを適用するには、以下のコマンドを使用します。
$ neutron-db-manage upgrade --expand
拡張以外の移行ルールを適用するには、以下のコマンドを使用します。
$ neutron-db-manage upgrade --contract
適用待ちの contract (縮小) 移行ルールがあり、オフラインでの移行が必要かを確認するには、以下のコマンドを実行します。
$ neutron-db-manage has_offline_migrations
注釈
オフライン移行を行うには、 contract スクリプトを適用する前に、クラスター内のすべての Neutron サーバーをシャットダウンする必要があります。
データベースを直接操作せず、代わりにコマンドスクリプトを生成するには、以下のコマンドを実行します。
$ neutron-db-manage upgrade heads --sql
.. note::
The `--sql` option causes the command to generate a script. The script
can be run later (online or offline), perhaps after verifying and/or
modifying it.
指定したバージョン間の移行を行うには、以下のコマンドを実行します。
$ neutron-db-manage upgrade <start version>:<end version>
データベースのアップグレードを少しずつ行うには、以下のコマンドを使用します。
$ neutron-db-manage upgrade --delta <# of revs>
注釈
データベースのダウングレードはサポートされていません。
To look for differences between the schema generated by the upgrade command and the schema defined by the models, use the revision --autogenerate command:
neutron-db-manage revision -m REVISION_DESCRIPTION --autogenerate
注釈
This generates a prepopulated template with the changes needed to match the database state with the models.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.