kitchen-driver-sakuracloud 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7440329492e8b816e0fe14030e49a7e509377c28
4
+ data.tar.gz: c560c6f244a0c649da679682dc71f9dba9e58f30
5
+ SHA512:
6
+ metadata.gz: 55101b8987d6d0c3d2e5d8182bc783d6430f897982966af113dbd5391b78befa01f477ba71a9180792a9381b6e1dafd89a320fb1175710541aa59cca98d5e106
7
+ data.tar.gz: fa68b6660583965ae1575661c68fdcc32e73e0462744729e6c56d164f325244968ec8f1764bdb42d225ce2b5ddbbdd876c20f284f0e76c99fcf3afc3e03176f7
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Kitchen::Driver::Sakuracloud
2
+
3
+
4
+
5
+ ```
6
+ ---
7
+ driver:
8
+ name: sakuracloud
9
+ api_token: API_TOKEN (or from env => SAKURACLOUD_API_TOKEN )
10
+ api_token_secret: API_TOKEN_SECRET (or from env => SAKURACLOUD_API_TOKEN_SECRET )
11
+ sshkey_id: 11260xxxx (or from env => SAKURACLOUD_SSH_KEYID )
12
+ serverplan: 1001
13
+ diskplan: 4
14
+ size_mb: 20480
15
+
16
+ transport:
17
+ username: root
18
+ ssh_key: ~/.ssh/path_to_keyfile
19
+
20
+ provisioner:
21
+ name: shell
22
+
23
+ verifier:
24
+ name: shell
25
+
26
+ platforms:
27
+ - name: ubuntu-14.04
28
+ driver:
29
+ sourcearchive: 112700955889
30
+ transport:
31
+ username: ubuntu
32
+
33
+ suites:
34
+ - name: default
35
+ run_list:
36
+ attributes:
37
+ ```
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kitchen/driver/sakuracloud_version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kitchen-driver-sakuracloud"
8
+ spec.version = Kitchen::Driver::SAKURACLOUD_VERSION
9
+ spec.authors = ["sawanoboly"]
10
+ spec.email = ["sawanoboriyu@higanworks.com"]
11
+
12
+ spec.summary = %q{Sakura no Cloud Driver for Test-Kitchen}
13
+ spec.description = %q{Sakura no Cloud Driver for Test-Kitchen}
14
+ spec.homepage = ""
15
+ spec.license = 'Apache 2.0'
16
+
17
+ spec.files = Dir['README.md','CHANGELOG.md','kitchen-driver-sakuracloud.gemspec','lib/**/*']
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "test-kitchen"
23
+ spec.add_dependency "fog-sakuracloud"
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,91 @@
1
+ require 'kitchen/driver/sakuracloud_version'
2
+ require 'kitchen'
3
+ require 'fog/sakuracloud'
4
+
5
+ module Kitchen
6
+ module Driver
7
+ class Sakuracloud < Kitchen::Driver::Base
8
+ kitchen_driver_api_version 2
9
+
10
+ plugin_version Kitchen::Driver::SAKURACLOUD_VERSION
11
+
12
+ default_config :api_token do
13
+ ENV['SAKURACLOUD_API_TOKEN']
14
+ end
15
+
16
+ default_config :api_token_secret do
17
+ ENV['SAKURACLOUD_API_TOKEN_SECRET']
18
+ end
19
+
20
+ default_config :serverplan, '1001' # 1 Core 1 GB
21
+ default_config :sourcearchive , "112700955889" #ubuntu14.04
22
+ default_config :sshkey_id do
23
+ ENV['SAKURACLOUD_SSH_KEYID']
24
+ end
25
+ default_config :diskplan , 4 # ssd
26
+ default_config :size_mb , 20480 # 20GB
27
+
28
+ def create(state)
29
+ server = create_server
30
+ state[:id] = server.id
31
+ state[:hostname] = server.interfaces.first["IPAddress"]
32
+ end
33
+
34
+ def destroy(state)
35
+ destroy_server(state[:id]) if state[:id]
36
+ end
37
+
38
+ def create_server
39
+ raise Kitchen::ActionFailed "" unless config[:sshkey_id]
40
+ begin
41
+ server = compute.servers.create(
42
+ :name => instance.name,
43
+ :sshkey => config[:sshkey_id],
44
+ :serverplan => config[:serverplan],
45
+ :volume => {
46
+ :diskplan => config[:diskplan],
47
+ :size_mb => config[:size_mb],
48
+ :sourcearchive => config[:sourcearchive]
49
+ },
50
+ :boot => true
51
+ )
52
+ rescue Excon::Errors::HTTPStatusError => e
53
+ logger.error JSON.parse(e.response.body)
54
+ raise e
55
+ end
56
+ server
57
+ end
58
+
59
+ def destroy_server(id)
60
+ logger.debug "Trying to delete #{id} ..."
61
+ begin
62
+ server = compute.servers.get(id)
63
+ server.stop(true)
64
+ server.reload
65
+
66
+ logger.debug("Waiting #{id} until down ... (in 15 sec)")
67
+ 3.times do
68
+ break if server.instance["Status"] == "down"
69
+ sleep 5
70
+ server.reload
71
+ end
72
+
73
+ server.delete(true)
74
+ rescue Excon::Errors::HTTPStatusError => e
75
+ logger.error JSON.parse(e.response.body)
76
+ raise e unless e.response.status == 404
77
+ end
78
+ end
79
+
80
+ private
81
+ def compute
82
+ return @compute if @compute
83
+ @compute = Fog::Compute::SakuraCloud.new(
84
+ sakuracloud_api_token: config[:api_token],
85
+ sakuracloud_api_token_secret: config[:api_token_secret]
86
+ )
87
+ @compute
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ module Kitchen
2
+ module Driver
3
+ SAKURACLOUD_VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kitchen-driver-sakuracloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - sawanoboly
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-kitchen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fog-sakuracloud
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Sakura no Cloud Driver for Test-Kitchen
84
+ email:
85
+ - sawanoboriyu@higanworks.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - README.md
91
+ - kitchen-driver-sakuracloud.gemspec
92
+ - lib/kitchen/driver/sakuracloud.rb
93
+ - lib/kitchen/driver/sakuracloud_version.rb
94
+ homepage: ''
95
+ licenses:
96
+ - Apache 2.0
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Sakura no Cloud Driver for Test-Kitchen
118
+ test_files: []