knife-zcloudjp 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MGNiZjA0ODE1NjAwMzI1Y2NkYmQ0NGFjZGRjNmYzNDkyYWEwYjFjYw==
5
- data.tar.gz: !binary |-
6
- MzVjZjJmNDhjNTE0NGIzMWY5YWQzM2M5OWE4ZTcxMzY3NjNlYzdjZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- ZDhhOTRhM2QyMjVhOTg3YjQ5ZGJiNzg4ODYxZGVhMmE2OWJkOGFhZDhhMTIx
10
- NzQ1NWZjZTVhYWYyYjMxZWYwNTA3ODg4Mzk1MDU4OTVhZTRjNjU5ZTU0NzVi
11
- MWJkYTkwMzhlZDQ4N2U5N2I3NTcwYzNmMDQzOWQzM2JjOTdmMzQ=
12
- data.tar.gz: !binary |-
13
- ZGM3MjYyYmY1ODFjMTMzNDQyOGI2MWJlZDVlNGJkYjc0MzZlZTRiYzBhYzEz
14
- M2U0YTg1MzUxZmQxMzY1NmYzZTUxZTI5YzRlMmJlNjMwOGUwYWU4NGYwNzk1
15
- Y2YwMGNiNzI0OWNiMjA5M2NiYThhY2VkY2ExY2MzYTQ4ZWQyOWE=
2
+ SHA1:
3
+ metadata.gz: e2906cbd29a2d2f0105328a6f82ee1cc46eb9b89
4
+ data.tar.gz: 9620762297555596cdc0d7c810a00e299cbf66ef
5
+ SHA512:
6
+ metadata.gz: 2ed63d8c94cdf6bed38bc9777ce1de81487b3ca5ce96405afe67dd7b3893e3d7ad262d0f95b18d43b45638883a65fb6ccf253edfb7ea418f01b615ac1b639785
7
+ data.tar.gz: 5ed24dc07fccac8ba324f2b24d039fe1540e740a275d5f4ae0ea862a7b2ff75af490121a9f877650530772e6cbc783d06a9474375831e37d470255b10a484781
data/.gitignore CHANGED
@@ -16,5 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .chef/
19
- *.swp
19
+ *.sw[a-z]
20
+ .rvmrc
20
21
  vendor/
@@ -1,7 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.2
4
3
  - 1.9.3
5
- - ree
6
- # - jruby-19mode
7
- - rbx-19mode
4
+ - 2.0.0
5
+ - 2.1.0
@@ -1,6 +1,12 @@
1
1
  ChangeLog for knife-zcloudjp
2
2
  ====
3
3
 
4
+ ## v0.2.0
5
+
6
+ * Renewal depend gems
7
+ * use 'zcloudjp' Gem for API Call. HT: @azukiwasher
8
+
9
+
4
10
  ## v0.1.7
5
11
 
6
12
  * Bugfix: cant retreve own version
data/README.md CHANGED
@@ -4,6 +4,13 @@
4
4
 
