knife-joyent 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/knife/joyent_base.rb +41 -5
- data/lib/chef/knife/joyent_flavor_list.rb +2 -0
- data/lib/chef/knife/joyent_fw_create.rb +3 -1
- data/lib/chef/knife/joyent_fw_delete.rb +3 -1
- data/lib/chef/knife/joyent_fw_get.rb +1 -2
- data/lib/chef/knife/joyent_fw_list.rb +2 -1
- data/lib/chef/knife/joyent_fw_update.rb +1 -1
- data/lib/chef/knife/joyent_image_create.rb +74 -0
- data/lib/chef/knife/joyent_image_list.rb +41 -7
- data/lib/chef/knife/joyent_key_add.rb +2 -1
- data/lib/chef/knife/joyent_key_delete.rb +3 -0
- data/lib/chef/knife/joyent_key_list.rb +2 -0
- data/lib/chef/knife/joyent_network_list.rb +2 -0
- data/lib/chef/knife/joyent_server_create.rb +1 -16
- data/lib/chef/knife/joyent_server_delete.rb +12 -9
- data/lib/chef/knife/joyent_server_fw_disable.rb +1 -1
- data/lib/chef/knife/joyent_server_fw_enable.rb +1 -1
- data/lib/chef/knife/joyent_server_list.rb +2 -0
- data/lib/chef/knife/joyent_server_metadata_delete.rb +3 -0
- data/lib/chef/knife/joyent_server_metadata_update.rb +2 -0
- data/lib/chef/knife/joyent_server_reboot.rb +3 -0
- data/lib/chef/knife/joyent_server_resize.rb +2 -0
- data/lib/chef/knife/joyent_server_start.rb +3 -1
- data/lib/chef/knife/joyent_server_stop.rb +2 -0
- data/lib/chef/knife/joyent_snapshot_create.rb +20 -29
- data/lib/chef/knife/joyent_snapshot_delete.rb +1 -13
- data/lib/chef/knife/joyent_snapshot_list.rb +2 -2
- data/lib/chef/knife/joyent_tag_create.rb +2 -2
- data/lib/chef/knife/joyent_tag_delete.rb +2 -0
- data/lib/chef/knife/joyent_tag_list.rb +3 -0
- data/lib/knife-joyent/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d785e10606c59d43b4031b90d2b0d0e752db4593
|
4
|
+
data.tar.gz: e703e79ffa5b7e7bc260e38e8fafd316ff9e69ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 364b38a35715a43c2cc528b53137d61fa7fbcd361fef0cc653a21a6d857aeaacbd0e639dda9a44cd6f15fada9879c007da62a80a016c0911b22a2898a0b4b38c
|
7
|
+
data.tar.gz: 201c979f3decc2d4c65cb19a4ff02d74fe72c96f8a94c0b0bd255623fb54e0f9e85e116f98f3c4fa968ef03681b3d7df3b543b1c1552b1c7119546f204de7eaf
|
@@ -82,13 +82,32 @@ class Chef
|
|
82
82
|
config[key] || Chef::Config[:knife][key]
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
|
87
|
-
|
85
|
+
def output_error(e)
|
86
|
+
res = case e
|
87
|
+
when Excon::Response
|
88
|
+
e
|
89
|
+
when Excon::Errors::Error
|
90
|
+
e.response
|
91
|
+
else
|
92
|
+
raise
|
88
93
|
end
|
89
94
|
|
90
|
-
if
|
91
|
-
|
95
|
+
if res.headers["Content-Type"] == 'application/json' && res.body.kind_of?(String)
|
96
|
+
body = json_decode(res.body)
|
97
|
+
else
|
98
|
+
body = res.body
|
99
|
+
end
|
100
|
+
|
101
|
+
if body['code']
|
102
|
+
ui.error ui.color("*#{body["code"]}*", :white)
|
103
|
+
end
|
104
|
+
|
105
|
+
if body['message']
|
106
|
+
ui.error ui.color(body["message"], :white)
|
107
|
+
end
|
108
|
+
|
109
|
+
if body["errors"]
|
110
|
+
errors = body["errors"]
|
92
111
|
errors.each do |e|
|
93
112
|
ui.error("[#{e["field"]}] #{e["message"]}")
|
94
113
|
end
|
@@ -100,6 +119,23 @@ class Chef
|
|
100
119
|
puts "#{ui.color(label, :cyan)}: #{value}"
|
101
120
|
end
|
102
121
|
end
|
122
|
+
|
123
|
+
def json_decode(body)
|
124
|
+
parsed = Fog::JSON.decode(body)
|
125
|
+
decode_time_attrs(parsed)
|
126
|
+
end
|
127
|
+
|
128
|
+
def decode_time_attrs(obj)
|
129
|
+
if obj.kind_of?(Hash)
|
130
|
+
obj["created"] = Time.parse(obj["created"]) unless obj["created"].nil? or obj["created"] == ''
|
131
|
+
obj["updated"] = Time.parse(obj["updated"]) unless obj["updated"].nil? or obj["updated"] == ''
|
132
|
+
elsif obj.kind_of?(Array)
|
133
|
+
obj.map do |o|
|
134
|
+
decode_time_attrs(o)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
obj
|
138
|
+
end
|
103
139
|
end
|
104
140
|
end
|
105
141
|
end
|
@@ -34,7 +34,7 @@ class Chef
|
|
34
34
|
)
|
35
35
|
|
36
36
|
unless res.status == 201
|
37
|
-
|
37
|
+
output_error(res)
|
38
38
|
else
|
39
39
|
r = res.body
|
40
40
|
|
@@ -42,6 +42,8 @@ class Chef
|
|
42
42
|
msg_pair "RULE", r["rule"]
|
43
43
|
msg_pair "ENABLED", (r["enabled"] ? ui.color("✓ YES", :cyan) : "✗ NO")
|
44
44
|
end
|
45
|
+
rescue => e
|
46
|
+
output_error(e)
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
]
|
29
29
|
|
30
30
|
if (res.status == 422)
|
31
|
-
|
31
|
+
output_error(res)
|
32
32
|
else
|
33
33
|
r = res.body
|
34
34
|
rules << r["id"]
|
@@ -36,7 +36,6 @@ class Chef
|
|
36
36
|
rules << r["rule"]
|
37
37
|
ui.list(rules, :uneven_columns_across, 3)
|
38
38
|
end
|
39
|
-
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'chef/knife/joyent_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentImageCreate < Knife
|
6
|
+
|
7
|
+
include Knife::JoyentBase
|
8
|
+
|
9
|
+
banner "knife joyent image create <options>"
|
10
|
+
|
11
|
+
option :server,
|
12
|
+
:long => "--server <server_uuid>",
|
13
|
+
:description => "server uuid to create machine from",
|
14
|
+
:required => true
|
15
|
+
|
16
|
+
option :name,
|
17
|
+
:long => "--name <image_name>",
|
18
|
+
:description => "name of custom image",
|
19
|
+
:required => true
|
20
|
+
|
21
|
+
option :version,
|
22
|
+
:long => "--version <image_version>",
|
23
|
+
:description => "version of custom image",
|
24
|
+
:required => true
|
25
|
+
|
26
|
+
option :description,
|
27
|
+
:long => "--description <image description>",
|
28
|
+
:description => "description of custom image (optional)"
|
29
|
+
|
30
|
+
option :homepage,
|
31
|
+
:long => "--homepage <homepage>",
|
32
|
+
:description => "homepage of custom image (optional)"
|
33
|
+
|
34
|
+
option :eula,
|
35
|
+
:long => "--eula <eula>",
|
36
|
+
:description => "EULA of custom image"
|
37
|
+
|
38
|
+
option :acl,
|
39
|
+
:long => "--acl <eula>",
|
40
|
+
:description => "ACL (json) of custom image see: https://images.joyent.com/docs/#manifest-acl"
|
41
|
+
|
42
|
+
option :tags,
|
43
|
+
:long => "--tags <tags>",
|
44
|
+
:description => "tags (json) of custom image"
|
45
|
+
|
46
|
+
def image_create_options
|
47
|
+
opts = {}
|
48
|
+
opts["machine"] = config[:server] if config[:server]
|
49
|
+
opts["name"] = config[:name] if config[:name]
|
50
|
+
opts["version"] = config[:version] if config[:version]
|
51
|
+
opts["description"] = config[:description] if config[:description]
|
52
|
+
opts["eula"] = config[:eula] if config[:eula]
|
53
|
+
opts["acl"] = config[:acl] if config[:acl]
|
54
|
+
opts["tags"] = config[:tags] if config[:tags]
|
55
|
+
opts
|
56
|
+
end
|
57
|
+
|
58
|
+
def run
|
59
|
+
# puts image_create_options.inspect
|
60
|
+
res = self.connection.request(
|
61
|
+
:method => "POST",
|
62
|
+
:path => "/my/images",
|
63
|
+
:body => image_create_options
|
64
|
+
)
|
65
|
+
if (res.status == 201)
|
66
|
+
ui.info ui.color("Creating Image from server #{config[:server]}...", :cyan)
|
67
|
+
ui.output(res.body)
|
68
|
+
else
|
69
|
+
output_error(res)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -8,6 +8,16 @@ class Chef
|
|
8
8
|
|
9
9
|
banner "knife joyent image list <options>"
|
10
10
|
|
11
|
+
option :public,
|
12
|
+
:boolean => true,
|
13
|
+
:long => "--public <true/false>",
|
14
|
+
:description => "filter public/private images"
|
15
|
+
|
16
|
+
option :state,
|
17
|
+
:long => "--state <all/active/unactivated/disabled>",
|
18
|
+
:default => "active",
|
19
|
+
:description => "filter images by state (default: active"
|
20
|
+
|
11
21
|
def run
|
12
22
|
images = [
|
13
23
|
ui.color('ID', :bold),
|
@@ -15,17 +25,41 @@ class Chef
|
|
15
25
|
ui.color('Version', :bold),
|
16
26
|
ui.color('OS', :bold),
|
17
27
|
ui.color('Type', :bold),
|
28
|
+
ui.color('State', :bold),
|
18
29
|
]
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
31
|
+
query = {}
|
32
|
+
query[:public] = config[:public] if config[:public]
|
33
|
+
query[:state] = config[:state] if config[:state]
|
34
|
+
|
35
|
+
res = self.connection.request(
|
36
|
+
:method => "GET",
|
37
|
+
:query => query,
|
38
|
+
:path => "/my/images",
|
39
|
+
)
|
40
|
+
|
41
|
+
if res.status == 200
|
42
|
+
data = res.body
|
43
|
+
else
|
44
|
+
output_error(res)
|
45
|
+
exit 1
|
26
46
|
end
|
27
47
|
|
28
|
-
|
48
|
+
data.sort_by do |v|
|
49
|
+
v["name"]
|
50
|
+
end.each do |i|
|
51
|
+
images << i["id"]
|
52
|
+
images << i["name"]
|
53
|
+
images << i["version"]
|
54
|
+
images << i["os"]
|
55
|
+
images << i["type"]
|
56
|
+
images << i["state"]
|
57
|
+
end
|
58
|
+
|
59
|
+
ui.output ui.list(images, :uneven_columns_across, 6)
|
60
|
+
rescue => e
|
61
|
+
output_error(e)
|
62
|
+
|
29
63
|
end
|
30
64
|
end
|
31
65
|
end
|
@@ -213,23 +213,8 @@ class Chef
|
|
213
213
|
|
214
214
|
bootstrap_for_node(server, bootstrap_ip).run
|
215
215
|
|
216
|
-
rescue Excon::Errors::Conflict => e
|
217
|
-
if e.response && e.response.body.kind_of?(String)
|
218
|
-
error = ::Fog::JSON.decode(e.response.body)
|
219
|
-
print ui.error(error['message'])
|
220
|
-
if error.key?('errors') && error['errors'].kind_of?(Array)
|
221
|
-
error['errors'].each do |err|
|
222
|
-
print ui.error " * [#{err['field']}] #{err['message']}"
|
223
|
-
end
|
224
|
-
end
|
225
|
-
exit 1
|
226
|
-
else
|
227
|
-
puts ui.error(e.message)
|
228
|
-
exit 1
|
229
|
-
end
|
230
|
-
|
231
216
|
rescue => e
|
232
|
-
|
217
|
+
output_error(e)
|
233
218
|
exit 1
|
234
219
|
end
|
235
220
|
|
@@ -19,22 +19,22 @@ class Chef
|
|
19
19
|
id = name_args.first
|
20
20
|
|
21
21
|
server = self.connection.servers.get(id)
|
22
|
-
|
22
|
+
|
23
23
|
msg("ID", server.id.to_s)
|
24
24
|
msg("Name", server.name)
|
25
25
|
msg("State", server.state)
|
26
26
|
msg("Type", server.type)
|
27
27
|
msg("Dataset", server.dataset)
|
28
28
|
msg("IPs", server.ips.join(" "))
|
29
|
-
|
29
|
+
|
30
30
|
unless server
|
31
31
|
puts ui.error("Unable to locate server: #{id}")
|
32
32
|
exit 1
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
puts "\n"
|
36
36
|
confirm("Do you really want to delete this server")
|
37
|
-
|
37
|
+
|
38
38
|
puts ui.color("Stopping server...", :cyan)
|
39
39
|
|
40
40
|
if server.stopped?
|
@@ -47,24 +47,27 @@ class Chef
|
|
47
47
|
exit 1
|
48
48
|
end
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
server.destroy
|
52
52
|
puts ui.color("Deleted server: #{id}", :cyan)
|
53
|
-
|
53
|
+
|
54
54
|
puts "\n"
|
55
55
|
confirm("Delete client and node for #{server.name}?")
|
56
|
-
|
56
|
+
|
57
57
|
node = Chef::Node.load(server.name)
|
58
58
|
puts "deleting node #{node.name}"
|
59
59
|
node.destroy
|
60
60
|
ui.warn("Deleted node named #{node.name}")
|
61
|
-
|
61
|
+
|
62
62
|
client = Chef::ApiClient.load(server.name)
|
63
63
|
puts "deleting client #{client.name}"
|
64
64
|
client.destroy
|
65
65
|
ui.warn("Deleted client named #{client.name}")
|
66
|
+
rescue => e
|
67
|
+
output_error(e)
|
68
|
+
exit 1
|
66
69
|
end
|
67
|
-
|
70
|
+
|
68
71
|
def msg(label, value)
|
69
72
|
if value && !value.empty?
|
70
73
|
puts "#{ui.color(label, :cyan)}: #{value}"
|
@@ -2,41 +2,32 @@ require 'chef/knife/joyent_base'
|
|
2
2
|
|
3
3
|
class Chef
|
4
4
|
class Knife
|
5
|
-
|
5
|
+
class JoyentSnapshotCreate < Knife
|
6
6
|
|
7
|
-
|
7
|
+
include Knife::JoyentBase
|
8
8
|
|
9
|
-
|
9
|
+
banner 'knife joyent snapshot create <server> <snapshot_name>'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
exit 1
|
15
|
-
end
|
16
|
-
|
17
|
-
server = name_args[0]
|
18
|
-
ssname = name_args[1]
|
19
|
-
|
20
|
-
snapshot = self.connection.snapshots.create(server, ssname)
|
21
|
-
puts ui.color("Created snapshot", :cyan)
|
22
|
-
puts ui.output({
|
23
|
-
:server => snapshot.machine_id,
|
24
|
-
:name => snapshot.name,
|
25
|
-
:state => snapshot.state,
|
26
|
-
:created => snapshot.created
|
27
|
-
})
|
28
|
-
exit 0
|
29
|
-
rescue Excon::Errors::Conflict => e
|
30
|
-
if e.response && e.response.body.kind_of?(String)
|
31
|
-
error = MultiJson.decode(e.response.body)
|
32
|
-
puts ui.error(error['message'])
|
33
|
-
exit 1
|
34
|
-
else
|
35
|
-
puts ui.error(e.message)
|
11
|
+
def run
|
12
|
+
unless name_args.size == 2
|
13
|
+
show_usage
|
36
14
|
exit 1
|
37
15
|
end
|
16
|
+
|
17
|
+
server = name_args[0]
|
18
|
+
ssname = name_args[1]
|
19
|
+
|
20
|
+
snapshot = self.connection.snapshots.create(server, ssname)
|
21
|
+
puts ui.color("Created snapshot", :cyan)
|
22
|
+
puts ui.output({
|
23
|
+
:server => snapshot.machine_id,
|
24
|
+
:name => snapshot.name,
|
25
|
+
:state => snapshot.state,
|
26
|
+
:created => snapshot.created
|
27
|
+
})
|
28
|
+
exit 0
|
38
29
|
rescue => e
|
39
|
-
|
30
|
+
output_error(e)
|
40
31
|
exit 1
|
41
32
|
end
|
42
33
|
end
|
@@ -21,20 +21,8 @@ class Chef
|
|
21
21
|
snapshot.destroy
|
22
22
|
puts ui.color("Deleted snapshot #{snapshot.name}", :cyan)
|
23
23
|
exit 0
|
24
|
-
rescue Excon::Errors::NotFound => e
|
25
|
-
puts ui.error("Snapshot #{ssname} on server #{server} not found")
|
26
|
-
exit 1
|
27
|
-
rescue Excon::Errors::Conflict => e
|
28
|
-
if e.response && e.response.body.kind_of?(String)
|
29
|
-
error = MultiJson.decode(e.response.body)
|
30
|
-
puts ui.error(error['message'])
|
31
|
-
exit 1
|
32
|
-
else
|
33
|
-
puts ui.error(e.message)
|
34
|
-
exit 1
|
35
|
-
end
|
36
24
|
rescue => e
|
37
|
-
|
25
|
+
output_error(e)
|
38
26
|
exit 1
|
39
27
|
end
|
40
28
|
end
|
@@ -31,8 +31,8 @@ class Chef
|
|
31
31
|
puts ui.color("Updated tags for #{server}", :cyan)
|
32
32
|
puts ui.list(tags, :uneven_columns_across, 2)
|
33
33
|
exit 0
|
34
|
-
rescue
|
35
|
-
|
34
|
+
rescue => e
|
35
|
+
output_error(e)
|
36
36
|
exit 1
|
37
37
|
end
|
38
38
|
end
|
data/lib/knife-joyent/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-joyent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/chef/knife/joyent_fw_get.rb
|
106
106
|
- lib/chef/knife/joyent_fw_list.rb
|
107
107
|
- lib/chef/knife/joyent_fw_update.rb
|
108
|
+
- lib/chef/knife/joyent_image_create.rb
|
108
109
|
- lib/chef/knife/joyent_image_list.rb
|
109
110
|
- lib/chef/knife/joyent_key_add.rb
|
110
111
|
- lib/chef/knife/joyent_key_delete.rb
|