knife-zcloudjp 0.1.3 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +19 -0
- data/README.md +48 -13
- data/knife-zcloudjp.gemspec +2 -2
- data/lib/chef/knife/zcloudjp_machine_start.rb +120 -0
- data/lib/chef/knife/zcloudjp_machine_stop.rb +120 -0
- data/lib/knife-zcloudjp.rb +1 -1
- metadata +7 -4
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -6,6 +6,12 @@ A Knife(Opscode Chef) plugin for [Z Cloud](http://z-cloud.jp). This plugin allow
|
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
+
### from Rubygems
|
10
|
+
|
11
|
+
gem install knife-zcloudjp
|
12
|
+
|
13
|
+
### from github
|
14
|
+
|
9
15
|
Drop the following line into your application's `Gemfile`.
|
10
16
|
|
11
17
|
gem 'knife-zcloudjp', :git => "git://github.com/higanworks/knife-zcloudjp.git"
|
@@ -24,19 +30,34 @@ Add the following entries to your `.chef/knife.rb`.
|
|
24
30
|
### Retrieve the product catalog that are currently available.
|
25
31
|
|
26
32
|
$ knife zcloudjp product list (options)
|
27
|
-
name os dataset
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
+
|
40
61
|
|
41
62
|
|
42
63
|
<pre><code>knife zcloudjp product list (options)
|
@@ -145,6 +166,20 @@ Login into a newly provisonned machine based on SmartOS via ssh, and introduce t
|
|
145
166
|
</code></pre>
|
146
167
|
|
147
168
|
|
169
|
+
### Start and stop machine.
|
170
|
+
|
171
|
+
Use '-n' option with UUID
|
172
|
+
|
173
|
+
knife zcloudjp machine [start}stop] -n ${MACHINE_UUID}
|
174
|
+
|
175
|
+
<pre><code>$ knife zcloudjp machine start -n ********-****-****-****-********
|
176
|
+
Waiting state of machine changed to running... (Timeout: 10 seconds)
|
177
|
+
ID: ********-****-****-****-********
|
178
|
+
ip: 210.152.xxx.xxx
|
179
|
+
type: smartmachine
|
180
|
+
dataset: sdc:sdc:standard:1.0.7
|
181
|
+
state: running</code></pre>
|
182
|
+
|
148
183
|
## Contributing
|
149
184
|
|
150
185
|
1. Fork it
|
data/knife-zcloudjp.gemspec
CHANGED
@@ -5,8 +5,8 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.version = Knife::Zcloudjp::VERSION
|
6
6
|
s.authors = ["sawanoboly"]
|
7
7
|
s.email = ["sawanoboriyu@gmail.com"]
|
8
|
-
s.description = %q{Knife(Opscode Chef) plugin for Z Cloud.}
|
9
|
-
s.summary = %q{Knife(Opscode Chef) plugin for Z Cloud.}
|
8
|
+
s.description = %q{Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).}
|
9
|
+
s.summary = %q{Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).}
|
10
10
|
s.homepage = ""
|
11
11
|
|
12
12
|
s.files = `git ls-files`.split($\)
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'chef/knife/zcloudjp_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class ZcloudjpMachineStart < Knife
|
6
|
+
include ZcloudjpBase
|
7
|
+
banner "knife zcloudjp machine start (options)"
|
8
|
+
|
9
|
+
|
10
|
+
deps do
|
11
|
+
require 'net/ssh/multi'
|
12
|
+
require 'readline'
|
13
|
+
require 'chef/json_compat'
|
14
|
+
require 'faraday'
|
15
|
+
end
|
16
|
+
|
17
|
+
option :machine_uuid,
|
18
|
+
:short => "-n UUID",
|
19
|
+
:long => "--machine-uuid UUID",
|
20
|
+
:description => "UUID of target machne to run"
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
# option :chef_node_name,
|
24
|
+
# :short => "-N NAME",
|
25
|
+
# :long => "--node-name NAME",
|
26
|
+
# :description => "The Chef node name of taget node. Will find uuid by nodename at attributes."
|
27
|
+
|
28
|
+
option :timeout,
|
29
|
+
:short => "-t TIMEOUT_SECONDS",
|
30
|
+
:long => "--timeout USERNAME",
|
31
|
+
:description => "Set Timeout(seconds). default value is 10.",
|
32
|
+
:default => 10
|
33
|
+
|
34
|
+
def run
|
35
|
+
$stdout.sync = true
|
36
|
+
|
37
|
+
unless config[:machine_uuid]
|
38
|
+
ui.error("You have not provided a machine uuid. Please note the short option for this value is '-n'.")
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
body = Hash.new()
|
42
|
+
|
43
|
+
Chef::Log.debug("Start machine.")
|
44
|
+
Chef::Log.debug(body)
|
45
|
+
|
46
|
+
|
47
|
+
locate_config_value(:zcloudjp_api_url)
|
48
|
+
connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false})
|
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
|
+
|
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']
|
71
|
+
end
|
72
|
+
|
73
|
+
## Exit if already runnning.
|
74
|
+
if check_current_state(connection, config[:machine_uuid]) == "running" then
|
75
|
+
ui.info("The machine #{config[:machine_uuid]} is already running.")
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
# 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
|
86
|
+
|
87
|
+
## Wait
|
88
|
+
ui.info("Waiting state of machine changed to running... (Timeout: #{config[:timeout]} seconds)")
|
89
|
+
config[:timeout].to_i.times do |idx|
|
90
|
+
if check_current_state(connection, config[:machine_uuid]) == "running" then
|
91
|
+
break
|
92
|
+
elsif (idx + 1) == config[:timeout].to_i
|
93
|
+
ui.warn("Timed out. Please check later.")
|
94
|
+
exit 1
|
95
|
+
else
|
96
|
+
sleep 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
## 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
|
+
msg_pair("ID", machine['id'])
|
111
|
+
msg_pair("ip", machine['ips'].last)
|
112
|
+
msg_pair("type", machine['type'])
|
113
|
+
msg_pair("dataset", machine['dataset'])
|
114
|
+
msg_pair("state", machine['state'])
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'chef/knife/zcloudjp_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class ZcloudjpMachineStop < Knife
|
6
|
+
include ZcloudjpBase
|
7
|
+
banner "knife zcloudjp machine stop (options)"
|
8
|
+
|
9
|
+
|
10
|
+
deps do
|
11
|
+
require 'net/ssh/multi'
|
12
|
+
require 'readline'
|
13
|
+
require 'chef/json_compat'
|
14
|
+
require 'faraday'
|
15
|
+
end
|
16
|
+
|
17
|
+
option :machine_uuid,
|
18
|
+
:short => "-n UUID",
|
19
|
+
:long => "--machine-uuid UUID",
|
20
|
+
:description => "UUID of target machne to stop"
|
21
|
+
|
22
|
+
# TODO
|
23
|
+
# option :chef_node_name,
|
24
|
+
# :short => "-N NAME",
|
25
|
+
# :long => "--node-name NAME",
|
26
|
+
# :description => "The Chef node name of taget node. Will find uuid by nodename at attributes."
|
27
|
+
|
28
|
+
option :timeout,
|
29
|
+
:short => "-t TIMEOUT_SECONDS",
|
30
|
+
:long => "--timeout USERNAME",
|
31
|
+
:description => "Set Timeout(seconds). default value is 10.",
|
32
|
+
:default => 10
|
33
|
+
|
34
|
+
def run
|
35
|
+
$stdout.sync = true
|
36
|
+
|
37
|
+
unless config[:machine_uuid]
|
38
|
+
ui.error("You have not provided a machine uuid. Please note the short option for this value is '-n'.")
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
body = Hash.new()
|
42
|
+
|
43
|
+
Chef::Log.debug("Stop machine.")
|
44
|
+
Chef::Log.debug(body)
|
45
|
+
|
46
|
+
|
47
|
+
locate_config_value(:zcloudjp_api_url)
|
48
|
+
connection = Faraday.new(:url => locate_config_value(:zcloudjp_api_url), :ssl => {:verify => false})
|
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
|
+
|
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']
|
71
|
+
end
|
72
|
+
|
73
|
+
## Exit if already stopped.
|
74
|
+
if check_current_state(connection, config[:machine_uuid]) == "stopped" then
|
75
|
+
ui.info("The machine #{config[:machine_uuid]} already stopped.")
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
|
79
|
+
# 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
|
86
|
+
|
87
|
+
## Wait
|
88
|
+
ui.info("Waiting state of machine changed to stopped... (Timeout: #{config[:timeout]} seconds)")
|
89
|
+
config[:timeout].to_i.times do |idx|
|
90
|
+
if check_current_state(connection, config[:machine_uuid]) == "stopped" then
|
91
|
+
break
|
92
|
+
elsif (idx + 1) == config[:timeout].to_i
|
93
|
+
ui.warn("Timed out. Please check later.")
|
94
|
+
exit 1
|
95
|
+
else
|
96
|
+
sleep 1
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
## 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
|
+
msg_pair("ID", machine['id'])
|
111
|
+
msg_pair("ip", machine['ips'].last)
|
112
|
+
msg_pair("type", machine['type'])
|
113
|
+
msg_pair("dataset", machine['dataset'])
|
114
|
+
msg_pair("state", machine['state'])
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
data/lib/knife-zcloudjp.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-zcloudjp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chef
|
@@ -107,7 +107,7 @@ dependencies:
|
|
107
107
|
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
|
-
description: Knife(Opscode Chef) plugin for Z Cloud.
|
110
|
+
description: Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).
|
111
111
|
email:
|
112
112
|
- sawanoboriyu@gmail.com
|
113
113
|
executables: []
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- .gitignore
|
118
118
|
- .rspec
|
119
119
|
- .travis.yml
|
120
|
+
- CHANGELOG.md
|
120
121
|
- Gemfile
|
121
122
|
- LICENSE
|
122
123
|
- README.md
|
@@ -126,6 +127,8 @@ files:
|
|
126
127
|
- lib/chef/knife/zcloudjp_base.rb
|
127
128
|
- lib/chef/knife/zcloudjp_machine_create.rb
|
128
129
|
- lib/chef/knife/zcloudjp_machine_list.rb
|
130
|
+
- lib/chef/knife/zcloudjp_machine_start.rb
|
131
|
+
- lib/chef/knife/zcloudjp_machine_stop.rb
|
129
132
|
- lib/chef/knife/zcloudjp_product_list.rb
|
130
133
|
- lib/knife-zcloudjp.rb
|
131
134
|
- spec/spec_helper.rb
|
@@ -156,7 +159,7 @@ rubyforge_project:
|
|
156
159
|
rubygems_version: 1.8.24
|
157
160
|
signing_key:
|
158
161
|
specification_version: 3
|
159
|
-
summary: Knife(Opscode Chef) plugin for Z Cloud.
|
162
|
+
summary: Knife(Opscode Chef) plugin for Z Cloud(Powered by Joyent).
|
160
163
|
test_files:
|
161
164
|
- spec/spec_helper.rb
|
162
165
|
- spec/unit/zcloudjp_base_spec.rb
|