vagrant-sakura 0.0.9 → 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.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +30 -0
- data/CHANGELOG.md +10 -0
- data/Gemfile +2 -0
- data/README.md +86 -16
- data/Rakefile +5 -0
- data/examples/centos.md +15 -0
- data/examples/centos6.md +15 -0
- data/examples/coreos.md +15 -0
- data/examples/debian.md +15 -0
- data/examples/freebsd.md +17 -0
- data/examples/rancheros.md +17 -0
- data/examples/ubuntu.md +15 -0
- data/lib/vagrant-sakura/action/complete_archive_id.rb +38 -0
- data/lib/vagrant-sakura/action/reinstall.rb +114 -0
- data/lib/vagrant-sakura/action/run_instance.rb +18 -2
- data/lib/vagrant-sakura/action.rb +24 -0
- data/lib/vagrant-sakura/{command.rb → command_list_id.rb} +1 -1
- data/lib/vagrant-sakura/command_reinstall.rb +16 -0
- data/lib/vagrant-sakura/config.rb +121 -5
- data/lib/vagrant-sakura/driver/api.rb +3 -2
- data/lib/vagrant-sakura/os_type.rb +34 -0
- data/lib/vagrant-sakura/plugin.rb +7 -2
- data/lib/vagrant-sakura/version.rb +1 -1
- data/locales/en.yml +4 -0
- data/test/test_config.rb +180 -14
- data/test/test_usacloud_config.rb +164 -0
- metadata +18 -4
@@ -20,10 +20,15 @@ module VagrantPlugins
|
|
20
20
|
server_name ||= env[:machine].name
|
21
21
|
server_plan = env[:machine].provider_config.server_plan
|
22
22
|
disk_plan = env[:machine].provider_config.disk_plan
|
23
|
+
disk_source_mode = env[:machine].provider_config.disk_source_mode
|
24
|
+
os_type = env[:machine].provider_config.os_type
|
23
25
|
disk_source_archive = env[:machine].provider_config.disk_source_archive
|
24
26
|
sshkey_id = env[:machine].provider_config.sshkey_id
|
25
27
|
public_key_path = env[:machine].provider_config.public_key_path
|
26
28
|
use_insecure_key = env[:machine].provider_config.use_insecure_key
|
29
|
+
enable_pw_auth = env[:machine].provider_config.enable_pw_auth
|
30
|
+
packet_filter = env[:machine].provider_config.packet_filter.to_s
|
31
|
+
startup_scripts = env[:machine].provider_config.startup_scripts
|
27
32
|
tags = env[:machine].provider_config.tags
|
28
33
|
description = env[:machine].provider_config.description
|
29
34
|
|
@@ -31,7 +36,10 @@ module VagrantPlugins
|
|
31
36
|
env[:ui].info(" -- Server Name: #{server_name}")
|
32
37
|
env[:ui].info(" -- Server Plan: #{server_plan}")
|
33
38
|
env[:ui].info(" -- Disk Plan: #{disk_plan}")
|
39
|
+
env[:ui].info(" -- Disk Source OS Type: #{os_type}") if os_type
|
34
40
|
env[:ui].info(" -- Disk Source Archive: #{disk_source_archive}")
|
41
|
+
env[:ui].info(" -- Packet Filter: #{packet_filter}") unless packet_filter.empty?
|
42
|
+
env[:ui].info(" -- Startup Scripts: #{startup_scripts.map {|item| item["ID"]}}") unless startup_scripts.empty?
|
35
43
|
env[:ui].info(" -- Tags: #{tags}") unless tags.empty?
|
36
44
|
env[:ui].info(" -- Description: \"#{description}\"") unless description.empty?
|
37
45
|
|
@@ -39,7 +47,6 @@ module VagrantPlugins
|
|
39
47
|
|
40
48
|
if env[:machine].provider_config.disk_id
|
41
49
|
diskid = env[:machine].provider_config.disk_id
|
42
|
-
|
43
50
|
else
|
44
51
|
data = {
|
45
52
|
"Disk" => {
|
@@ -92,8 +99,14 @@ module VagrantPlugins
|
|
92
99
|
raise 'no Server ID returned'
|
93
100
|
end
|
94
101
|
env[:machine].id = serverid = response["Server"]["ID"]
|
102
|
+
interface_id = response["Server"]["Interfaces"][0]["ID"]
|
95
103
|
# Server Created
|
96
104
|
|
105
|
+
unless packet_filter.empty?
|
106
|
+
response = api.put("/interface/#{interface_id}/to/packetfilter/#{packet_filter}")
|
107
|
+
# Packet Filter connected to Server
|
108
|
+
end
|
109
|
+
|
97
110
|
begin
|
98
111
|
response = api.put("/disk/#{diskid}/to/server/#{serverid}")
|
99
112
|
# Disk mounted to Server
|
@@ -103,7 +116,9 @@ module VagrantPlugins
|
|
103
116
|
end
|
104
117
|
|
105
118
|
data = {
|
106
|
-
"UserSubnet" => {}
|
119
|
+
"UserSubnet" => {},
|
120
|
+
"Notes" => startup_scripts,
|
121
|
+
"DisablePWAuth" => !enable_pw_auth
|
107
122
|
}
|
108
123
|
if sshkey_id
|
109
124
|
data["SSHKey"] = { "ID" => sshkey_id }
|
@@ -115,6 +130,7 @@ module VagrantPlugins
|
|
115
130
|
else
|
116
131
|
raise 'failsafe'
|
117
132
|
end
|
133
|
+
|
118
134
|
response = api.put("/disk/#{diskid}/config", data)
|
119
135
|
# Config
|
120
136
|
|
@@ -35,6 +35,27 @@ module VagrantPlugins
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.action_reinstall
|
39
|
+
Vagrant::Action::Builder.new.tap do |b|
|
40
|
+
b.use ConfigValidate
|
41
|
+
b.use ConnectSakura
|
42
|
+
b.use CompleteArchiveId
|
43
|
+
b.use Call, ReadState do |env, b2|
|
44
|
+
case env[:machine_state_id]
|
45
|
+
when :up
|
46
|
+
b2.use Halt
|
47
|
+
b2.use Reinstall
|
48
|
+
b2.use Provision
|
49
|
+
when :down, :cleaning
|
50
|
+
b2.use Reinstall
|
51
|
+
b2.use Provision
|
52
|
+
when :not_created
|
53
|
+
b2.use MessageNotCreated
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
38
59
|
def self.action_list_id
|
39
60
|
Vagrant::Action::Builder.new.tap do |b|
|
40
61
|
b.use ConfigValidate
|
@@ -134,6 +155,7 @@ module VagrantPlugins
|
|
134
155
|
b.use HandleBox
|
135
156
|
b.use ConfigValidate
|
136
157
|
b.use ConnectSakura
|
158
|
+
b.use CompleteArchiveId
|
137
159
|
b.use Call, ReadState do |env, b2|
|
138
160
|
case env[:machine_state_id]
|
139
161
|
when :up
|
@@ -150,6 +172,7 @@ module VagrantPlugins
|
|
150
172
|
end
|
151
173
|
|
152
174
|
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
175
|
+
autoload :CompleteArchiveId, action_root.join("complete_archive_id")
|
153
176
|
autoload :ConnectSakura, action_root.join("connect_sakura")
|
154
177
|
autoload :DeleteServer, action_root.join("delete_server")
|
155
178
|
autoload :IsCreated, action_root.join("is_created")
|
@@ -162,6 +185,7 @@ module VagrantPlugins
|
|
162
185
|
autoload :PowerOn, action_root.join("power_on")
|
163
186
|
autoload :ReadSSHInfo, action_root.join("read_ssh_info")
|
164
187
|
autoload :ReadState, action_root.join("read_state")
|
188
|
+
autoload :Reinstall, action_root.join("reinstall")
|
165
189
|
autoload :Reset, action_root.join("reset")
|
166
190
|
autoload :RunInstance, action_root.join("run_instance")
|
167
191
|
autoload :SyncFolders, action_root.join("sync_folders")
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Sakura
|
3
|
+
class CommandReinstall < Vagrant.plugin(2, :command)
|
4
|
+
def self.synopsis
|
5
|
+
"Reinstall Sakura cloud disk"
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
with_target_vms(nil, { :provider => "sakura" }) do |vm|
|
10
|
+
vm.action(:reinstall)
|
11
|
+
end
|
12
|
+
0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
require "vagrant"
|
2
|
+
require "json"
|
3
|
+
require "vagrant-sakura/os_type"
|
2
4
|
|
3
5
|
module VagrantPlugins
|
4
6
|
module Sakura
|
5
7
|
class Config < Vagrant.plugin("2", :config)
|
8
|
+
|
6
9
|
# The ACCESS TOKEN to access Sakura Cloud API.
|
7
10
|
#
|
8
11
|
# @return [String]
|
@@ -28,6 +31,11 @@ module VagrantPlugins
|
|
28
31
|
# @return [String]
|
29
32
|
attr_accessor :disk_source_archive
|
30
33
|
|
34
|
+
# The source archive os-type.
|
35
|
+
#
|
36
|
+
# @return [String]
|
37
|
+
attr_accessor :os_type
|
38
|
+
|
31
39
|
# The pathname of the SSH public key to register on the server.
|
32
40
|
#
|
33
41
|
# @return [String]
|
@@ -53,9 +61,29 @@ module VagrantPlugins
|
|
53
61
|
# @return [Boolean]
|
54
62
|
attr_accessor :use_insecure_key
|
55
63
|
|
64
|
+
# Enable password auth to connecting via ssh.
|
65
|
+
#
|
66
|
+
# @return [Boolean]
|
67
|
+
attr_accessor :enable_pw_auth
|
68
|
+
|
69
|
+
# The packet filter ID of the server's first NIC.
|
70
|
+
#
|
71
|
+
# @return [String]
|
72
|
+
attr_accessor :packet_filter
|
73
|
+
|
74
|
+
# The startup script IDs of the server.
|
75
|
+
#
|
76
|
+
# @return [Array<String>]
|
77
|
+
attr_accessor :startup_scripts
|
78
|
+
|
56
79
|
# The ID of the zone.
|
57
80
|
attr_accessor :zone_id
|
58
81
|
|
82
|
+
# The path of the usacloud config.
|
83
|
+
#
|
84
|
+
# @return [String]
|
85
|
+
attr_accessor :config_path
|
86
|
+
|
59
87
|
# The tags of the server and disk.
|
60
88
|
#
|
61
89
|
# @return [Array<String>]
|
@@ -72,24 +100,49 @@ module VagrantPlugins
|
|
72
100
|
@disk_id = UNSET_VALUE
|
73
101
|
@disk_plan = UNSET_VALUE
|
74
102
|
@disk_source_archive = UNSET_VALUE
|
103
|
+
@os_type = UNSET_VALUE
|
75
104
|
@public_key_path = UNSET_VALUE
|
76
105
|
@server_name = UNSET_VALUE
|
77
106
|
@server_plan = UNSET_VALUE
|
78
107
|
@sshkey_id = UNSET_VALUE
|
79
108
|
@use_insecure_key = UNSET_VALUE
|
109
|
+
@enable_pw_auth = UNSET_VALUE
|
110
|
+
@packet_filter = UNSET_VALUE
|
111
|
+
@startup_scripts = UNSET_VALUE
|
80
112
|
@zone_id = UNSET_VALUE
|
113
|
+
@config_path = UNSET_VALUE
|
81
114
|
@tags = UNSET_VALUE
|
82
115
|
@description = UNSET_VALUE
|
83
116
|
end
|
84
117
|
|
118
|
+
# @return one of [:disk, :archive, :os_type]
|
119
|
+
def disk_source_mode
|
120
|
+
return :disk unless @disk_id.to_s.empty?
|
121
|
+
return :archive unless @disk_source_archive.to_s.empty?
|
122
|
+
:os_type
|
123
|
+
end
|
124
|
+
|
85
125
|
def finalize!
|
126
|
+
|
127
|
+
usacloud_config = get_usacloud_config(@config_path)
|
128
|
+
|
86
129
|
if @access_token == UNSET_VALUE
|
87
|
-
|
130
|
+
if usacloud_config.nil?
|
131
|
+
@access_token = nil
|
132
|
+
else
|
133
|
+
@access_token = usacloud_config["AccessToken"]
|
134
|
+
end
|
135
|
+
@access_token = ENV['SAKURA_ACCESS_TOKEN'] if @access_token.nil?
|
88
136
|
@access_token = ENV['SAKURACLOUD_ACCESS_TOKEN'] if @access_token.nil?
|
89
137
|
end
|
90
138
|
|
91
139
|
if @access_token_secret == UNSET_VALUE
|
92
|
-
|
140
|
+
if usacloud_config.nil?
|
141
|
+
@access_token_secret = nil
|
142
|
+
else
|
143
|
+
@access_token_secret = usacloud_config["AccessTokenSecret"]
|
144
|
+
end
|
145
|
+
@access_token_secret = ENV['SAKURA_ACCESS_TOKEN_SECRET'] if @access_token_secret.nil?
|
93
146
|
@access_token_secret = ENV['SAKURACLOUD_ACCESS_TOKEN_SECRET'] if @access_token_secret.nil?
|
94
147
|
end
|
95
148
|
|
@@ -101,8 +154,10 @@ module VagrantPlugins
|
|
101
154
|
@disk_plan = 4 # SSD
|
102
155
|
end
|
103
156
|
|
104
|
-
if @disk_source_archive == UNSET_VALUE
|
105
|
-
|
157
|
+
@disk_source_archive = nil if @disk_source_archive == UNSET_VALUE
|
158
|
+
@os_type = nil if @os_type == UNSET_VALUE
|
159
|
+
if @disk_source_archive.to_s.empty? && @os_type.to_s.empty?
|
160
|
+
@os_type = "ubuntu"
|
106
161
|
end
|
107
162
|
|
108
163
|
@public_key_path = nil if @public_key_path == UNSET_VALUE
|
@@ -118,9 +173,21 @@ module VagrantPlugins
|
|
118
173
|
@sshkey_id = nil if @sshkey_id == UNSET_VALUE
|
119
174
|
|
120
175
|
@use_insecure_key = false if @use_insecure_key == UNSET_VALUE
|
176
|
+
@enable_pw_auth = false if @enable_pw_auth == UNSET_VALUE
|
177
|
+
|
178
|
+
@packet_filter = "" if @packet_filter == UNSET_VALUE
|
179
|
+
|
180
|
+
@startup_scripts = [] if @startup_scripts == UNSET_VALUE
|
181
|
+
@startup_scripts = [@startup_scripts] unless @startup_scripts.is_a?(Array)
|
182
|
+
@startup_scripts.map! { |id| {"ID" => id.to_s} }
|
121
183
|
|
122
184
|
if @zone_id == UNSET_VALUE
|
123
|
-
|
185
|
+
if usacloud_config.nil?
|
186
|
+
@zone_id = nil
|
187
|
+
else
|
188
|
+
@zone_id = usacloud_config["Zone"]
|
189
|
+
end
|
190
|
+
@zone_id = ENV['SAKURACLOUD_ZONE'] if @zone_id.nil?
|
124
191
|
@zone_id = "is1b" if @zone_id.nil?
|
125
192
|
end
|
126
193
|
|
@@ -146,8 +213,57 @@ module VagrantPlugins
|
|
146
213
|
errors << I18n.t("vagrant_sakura.config.need_ssh_key_config")
|
147
214
|
end
|
148
215
|
|
216
|
+
if not VagrantPlugins::Sakura::OSType::os_types.include? @os_type
|
217
|
+
errors << I18n.t("vagrant_sakura.config.need_valid_os_type")
|
218
|
+
end
|
219
|
+
|
149
220
|
{ "Sakura Provider" => errors }
|
150
221
|
end
|
222
|
+
|
223
|
+
def choose_usacloud_profile_dir
|
224
|
+
profile_path = ENV.fetch("USACLOUD_PROFILE_DIR", "")
|
225
|
+
if profile_path.empty?
|
226
|
+
File.expand_path("~/.usacloud")
|
227
|
+
else
|
228
|
+
File.join(File.expand_path(profile_path), ".usacloud")
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def get_usacloud_profile_name
|
233
|
+
profile_dir = choose_usacloud_profile_dir
|
234
|
+
current_file = File.join(profile_dir, "current")
|
235
|
+
|
236
|
+
return "default" unless FileTest.exist? current_file
|
237
|
+
File.open(current_file) do |file|
|
238
|
+
file.read.split("\n").each do |line|
|
239
|
+
return line
|
240
|
+
end
|
241
|
+
end
|
242
|
+
"default"
|
243
|
+
end
|
244
|
+
|
245
|
+
def get_usacloud_config(config_path = nil)
|
246
|
+
if config_path.nil? || config_path == UNSET_VALUE
|
247
|
+
profile_dir = choose_usacloud_profile_dir
|
248
|
+
profile_name = get_usacloud_profile_name
|
249
|
+
|
250
|
+
return nil if profile_name.empty?
|
251
|
+
config_path = File.join(profile_dir, profile_name, "config.json")
|
252
|
+
end
|
253
|
+
|
254
|
+
if FileTest.exist?(config_path)
|
255
|
+
File.open(config_path) do |file|
|
256
|
+
begin
|
257
|
+
json = JSON.load(file)
|
258
|
+
return json
|
259
|
+
rescue JSON::ParserError
|
260
|
+
return nil
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
nil
|
266
|
+
end
|
151
267
|
end
|
152
268
|
end
|
153
269
|
end
|
@@ -30,8 +30,9 @@ module VagrantPlugins
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def get(resource, data = nil)
|
33
|
-
|
34
|
-
|
33
|
+
uri = URI.parse(@prefix + resource)
|
34
|
+
uri.query = data.to_json if data
|
35
|
+
request = Net::HTTP::Get.new uri.to_s
|
35
36
|
do_request request
|
36
37
|
end
|
37
38
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Sakura
|
3
|
+
module OSType
|
4
|
+
OS_TYPE_QUERIES = {
|
5
|
+
"centos" => {
|
6
|
+
"Tags.Name" => [%w(current-stable distro-centos)]
|
7
|
+
},
|
8
|
+
"centos6" => {
|
9
|
+
"Tags.Name" => [%w(distro-centos distro-ver-6.10)]
|
10
|
+
},
|
11
|
+
"ubuntu" => {
|
12
|
+
"Tags.Name" => [%w(current-stable distro-ubuntu)]
|
13
|
+
},
|
14
|
+
"debian" => {
|
15
|
+
"Tags.Name" => [%w(current-stable distro-debian)]
|
16
|
+
},
|
17
|
+
"coreos" => {
|
18
|
+
"Tags.Name" => [%w(current-stable distro-coreos)]
|
19
|
+
},
|
20
|
+
"rancheros" => {
|
21
|
+
"Tags.Name" => [%w(current-stable distro-rancheros)]
|
22
|
+
},
|
23
|
+
"freebsd" => {
|
24
|
+
"Tags.Name" => [%w(current-stable distro-freebsd)]
|
25
|
+
},
|
26
|
+
}
|
27
|
+
|
28
|
+
def self.os_types
|
29
|
+
OS_TYPE_QUERIES.keys
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -23,9 +23,14 @@ module VagrantPlugins
|
|
23
23
|
Provider
|
24
24
|
end
|
25
25
|
|
26
|
+
command(:'sakura-reinstall') do
|
27
|
+
require_relative "command_reinstall"
|
28
|
+
CommandReinstall
|
29
|
+
end
|
30
|
+
|
26
31
|
command(:'sakura-list-id') do
|
27
|
-
require_relative "
|
28
|
-
|
32
|
+
require_relative "command_list_id"
|
33
|
+
CommandListId
|
29
34
|
end
|
30
35
|
|
31
36
|
def self.setup_i18n
|
data/locales/en.yml
CHANGED
@@ -8,6 +8,8 @@ en:
|
|
8
8
|
Warning! You are using insecure default key to login to the server on
|
9
9
|
Sakura-no-cloud. The key is publicly available (bundled in Vagrant
|
10
10
|
distribution) so malicious people can login to your server.
|
11
|
+
reinstalling_disk: |-
|
12
|
+
Re-installing a disk with the following settings...
|
11
13
|
down: |-
|
12
14
|
The server is down.
|
13
15
|
not_created: |-
|
@@ -48,3 +50,5 @@ en:
|
|
48
50
|
An access token secret is required via "access_token_secret"
|
49
51
|
need_ssh_key_config: |-
|
50
52
|
You must set one of "sshkey_id", "pubic_key_path", or "use_insecure_key".
|
53
|
+
need_valid_os_type: |-
|
54
|
+
You must set valid os_type value.
|
data/test/test_config.rb
CHANGED
@@ -4,14 +4,7 @@ require "vagrant-sakura/config"
|
|
4
4
|
module VagrantPlugins
|
5
5
|
module Sakura
|
6
6
|
class TestConfig < Test::Unit::TestCase
|
7
|
-
|
8
|
-
def setup
|
9
|
-
%w("SAKURACLOUD_ACCESS_TOKEN" "SAKURACLOUD_ACCESS_TOKEN_SECRET" "SAKURACLOUD_ZONE").map do |k|
|
10
|
-
ENV.delete(k)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_apikeys
|
7
|
+
def test_load_config
|
15
8
|
cases = {
|
16
9
|
"config only" => {
|
17
10
|
"config" => {
|
@@ -65,6 +58,30 @@ module VagrantPlugins
|
|
65
58
|
"zone" => "tk1a"
|
66
59
|
}
|
67
60
|
},
|
61
|
+
"profile only" => {
|
62
|
+
"config" => {},
|
63
|
+
"env" => {},
|
64
|
+
"profile" => '{"AccessToken": "foo", "AccessTokenSecret": "bar", "Zone": "tk1a"}',
|
65
|
+
"expects" => {
|
66
|
+
"token" => "foo",
|
67
|
+
"secret" => "bar",
|
68
|
+
"zone" => "tk1a"
|
69
|
+
}
|
70
|
+
},
|
71
|
+
"conf and profile order" => {
|
72
|
+
"config" => {
|
73
|
+
"access_token" => "foo",
|
74
|
+
"access_token_secret" => "bar",
|
75
|
+
"zone_id" => "tk1a"
|
76
|
+
},
|
77
|
+
"env" => {},
|
78
|
+
"profile" => '{"AccessToken": "not_use", "AccessTokenSecret": "not_use", "Zone": "not_use"}',
|
79
|
+
"expects" => {
|
80
|
+
"token" => "foo",
|
81
|
+
"secret" => "bar",
|
82
|
+
"zone" => "tk1a"
|
83
|
+
}
|
84
|
+
},
|
68
85
|
"conf and env order" => {
|
69
86
|
"config" => {
|
70
87
|
"access_token" => "foo",
|
@@ -83,22 +100,171 @@ module VagrantPlugins
|
|
83
100
|
"secret" => "bar",
|
84
101
|
"zone" => "tk1a"
|
85
102
|
}
|
103
|
+
},
|
104
|
+
"profile and env order" => {
|
105
|
+
"config" => {},
|
106
|
+
"env" => {
|
107
|
+
"SAKURA_ACCESS_TOKEN" => "not_use",
|
108
|
+
"SAKURA_ACCESS_TOKEN_SECRET" => "not_use",
|
109
|
+
"SAKURACLOUD_ACCESS_TOKEN" => "not_use",
|
110
|
+
"SAKURACLOUD_ACCESS_TOKEN_SECRET" => "not_use",
|
111
|
+
"SAKURACLOUD_ZONE" => "not_use",
|
112
|
+
},
|
113
|
+
"profile" => '{"AccessToken": "foo", "AccessTokenSecret": "bar", "Zone": "tk1a"}',
|
114
|
+
"expects" => {
|
115
|
+
"token" => "foo",
|
116
|
+
"secret" => "bar",
|
117
|
+
"zone" => "tk1a"
|
118
|
+
}
|
86
119
|
}
|
87
120
|
}
|
88
121
|
|
89
|
-
|
90
|
-
|
122
|
+
|
123
|
+
cases.map do |name, c|
|
124
|
+
Dir.mktmpdir do |dir|
|
125
|
+
env = { "USACLOUD_PROFILE_DIR" => dir }
|
126
|
+
ENV.update env
|
127
|
+
|
128
|
+
%w(SAKURA_ACCESS_TOKEN SAKURACLOUD_ACCESS_TOKEN SAKURA_ACCESS_TOKEN_SECRET SAKURACLOUD_ACCESS_TOKEN_SECRET SAKURACLOUD_ZONE).map do |k|
|
129
|
+
ENV.delete(k)
|
130
|
+
end
|
131
|
+
|
132
|
+
if !c["profile"].nil?
|
133
|
+
current_file = File.join(dir, ".usacloud", "current")
|
134
|
+
FileUtils.mkdir_p(File.dirname(current_file))
|
135
|
+
File.open(current_file, "w") do |file|
|
136
|
+
file.puts "default"
|
137
|
+
end
|
138
|
+
|
139
|
+
profile_file = File.join(dir, ".usacloud", "default", "config.json")
|
140
|
+
FileUtils.mkdir_p(File.dirname(profile_file))
|
141
|
+
File.open(profile_file, "w") do |file|
|
142
|
+
file.puts c["profile"]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
conf = Config.new
|
147
|
+
conf.set_options c["config"]
|
148
|
+
|
149
|
+
ENV.update c["env"]
|
150
|
+
|
151
|
+
conf.finalize!
|
152
|
+
|
153
|
+
assert_equal c["expects"]["token"], conf.access_token
|
154
|
+
assert_equal c["expects"]["secret"], conf.access_token_secret
|
155
|
+
assert_equal c["expects"]["zone"], conf.zone_id
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_startup_scripts_handling
|
162
|
+
cases = {
|
163
|
+
"startup_scripts is empty" => {
|
164
|
+
"config" => {},
|
165
|
+
"expects" => {
|
166
|
+
"startup_scripts" => []
|
167
|
+
}
|
168
|
+
},
|
169
|
+
|
170
|
+
"startup_scripts is a number" => {
|
171
|
+
"config" => {
|
172
|
+
"startup_scripts" => 999999999999
|
173
|
+
},
|
174
|
+
"expects" => {
|
175
|
+
"startup_scripts" => [{"ID" => "999999999999"}]
|
176
|
+
}
|
177
|
+
},
|
178
|
+
|
179
|
+
"startup_scripts is array" => {
|
180
|
+
"config" => {
|
181
|
+
"startup_scripts" => [999999999999,888888888888]
|
182
|
+
},
|
183
|
+
"expects" => {
|
184
|
+
"startup_scripts" => [{"ID" => "999999999999"}, {"ID" => "888888888888"}]
|
185
|
+
}
|
186
|
+
},
|
187
|
+
}
|
188
|
+
|
189
|
+
cases.map do |name, c|
|
91
190
|
conf = Config.new
|
92
191
|
conf.set_options c["config"]
|
192
|
+
conf.finalize!
|
193
|
+
|
194
|
+
assert_equal c["expects"]["startup_scripts"], conf.startup_scripts
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
def test_disk_source_mode
|
200
|
+
cases = {
|
201
|
+
"mode is :disk" => {
|
202
|
+
"config" => {
|
203
|
+
"disk_id" => 999999999999
|
204
|
+
},
|
205
|
+
"expect" => :disk
|
206
|
+
},
|
207
|
+
|
208
|
+
"mode is :archive" => {
|
209
|
+
"config" => {
|
210
|
+
"disk_source_archive" => 999999999999
|
211
|
+
},
|
212
|
+
"expect" => :archive
|
213
|
+
},
|
214
|
+
|
215
|
+
"mode is :os_type" => {
|
216
|
+
"config" => {
|
217
|
+
"os_type" => "centos"
|
218
|
+
},
|
219
|
+
"expect" => :os_type
|
220
|
+
},
|
93
221
|
|
94
|
-
|
222
|
+
"mode is :os_type with defaults" => {
|
223
|
+
"config" => {},
|
224
|
+
"expect" => :os_type
|
225
|
+
},
|
226
|
+
}
|
95
227
|
|
228
|
+
cases.map do |name, c|
|
229
|
+
conf = Config.new
|
230
|
+
conf.set_options c["config"]
|
96
231
|
conf.finalize!
|
97
|
-
|
98
|
-
assert_equal c["
|
99
|
-
|
232
|
+
|
233
|
+
assert_equal c["expect"], conf.disk_source_mode
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def test_os_type
|
238
|
+
cases = {
|
239
|
+
"os_type is valid" => {
|
240
|
+
"config" => {
|
241
|
+
"use_insecure_key" => true,
|
242
|
+
"os_type" => "ubuntu"
|
243
|
+
},
|
244
|
+
"expect" => true
|
245
|
+
},
|
246
|
+
|
247
|
+
"os_type is invalid" => {
|
248
|
+
"config" => {
|
249
|
+
"use_insecure_key" => true,
|
250
|
+
"os_type" => "invalid",
|
251
|
+
},
|
252
|
+
"expect" => false
|
253
|
+
},
|
100
254
|
}
|
255
|
+
|
256
|
+
cases.map do |name, c|
|
257
|
+
conf = Config.new
|
258
|
+
conf.set_options c["config"]
|
259
|
+
conf.finalize!
|
260
|
+
|
261
|
+
res = conf.validate(nil)
|
262
|
+
|
263
|
+
assert_equal c["expect"], res["Sakura Provider"].empty?
|
264
|
+
end
|
101
265
|
end
|
266
|
+
|
267
|
+
|
102
268
|
end
|
103
269
|
end
|
104
270
|
end
|