5
5
  A Knife(Opscode Chef) plugin for [Z Cloud](http://z-cloud.jp). This plugin allows you to retrieve product catalog, print the current machines and bootstrap a machine.
6
6
 
7
+ ## F.Y.I
8
+
9
+ SmartOS Bootstrap template is here.
10
+
11
+ [higanworks/knife-bootstrap-smartos](https://github.com/higanworks/knife-bootstrap-smartos)
12
+
13
+
7
14
  ## Installation
8
15
 
9
16
  ### from Rubygems
@@ -29,35 +36,70 @@ Add the following entries to your `.chef/knife.rb`.
29
36
 
30
37
  ### Retrieve the product catalog that are currently available.
31
38
 
32
- $ knife zcloudjp product list (options)
33
- name os dataset package
34
- MySQL Small 1 SmartOS sdc:sdc:mysql:1.4.1 Small_1GB
35
- MySQL Large 1 SmartOS sdc:sdc:mysql:1.4.1 Large_8GB
36
- Ubuntu Small 1 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Small_1GB
37
- Ubuntu Large 8 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Large_8GB
38
- CentOS Small 1 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Small_1GB
39
- CentOS Large 8 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Large_8GB
40
- Fedora Small 1 Fedora 14 sdc:sdc:fedora-14:1.0.1 Small_1GB
41
- Fedora Large 8 Fedora 14 sdc:sdc:fedora-14:1.0.1 Large_8GB
42
- Node.js Small 1 SmartOS sdc:sdc:nodejs:1.4.0 Small_1GB
43
- Node.js Large 8 SmartOS sdc:sdc:nodejs:1.4.0 Large_8GB
44
- Percona Small 1 SmartOS sdc:sdc:percona:1.6.0 Small_1GB
45
- Percona Large 8 SmartOS sdc:sdc:percona:1.6.0 Large_8GB
46
- Riak Small 1 SmartOS sdc:sdc:riak:1.6.1 Small_1GB
47
- Riak Large 1 SmartOS sdc:sdc:riak:1.6.1 Large_8GB
48
- SmartOS Small 1 SmartOS sdc:sdc:base64:1.8.4 Small_1GB
49
- SmartOS Large 8 SmartOS sdc:sdc:base64:1.8.4 Large_8GB
50
- CentOS Small 1 CentOS 6.0 sdc:jpc:centos-6:1.3.0 Small_1GB
51
- CentOS Large 8 CentOS 6.0 sdc:jpc:centos-6:1.3.0 Large_8GB
52
- Debian Small 1 Debian 6.0.3 sdc:sdc:debian-6.03:1.0.0 Small_1GB
53
- Debian Large 8 Debian 6.0.3 sdc:sdc:debian-6.03:1.0.0 Large_8GB
54
- SmartOS Plus Small 1 SmartOS sdc:sdc:standard:1.0.7 Small_1GB
55
- SmartOS Plus Large 8 SmartOS sdc:sdc:standard:1.0.7 Large_8GB
56
- Ubuntu Small 1 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.2.1 Small_1GB
57
- Ubuntu Medium 8 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.2.1 Large_8GB
58
- MongoDB Small 1 SmartOS sdc:sdc:mongodb:1.4.0 Small_1GB
59
- MongoDB Large 8 SmartOS sdc:sdc:mongodb:1.4.0 Large_8GB
60
-
39
+ ```
40
+ $ knife zcloudjp product list (options)
41
+ name os dataset package
42
+ MySQL Small 1 SmartOS sdc:sdc:mysql:1.4.1 Small_1GB
43
+ MySQL Medium 2 SmartOS sdc:sdc:mysql:1.4.1 Medium_2GB
44
+ MySQL Medium 4 SmartOS sdc:sdc:mysql:1.4.1 Medium_4GB
45
+ MySQL Large 1 SmartOS sdc:sdc:mysql:1.4.1 Large_8GB
46
+ Fedora Small 1 Fedora 14 sdc:sdc:fedora-14:1.0.1 Small_1GB
47
+ Fedora Medium 2 Fedora 14 sdc:sdc:fedora-14:1.0.1 Medium_2GB
48
+ Fedora Medium 4 Fedora 14 sdc:sdc:fedora-14:1.0.1 Medium_4GB
49
+ Fedora Large 8 Fedora 14 sdc:sdc:fedora-14:1.0.1 Large_8GB
50
+ CentOS Small 1 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Small_1GB
51
+ CentOS Medium 2 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Medium_2GB
52
+ CentOS Medium 4 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Medium_4GB
53
+ CentOS Large 8 CentOS 5.7 sdc:jpc:centos-5.7:1.3.0 Large_8GB
54
+ Ubuntu Small 1 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Small_1GB
55
+ Ubuntu Medium 2 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Medium_2GB
56
+ Ubuntu Medium 4 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Medium_4GB
57
+ Ubuntu Large 8 Ubuntu 10.04 sdc:sdc:ubuntu10.04:0.1.0 Large_8GB
58
+ SmartOS Plus Small 1 SmartOS sdc:sdc:standard:1.0.7 Small_1GB
59
+ SmartOS Plus Medium 2 SmartOS sdc:sdc:standard:1.0.7 Medium_2GB
60
+ SmartOS Plus Medium 4 SmartOS sdc:sdc:standard:1.0.7 Medium_4GB
61
+ SmartOS Plus Large 8 SmartOS sdc:sdc:standard:1.0.7 Large_8GB
62
+ Hadoop Small 1 SmartOS sdc:sdc:hadoop:1.0.0 Small_1GB
63
+ Hadoop Medium 2 SmartOS sdc:sdc:hadoop:1.0.0 Medium_2GB
64
+ Hadoop Medium 4 SmartOS sdc:sdc:hadoop:1.0.0 Medium_4GB
65
+ Hadoop Large 8 SmartOS sdc:sdc:hadoop:1.0.0 Large_8GB
66
+ Chef Server Small 1 SmartOS sdc:sdc:chefserver:1.0.0 Small_1GB
67
+ Chef Server Medium 2 SmartOS sdc:sdc:chefserver:1.0.0 Medium_2GB
68
+ Chef Server Medium 4 SmartOS sdc:sdc:chefserver:1.0.0 Medium_4GB
69
+ Chef Server Large 8 SmartOS sdc:sdc:chefserver:1.0.0 Large_8GB
70
+ Ubuntu Small 1 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.4.1 Small_1GB
71
+ Ubuntu Medium 2 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.4.1 Medium_2GB
72
+ Ubuntu Medium 4 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.4.1 Medium_4GB
73
+ Ubuntu Medium 8 Ubuntu 12.04 sdc:jpc:ubuntu-12.04:2.4.1 Large_8GB
74
+ Debian Small 1 Debian 6.0.7 sdc:sdc:debian-6.0.7:2.4.1 Small_1GB
75
+ Debian Medium 2 Debian 6.0.7 sdc:sdc:debian-6.0.7:2.4.1 Medium_2GB
76
+ Debian Medium 4 Debian 6.0.7 sdc:sdc:debian-6.0.7:2.4.1 Medium_4GB
77
+ Debian Large 8 Debian 6.0.7 sdc:sdc:debian-6.0.7:2.4.1 Large_8GB
78
+ SmartOS Small 1 SmartOS sdc:sdc:base64:13.1.0 Small_1GB
79
+ SmartOS Medium 2 SmartOS sdc:sdc:base64:13.1.0 Medium_2GB
80
+ SmartOS Medium 4 SmartOS sdc:sdc:base64:13.1.0 Medium_4GB
81
+ SmartOS Large 8 SmartOS sdc:sdc:base64:13.1.0 Large_8GB
82
+ MongoDB Small 1 SmartOS sdc:sdc:mongodb:1.4.5 Small_1GB
83
+ MongoDB Medium 2 SmartOS sdc:sdc:mongodb:1.4.5 Medium_2GB
84
+ MongoDB Medium 4 SmartOS sdc:sdc:mongodb:1.4.5 Medium_4GB
85
+ MongoDB Large 8 SmartOS sdc:sdc:mongodb:1.4.5 Large_8GB
86
+ Node.js Small 1 SmartOS sdc:sdc:nodejs:13.1.0 Small_1GB
87
+ Node.js Medium 2 SmartOS sdc:sdc:nodejs:13.1.0 Medium_2GB
88
+ Node.js Medium 4 SmartOS sdc:sdc:nodejs:13.1.0 Medium_4GB
89
+ Node.js Large 8 SmartOS sdc:sdc:nodejs:13.1.0 Large_8GB
90
+ Percona Small 1 SmartOS sdc:sdc:percona:13.1.0 Small_1GB
91
+ Percona Medium 2 SmartOS sdc:sdc:percona:13.1.0 Medium_2GB
92
+ Percona Medium 4 SmartOS sdc:sdc:percona:13.1.0 Medium_4GB
93
+ Percona Large 8 SmartOS sdc:sdc:percona:13.1.0 Large_8GB
94
+ Riak Small 1 SmartOS sdc:sdc:riak:13.1.0 Small_1GB
95
+ Riak Medium 2 SmartOS sdc:sdc:riak:13.1.0 Medium_2GB
96
+ Riak Medium 4 SmartOS sdc:sdc:riak:13.1.0 Medium_4GB
97
+ Riak Large 1 SmartOS sdc:sdc:riak:13.1.0 Large_8GB
98
+ CentOS Small 1 CentOS 6.4 sdc:sdc:centos-6:2.4.1 Small_1GB
99
+ CentOS Medium 2 CentOS 6.4 sdc:sdc:centos-6:2.4.1 Medium_2GB
100
+ CentOS Medium 4 CentOS 6.4 sdc:sdc:centos-6:2.4.1 Medium_4GB
101
+ CentOS Large 8 CentOS 6.4 sdc:sdc:centos-6:2.4.1 Large_8GB
102
+ ```
61
103
 
62
104
 
63
105
  <pre><code>knife zcloudjp product list (options)
data/Rakefile CHANGED
@@ -2,8 +2,8 @@
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
4
  require 'rubygems'
5
+ require "bundler/gem_tasks"
5
6
  require 'rspec/core/rake_task'
6
- require 'yard'
7
7
 
8
8
  desc "Run all specs in spec directory"
9
9
  RSpec::Core::RakeTask.new(:spec) do |t|
@@ -11,8 +11,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
11
11
  t.rspec_opts = %w[--color]
12
12
  end
13
13
 
14
- YARD::Rake::YardocTask.new do |t|
15
- t.files = ['lib/**/*.rb']
16
- end
17
-
18
14
  task :default => [:spec]
@@ -16,10 +16,13 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_dependency "chef", ">= 0.10.10"
19
- s.add_dependency "faraday"
19
+ s.add_dependency "zcloudjp"
20
+ s.add_dependency "formatador"
20
21
 
21
22
  s.add_development_dependency("rspec", [">= 2.2.0"])
22
- s.add_development_dependency("yard", [">= 0.5.8"])
23
- s.add_development_dependency("fuubar", [">= 0.0.1"])
24
23
  s.add_development_dependency("rake")
24
+ s.add_development_dependency("fuubar")
25
+ s.add_development_dependency("pry")
26
+ s.add_development_dependency("pry-doc")
27
+ s.add_development_dependency("cane")
25
28
  end
@@ -10,9 +10,8 @@ class Chef
10
10
 
11
11
  deps do
12
12
  require 'net/ssh/multi'
13
- require 'readline'
13
+ require 'zcloudjp'
14
14
  require 'chef/json_compat'
15
- require 'faraday'
16
15
  end
17
16
 
18
17
  option :zcloudjp_api_token,
@@ -31,10 +30,8 @@ class Chef
31
30
 
32
31
  private
33
32
 
34
- def connection
35
- @connection = Faraday.new(:url => Chef::Config[:knife][:zcloudjp_api_url]) do |faraday|
36
- faraday.request :url_encoded
37
- end
33
+ def client
34
+ Zcloudjp::Client.new(:api_key => Chef::Config[:knife][:zcloudjp_api_token])
38
35
  end
39
36
 
40
37
  def locate_config_value(key)
@@ -8,10 +8,7 @@ class Chef
8
8
 
9
9
 
10
10
  deps do
11
- require 'net/ssh/multi'
12
- require 'readline'
13
11
  require 'chef/json_compat'
14
- require 'faraday'
15
12
  require 'chef/knife/bootstrap'
16
13
  Chef::Knife::Bootstrap.load_deps
17
14
  end
@@ -136,27 +133,19 @@ class Chef
136
133
  ui.error("You have not provided a valid dataset image value. Please note the short option for this value recently changed from '-i' to '-I'.")
137
134
  exit 1
138
135
  end
139
- body = Hash.new()
140
- body["dataset"] = config[:dataset]
141
- body["package"] = locate_config_value(:package)
142
- body["name"] = config[:chef_node_name]
143
- body["locale"] = "en"
136
+ options = Hash.new()
137
+ options[:dataset] = config[:dataset]
138
+ options[:package] = locate_config_value(:package)
139
+ options[:name] = config[:chef_node_name]
140
+ options[:locale] = "en"
144
141
 
145
142
  Chef::Log.debug("Create machine with parameters below")
146
- Chef::Log.debug(body)
147
-
143
+ Chef::Log.debug(options)
144
+
148
145
 
149
146
  locate_config_value(:zcloudjp_api_url)
150
- connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false}, :headers => {"User-Agent" => "Knife-Zcloudjp/#{::Knife::Zcloudjp::VERSION}"})
151
-
152
- response = connection.post do |req|
153
- req.url '/machines.json'
154
- req.headers['Content-Type'] = 'application/json'
155
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
156
- req.body = body.to_json
157
- end
158
147
 
159
- machine = JSON.parse(response.body, :symbolized_names =>true )
148
+ machine = client.machine.create(options)
160
149
 
161
150
  msg_pair("ID", machine['id'])
162
151
  msg_pair("ip", machine['ips'].last)
@@ -179,7 +168,6 @@ class Chef
179
168
  # wait for provision the machine.
180
169
  print(".") until verify_ssh_connection(bootstrap_ip_address) {
181
170
  sleep @initial_sleep_delay ||= 10
182
- # puts("done")
183
171
  }
184
172
 
185
173
  # for smartdc workaround. check twice.
@@ -192,15 +180,16 @@ class Chef
192
180
  }
193
181
 
194
182
  # add name tag for zcloud machine
183
+ # sdc has bug. should update manualy..
195
184
  body = Hash.new()
196
185
  body["value"] = config[:machine_name]
197
-
198
- response = connection.put do |req|
199
- req.url "/machines/#{machine['id']}/name"
200
- req.headers['Content-Type'] = 'application/json'
201
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
202
- req.body = body.to_json
203
- end
186
+ HTTParty.put(
187
+ "#{Chef::Config[:knife][:zcloudjp_api_url]}/machines/#{machine['id']}/name",
188
+ :headers => {
189
+ "X-API-KEY" => Chef::Config[:knife][:zcloudjp_api_token]
190
+ },
191
+ :body => body
192
+ )
204
193
 
