orenoblog

エンジニアになりたいExcel方眼紙erの物語

VagrantでIDCフロンティアのcloudstackと遊ぶ

普段IDCフロンティアさんのクラウドサービスにお世話になってまして、
IDCFさんのCloudstack対応Vagrant Pluginなんて都合のいいものないですかねと伺っていたところ、
対応しましたよとご連絡を頂いたので試してみた。

(0)自分の環境
Mac OSX
Vagrant 1.3.1

Plugin

sahara (0.0.14)
vagrant-aws (0.4.0)
vagrant-cloudstack (0.1.0)
vagrant-niftycloud (0.3.0)

(1)インストール

pluginとboxを準備します。
しかし何故かbox listしたときにvagrant-cloudstackのロードエラーが出てますね

$ vagrant plugin install vagrant-cloudstack
$ vagrant plugin list
sahara (0.0.14)
vagrant-aws (0.4.0)
vagrant-cloudstack (0.1.0)
vagrant-niftycloud (0.3.0)
$ vagrant box add dummy https://github.com/klarna/vagrant-cloudstack/raw/master/dummy.box
$ vagrant box list
Failed to load the "vagrant-cloudstack" plugin. View logs for more details.

bokuno_centos   (virtualbox)
dummy            (aws)
dummy            (cloudstack)
dummy            (niftycloud)

(2)IDCF Cloud側での事前準備

・IDCFのAPIキー取得しておきます
グローバルIP払い出します
・sudoでNOPASSWD: ALL可能なアカウントを作成したテンプレートを作成して登録しておきます
・(3)で準備するVagrantfileに記述する情報をCLI等で取得しておきます

(3)Vagrantfileの準備

$ vagrant init
$ vi Vagrantfile
Vagrant.configure("2") do |config|

 config.ssh.username = "vagrant"
 config.ssh.private_key_path = "~/.ssh/id_rsa"
 config.ssh.port = "2222"

 config.vm.box = "dummy"

 config.vm.provider :cloudstack do |cloudstack, override|
   cloudstack.scheme = "https"
   cloudstack.host = "api.noahcloud.jp"
   cloudstack.port = "443"
   cloudstack.path = "/portal/client/api"
   cloudstack.api_key = "<APIキー>"
   cloudstack.secret_key = "<シークレットキー>"

   cloudstack.template_id = "<Vagrantで起動するテンプレートID>"
   cloudstack.service_offering_id = "<IDCF APIの listOfferingsで取得できる各インスタンスサイズのID"
   cloudstack.zone_id = "1"
   cloudstack.keypair = "*****"

   cloudstack.pf_ip_address_id = "<Vagrantで利用するグローバルIP>"
   cloudstack.pf_public_port = "<Vagrantがsshで利用するPUBLICポート>"
   cloudstack.pf_private_port = "<PRIVATEポート>"
   cloudstack.instance_ready_timeout = 3600
 end
end

(4)起動...

準備ができたので起動してみます

$ vagrant up --provider=cloudstack
Failed to load the "vagrant-cloudstack" plugin. View logs for more details.

The provider 'cloudstack' could not be found, but was requested to
back the machine 'default'. Please use a provider that exists.

