vagrant-sakura 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -1
- data/README.md +15 -3
- data/lib/vagrant-sakura/action/connect_sakura.rb +3 -4
- data/lib/vagrant-sakura/action/list_id.rb +38 -0
- data/lib/vagrant-sakura/action/run_instance.rb +0 -2
- data/lib/vagrant-sakura/action.rb +9 -0
- data/lib/vagrant-sakura/command.rb +2 -2
- data/lib/vagrant-sakura/config.rb +7 -2
- data/lib/vagrant-sakura/driver/api.rb +10 -6
- data/lib/vagrant-sakura/plugin.rb +4 -4
- data/lib/vagrant-sakura/version.rb +1 -1
- data/vagrant-sakura.gemspec +23 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa036bfb2f34ad5a5927efc3a83b28322ddd64b3
|
4
|
+
data.tar.gz: e40636b2131472717a7a84fa2e588a120354160c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfe40bc2ccd583e3806d1e98d12e04904f0997c0a921a9a32e37fa599dbdc4099a216d24b334071a4508c5e3d7889108e853370dd7b7854be72713f8f67294c5
|
7
|
+
data.tar.gz: 9271eaaafdbc25c4b60587985f43d709498048de14c20b80f0820054d12434ae919c79cef9b5f6ebab700290c5a73b57d03afcfd3ff1fb03bc6485435bb073b7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,23 +44,35 @@ $ vagrant box add dummy https://github.com/tsahara/vagrant-sakura/raw/master/dum
|
|
44
44
|
Vagrant.configure("2") do |config|
|
45
45
|
config.vm.box = "dummy"
|
46
46
|
config.ssh.username = "ubuntu"
|
47
|
+
config.ssh.private_key_path = File.expand_path "~/.ssh/id_rsa"
|
47
48
|
|
48
49
|
config.vm.provider :sakura do |sakura|
|
49
50
|
sakura.access_token = 'YOUR ACCESS TOKEN'
|
50
51
|
sakura.access_token_secret = 'YOUR ACCESS TOKEN SECRET'
|
51
|
-
|
52
|
-
#sakura.disk_source_archive = 112500182464
|
52
|
+
sakura.sshkey_id = 'YOUR PUBLIC KEY ID'
|
53
53
|
end
|
54
54
|
end
|
55
55
|
```
|
56
56
|
|
57
57
|
そして ``vagrant up --provider=sakrua`` を実行してください。
|
58
58
|
|
59
|
+
サーバのディスクソースを ``sakura.disk_source_archive`` で指定しなかった
|
60
|
+
場合のデフォルトは ``112500182464`` で Ubuntu 12.04.2LTS-server 64bit です。
|
61
|
+
このディスクソースのログインアカウントは ``root`` ではないため、
|
62
|
+
``config.ssh.username`` で指定してやる必要があります。
|
63
|
+
|
59
64
|
なお、さくらのクラウド API を利用するための API キー(ACCESS TOKEN)と
|
60
65
|
シークレットトークン(ACCESS TOKEN SECRET)は環境変数
|
61
66
|
``SAKURA_ACCESS_TOKEN`` と ``SAKURA_ACCESS_TOKEN_SECRET``で指定することも
|
62
67
|
できます。
|
63
68
|
|
69
|
+
## コマンド
|
70
|
+
`sakura-list-id` コマンドを使って、`Vagrantfile` で指定するリソース ID
|
71
|
+
を調べることができます。
|
72
|
+
```
|
73
|
+
$ vagrant sakuara-list-id
|
74
|
+
...
|
75
|
+
```
|
64
76
|
|
65
77
|
## 設定
|
66
78
|
|
@@ -73,7 +85,7 @@ end
|
|
73
85
|
- ``server_name`` - サーバ名
|
74
86
|
- ``server_plan`` - 作成するサーバのプラン ID
|
75
87
|
- ``sshkey_id`` - サーバへのログインに利用する SSH 公開鍵のリソース ID
|
76
|
-
- ``zone_id`` -
|
88
|
+
- ``zone_id`` - ゾーン ID (石狩第1=`is1a`, 石狩第2=`is1b`)
|
77
89
|
|
78
90
|
## ネットワーク
|
79
91
|
``vagrant-sakura`` は ``config.vm.network`` を利用したネットワークの構築を
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require "log4r"
|
2
1
|
require 'vagrant-sakura/driver/api'
|
3
2
|
|
4
3
|
module VagrantPlugins
|
@@ -6,14 +5,14 @@ module VagrantPlugins
|
|
6
5
|
module Action
|
7
6
|
class ConnectSakura
|
8
7
|
def initialize(app, env)
|
9
|
-
@app
|
10
|
-
@logger = Log4r::Logger.new("vagrant_sakura::action::connect_sakura")
|
8
|
+
@app = app
|
11
9
|
end
|
12
10
|
|
13
11
|
def call(env)
|
14
12
|
token = env[:machine].provider_config.access_token
|
15
13
|
secret = env[:machine].provider_config.access_token_secret
|
16
|
-
env[:
|
14
|
+
zone = env[:machine].provider_config.zone_id
|
15
|
+
env[:sakura_api] = Driver::API.new(token, secret, zone)
|
17
16
|
|
18
17
|
@app.call(env)
|
19
18
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Sakura
|
3
|
+
module Action
|
4
|
+
class ListId
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
api = env[:sakura_api]
|
11
|
+
|
12
|
+
puts "Zone: %s" % env[:machine].provider_config.zone_id
|
13
|
+
puts ""
|
14
|
+
|
15
|
+
puts "---- Archives ----"
|
16
|
+
puts "%-14s %s" % ["ID", "Name"]
|
17
|
+
r = api.get("/archive")
|
18
|
+
r["Archives"].sort { |a, b|
|
19
|
+
a["DisplayOrder"] <=> b["DisplayOrder"]
|
20
|
+
}.each { |archive|
|
21
|
+
puts "%-14u %s" % [archive["ID"], archive["Name"]]
|
22
|
+
}
|
23
|
+
puts ""
|
24
|
+
|
25
|
+
puts "---- Server Plans ----"
|
26
|
+
puts "%-7s %-70s" % ["ID", "Name"]
|
27
|
+
r = api.get("/product/server")
|
28
|
+
r["ServerPlans"].each { |plan|
|
29
|
+
puts "%-7u %s" % [plan["ID"], plan["Name"]]
|
30
|
+
}
|
31
|
+
puts ""
|
32
|
+
|
33
|
+
@app.call(env)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -33,7 +33,6 @@ module VagrantPlugins
|
|
33
33
|
data = {
|
34
34
|
"Disk" => {
|
35
35
|
"Name" => server_name,
|
36
|
-
"Zone" => { "ID" => 31001 }, # Ishikari only
|
37
36
|
"Plan" => { "ID" => disk_plan },
|
38
37
|
"Connection" => "virtio",
|
39
38
|
"SourceArchive" => {
|
@@ -68,7 +67,6 @@ module VagrantPlugins
|
|
68
67
|
data = {
|
69
68
|
"Server" => {
|
70
69
|
"Name" => server_name,
|
71
|
-
"Zone" => { "ID" => 31001 }, # Ishikari
|
72
70
|
"ServerPlan" => { "ID" => server_plan },
|
73
71
|
"ConnectedSwitches" => [
|
74
72
|
{ "Scope" => "shared", "BandWidthMbps" => 100 }
|
@@ -35,6 +35,14 @@ module VagrantPlugins
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.action_list_id
|
39
|
+
Vagrant::Action::Builder.new.tap do |b|
|
40
|
+
b.use ConfigValidate
|
41
|
+
b.use ConnectSakura
|
42
|
+
b.use ListId
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
38
46
|
# def self.action_provision
|
39
47
|
# Vagrant::Action::Builder.new.tap do |b|
|
40
48
|
# b.use ConfigValidate
|
@@ -143,6 +151,7 @@ module VagrantPlugins
|
|
143
151
|
autoload :DeleteServer, action_root.join("delete_server")
|
144
152
|
autoload :IsCreated, action_root.join("is_created")
|
145
153
|
autoload :Halt, action_root.join("halt")
|
154
|
+
autoload :ListId, action_root.join("list_id")
|
146
155
|
autoload :MessageAlreadyCreated, action_root.join("message_already_created")
|
147
156
|
autoload :MessageDown, action_root.join("message_down")
|
148
157
|
autoload :MessageNotCreated, action_root.join("message_not_created")
|
@@ -38,8 +38,8 @@ module VagrantPlugins
|
|
38
38
|
# @return [String]
|
39
39
|
attr_accessor :sshkey_id
|
40
40
|
|
41
|
-
#
|
42
|
-
|
41
|
+
# The ID of the zone.
|
42
|
+
attr_accessor :zone_id
|
43
43
|
|
44
44
|
def initialize
|
45
45
|
@access_token = UNSET_VALUE
|
@@ -49,6 +49,7 @@ module VagrantPlugins
|
|
49
49
|
@server_name = UNSET_VALUE
|
50
50
|
@server_plan = UNSET_VALUE
|
51
51
|
@sshkey_id = UNSET_VALUE
|
52
|
+
@zone_id = UNSET_VALUE
|
52
53
|
end
|
53
54
|
|
54
55
|
def finalize!
|
@@ -79,6 +80,10 @@ module VagrantPlugins
|
|
79
80
|
if @sshkey_id == UNSET_VALUE
|
80
81
|
@sshkey_id = nil
|
81
82
|
end
|
83
|
+
|
84
|
+
if @zone_id == UNSET_VALUE
|
85
|
+
@zone_id = "is1a" # the first zone
|
86
|
+
end
|
82
87
|
end
|
83
88
|
|
84
89
|
def validate(machine)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'log4r'
|
1
2
|
require 'net/https'
|
2
3
|
require 'json'
|
3
4
|
|
@@ -5,15 +6,15 @@ module VagrantPlugins
|
|
5
6
|
module Sakura
|
6
7
|
module Driver
|
7
8
|
APIHOST = "secure.sakura.ad.jp"
|
8
|
-
APIPREFIX = "/cloud/api/cloud/1.0"
|
9
9
|
CERTFILE = File.expand_path("../cert.pem", __FILE__)
|
10
10
|
|
11
11
|
class API
|
12
|
-
def initialize(access_token, access_token_secret)
|
12
|
+
def initialize(access_token, access_token_secret, zone_id)
|
13
13
|
@logger = Log4r::Logger.new("vagrant::provider::sakura")
|
14
14
|
|
15
15
|
@access_token = access_token
|
16
16
|
@access_token_secret = access_token_secret
|
17
|
+
@prefix = "/cloud/zone/#{zone_id}/api/cloud/1.1"
|
17
18
|
|
18
19
|
@https = Net::HTTP.new(APIHOST, 443)
|
19
20
|
@https.use_ssl = true
|
@@ -23,25 +24,25 @@ module VagrantPlugins
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def delete(resource, data = nil)
|
26
|
-
request = Net::HTTP::Delete.new(
|
27
|
+
request = Net::HTTP::Delete.new(@prefix + resource)
|
27
28
|
request.body = data.to_json if data
|
28
29
|
do_request request
|
29
30
|
end
|
30
31
|
|
31
32
|
def get(resource, data = nil)
|
32
|
-
request = Net::HTTP::Get.new(
|
33
|
+
request = Net::HTTP::Get.new(@prefix + resource)
|
33
34
|
request.body = data.to_json if data
|
34
35
|
do_request request
|
35
36
|
end
|
36
37
|
|
37
38
|
def post(resource, data)
|
38
|
-
request = Net::HTTP::Post.new(
|
39
|
+
request = Net::HTTP::Post.new(@prefix + resource)
|
39
40
|
request.body = data.to_json
|
40
41
|
do_request request
|
41
42
|
end
|
42
43
|
|
43
44
|
def put(resource, data = nil)
|
44
|
-
request = Net::HTTP::Put.new(
|
45
|
+
request = Net::HTTP::Put.new(@prefix + resource)
|
45
46
|
request.body = if data then data.to_json else '' end
|
46
47
|
do_request request
|
47
48
|
end
|
@@ -56,6 +57,8 @@ module VagrantPlugins
|
|
56
57
|
case response.code
|
57
58
|
when /2../
|
58
59
|
# Success
|
60
|
+
when "400"
|
61
|
+
raise BadRequestError, emsg
|
59
62
|
when "404"
|
60
63
|
raise NotFoundError, emsg
|
61
64
|
when "409"
|
@@ -69,6 +72,7 @@ module VagrantPlugins
|
|
69
72
|
private :do_request
|
70
73
|
end
|
71
74
|
|
75
|
+
class BadRequestError < RuntimeError; end
|
72
76
|
class ConflictError < RuntimeError; end
|
73
77
|
class GenericError < RuntimeError; end
|
74
78
|
class NotFoundError < RuntimeError; end
|
@@ -23,10 +23,10 @@ module VagrantPlugins
|
|
23
23
|
Provider
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
command(:'sakura-list-id') do
|
27
|
+
require_relative "command"
|
28
|
+
Command
|
29
|
+
end
|
30
30
|
|
31
31
|
def self.setup_i18n
|
32
32
|
I18n.load_path << File.expand_path("locales/en.yml", Sakura.source_root)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vagrant-sakura/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vagrant-sakura"
|
8
|
+
spec.version = VagrantPlugins::Sakura::VERSION
|
9
|
+
spec.authors = ["Tomoyuki Sahara"]
|
10
|
+
spec.email = ["sahara@surt.net"]
|
11
|
+
spec.description = %q{Enables Vagrant to manage machines in Sakura Cloud.}
|
12
|
+
spec.summary = %q{Enables Vagrant to manage machines in Sakura Cloud.}
|
13
|
+
spec.homepage = ""
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vagrant-sakura
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomoyuki Sahara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ files:
|
|
60
60
|
- lib/vagrant-sakura/action/delete_server.rb
|
61
61
|
- lib/vagrant-sakura/action/halt.rb
|
62
62
|
- lib/vagrant-sakura/action/is_created.rb
|
63
|
+
- lib/vagrant-sakura/action/list_id.rb
|
63
64
|
- lib/vagrant-sakura/action/message_already_created.rb
|
64
65
|
- lib/vagrant-sakura/action/message_down.rb
|
65
66
|
- lib/vagrant-sakura/action/message_not_created.rb
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- lib/vagrant-sakura/provider.rb
|
79
80
|
- lib/vagrant-sakura/version.rb
|
80
81
|
- locales/en.yml
|
82
|
+
- vagrant-sakura.gemspec
|
81
83
|
homepage: ''
|
82
84
|
licenses:
|
83
85
|
- MIT
|