205
194
  bootstrap_node(machine, bootstrap_ip_address).run
206
195
  end
@@ -211,7 +200,6 @@ class Chef
211
200
  bootstrap.config[:run_list] = config[:run_list]
212
201
  bootstrap.config[:first_boot_attributes] = config[:first_boot_attributes]
213
202
  bootstrap.config[:ssh_user] = config[:ssh_user] || "root"
214
- # bootstrap.config[:ssh_password] = machine.password
215
203
  bootstrap.config[:identity_file] = config[:identity_file]
216
204
  bootstrap.config[:host_key_verify] = config[:host_key_verify]
217
205
  bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
@@ -10,14 +10,6 @@ class Chef
10
10
  def run
11
11
  Chef::Log.debug("Connect to Z Cloud API #{locate_config_value(:zcloudjp_api_url)}")
12
12
 
13
- connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false}, :headers => {"User-Agent" => "Knife-Zcloudjp/#{::Knife::Zcloudjp::VERSION}"})
14
-
15
- response = connection.get do |req|
16
- req.url '/machines.json'
17
- req.headers['Content-Type'] = 'application/json'
18
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
19
- end
20
-
21
13
  machine_list = [
22
14
  ui.color('name', :bold),
23
15
  ui.color('id', :bold),
@@ -27,7 +19,7 @@ class Chef
27
19
  ui.color('state', :bold),
28
20
  ]
