CloudStackのメーリングリストでアナウンスされたように CloudStack APIのCLIクライアントであるcloudmonkeyの5.2.0がリリースされています。
このクライアント自体は非常に便利なのですが、アップデートされるたびにプロファイルの互換性がなくなるため、pip install cloudmonkey --upgrade しただけではエラーをはいて起動しなくなります。
毎度面倒なのでなんとかしてほしいなぁと思いつつ、とりあえず今回のconfig直しについて書きます。
今回のアップデート箇所
メーリングリストによると 以下の通りです。
- Multiple server profiles where users can use CloudMonkey against
different CloudStack management servers and switch between them using a
profile option;
- 複数プロファイルのサポート
- 端的にいうと複数のマネジメントサーバをプロファイル切り替えて利用可能に
- 今までシェルでプロファイル切り替えのスクリプトとか書いていた僕のようなユーザには朗報
- A default profile under the section [local] is added with default values;
- [local]というセクションでデフォルトプロファイルが定義されます
- Some bugfixes related to network requests, error handling, JSON decoding
and shell interactivity;
- ネットワーク系のAPIリクエスト、エラーハンドリング、JSONデコーディングとシェルの動きに関するバグフィックス
- Every time 'set' is called, CloudMonkey will write the config and reload
config file;
- "set" コマンドが呼ばれるごとにコンフィグ変更とリロードを行うように改善
- Configuration options 'protocol', 'host', 'port', 'path' are deprecated
now but setting them is still allowed which sets a single "url" option, in
the config file the [server] section is deprecated now and CloudMonkey
won't read values from this section anymore but instead read from current
server profile;
- 'protocol', 'host', 'port', 'path' コンフィグの廃止
- これからは'url'というオプションでhttp(s)://からなる完全urlを入力すればよきにはからえしてくれるように
- Missing key/values are automatically set with defaults by CloudMonkey;
- apiコールの際に、key/valuesをデフォルトでよきにはからえしてくれるように
- During installation and upgrades, it will detect the platform to install
either pyreadline (Windows) or readline (OSX and Linux);
- インストールとアップデートの時プラットフォームを検知し、pyreadlineとreadlineを使い分けるようにアップデート
上記のうち、'url'でのコンフィグのサポート、および'[local]'セクションのサポート、複数プロファイルのサポートがconfigに影響します。
Cloudmonkeyのアップデート
まずはアップデートから実施。
pip install cloudmoneky --upgrade
僕は5.1.0からのアップデートでした。
なので、起動しようとすると以下のようなエラーが出てきます。
(On Mac OS X)
Traceback (most recent call last):
File "/Users/User/.pyenv/versions/2.7.8/bin/cloudmonkey", line 9, in <module>
load_entry_point('cloudmonkey==5.2.0', 'console_scripts', 'cloudmonkey')()
File "/Users/User/.pyenv/versions/2.7.8/lib/python2.7/site-packages/cloudmonkey/cloudmonkey.py", line 585, in main
shell = CloudMonkeyShell(sys.argv[0], options.cfile)
File "/Users/User/.pyenv/versions/2.7.8/lib/python2.7/site-packages/cloudmonkey/cloudmonkey.py", line 82, in __init__
self.config_file)
File "/Users/User/.pyenv/versions/2.7.8/lib/python2.7/site-packages/cloudmonkey/config.py", line 153, in read_config
profile = config.get('core', 'profile')
File "/Users/User/.pyenv/versions/2.7.8/lib/python2.7/ConfigParser.py", line 618, in get
raise NoOptionError(option, section)
ConfigParser.NoOptionError: No option 'profile' in section: 'core'
Configの修正
とりあえずconfigのバックアップをとってから編集します。
cp ~/.cloudmonkey/config ~/.cloudmonkey/config.bak20140906
vim ~/.cloudmonkey/config
まずは'[local]'セクションの設定から。
何を直さなければいけないかというと、
を参考にしてみると、典型的な設定は以下の通り。
[core]
profile = local
...
[local]
url = http://localhost:8080/client/api
username = admin
password = password
apikey =
secretkey =
timeout = 3600
expires = 600
上記とくらべて5.1.0のファイル群は、
- '[core]'セクションにprofileがない
- '[local]'がない(前は'[user]'と'[server]'で定義されています。)
なので、以下のような感じで編集。
MBA-3@16:56:~$ diff ~/.cloudmonkey/config.bak20140906 ~/.cloudmonkey/config
--- /Users/User/.cloudmonkey/config.bak20140906 2014-09-06 16:18:15.000000000 +0900
+++ /Users/User/.cloudmonkey/config 2014-09-06 16:56:21.000000000 +0900
@@ -4,23 +4,20 @@
asyncblock = true
paramcompletion = false
history_file = /Users/User/.cloudmonkey/history
+profile = local
[ui]
color = true
prompt = >
display = json
-[user]
+[local]
secretkey = SECRETKEY
username = user
password = user
apikey = APIKEY
-
-[server]
-protocol = https
+protocol = https://comp-api.jp-e1.cloudn-service.com/client/api
expires = 600
-host = comp-api.jp-e1.cloudn-service.com
timeout = 3600
-path = /client/api
-port = 443
+url = http://localhost:8080/client/api
(上記の例ではCloudnの東日本リージョン、ComputeFLATタイプを使っていました。とりあえずManagement ServerのAPIエンドポイントを指していれば自宅環境でもdevstackでもなんでもOK。)
(また、上記ではlocalにしていますが、別に上のprofile=local
を書き換えれば、デフォルトプロファイル名も変更可能です。とりあえず公式ドキュメントにしたがって見ました。)
以降、[セクション名]
のような形で各Management Serverのプロファイルを追加していけば、いろんなものを使えます。
なお、Cloudmonekeyシェル内部でプロファイルを切り替えるには以下。
set profile <profile-name>
こんなかんじで、使えます。