!?
pluginをインストールしたのに起動したらfailした
何を言ってるのかよくわからねーが(AA略

Vagrantのログ出力を有効にして確認します。
☆☆部分でfogの競合が発生しています。どうやらこれが原因のようです。

$ VAGRANT_LOG=debug vagrant box list
..省略..
 INFO environment:   - cwd: ~/demo
 INFO environment: Home path: ~/.vagrant.d
 INFO environment: Local data path: ~/demo/.vagrant
DEBUG environment: Creating: ~/demo/.vagrant
DEBUG environment: Loading plugins from: ~/.vagrant.d/plugins.json
 INFO environment: Loading plugin from JSON: sahara
 INFO manager: Registered plugin: sahara
 INFO environment: Loading plugin from JSON: vagrant-aws
 INFO manager: Registered plugin: AWS
 INFO environment: Loading plugin from JSON: vagrant-cloudstack
ERROR root: Failed to load plugin: vagrant-cloudstack
☆☆ERROR root:  -- Error: #<Gem::LoadError: Unable to activate vagrant-cloudstack-0.1.0, because fog-1.15.0 conflicts with fog (~> 1.18.0)>
ERROR root:  -- Backtrace:
ERROR root: /Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/specification.rb:1637:in `raise_if_conflicts'
/Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/specification.rb:746:in `activate'
/Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems.rb:212:in `rescue in try_activate'
/Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems.rb:209:in `try_activate'
/Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:59:in `rescue in require'
/Applications/Vagrant/embedded/lib/ruby/1.9.1/rubygems/custom_require.rb:35:in `require'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant.rb:196:in `require_plugin'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:750:in `block in load_plugins'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:747:in `each'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:747:in `load_plugins'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/lib/vagrant/environment.rb:132:in `initialize'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/bin/vagrant:74:in `new'
/Applications/Vagrant/embedded/gems/gems/vagrant-1.3.1/bin/vagrant:74:in `<top (required)>'
/Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `load'
/Applications/Vagrant/bin/../embedded/gems/bin/vagrant:23:in `<main>'
 INFO interface: error: Failed to load the "vagrant-cloudstack" plugin. View logs for more details.

Failed to load the "vagrant-cloudstack" plugin. View logs for more details.

調べた結果、vagrant-awsとvagrant-cloudstackに指定されてたfogのバージョンが異なってました。
~/.vagrant.d/gems/gems/vagrant-aws-0.4.0.gemspecに記述されていたfogが1.15.0
~/.vagrant.d/gems/gems/vagrant-cloudstac-0.1.0.gemspecに記述されていたfogは1.18.0

vagrant-cloudstackでfog-1.18.0をactivateできないのが原因だったので、
とりあえずvagrant-aws-0.4.0.gemspecに記述されていたfogの要求バージョンをvagrant-cloudstackと同一にします。

$ vi ~/.vagrant.d/gems/gems/vagrant-aws-0.4.0.gemspec
 s.add_runtime_dependency "fog", "~> 1.15.0"
↓
 s.add_runtime_dependency "fog", "~> 1.18.0"

(5)改めて起動確認

$ vagrant up --provider=cloudstack
Bringing machine 'default' up with 'cloudstack' provider...
[fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.
[default] Warning! The Cloudstack provider doesn't support any of the Vagrant
high-level network configurations (`config.vm.network`). They
will be silently ignored.
[default] Launching an instance with the following settings...
[default]  -- Service offering UUID: 24
[default]  -- Template UUID: ****
[default]  -- Zone UUID: 1
[default]  -- Keypair: ****
[default] Waiting for instance to become "ready"...
[default] Creating a port forwarding rule for this instance ...
[default]  -- IP address ID: ****
[default]  -- IP address: ***.***.***.***
[default]  -- Public port: 2222
[default]  -- Private port: 22
[default] Waiting for SSH to become available...
[default] Machine is booted and ready for use!
[default] Rsyncing folder: ~/demo/ => /vagrant
An error occurred while executing multiple actions in parallel.
Any errors that occurred are shown below.

An error occurred while executing the action on the 'default'
machine. Please handle this error then try again:

The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

mkdir -p '/vagrant'

Stdout from the command:


Stderr from the command:

sudo: sorry, you must have a tty to run sudo

$ vagrant ssh
[fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.
Welcome
[vagrant@vagrant-cloudstack ~]$

見事動作しました。fogのWARNINGがうるさいけどvagrant --provider=awsも動くのでとりあえずいいかな・・

[fog][WARNING] Unable to load the 'unf' gem. Your AWS strings may not be properly encoded.

追記 上記fogのWARNING対策方法

StackOverflowに対応方法が載ってました。