29
21
 
30
- machines = JSON.parse(response.body)
22
+ machines = client.machine.list
31
23
 
32
24
  machines.map do |machine|
33
25
  machine_list << machine["name"].to_s
@@ -8,10 +8,7 @@ class Chef
8
8
 
9
9
 
10
10
  deps do
11
- require 'net/ssh/multi'
12
- require 'readline'
13
11
  require 'chef/json_compat'
14
- require 'faraday'
15
12
  end
16
13
 
17
14
  option :machine_uuid,
@@ -28,8 +25,8 @@ class Chef
28
25
  option :timeout,
29
26
  :short => "-t TIMEOUT_SECONDS",
30
27
  :long => "--timeout USERNAME",
31
- :description => "Set Timeout(seconds). default value is 10.",
32
- :default => 10
28
+ :description => "Set Timeout(seconds). default value is 20.",
29
+ :default => 20
33
30
 
34
31
  def run
35
32
  $stdout.sync = true
@@ -38,75 +35,44 @@ class Chef
38
35
  ui.error("You have not provided a machine uuid. Please note the short option for this value is '-n'.")
39
36
  exit 1
40
37
  end
41
- body = Hash.new()
42
38
 
43
39
  Chef::Log.debug("Start machine.")
44
- Chef::Log.debug(body)
45
-
46
40
 
