vagrant-niftycloud 0.1.0.dev → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Vagrant NiftyCloud Provider
2
2
 
3
- `開発中!まだ動作しません!!`
3
+ `開発中!8月頭を目処に処理をブラッシュアップします`
4
+
5
+ `リージョン・ゾーン周り以外のロジックはほぼ問題ないと思います`
4
6
 
5
7
  [Vagrant](http://www.vagrantup.com) 1.2以降のバージョンで[ニフティクラウド](http://cloud.nifty.com/)
6
8
  を操作するためのprovider機能を追加するプラグインです。
@@ -26,16 +28,12 @@ Chef以外の動作確認は行なっていませんが、プラグインで行
26
28
 
27
29
  vagrant upを実行する前に通常のVagrant使用時と同じようにboxファイルをVagrantに追加する必要があります。
28
30
 
29
- 自分でboxファイルを作成するかこちらで用意しているboxファイルを使用して、任意の名前でダミーのboxを追加して下さい。
31
+ 自分でboxファイルを作成するか、こちらで用意しているboxファイルを使用して、任意の名前でダミーのboxを追加して下さい。
30
32
 
31
33
  ```
32
- $ git clone https://github.com/sakama/vagrant-niftycloud.git
33
- $ cd vagrant-niftycloud
34
- $ bundle install
35
- $ bundle exec rake build
36
- $ vagrant plugin install pkg/vagrant-niftycloud-0.1.0.dev.gem
34
+ $ vagrant plugin install vagrant-niftycloud
37
35
  $ vagrant box add dummy https://github.com/sakama/vagrant-niftycloud/raw/master/dummy.box
38
- ...
36
+
39
37
  ```
40
38
 
41
39
  ### OSイメージの作成
@@ -51,6 +49,9 @@ Vagrant自体の仕様により、以下の制約があります。
51
49
  上記条件をクリアしたサーバイメージをプライベートイメージ等で用意する必要があります。
52
50
 
53
51
  OSイメージ作成の手順は以下のようになります。
52
+ chef-soloやchef-clientを予めインストールしておくかどうかはケースバイケースです。
53
+
54
+ vagrant up時に[vagrant-omnibus](https://github.com/schisamo/vagrant-omnibus)を使うという手もあります。
54
55
 
55
56
  ```
56
57
  ## rootで実行
@@ -61,13 +62,17 @@ OSイメージ作成の手順は以下のようになります。
61
62
  # su - vagrant
62
63
  ## vagrantユーザで実行
63
64
  $ ssh-keygen -t rsa
65
+ $ cd .ssh
64
66
  $ mv id_rsa.pub authorized_keys(id_rsaをローカルに保存する=接続する際のSSH秘密鍵となる)
65
67
 
66
68
  ## rootで実行
67
69
  # visudo
68
70
  # Defaults specificationをコメントアウト
69
- # 最終行に以下を追加
71
+ ## 最終行に以下を追加
70
72
  # vagrant ALL=(ALL) NOPASSWD: ALL
73
+
74
+ ## chef-soloやchef-clientをインストールしておく場合
75
+ # curl -L https://www.opscode.com/chef/install.sh | sudo bash
71
76
  ```
72
77
 
73
78
  作成したイメージのimage_idをVagrantfile内で指定する必要があります。
@@ -77,6 +82,7 @@ image_idについては[ニフティクラウドSDK for Ruby](http://cloud.nifty
77
82
  ### Vagrantfileの作成
78
83
 
79
84
  Vagrantfileを以下のような内容で作成します。
85
+ サンプルのVagrantfile ([Chef用](https://github.com/sakama/vagrant-niftycloud/blob/master/Vagrantfile.chef.sample)) も参考にして下さい。
80
86
 
81
87
  Vagrantfileの`config.vm.provider`ブロックで各種パラメータを指定して下さい。
82
88
 
@@ -90,6 +96,7 @@ Vagrant.configure("2") do |config|
90
96
 
91
97
  niftycloud.image_id = "26"
92
98
  niftycloud.key_name = "<YOUR SSH KEY NAME>"
99
+ niftycloud.password = "<ROOT PASSWORD YOU WANT TO SET>"
93
100
  override.ssh.username = "vagrant"
94
101
  override.ssh.private_key_path = "PATH TO YOUR PRIVATE KEY"
95
102
  end
@@ -102,7 +109,7 @@ end
102
109
 
103
110
  ```
104
111
 
105
- # サーバ立ちあげ、provisioningの実行
112
+ # サーバ立ち上げ、provisioningの実行
106
113
  $ vagrant up --provider=niftycloud
107
114
 
108
115
  # 立ち上げたサーバへのprovisioningの実行
@@ -153,14 +160,16 @@ boxフォーマットには`metadata.json`が必要です。
153
160
  以下の様なパラメータに対応しています。
154
161
 
155
162
 
156
- * `access_key_id` - ニフティクラウドのAccessKey。[コントロールパネルから取得した値](http://cloud.nifty.com/help/status/api_key.htm)を指定して下さい。
163
+ * `access_key_id` - ニフティクラウドのAccessKey。[コントロールパネルから取得した値](http://cloud.nifty.com/help/status/api_key.htm)を指定。
164
+ * `secret_access_key` - ニフティクラウドAPI経由でアクセスするためのSecretAccessKey。[コントロールパネルから取得した値](http://cloud.nifty.com/help/status/api_key.htm)を指定して下さい。
165
+ * `instance_id` - サーバ名。指定がない場合ランダムなIDを付与。Vagrantfileを複数人で共有している場合、指定なしがいいかもしれません(同じサーバ名を持つサーバは立てられないため)
157
166
  * `image_id` - サーバ立ち上げ時に指定するimage_id。ニフティクラウド公式のOSイメージでは動作しません。
158
167
  * `key_name` - サーバ接続時に使用するSSHキー名。[コントロールパネルで設定した値](http://cloud.nifty.com/help/netsec/ssh_key.htm)を指定して下さい。
159
168
  * `zone` - ニフティクラウドのゾーン。例)"east-12"
160
- * `instance_ready_timeout` - インスタンス起動実行からタイムアウトとなるまでの秒数。デフォルトは300秒です。
161
- * `instance_type` - サーバタイプ。例)"small2"。指定がない場合のデフォルト値は"mini"です。
162
- * `secret_access_key` - ニフティクラウドAPI経由でアクセスするためのSecretAccessKey。[コントロールパネルから取得した値](http://cloud.nifty.com/help/status/api_key.htm)を指定して下さい。
169
+ * `instance_ready_timeout` - インスタンス起動実行からタイムアウトとなるまでの秒数。デフォルトは300秒。
170
+ * `instance_type` - サーバタイプ。例)"small2"。指定がない場合のデフォルト値は"mini"
163
171
  * `firewall` - Firewall名。
172
+ * `password` - rootのパスワードとして設定したい値
164
173
 
165
174
  上記のパラメータはVagrantfile中で以下のように設定することができます。
166
175
 
@@ -191,6 +200,7 @@ Vagrant.configure("2") do |config|
191
200
  niftycloud.zone = "east-12"
192
201
  niftycloud.key_name = "vagrantkey"
193
202
  niftycloud.firewall = "test"
203
+ niftycloud.password = "password"
194
204
  override.ssh.username = "vagrant"
195
205
  override.ssh.private_key_path = "/path/to/private_key.pem"
196
206
 
@@ -221,7 +231,7 @@ Vagrantの`config.vm.network`で設定可能なネットワーク機能につい
221
231
 
222
232
  フォルダの同期についてはshell、chef、puppetといったVagrantのprovisionersを動作させるための最低限のサポートとなります。
223
233
 
224
- `vagrant up`、`vagrant reload`、`vagrant provision`コマンドが実行された場合、
234
+ `vagrant up`、`vagrant provision`コマンドが実行された場合、
225
235
  このプラグインは`rsync`を使用しSSH経由でローカル→リモートサーバへの単方向同期を行います。
226
236
 
227
237
 
@@ -0,0 +1,33 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+
7
+ config.vm.provider :niftycloud do |niftycloud, override|
8
+ niftycloud.access_key_id = ENV["NIFTY_CLOUD_ACCESS_KEY"] || "foo"
9
+ niftycloud.secret_access_key = ENV["NIFTY_CLOUD_SECRET_KEY"] || "bar"
10
+ niftycloud.image_id = "26"
11
+ niftycloud.zone= "east-12"
12
+ niftycloud.instance_type= "mini"
13
+ niftycloud.key_name = "sshkeypairname"
14
+ niftycloud.firewall = "vagrantservers"
15
+ niftycloud.password = "password"
16
+ override.ssh.username = "vagrant"
17
+ override.ssh.private_key_path = "/path/to/vagrant_private.pem"
18
+
19
+ config.vm.provision :chef_solo do |chef|
20
+ chef_root = '/path/to/chef_root'
21
+ chef.cookbooks_path = "#{chef_root}/chef-repo/cookbooks"
22
+ chef.roles_path = "#{chef_root}/chef-repo/roles"
23
+ chef.data_bags_path = "#{chef_root}/chef-repo/data_bags"
24
+ chef.json = {
25
+ :mysql => {
26
+ :server_root_password => "p@ssw0rd",
27
+ :server_repl_password => "p@ssw0rd",
28
+ :server_debian_password => "p@ssw0rd"
29
+ }
30
+ }
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require "NIFTY"
3
3
  require "log4r"
4
- NIFTY::LOG.level = Logger::DEBUG
4
+
5
+ if !ENV["VAGRANT_LOG"].nil? && ENV["VAGRANT_LOG"].upcase=='DEBUG'
6
+ NIFTY::LOG.level = Logger::DEBUG
7
+ end
5
8
 
6
9
  module VagrantPlugins
7
10
  module NiftyCloud
@@ -23,6 +23,7 @@ module VagrantPlugins
23
23
  while server.instanceState.name == 'pending'
24
24
  sleep 5
25
25
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
26
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
26
27
  end
27
28
 
28
29
  if server.instanceState.name != 'running'
@@ -30,6 +31,7 @@ module VagrantPlugins
30
31
  while server.instanceState.name != 'running'
31
32
  sleep 5
32
33
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
34
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
33
35
  end
34
36
  end
35
37
 
@@ -17,21 +17,18 @@ module VagrantPlugins
17
17
  def call(env)
18
18
  # Initialize metrics if they haven't been
19
19
  env[:metrics] ||= {}
20
-
21
20
  # Get the zone we're going to booting up in
22
21
  zone = env[:machine].provider_config.zone
23
-
24
22
  # Get the configs
25
- # TODO 開発フェーズなのでinstance_idを固定にしている
26
- # Vagrantfileで設定できるようにすべきか、その場合Vagrantfileを共有している環境では同じIDでサーバ立てるとエラーになることを考慮する
27
- instance_id = 'test2'
28
23
  zone_config = env[:machine].provider_config.get_zone_config(zone)
24
+ instance_id = zone_config.instance_id.nil? ? get_instance_id(5) : zone_config.instance_id
29
25
  image_id = zone_config.image_id
30
26
  zone = zone_config.zone
31
27
  instance_type = zone_config.instance_type
32
28
  key_name = zone_config.key_name,
33
29
  firewall = zone_config.firewall,
34
- user_data = zone_config.user_data
30
+ user_data = zone_config.user_data,
31
+ password = zone_config.password
35
32
 
36
33
  # Launch!
37
34
  env[:ui].info(I18n.t("vagrant_niftycloud.launching_instance"))
@@ -49,8 +46,8 @@ module VagrantPlugins
49
46
  :instance_type => instance_type,
50
47
  :image_id => image_id,
51
48
  :key_name => zone_config.key_name,
52
- :password => 'password',
53
49
  :user_data => user_data,
50
+ :password => password,
54
51
  :accounting_type => 2, #従量課金
55
52
  :disable_api_termination => false #APIから即terminate可
56
53
  }
@@ -91,6 +88,7 @@ module VagrantPlugins
91
88
  count += 1
92
89
  sleep 5
93
90
  server = env[:niftycloud_compute].describe_instances(:instance_id => instance_id).reservationSet.item.first.instancesSet.item.first
91
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
94
92
  if count > tries
95
93
  # Delete the instance
96
94
  terminate(env)
@@ -125,6 +123,13 @@ module VagrantPlugins
125
123
  destroy_env[:force_confirm_destroy] = true
126
124
  env[:action_runner].run(Action.action_destroy, destroy_env)
127
125
  end
126
+
127
+ def get_instance_id(length)
128
+ result = "vagrant"
129
+ uid = (("a".."z").to_a + (0..9).to_a).shuffle[0..length].join
130
+ result << uid.capitalize!
131
+ result
132
+ end
128
133
  end
129
134
  end
130
135
  end
@@ -23,6 +23,7 @@ module VagrantPlugins
23
23
  while server.instanceState.name == 'pending'
24
24
  sleep 5
25
25
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
26
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
26
27
  end
27
28
 
28
29
  if server.instanceState.name != 'stopped'
@@ -30,6 +31,7 @@ module VagrantPlugins
30
31
  while server.instanceState.name != 'stopped'
31
32
  sleep 5
32
33
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
34
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
33
35
  end
34
36
  end
35
37
 
@@ -23,6 +23,7 @@ module VagrantPlugins
23
23
  while server.instanceState.name == 'pending'
24
24
  sleep 5
25
25
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
26
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
26
27
  end
27
28
 
28
29
  attribute = env[:niftycloud_compute].describe_instance_attribute(:instance_id => env[:machine].id, :attribute => 'disableApiTermination')
@@ -35,6 +36,7 @@ module VagrantPlugins
35
36
  while server.instanceState.name != 'stopped'
36
37
  sleep 5
37
38
  server = env[:niftycloud_compute].describe_instances(:instance_id => env[:machine].id).reservationSet.item.first.instancesSet.item.first
39
+ env[:ui].info(I18n.t("vagrant_niftycloud.processing"))
38
40
  end
39
41
  end
40
42
  end
@@ -8,6 +8,11 @@ module VagrantPlugins
8
8
  # @return [String]
9
9
  attr_accessor :access_key_id
10
10
 
11
+ # The ID of the AMI to use.
12
+ #
13
+ # @return [String]
14
+ attr_accessor :instance_id
15
+
11
16
  # The ID of the AMI to use.
12
17
  #
13
18
  # @return [String]
@@ -45,6 +50,11 @@ module VagrantPlugins
45
50
  # @return [Array<String>]
46
51
  attr_accessor :firewall
47
52
 
53
+ # The password string
54
+ #
55
+ # @return [String]
56
+ attr_accessor :password
57
+
48
58
  # The user data string
49
59
  #
50
60
  # @return [String]
@@ -52,13 +62,15 @@ module VagrantPlugins
52
62
 
53
63
  def initialize(zone_specific=false)
54
64
  @access_key_id = UNSET_VALUE
65
+ @instance_id = UNSET_VALUE
55
66
  @image_id = UNSET_VALUE
56
- @zone = UNSET_VALUE
67
+ @zone = UNSET_VALUE
57
68
  @instance_ready_timeout = UNSET_VALUE
58
69
  @instance_type = UNSET_VALUE
59
70
  @key_name = UNSET_VALUE
60
71
  @secret_access_key = UNSET_VALUE
61
72
  @firewall = UNSET_VALUE
73
+ @password = UNSET_VALUE
62
74
  @user_data = UNSET_VALUE
63
75
 
64
76
  # Internal state (prefix with __ so they aren't automatically
@@ -131,6 +143,8 @@ module VagrantPlugins
131
143
  @access_key_id = ENV['NIFTY_ACCESS_KEY'] if @access_key_id == UNSET_VALUE
132
144
  @secret_access_key = ENV['NIFTY_SECRET_KEY'] if @secret_access_key == UNSET_VALUE
133
145
 
146
+ @instance_id = nil if @instance_id == UNSET_VALUE
147
+
134
148
  # AMI must be nil, since we can't default that
135
149
  @image_id = nil if @image_id == UNSET_VALUE
136
150
 
@@ -148,6 +162,9 @@ module VagrantPlugins
148
162
  # The firewall are empty by default.
149
163
  @firewall = [] if @firewall == UNSET_VALUE
150
164
 
165
+ # The password are empty by default.
166
+ @password = [] if @password == UNSET_VALUE
167
+
151
168
  # User Data is nil by default
152
169
  @user_data = nil if @user_data == UNSET_VALUE
153
170
 
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module NiftyCloud
3
- VERSION = "0.1.0.dev"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
data/locales/en.yml CHANGED
@@ -17,8 +17,14 @@ en:
17
17
  Terminating the instance...
18
18
  waiting_for_ready: |-
19
19
  Waiting for instance to become "ready"...
20
+ processing: |-
21
+ Processing...
20
22
  waiting_for_ssh: |-
21
23
  Waiting for SSH to become available...
24
+ suspending: |-
25
+ Waiting for instance to become "stopped"...
26
+ resuming: |-
27
+ Waiting for instance to become "running"...
22
28
  will_not_destroy: |-
23
29
  The instance '%{name}' will not be destroyed, since the confirmation
24
30
  was declined.
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-niftycloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.dev
5
- prerelease: 6
4
+ version: 0.1.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Satoshi Akama
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-19 00:00:00.000000000 Z
12
+ date: 2013-07-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -129,6 +129,7 @@ files:
129
129
  - README.md
130
130
  - spec/vagrant-niftycloud/config_spec.rb
131
131
  - vagrant-niftycloud.gemspec
132
+ - Vagrantfile.chef.sample
132
133
  - .gitignore
133
134
  homepage: http://www.vagrantup.com
134
135
  licenses: []
@@ -142,6 +143,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  - - ! '>='
143
144
  - !ruby/object:Gem::Version
144
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: -273229777575097773
145
149
  required_rubygems_version: !ruby/object:Gem::Requirement
146
150
  none: false
147
151
  requirements: