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
@@ -0,0 +1,31 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class StopVirtualMachine
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::stop_virtual_machine")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
@env = env
|
12
|
+
|
13
|
+
force = env[:force_halt] if env.has_key?(:force_halt)
|
14
|
+
env[:ui].info I18n.t("vagrant.actions.vm.halt.#{force ? "force" : "graceful"}")
|
15
|
+
|
16
|
+
config = env[:machine].provider_config
|
17
|
+
gp = config.gp_service_code
|
18
|
+
gc = env[:machine].id
|
19
|
+
|
20
|
+
vm = env[:iijapi].gp(gp).gc(gc)
|
21
|
+
vm.stop(force)
|
22
|
+
|
23
|
+
env[:ui].info I18n.t("vagrant_iijgp.wait_for_stop")
|
24
|
+
vm.wait_for_stop { env[:ui].info "-- current_status: #{vm.status}" }
|
25
|
+
|
26
|
+
@app.call(env)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "vagrant/util/scoped_hash_override"
|
2
|
+
require "vagrant/util/subprocess"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ProviderIijGp
|
6
|
+
module Action
|
7
|
+
class SyncFolders
|
8
|
+
include Vagrant::Util::ScopedHashOverride
|
9
|
+
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::sync_folders")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
@env = env
|
17
|
+
|
18
|
+
prepare_folders
|
19
|
+
|
20
|
+
@app.call(env)
|
21
|
+
|
22
|
+
install_rsync_guest
|
23
|
+
rsync
|
24
|
+
end
|
25
|
+
|
26
|
+
def install_rsync_guest
|
27
|
+
@env[:ui].info I18n.t("vagrant_iijgp.install_rsync")
|
28
|
+
@env[:machine].communicate.execute("yum install -y rsync")
|
29
|
+
end
|
30
|
+
|
31
|
+
def rsync
|
32
|
+
ssh_info = @env[:machine].ssh_info
|
33
|
+
|
34
|
+
synced_folders.each do |id, data|
|
35
|
+
hostpath = File.expand_path(data[:hostpath], @env[:root_path])
|
36
|
+
guestpath = data[:guestpath]
|
37
|
+
|
38
|
+
# append tailing slash for rsync
|
39
|
+
hostpath = hostpath + '/' if hostpath !~ /\/$/
|
40
|
+
guestpath = guestpath + '/' if guestpath !~ /\/$/
|
41
|
+
|
42
|
+
@env[:machine].communicate.execute(%Q[mkdir -p "#{guestpath}" && chown "#{ssh_info[:username]}" "#{guestpath}"])
|
43
|
+
|
44
|
+
ssh_command = %Q[ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o IdentitiesOnly=yes -i "#{ssh_info[:private_key_path]}"]
|
45
|
+
command = %w[rsync -avz --exclude .vagrant/ -e] +
|
46
|
+
[ssh_command, hostpath, "#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
47
|
+
|
48
|
+
@logger.info ("-- rsync command: #{command.inspect}")
|
49
|
+
@env[:ui].info I18n.t("vagrant_iijgp.rsync_folder", :hostpath => hostpath, :guestpath => guestpath)
|
50
|
+
ret = Vagrant::Util::Subprocess.execute(*command)
|
51
|
+
if ret.exit_code != 0
|
52
|
+
raise Errors::RsyncError, :guestpath => guestpath, :hostpath => hostpath, :stderr => ret.stderr
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns an actual list of IIJGP shared folders
|
58
|
+
def synced_folders
|
59
|
+
{}.tap do |result|
|
60
|
+
@env[:machine].config.vm.synced_folders.each do |id, data|
|
61
|
+
data = scoped_hash_override(data, :iijgp)
|
62
|
+
|
63
|
+
# Ignore NFS shared folders
|
64
|
+
next if data[:nfs]
|
65
|
+
|
66
|
+
# Ignore disabled shared folders
|
67
|
+
next if data[:disabled]
|
68
|
+
|
69
|
+
result[id] = data.dup
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Prepares the synced folders by verifying they exist and creating them
|
75
|
+
# if they don't.
|
76
|
+
def prepare_folders
|
77
|
+
synced_folders.each do |id, options|
|
78
|
+
hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])
|
79
|
+
|
80
|
+
if !hostpath.directory? && options[:create]
|
81
|
+
# Host path doesn't exist, so let's create it.
|
82
|
+
@logger.debug("Host path doesn't exist, creating: #{hostpath}")
|
83
|
+
|
84
|
+
begin
|
85
|
+
hostpath.mkpath
|
86
|
+
rescue Errno::EACCES
|
87
|
+
raise Vagrant::Errors::SharedFolderCreateFailed,
|
88
|
+
:path => hostpath.to_s
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
module Action
|
4
|
+
class VagrantTweaks
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
@logger = Log4r::Logger.new("vagrant_iijgp::action::vagrant_tweaks")
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
case env[:machine].provider_config.vagrant_tweaks
|
12
|
+
when :allow_root_notty_sudo
|
13
|
+
env[:machine].communicate.execute(%q[grep "^Defaults:root !requiretty$" /etc/sudoers ||] +
|
14
|
+
%q[(chmod 600 /etc/sudoers && sed -i.bak 's/^Defaults\s*requiretty/Defaults requiretty\nDefaults:root !requiretty/g' /etc/sudoers; chmod 400 /etc/sudoers)])
|
15
|
+
end
|
16
|
+
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require "vagrant/action/builder"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderIijGp
|
5
|
+
module Action
|
6
|
+
include Vagrant::Action::Builtin
|
7
|
+
|
8
|
+
def self.action_boot
|
9
|
+
Vagrant::Action::Builder.new.tap do |b|
|
10
|
+
b.use Provision
|
11
|
+
b.use SyncFolders
|
12
|
+
b.use SetLabel
|
13
|
+
b.use Boot
|
14
|
+
b.use WaitForCommunicator, [:starting, :running]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.action_destroy
|
19
|
+
Vagrant::Action::Builder.new.tap do |b|
|
20
|
+
b.use Call, IsCreated do |env1, b1|
|
21
|
+
if !env1[:result]
|
22
|
+
b1.use MessageNotCreated
|
23
|
+
next
|
24
|
+
end
|
25
|
+
|
26
|
+
b1.use Call, DestroyConfirm do |env2, b2|
|
27
|
+
if env2[:result]
|
28
|
+
b2.use EnvSet, :force_halt => true
|
29
|
+
b2.use action_halt
|
30
|
+
b2.use Destroy
|
31
|
+
b2.use ProvisionerCleanup
|
32
|
+
else
|
33
|
+
b2.use MessageWillNotDestroy
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.action_halt
|
41
|
+
Vagrant::Action::Builder.new.tap do |b|
|
42
|
+
b.use ConfigValidate
|
43
|
+
b.use PrepareIIJAPI
|
44
|
+
b.use Call, IsCreated do |env1, b1|
|
45
|
+
if env1[:result]
|
46
|
+
b1.use Call, IsStopped do |env2, b2|
|
47
|
+
if !env2[:result]
|
48
|
+
b2.use StopVirtualMachine
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
b1.use MessageNotCreated
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.action_provision
|
59
|
+
Vagrant::Action::Builder.new.tap do |b|
|
60
|
+
b.use ConfigValidate
|
61
|
+
b.use PrepareIIJAPI
|
62
|
+
b.use Call, ReadState do |env1, b1|
|
63
|
+
case env1[:machine_state]
|
64
|
+
when :running
|
65
|
+
b1.use Provision
|
66
|
+
b1.use SyncFolders
|
67
|
+
b1.use VagrantTweaks
|
68
|
+
when :not_created, :initialized
|
69
|
+
b1.use MessageNotCreated
|
70
|
+
else
|
71
|
+
b1.use MessageInvalidStatus
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.action_reload
|
78
|
+
Vagrant::Action::Builder.new.tap do |b|
|
79
|
+
b.use ConfigValidate
|
80
|
+
b.use PrepareIIJAPI
|
81
|
+
b.use Call, IsCreated do |env1, b1|
|
82
|
+
if !env1[:result]
|
83
|
+
b1.use MessageNotCreated
|
84
|
+
next
|
85
|
+
end
|
86
|
+
|
87
|
+
b1.use action_halt
|
88
|
+
b1.use action_up
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.action_read_ssh_info
|
94
|
+
Vagrant::Action::Builder.new.tap do |b|
|
95
|
+
b.use ConfigValidate
|
96
|
+
b.use PrepareIIJAPI
|
97
|
+
b.use ReadSSHInfo
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.action_read_state
|
102
|
+
Vagrant::Action::Builder.new.tap do |b|
|
103
|
+
b.use ConfigValidate
|
104
|
+
b.use PrepareIIJAPI
|
105
|
+
b.use ReadState
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.action_ssh
|
110
|
+
Vagrant::Action::Builder.new.tap do |b|
|
111
|
+
b.use ConfigValidate
|
112
|
+
b.use PrepareIIJAPI
|
113
|
+
b.use CheckRunning
|
114
|
+
b.use SSHExec
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.action_ssh_run
|
119
|
+
Vagrant::Action::Builder.new.tap do |b|
|
120
|
+
b.use ConfigValidate
|
121
|
+
b.use PrepareIIJAPI
|
122
|
+
b.use CheckRunning
|
123
|
+
b.use SSHRun
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.action_start
|
128
|
+
Vagrant::Action::Builder.new.tap do |b|
|
129
|
+
b.use Call, IsStopped do |env1, b1|
|
130
|
+
if env1[:result]
|
131
|
+
b1.use action_boot
|
132
|
+
else
|
133
|
+
b1.use MessageAlreadyRunning
|
134
|
+
next
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def self.action_up
|
141
|
+
Vagrant::Action::Builder.new.tap do |b|
|
142
|
+
b.use ConfigValidate
|
143
|
+
b.use PrepareIIJAPI
|
144
|
+
b.use Call, ReadState do |env1, b1|
|
145
|
+
case env1[:machine_state]
|
146
|
+
when :not_created, :initialized
|
147
|
+
b1.use CreateVM
|
148
|
+
b1.use action_start
|
149
|
+
b1.use VagrantTweaks
|
150
|
+
when :stopped
|
151
|
+
b1.use action_start
|
152
|
+
when :running
|
153
|
+
b1.use MessageAlreadyRunning
|
154
|
+
else
|
155
|
+
b1.use MessageInvalidStatus
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
162
|
+
autoload :Boot, action_root.join("boot")
|
163
|
+
autoload :CheckRunning, action_root.join("check_running")
|
164
|
+
autoload :CreateVM, action_root.join("create_vm")
|
165
|
+
autoload :Destroy, action_root.join("destroy")
|
166
|
+
autoload :IsCreated, action_root.join("is_created")
|
167
|
+
autoload :IsStopped, action_root.join("is_stopped")
|
168
|
+
autoload :MessageAlreadyRunning, action_root.join("message_already_running")
|
169
|
+
autoload :MessageInvalidStatus, action_root.join("message_invalid_status")
|
170
|
+
autoload :MessageNotCreated, action_root.join("message_not_created")
|
171
|
+
autoload :MessageWillNotDestroy, action_root.join("message_will_not_destroy")
|
172
|
+
autoload :PrepareIIJAPI, action_root.join("prepare_iijapi")
|
173
|
+
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
174
|
+
autoload :ReadState, action_root.join("read_state")
|
175
|
+
autoload :SetLabel, action_root.join("set_label")
|
176
|
+
autoload :StopVirtualMachine, action_root.join("stop_virtual_machine")
|
177
|
+
autoload :SyncFolders, action_root.join("sync_folders")
|
178
|
+
autoload :VagrantTweaks, action_root.join("vagrant_tweaks")
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
class Config < Vagrant.plugin("2", :config)
|
4
|
+
attr_accessor :endpoint
|
5
|
+
|
6
|
+
attr_accessor :access_key
|
7
|
+
attr_accessor :secret_key
|
8
|
+
|
9
|
+
attr_accessor :gp_service_code
|
10
|
+
attr_accessor :gc_service_code
|
11
|
+
|
12
|
+
attr_accessor :virtual_machine_type
|
13
|
+
attr_accessor :os
|
14
|
+
|
15
|
+
attr_accessor :ssh_public_key
|
16
|
+
|
17
|
+
attr_accessor :label
|
18
|
+
|
19
|
+
attr_accessor :vagrant_tweaks
|
20
|
+
|
21
|
+
attr_accessor :api_max_retry_count
|
22
|
+
attr_accessor :api_retry_wait
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@endpoint = UNSET_VALUE
|
26
|
+
@access_key = UNSET_VALUE
|
27
|
+
@secret_key = UNSET_VALUE
|
28
|
+
@gp_service_code = UNSET_VALUE
|
29
|
+
@gc_service_code = UNSET_VALUE
|
30
|
+
@virtual_machine_type = UNSET_VALUE
|
31
|
+
@os = UNSET_VALUE
|
32
|
+
@ssh_public_key = UNSET_VALUE
|
33
|
+
@label = UNSET_VALUE
|
34
|
+
@vagrant_tweaks = UNSET_VALUE
|
35
|
+
@api_max_retry_count = UNSET_VALUE
|
36
|
+
@api_retry_wait = UNSET_VALUE
|
37
|
+
end
|
38
|
+
|
39
|
+
def finalize!
|
40
|
+
@endpoint = nil if @endpoint == UNSET_VALUE
|
41
|
+
@access_key = ENV['IIJAPI_ACCESS_KEY'] if @access_key == UNSET_VALUE
|
42
|
+
@secret_key = ENV['IIJAPI_SECRET_KEY'] if @secret_key == UNSET_VALUE
|
43
|
+
|
44
|
+
@gc_service_code = nil if @gc_service_code == UNSET_VALUE
|
45
|
+
|
46
|
+
@virtual_machine_type = 'V10' if @virtual_machine_type == UNSET_VALUE
|
47
|
+
@os = 'CentOS6_64_U' if @os == UNSET_VALUE
|
48
|
+
@ssh_public_key = nil if @ssh_public_key == UNSET_VALUE
|
49
|
+
@label = nil if @label == UNSET_VALUE
|
50
|
+
@vagrant_tweaks = :allow_root_notty_sudo if @vagrant_tweaks == UNSET_VALUE
|
51
|
+
@api_max_retry_count = 10 if @api_max_retry_count == UNSET_VALUE
|
52
|
+
@api_retry_wait = 60 if @api_retry_wait == UNSET_VALUE
|
53
|
+
end
|
54
|
+
|
55
|
+
def validate(machine)
|
56
|
+
errors = _detected_errors
|
57
|
+
|
58
|
+
unless @access_key
|
59
|
+
errors << I18n.t("vagrant_iijgp.config.access_key_is_required")
|
60
|
+
end
|
61
|
+
|
62
|
+
unless @secret_key
|
63
|
+
errors << I18n.t("vagrant_iijgp.config.secret_key_is_required")
|
64
|
+
end
|
65
|
+
|
66
|
+
unless @ssh_public_key
|
67
|
+
errors << I18n.t("vagrant_iijgp.config.ssh_public_key_is_required")
|
68
|
+
end
|
69
|
+
|
70
|
+
if @gp_service_code.nil? or @gp_service_code == UNSET_VALUE
|
71
|
+
errors << I18n.t("vagrant_iijgp.config.gp_service_code_is_required")
|
72
|
+
end
|
73
|
+
|
74
|
+
{ "IIJ GP Provider" => errors }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ProviderIijGp
|
5
|
+
module Errors
|
6
|
+
class VagrantIijGpError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_iijgp.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
class RsyncError < VagrantIijGpError
|
11
|
+
error_key(:rsync_error)
|
12
|
+
end
|
13
|
+
|
14
|
+
class MismatchServiceCode < VagrantIijGpError
|
15
|
+
error_key(:mismatch_service_code)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
require "log4r"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ProviderIijGp
|
6
|
+
class Plugin < Vagrant.plugin("2")
|
7
|
+
name "IIJ GP provider"
|
8
|
+
description <<-EOF
|
9
|
+
The IIJ GP provider allows Vagrant to manage and control
|
10
|
+
virtual machine in IIJ GIO hosting package service.
|
11
|
+
EOF
|
12
|
+
|
13
|
+
config(:iijgp, :provider) do
|
14
|
+
require_relative "config"
|
15
|
+
Config
|
16
|
+
end
|
17
|
+
|
18
|
+
provider(:iijgp, :parallel => true) do
|
19
|
+
setup_logging
|
20
|
+
setup_i18n
|
21
|
+
|
22
|
+
require_relative "provider"
|
23
|
+
Provider
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.setup_logging
|
27
|
+
require "log4r"
|
28
|
+
|
29
|
+
level = nil
|
30
|
+
begin
|
31
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
32
|
+
rescue NameError
|
33
|
+
end
|
34
|
+
|
35
|
+
level = nil unless level.is_a?(Integer)
|
36
|
+
|
37
|
+
# Set the logging level on all "vagrant_iijgp" namespaced
|
38
|
+
# logs as long as we have a valid level.
|
39
|
+
if level
|
40
|
+
logger = Log4r::Logger.new("vagrant_iijgp")
|
41
|
+
logger.outputters = Log4r::Outputter.stderr
|
42
|
+
logger.level = level
|
43
|
+
logger = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.setup_i18n
|
48
|
+
I18n.load_path << File.expand_path("locales/en.yml", ProviderIijGp.source_root)
|
49
|
+
I18n.reload!
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ProviderIijGp
|
3
|
+
class Provider < Vagrant.plugin('2', :provider)
|
4
|
+
def initialize(machine)
|
5
|
+
@logger = Log4r::Logger.new("")
|
6
|
+
@machine = machine
|
7
|
+
end
|
8
|
+
attr_reader :machine
|
9
|
+
|
10
|
+
# @param [Symbol] name Name of the action.
|
11
|
+
# @return [Object] A callable action sequence object.
|
12
|
+
# +nil+ means that we don't support the given action.
|
13
|
+
def action(name)
|
14
|
+
method = "action_#{name}"
|
15
|
+
if Action.respond_to? method
|
16
|
+
Action.send(method)
|
17
|
+
else
|
18
|
+
# the specified action is not supported
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Hash] SSH information. For the structure of this hash
|
24
|
+
# read the accompanying documentation for this method.
|
25
|
+
def ssh_info
|
26
|
+
env = @machine.action('read_ssh_info')
|
27
|
+
env[:machine_ssh_info]
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [MachineState]
|
31
|
+
def state
|
32
|
+
env = @machine.action('read_state')
|
33
|
+
|
34
|
+
state = env[:machine_state]
|
35
|
+
|
36
|
+
# Translate into short/long descriptions
|
37
|
+
short = I18n.t("vagrant_iijgp.state.#{state}.short")
|
38
|
+
long = I18n.t("vagrant_iijgp.state.#{state}.long")
|
39
|
+
|
40
|
+
# Return the MachineState object
|
41
|
+
Vagrant::MachineState.new(state, short, long)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "pathname"
|
2
|
+
|
3
|
+
require "vagrant-iijgp/plugin"
|
4
|
+
|
5
|
+
module VagrantPlugins
|
6
|
+
module ProviderIijGp
|
7
|
+
lib_path = Pathname.new(File.expand_path("../vagrant-iijgp", __FILE__))
|
8
|
+
autoload :Action, lib_path.join("action")
|
9
|
+
autoload :Errors, lib_path.join("errors")
|
10
|
+
|
11
|
+
# This returns the path to the source of this plugin.
|
12
|
+
#
|
13
|
+
# @return [Pathname]
|
14
|
+
def self.source_root
|
15
|
+
@source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_iijgp:
|
3
|
+
wait_for_configured: |-
|
4
|
+
Waiting for the import of the root SSH key to complete.
|
5
|
+
wait_for_start: |-
|
6
|
+
Waiting for start...
|
7
|
+
wait_for_stop: |-
|
8
|
+
Waiting for stop...
|
9
|
+
vm_already_running: |-
|
10
|
+
Virtual Machine already running.
|
11
|
+
vm_not_created: |-
|
12
|
+
Virtual Machine is not created.
|
13
|
+
invalid_status: |-
|
14
|
+
The action is not allowed in the current status (%{state}).
|
15
|
+
import_root_ssh_public_key: |-
|
16
|
+
Importing your SSH public key into the Virtual Machine.
|
17
|
+
install_rsync: |-
|
18
|
+
Installing rsync on the Virtual Machine.
|
19
|
+
rsync_folder: |-
|
20
|
+
Rsyncing folder: %{hostpath} => %{guestpath}
|
21
|
+
|
22
|
+
config:
|
23
|
+
access_key_is_required: |-
|
24
|
+
access_key is required
|
25
|
+
secret_key_is_required: |-
|
26
|
+
secret_key is required
|
27
|
+
gp_service_code_is_required: |-
|
28
|
+
gp_service_code is required
|
29
|
+
ssh_public_key_is_required: |-
|
30
|
+
ssh_public_key is required
|
31
|
+
|
32
|
+
state:
|
33
|
+
running:
|
34
|
+
short: |-
|
35
|
+
Running
|
36
|
+
long: |-
|
37
|
+
The virtual machine is running.
|
38
|
+
|
39
|
+
stopped:
|
40
|
+
short: |-
|
41
|
+
Stopped
|
42
|
+
long: |-
|
43
|
+
The virtual machine is stopped.
|
44
|
+
|
45
|
+
starting:
|
46
|
+
short: |-
|
47
|
+
Starting
|
48
|
+
long: |-
|
49
|
+
The virtual machine is starting.
|
50
|
+
|
51
|
+
stopping:
|
52
|
+
short: |-
|
53
|
+
Stopping
|
54
|
+
long: |-
|
55
|
+
The virtual machine is stopping.
|
56
|
+
|
57
|
+
initialized:
|
58
|
+
short: |-
|
59
|
+
Initialized
|
60
|
+
long: |-
|
61
|
+
The virtual machine is initialized.
|
62
|
+
|
63
|
+
errors:
|
64
|
+
rsync_error: |-
|
65
|
+
An error occured while attempting to rsync.
|
66
|
+
mismatch_service_code: |-
|
67
|
+
There is no match between the service code which is stored in vagrant (%{machine_id})
|
68
|
+
and the service code which is specified in the configuration file (%{provider_config}).
|
69
|
+
If you changed the service code in the setting file after `vagrant up`,
|
70
|
+
you should wipe out the setting in `.vagrant/machines/<name>/id`.
|
data/sample/Vagrantfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
# vi: set ft=ruby :
|
3
|
+
|
4
|
+
Vagrant.configure("2") do |config|
|
5
|
+
config.vm.box = "dummy"
|
6
|
+
|
7
|
+
config.vm.provider :iijgp do |iijgp, override|
|
8
|
+
iijgp.access_key = "YOUR ACCESS KEY"
|
9
|
+
iijgp.secret_key = "YOUR SECRET KEY"
|
10
|
+
iijgp.gp_service_code = "gpXXXXXXXX"
|
11
|
+
iijgp.ssh_public_key = File.read("#{ENV['HOME']}/.ssh/id_rsa.pub")
|
12
|
+
|
13
|
+
override.ssh.username = "root"
|
14
|
+
override.ssh.private_key_path = "#{ENV['HOME']}/.ssh/id_rsa"
|
15
|
+
end
|
16
|
+
|
17
|
+
config.vm.define "vm1" do |c|
|
18
|
+
c.vm.provider :iijgp do |iijgp|
|
19
|
+
iijgp.gc_service_code = "gcXXXXXXXX"
|
20
|
+
iijgp.label = "vagrant-iijgp test vm1"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
config.vm.define "vm2" do |c|
|
25
|
+
c.vm.provider :iijgp do |iijgp|
|
26
|
+
iijgp.gc_service_code = "gcYYYYYYYY"
|
27
|
+
iijgp.label = "vagrant-iijgp test vm2"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
config.vm.define "another_gp_vm3" do |c|
|
32
|
+
c.vm.provider :iijgp do |iijgp, override|
|
33
|
+
iijgp.gp_service_code = "gpZZZZZZZZ"
|
34
|
+
iijgp.gc_service_code = "gcZZZZZZZZ"
|
35
|
+
iijgp.label = "vagrant-iijgp test vm3"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-iijgp/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-iijgp"
|
8
|
+
spec.version = VagrantPlugins::ProviderIijGp::VERSION
|
9
|
+
spec.authors = ["Takahiro HIMURA"]
|
10
|
+
spec.email = ["taka@himura.jp"]
|
11
|
+
spec.description = %q{Vagrant plugin for IIJ GIO Hosting Package service}
|
12
|
+
spec.summary = %q{Vagrant plugin for IIJ GIO Hosting Package service}
|
13
|
+
spec.homepage = "https://github.com/iij/vagrant-iijgp/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "iij-sakagura"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec-core"
|
26
|
+
spec.add_development_dependency "rspec-expectations"
|
27
|
+
spec.add_development_dependency "mocha"
|
28
|
+
end
|