47
- locate_config_value(:zcloudjp_api_url)
48
- connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false}, :headers => {"User-Agent" => "Knife-Zcloudjp/#{::Knife::Zcloudjp::VERSION}"})
49
-
50
- def check_current_state(connection,machine_uuid)
51
- response = connection.get do |req|
52
- req.url "/machines/#{machine_uuid}.json"
53
- req.headers['Content-Type'] = 'application/json'
54
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
55
- end
56
41
 
57
- Chef::Log.debug(response.inspect)
58
- case response.status
59
- when 200
60
- # do nothing.
61
- when 404
62
- ui.warn("The machine #{config[:machine_uuid]} was not found.")
63
- exit
64
- else
65
- ui.fatal("Exit", "Unknown Error occured in API response.")
66
- exit
67
- end
42
+ locate_config_value(:zcloudjp_api_url)
43
+ machine = client.machine.show(:id => config[:machine_uuid])
68
44
 
69
- machine = JSON.parse(response.body, :symbolized_names =>true )
70
- machine['state']
45
+ ## Exit if missing
46
+ if machine[:error]
47
+ ui.warn("The machine #{config[:machine_uuid]} was not found.")
48
+ exit
71
49
  end
72
50
 
73
- ## Exit if already runnning.
74
- if check_current_state(connection, config[:machine_uuid]) == "running" then
51
+ ## Exit if already running.
52
+ if machine[:state] == "running" then
75
53
  ui.info("The machine #{config[:machine_uuid]} is already running.")
76
54
  exit
77
55
  end
78
56
 
79
57
  # Start Machine
80
- response = connection.post do |req|
81
- req.url "/machines/#{config[:machine_uuid]}/start.json"
82
- req.headers['Content-Type'] = 'application/json'
83
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
84
- req.body = body.to_json
85
- end
58
+ machine.start
86
59
 
87
60
  ## Wait
88
61
  ui.info("Waiting state of machine changed to running... (Timeout: #{config[:timeout]} seconds)")
89
62
  config[:timeout].to_i.times do |idx|
90
- if check_current_state(connection, config[:machine_uuid]) == "running" then
63
+ if machine.reload[:state] == "running" then
64
+ puts ''
91
65
  break
92
- elsif (idx + 1) == config[:timeout].to_i
66
+ elsif (idx + 2) == config[:timeout].to_i
93
67
  ui.warn("Timed out. Please check later.")
94
68
  exit 1
95
69
  else
96
- sleep 1
70
+ print '.'
71
+ sleep 2
97
72
  end
98
73
  end
99
74
 
100
75
  ## print current status
