vagrant-iijgp 0.0.1
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/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.ja.md +106 -0
- data/README.md +109 -0
- data/Rakefile +1 -0
- data/dummy.box +0 -0
- data/example_box/README.md +10 -0
- data/example_box/Vagrantfile +9 -0
- data/example_box/metadata.json +1 -0
- data/lib/vagrant-iijgp/action/boot.rb +28 -0
- data/lib/vagrant-iijgp/action/check_running.rb +19 -0
- data/lib/vagrant-iijgp/action/create_vm.rb +59 -0
- data/lib/vagrant-iijgp/action/destroy.rb +27 -0
- data/lib/vagrant-iijgp/action/is_created.rb +16 -0
- data/lib/vagrant-iijgp/action/is_stopped.rb +16 -0
- data/lib/vagrant-iijgp/action/message_already_running.rb +16 -0
- data/lib/vagrant-iijgp/action/message_invalid_status.rb +16 -0
- data/lib/vagrant-iijgp/action/message_not_created.rb +16 -0
- data/lib/vagrant-iijgp/action/message_will_not_destroy.rb +17 -0
- data/lib/vagrant-iijgp/action/prepare_iijapi.rb +38 -0
- data/lib/vagrant-iijgp/action/read_ssh_info.rb +27 -0
- data/lib/vagrant-iijgp/action/read_state.rb +41 -0
- data/lib/vagrant-iijgp/action/set_label.rb +25 -0
- data/lib/vagrant-iijgp/action/stop_virtual_machine.rb +31 -0
- data/lib/vagrant-iijgp/action/sync_folders.rb +96 -0
- data/lib/vagrant-iijgp/action/vagrant_tweaks.rb +22 -0
- data/lib/vagrant-iijgp/action.rb +182 -0
- data/lib/vagrant-iijgp/config.rb +78 -0
- data/lib/vagrant-iijgp/errors.rb +19 -0
- data/lib/vagrant-iijgp/plugin.rb +53 -0
- data/lib/vagrant-iijgp/provider.rb +45 -0
- data/lib/vagrant-iijgp/version.rb +5 -0
- data/lib/vagrant-iijgp.rb +18 -0
- data/locales/en.yml +70 -0
- data/sample/Vagrantfile +38 -0
- data/vagrant-iijgp.gemspec +28 -0
- metadata +179 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Takahiro HIMURA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.ja.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
# Vagrant IIJ GIO Provider
|
2
|
+
|
3
|
+
これは [Vagrant](http://www.vagrantup.com) 1.3+ に IIJ GIO ホスティングパッケージサービスの
|
4
|
+
仮想サーバを操作する機能を追加する provider です。
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
- IIJ GIO ホスティングパッケージサービスの仮想マシンを起動することができます
|
9
|
+
- 仮想サーバに SSH ログインができます
|
10
|
+
- Chef による仮想サーバの provisioning ができます
|
11
|
+
- `rsync` を用いた synced folder をサポートしています
|
12
|
+
- IIJ CentOS イメージに対して、いくつかの調整を行ないます
|
13
|
+
- root ユーザに対する sudo の `Default requiretty` 設定を無効化します
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
通常の Vagrant 1.1+ 以降のプラグインの導入方法と同様にインストールできます。
|
18
|
+
インストール後は、`iijgp` provider を指定して `vagrant up` してください。
|
19
|
+
以下に例を示します
|
20
|
+
|
21
|
+
~~~~ {.shell}
|
22
|
+
$ vagrant plugin install vagrant-iijgp
|
23
|
+
...
|
24
|
+
$ vagrant up --provider=iijgp
|
25
|
+
...
|
26
|
+
~~~~
|
27
|
+
|
28
|
+
上記を実行する前に、iijgp 用の Vagrant box を入手しておく必要があります。
|
29
|
+
|
30
|
+
## Quick Start
|
31
|
+
|
32
|
+
プラグインを(前述の通り)インストールした後、
|
33
|
+
手っ取り早く始めるには、ダミーの IIJGP box を使い、
|
34
|
+
詳しいパラメータは `config.vm.provider` ブロックに都度指定する方法があります。
|
35
|
+
まず、はじめにダミーの box を任意の名前で追加します:
|
36
|
+
|
37
|
+
~~~~ {.shell}
|
38
|
+
$ vagrant box add dummy https://...
|
39
|
+
....
|
40
|
+
~~~~
|
41
|
+
|
42
|
+
次に、Vagrantfile を以下のように作成し、必要な情報を埋めてください。
|
43
|
+
|
44
|
+
~~~~ {.ruby}
|
45
|
+
Vagrant.configure("2") do |config|
|
46
|
+
config.vm.box = "dummy"
|
47
|
+
|
48
|
+
config.vm.provider :iijgp do |iijgp, override|
|
49
|
+
iijgp.access_key = "YOUR ACCESS KEY"
|
50
|
+
iijgp.secret_key = "YOUR SECRET KEY"
|
51
|
+
iijgp.gp_service_code = "gpXXXXXXXX"
|
52
|
+
iijgp.ssh_public_key = "YOUR PUBLIC SSH KEY"
|
53
|
+
|
54
|
+
override.ssh.username = "root"
|
55
|
+
override.ssh.private_key_path = "#{ENV['HOME']}/.ssh/id_rsa"
|
56
|
+
end
|
57
|
+
|
58
|
+
config.vm.define "vm1" do |c|
|
59
|
+
c.vm.provider :iijgp do |iijgp|
|
60
|
+
iijgp.gc_service_code = "gcXXXXXXXX"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
~~~~
|
65
|
+
|
66
|
+
そして `vagrant up --provider=iijgp vm1` を実行してください。
|
67
|
+
|
68
|
+
これは、既に GP "gpXXXXXXXX" 内に作成済みの "gcXXXXXXXX" を起動します。
|
69
|
+
また、SSH 用の情報が正しく Vagrantfile に設定されていれば、
|
70
|
+
SSH と provisioning が行なわれます。
|
71
|
+
|
72
|
+
もし、あなたが iijgp provider をデフォルトで利用したい場合、
|
73
|
+
以下のようにシェルを設定することで、`vagrant up` だけで iijgp provider が利用できます。
|
74
|
+
~~~~ {.shell}
|
75
|
+
export VAGRANT_DEFAULT_PROVIDER=iijgp
|
76
|
+
~~~~
|
77
|
+
|
78
|
+
## Box Format
|
79
|
+
|
80
|
+
全ての Vagrant provider は、それ用にカスタムの box を導入する必要があります。
|
81
|
+
box の例は example_box/ ディレクトリにあります。
|
82
|
+
|
83
|
+
## Configuration
|
84
|
+
|
85
|
+
IIJ GIP provider 固有の設定は以下の通りとなります:
|
86
|
+
|
87
|
+
- 必須パラメータ
|
88
|
+
- `access_key` - IIJ API にアクセスするためのアクセスキー
|
89
|
+
- `secret_key` - IIJ API にアクセスするためのシークレット
|
90
|
+
- `gp_service_code` - 仮想サーバを実行する gp サービスコード
|
91
|
+
- `ssh_public_key` - 仮想サーバにアクセスするための SSH 公開鍵の内容。
|
92
|
+
この設定は、仮想サーバを最初に起動する際のみ利用されます。
|
93
|
+
もし、SSH キーの設定を変更したい場合、仮想サーバの初期化をするか、
|
94
|
+
手動で ImportRootSshPublicKey API を実行する必要があります。
|
95
|
+
- 任意
|
96
|
+
- `label` - 仮想サーバのラベル。もし設定が無い場合には vagrant の vm name が利用されます
|
97
|
+
- `virtual_machine_type` - 仮想サーバの品目。この設定は新規に仮想サーバを契約する場合のみ必要です
|
98
|
+
- `os` - OS の種類。Chef provisioner を利用する場合、CentOS6 のイメージを指定する必要があります
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
1. Fork it
|
103
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
104
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
105
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
106
|
+
5. Create new Pull Request
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Vagrant IIJ GIO Provider
|
2
|
+
|
3
|
+
This is a [Vagrant](http://www.vagrantup.com) 1.3+ plugin that adds a IIJGP provider to Vagrant,
|
4
|
+
allowing Vagrant to control and provision VMs in IIJ GIO Hosting package service.
|
5
|
+
|
6
|
+
## Features
|
7
|
+
|
8
|
+
- Boot Virtual Machines in IIJ GIO Hosting package service
|
9
|
+
- SSH into the VMs.
|
10
|
+
- Provision the VMs with the Chef provisioner.
|
11
|
+
- Supports synced folder via `rsync`.
|
12
|
+
- Do some tweaks for IIJ CentOS VM
|
13
|
+
- disabling `Default requiretty` sudo settings for the root user.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Install using standard Vagrant 1.1+ plugin installation methods.
|
18
|
+
After installing, `vagrant up` and specify the `iijgp` provider.
|
19
|
+
An example shown below.
|
20
|
+
|
21
|
+
~~~~ {.shell}
|
22
|
+
$ vagrant plugin install vagrant-iijgp
|
23
|
+
...
|
24
|
+
$ vagrant up --provider=iijgp
|
25
|
+
...
|
26
|
+
~~~~
|
27
|
+
|
28
|
+
Of course prior to doing this, you'll need to obtain a iijgp-compatible box file for Vagrant.
|
29
|
+
|
30
|
+
## Quick Start
|
31
|
+
|
32
|
+
After installing the plugin (instructions above),
|
33
|
+
the quickest way to get started is to actually use a dummy IIJGP box
|
34
|
+
and specify all the details manually within a `config.vm.provider` block.
|
35
|
+
So first, add the dummy box using any name you want:
|
36
|
+
|
37
|
+
~~~~ {.shell}
|
38
|
+
$ vagrant box add dummy https://github.com/iij/vagrant-iijgp/raw/master/dummy.box
|
39
|
+
....
|
40
|
+
~~~~
|
41
|
+
|
42
|
+
And then make a Vagrantfile that looks like the following,
|
43
|
+
filling in your informathion where necessary.
|
44
|
+
|
45
|
+
~~~~ {.ruby}
|
46
|
+
Vagrant.configure("2") do |config|
|
47
|
+
config.vm.box = "dummy"
|
48
|
+
|
49
|
+
config.vm.provider :iijgp do |iijgp, override|
|
50
|
+
iijgp.access_key = "YOUR ACCESS KEY"
|
51
|
+
iijgp.secret_key = "YOUR SECRET KEY"
|
52
|
+
iijgp.gp_service_code = "gpXXXXXXXX"
|
53
|
+
iijgp.ssh_public_key = "YOUR PUBLIC SSH KEY"
|
54
|
+
|
55
|
+
override.ssh.username = "root"
|
56
|
+
override.ssh.private_key_path = "#{ENV['HOME']}/.ssh/id_rsa"
|
57
|
+
end
|
58
|
+
|
59
|
+
config.vm.define "vm1" do |c|
|
60
|
+
c.vm.provider :iijgp do |iijgp|
|
61
|
+
iijgp.gc_service_code = "gcXXXXXXXX"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
~~~~
|
66
|
+
|
67
|
+
And then run `vagrant up --provider=iijgp vm1`.
|
68
|
+
|
69
|
+
This will start the VM which is already created and specified with
|
70
|
+
the service code "gcXXXXXXXX" in GP "gpXXXXXXXX".
|
71
|
+
And if your SSH information was filled in properly,
|
72
|
+
SSH and provisioning will work as well.
|
73
|
+
|
74
|
+
If you always use iijgp provider as default, please set it in your shell setting:
|
75
|
+
~~~~ {.shell}
|
76
|
+
export VAGRANT_DEFAULT_PROVIDER=iijgp
|
77
|
+
~~~~
|
78
|
+
then you can simply run `vagrant up` with iijgp provider.
|
79
|
+
|
80
|
+
## Box Format
|
81
|
+
|
82
|
+
Every provider in Vagrant must introduce a custom box format.
|
83
|
+
This provider introduce `iijgp` boxes.
|
84
|
+
You can view an example box in the example_box/ directory.
|
85
|
+
|
86
|
+
## Configuration
|
87
|
+
|
88
|
+
There are some provider specific configuration option to control IIJ GIO VMs:
|
89
|
+
|
90
|
+
- mandatory parameters
|
91
|
+
- `access_key` - The access key for manipulating IIJ API.
|
92
|
+
- `secret_key` - The secret key for manipulating IIJ API.
|
93
|
+
- `gp_service_code` - The gp service code to launch the VMs.
|
94
|
+
- `ssh_public_key` - The SSH public key content to accessing IIJ VMs.
|
95
|
+
This is used only for the first start up of the VM.
|
96
|
+
If you intend to change the SSH key, you should initialize virtual machine.
|
97
|
+
(Or, call ImportRootSshPublicKey API manually...)
|
98
|
+
- optional parameters
|
99
|
+
- `label` - The label for the VM. If it is missing, the vagrant VM name will be used.
|
100
|
+
- `virtual_machine_type` - The type of virtual machine. This setting is only required if you want to add a new VM contract.
|
101
|
+
- `os` - The operating system. If you intend to use Chef provisioner, you need to use a kind of CentOS6 images.
|
102
|
+
|
103
|
+
## Contributing
|
104
|
+
|
105
|
+
1. Fork it
|
106
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
107
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
108
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
109
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/dummy.box
ADDED
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Vagrant IIJGP Example Box
|
2
|
+
|
3
|
+
Vagrant providers each require a custom provider-specific box format.
|
4
|
+
This folder shows the example contents of a box for the `iijgp` provider.
|
5
|
+
|
6
|
+
To turn this into a box file:
|
7
|
+
|
8
|
+
~~~~
|
9
|
+
$ fakeroot tar cvzf dummy.box ./metadata.json ./Vagrantfile
|
10
|
+
~~~~
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "provider": "iijgp" }
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class Boot
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::boot")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
@env = env
|
12
|
+
|
13
|
+
env[:ui].info I18n.t("vagrant.actions.vm.boot.booting")
|
14
|
+
gp = env[:machine].provider_config.gp_service_code
|
15
|
+
gc = env[:machine].id
|
16
|
+
|
17
|
+
vm = env[:iijapi].gp(gp).gc(gc)
|
18
|
+
vm.start
|
19
|
+
|
20
|
+
env[:ui].info I18n.t("vagrant_iijgp.wait_for_start")
|
21
|
+
vm.wait_for_start { env[:ui].info "-- current_status: #{vm.status}" }
|
22
|
+
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class CheckRunning
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env[:machine].state.id != :running
|
11
|
+
raise Vagrant::Errors::VMNotRunningError
|
12
|
+
end
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class CreateVM
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::create_vm")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
@env = env
|
12
|
+
|
13
|
+
config = env[:machine].provider_config
|
14
|
+
gp = config.gp_service_code
|
15
|
+
|
16
|
+
if env[:machine].id.nil?
|
17
|
+
opts = {
|
18
|
+
"VirtualMachineType" => config.virtual_machine_type,
|
19
|
+
"OS" => config.os,
|
20
|
+
"ContractNum" => "1"
|
21
|
+
}
|
22
|
+
env[:ui].info "-- AddVirtualMachines option: #{opts}"
|
23
|
+
|
24
|
+
res = env[:iijapi].gp(gp).add_virtual_machines(opts)
|
25
|
+
env[:ui].info "-- AddVirtualMachines response: #{res}"
|
26
|
+
env[:machine].id = res['GcServiceCodeList'].first
|
27
|
+
end
|
28
|
+
|
29
|
+
gc = env[:machine].id
|
30
|
+
vm = env[:iijapi].gp(gp).gc(gc)
|
31
|
+
|
32
|
+
retry_left = config.api_max_retry_count
|
33
|
+
begin
|
34
|
+
vm.wait_while(proc { vm.contract_status! == "InPreparation" }) do
|
35
|
+
env[:ui].info "-- contract status: #{vm.contract_status}"
|
36
|
+
end
|
37
|
+
rescue IIJ::Sakagura::Core::Error::APIError => e
|
38
|
+
env[:ui].warn "Failed to fetch the status of contract: #{e.inspect}"
|
39
|
+
retry_left -= 1
|
40
|
+
if retry_left > 0
|
41
|
+
sleep config.api_retry_wait
|
42
|
+
retry
|
43
|
+
else
|
44
|
+
raise
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
env[:ui].info I18n.t("vagrant_iijgp.import_root_ssh_public_key")
|
49
|
+
vm.import_ssh_public_key(config.ssh_public_key)
|
50
|
+
|
51
|
+
env[:ui].info I18n.t("vagrant_iijgp.wait_for_configured")
|
52
|
+
vm.wait_while(proc { vm.status! == "Configuring" }) { env[:ui].info "-- current_status: #{vm.status}" }
|
53
|
+
|
54
|
+
@app.call(env)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class Destroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::destroy")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:ui].info I18n.t("vagrant_iijgp.initialize_vm")
|
12
|
+
|
13
|
+
gp = env[:machine].provider_config.gp_service_code
|
14
|
+
gc = env[:machine].id
|
15
|
+
|
16
|
+
vm = env[:iijapi].gp(gp).gc(gc)
|
17
|
+
vm.initialize_vm
|
18
|
+
|
19
|
+
env[:ui].info I18n.t("vagrant_iijgp.wait_for_stop")
|
20
|
+
vm.wait_while(proc { vm.status! == "Initializing" }) { env[:ui].info "-- current_status: #{vm.status}" }
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class IsCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:result] = env[:machine].state.id != :not_created
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class MessageAlreadyRunning
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant_iijgp.vm_already_running", :name => env[:machine].name)
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class MessageInvalidStatus
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant_iijgp.invalid_status", :name => env[:machine].name, :state => env[:machine_state])
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant_iijgp.vm_not_created", :name => env[:machine].name)
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class MessageWillNotDestroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
11
|
+
:name => env[:machine].name)
|
12
|
+
@app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'iij/sakagura'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderIijGp
|
5
|
+
module Action
|
6
|
+
class PrepareIIJAPI
|
7
|
+
def initialize(app, env)
|
8
|
+
@app = app
|
9
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::prepare_iijapi")
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
config = env[:machine].provider_config
|
14
|
+
|
15
|
+
# use the existing gc contract.
|
16
|
+
if config.gc_service_code
|
17
|
+
if env[:machine].id.nil?
|
18
|
+
# first time `vagrant up`
|
19
|
+
env[:machine].id = config.gc_service_code
|
20
|
+
elsif config.gc_service_code != env[:machine].id
|
21
|
+
raise Errors::MismatchServiceCode, :provider_config => config.gc_service_code, :machine_id => env[:machine].id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
opts = {
|
26
|
+
:access_key => config.access_key,
|
27
|
+
:secret_key => config.secret_key
|
28
|
+
}
|
29
|
+
opts[:endpoint] = config.endpoint if config.endpoint
|
30
|
+
|
31
|
+
env[:iijapi] = IIJ::Sakagura::GP::Client.new(opts)
|
32
|
+
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class ReadSSHInfo
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::read_ssh_info")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
env[:machine_ssh_info] = read_ssh_info(env[:iijapi], env[:machine])
|
12
|
+
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_ssh_info(cli, machine)
|
17
|
+
vm = cli.gp(machine.provider_config.gp_service_code).gc(machine.id)
|
18
|
+
|
19
|
+
{
|
20
|
+
:host => vm.info['GlobalAddress']['IPv4Address'],
|
21
|
+
:port => 22
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class ReadState
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::read_state")
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_snake_sym(str)
|
11
|
+
str.gsub(/[A-Z]/) {|s| "_#{s.downcase}" }.sub(/^_/, '').to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state] = read_state(env)
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_state(env)
|
20
|
+
machine = env[:machine]
|
21
|
+
return :not_created if machine.id.nil?
|
22
|
+
|
23
|
+
vm = env[:iijapi].gp(machine.provider_config.gp_service_code).gc(machine.id)
|
24
|
+
if contract_status = vm.contract_status
|
25
|
+
if contract_status == "InService"
|
26
|
+
return to_snake_sym(vm.status)
|
27
|
+
elsif contract_status == "InPreparation"
|
28
|
+
return :in_preparation
|
29
|
+
else
|
30
|
+
machine.id = nil
|
31
|
+
return :not_created
|
32
|
+
end
|
33
|
+
else
|
34
|
+
machine.id = nil
|
35
|
+
return :not_created
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class SetLabel
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::set_label")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
gp = env[:machine].provider_config.gp_service_code
|
12
|
+
gc = env[:machine].id
|
13
|
+
|
14
|
+
vm = env[:iijapi].gp(gp).gc(gc)
|
15
|
+
label = env[:machine].provider_config.label || env[:machine].name.to_s || Time.now.strftime('%F %T')
|
16
|
+
|
17
|
+
@logger.info("Setting the label of the VM [#{gp}/#{gc}]: #{label}")
|
18
|
+
vm.label = label
|
19
|
+
|
20
|
+
@app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|