101
- response = connection.get do |req|
102
- req.url "/machines/#{config[:machine_uuid]}.json"
103
- req.headers['Content-Type'] = 'application/json'
104
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
105
- req.body = body.to_json
106
- end
107
-
108
- machine = JSON.parse(response.body, :symbolized_names =>true )
109
-
110
76
  msg_pair("ID", machine['id'])
111
77
  msg_pair("ip", machine['ips'].last)
112
78
  msg_pair("type", machine['type'])
@@ -8,10 +8,7 @@ class Chef
8
8
 
9
9
 
10
10
  deps do
11
- require 'net/ssh/multi'
12
- require 'readline'
13
11
  require 'chef/json_compat'
14
- require 'faraday'
15
12
  end
16
13
 
17
14
  option :machine_uuid,
@@ -28,8 +25,8 @@ class Chef
28
25
  option :timeout,
29
26
  :short => "-t TIMEOUT_SECONDS",
30
27
  :long => "--timeout USERNAME",
31
- :description => "Set Timeout(seconds). default value is 10.",
32
- :default => 10
28
+ :description => "Set Timeout(seconds). default value is 20.",
29
+ :default => 20
33
30
 
34
31
  def run
35
32
  $stdout.sync = true
@@ -38,75 +35,43 @@ class Chef
38
35
  ui.error("You have not provided a machine uuid. Please note the short option for this value is '-n'.")
39
36
  exit 1
40
37
  end
41
- body = Hash.new()
42
38
 
43
39
  Chef::Log.debug("Stop machine.")
44
- Chef::Log.debug(body)
45
-
46
40
 
47
41
  locate_config_value(:zcloudjp_api_url)
48
- connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false}, :headers => {"User-Agent" => "Knife-Zcloudjp/#{::Knife::Zcloudjp::VERSION}"})
49
-
50
- def check_current_state(connection,machine_uuid)
51
- response = connection.get do |req|
52
- req.url "/machines/#{machine_uuid}.json"
53
- req.headers['Content-Type'] = 'application/json'
54
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
55
- end
42
+ machine = client.machine.show(:id => config[:machine_uuid])
56
43
 
57
- Chef::Log.debug(response.inspect)
58
- case response.status
59
- when 200
60
- # do nothing.
61
- when 404
62
- ui.warn("The machine #{config[:machine_uuid]} was not found.")
63
- exit
64
- else
65
- ui.fatal("Exit", "Unknown Error occured in API response.")
66
- exit
67
- end
68
-
69
- machine = JSON.parse(response.body, :symbolized_names =>true )
70
- machine['state']
44
+ ## Exit if missing
45
+ if machine[:error]
46
+ ui.warn("The machine #{config[:machine_uuid]} was not found.")
47
+ exit
71
48
  end
72
49
 
73
50
  ## Exit if already stopped.
74
- if check_current_state(connection, config[:machine_uuid]) == "stopped" then
51
+ if machine[:state] == "stopped" then
75
52
  ui.info("The machine #{config[:machine_uuid]} already stopped.")
76
53
  exit
77
54
  end
78
55
 
79
56
  # Stop Machine
80
- response = connection.post do |req|
81
- req.url "/machines/#{config[:machine_uuid]}/stop.json"
82
- req.headers['Content-Type'] = 'application/json'
83
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
84
- req.body = body.to_json
85
- end
57
+ machine.stop
86
58
 
87
59
  ## Wait
88
60
  ui.info("Waiting state of machine changed to stopped... (Timeout: #{config[:timeout]} seconds)")
89
61
  config[:timeout].to_i.times do |idx|
90
- if check_current_state(connection, config[:machine_uuid]) == "stopped" then
62
+ if machine.reload[:state] == "stopped" then
63
+ puts ''
91
64
  break
92
- elsif (idx + 1) == config[:timeout].to_i
65
+ elsif (idx + 2) == config[:timeout].to_i
93
66
  ui.warn("Timed out. Please check later.")
94
67
  exit 1
95
68
  else
96
- sleep 1
69
+ print '.'
70
+ sleep 2
97
71
  end
98
72
  end
99
73
 
100
74
  ## print current status
101
- response = connection.get do |req|
102
- req.url "/machines/#{config[:machine_uuid]}.json"
103
- req.headers['Content-Type'] = 'application/json'
104
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
105
- req.body = body.to_json
106
- end
107
-
108
- machine = JSON.parse(response.body, :symbolized_names =>true )
109
-
110
75
  msg_pair("ID", machine['id'])
111
76
  msg_pair("ip", machine['ips'].last)
112
77
  msg_pair("type", machine['type'])
@@ -10,13 +10,11 @@ class Chef
10
10
 
11
11
  def run
12
12
  Chef::Log.debug("Connect to Z Cloud API #{locate_config_value(:zcloudjp_api_url)}")
13
- connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false}, :headers => {"User-Agent" => "Knife-Zcloudjp/#{::Knife::Zcloudjp::VERSION}"})
14
13
 
15
- response = connection.get do |req|
16
- req.url '/products.json'
17
- req.headers['Content-Type'] = 'application/json'
18
- req.headers['X-API-KEY'] = Chef::Config[:knife][:zcloudjp_api_token]
19
- end
14
+ response = HTTParty.get(
15
+ "#{Chef::Config[:knife][:zcloudjp_api_url]}/products.json",
16
+ :headers => {"X-API-KEY" => Chef::Config[:knife][:zcloudjp_api_token]}
17
+ )
20
18
 
21
19
  products = JSON.parse(response.body)
22
20
 
@@ -1,6 +1,6 @@
1
1
  module Knife
2
2
  module Zcloudjp
3
- VERSION = "0.1.7"
3
+ VERSION = "0.2.0"
4
4
  MAJOR, MINOR, TINY = VERSION.split('.')
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,97 +1,139 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-zcloudjp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - sawanoboly
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-29 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.10.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.10
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday
28
+ name: zcloudjp
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: formatador
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ! '>='
59
+ - - '>='
46
60
  - !ruby/object:Gem::Version
47
61
  version: 2.2.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ! '>='
66
+ - - '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: 2.2.0
55
69
  - !ruby/object:Gem::Dependency
56
- name: yard
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ! '>='
73
+ - - '>='
60
74
  - !ruby/object:Gem::Version
61
- version: 0.5.8
75
+ version: '0'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ! '>='
80
+ - - '>='
67
81
  - !ruby/object:Gem::Version
68
- version: 0.5.8
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: fuubar
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ! '>='
87
+ - - '>='
74
88
  - !ruby/object:Gem::Version
75
- version: 0.0.1
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ! '>='
94
+ - - '>='
81
95
  - !ruby/object:Gem::Version
82
- version: 0.0.1
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rake
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-doc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: cane
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
- - - ! '>='
129
+ - - '>='
88
130
  - !ruby/object:Gem::Version
89
131
  version: '0'
90
132
  type: :development
91
133
  prerelease: false
92
134
  version_requirements: !ruby/object:Gem::Requirement
93
135
  requirements:
94
- - - ! '>='
136
+ - - '>='
95
137
  - !ruby/object:Gem::Version
96
138
  version: '0'
97
139
  description: Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).
@@ -132,17 +174,17 @@ require_paths:
132
174
  - lib
133
175
  required_ruby_version: !ruby/object:Gem::Requirement
134
176
  requirements:
135
- - - ! '>='
177
+ - - '>='
136
178
  - !ruby/object:Gem::Version
137
179
  version: '0'
138
180
  required_rubygems_version: !ruby/object:Gem::Requirement
139
181
  requirements:
140
- - - ! '>='
182
+ - - '>='
141
183
  - !ruby/object:Gem::Version
142
184
  version: '0'
143
185
  requirements: []
144
186
  rubyforge_project:
145
- rubygems_version: 2.0.3
187
+ rubygems_version: 2.1.11
146
188
  signing_key:
147
189
  specification_version: 4
148
190
  summary: Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).