knife-joyent 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/knife-joyent.gemspec +3 -3
- data/lib/chef/knife/joyent_base.rb +60 -0
- data/lib/chef/knife/joyent_flavor_list.rb +20 -19
- data/lib/chef/knife/joyent_image_list.rb +23 -21
- data/lib/chef/knife/joyent_key_add.rb +39 -38
- data/lib/chef/knife/joyent_key_delete.rb +23 -22
- data/lib/chef/knife/joyent_key_list.rb +17 -16
- data/lib/chef/knife/joyent_server_create.rb +238 -151
- data/lib/chef/knife/joyent_server_delete.rb +58 -56
- data/lib/chef/knife/joyent_server_list.rb +47 -44
- data/lib/chef/knife/joyent_server_reboot.rb +24 -23
- data/lib/chef/knife/joyent_server_resize.rb +41 -40
- data/lib/chef/knife/joyent_server_start.rb +29 -27
- data/lib/chef/knife/joyent_server_stop.rb +28 -27
- data/lib/chef/knife/joyent_snapshot_create.rb +16 -15
- data/lib/chef/knife/joyent_snapshot_delete.rb +30 -29
- data/lib/chef/knife/joyent_snapshot_list.rb +34 -33
- data/lib/chef/knife/joyent_tag_create.rb +29 -27
- data/lib/chef/knife/joyent_tag_delete.rb +45 -43
- data/lib/chef/knife/joyent_tag_list.rb +26 -24
- data/lib/knife-joyent/version.rb +1 -1
- metadata +9 -9
- data/lib/chef/knife/base.rb +0 -58
@@ -1,33 +1,34 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentServerReboot < Knife
|
3
6
|
|
4
|
-
|
5
|
-
class JoyentServerReboot < Chef::Knife
|
7
|
+
include Knife::JoyentBase
|
6
8
|
|
7
|
-
|
9
|
+
banner 'knife joyent server reboot <server_id>'
|
8
10
|
|
9
|
-
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
unless name_args.size === 1
|
13
|
-
show_usage
|
14
|
-
exit 1
|
15
|
-
end
|
16
|
-
|
17
|
-
id = name_args.first
|
17
|
+
id = name_args.first
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
server = self.connection.servers.get(id)
|
20
|
+
unless server
|
21
|
+
puts ui.error("Server with id: #{id} not found")
|
22
|
+
exit 1
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
if server.reboot
|
26
|
+
puts ui.color("Rebooted Server #{id}", :cyan)
|
27
|
+
exit 0
|
28
|
+
else
|
29
|
+
puts ui.error("Reboot server failed")
|
30
|
+
exit 1
|
31
|
+
end
|
31
32
|
end
|
32
33
|
end
|
33
34
|
end
|
@@ -1,43 +1,44 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
require 'chef/knife/joyent_base'
|
2
|
+
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentServerResize < Knife
|
6
|
+
|
7
|
+
include Knife::JoyentBase
|
8
|
+
|
9
|
+
banner 'knife joyent server resize <server_id> -f <flavor>'
|
10
|
+
|
11
|
+
option :flavor,
|
12
|
+
:short => "-f <flavor>",
|
13
|
+
:long => "--flavor <flavor>",
|
14
|
+
:description => "name of flavor/package to resize to"
|
15
|
+
|
16
|
+
def run
|
17
|
+
unless config[:flavor]
|
18
|
+
show_usage
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
unless name_args.size === 1
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
id = name_args.first
|
28
|
+
|
29
|
+
server = self.connection.servers.get(id)
|
30
|
+
unless server
|
31
|
+
puts ui.error("Server with id: #{id} not found")
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
if self.connection.resize_machine(id, config[:flavor])
|
36
|
+
puts ui.color("Resized server #{id}", :cyan)
|
37
|
+
exit 0
|
38
|
+
else
|
39
|
+
puts ui.error("Resize server failed")
|
40
|
+
exit 1
|
41
|
+
end
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
@@ -1,39 +1,41 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentServerStart < Knife
|
5
6
|
|
6
|
-
|
7
|
+
include Knife::JoyentBase
|
7
8
|
|
8
|
-
|
9
|
+
banner 'knife joyent server start <server_id>'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
+
id = name_args.first
|
17
18
|
|
18
|
-
|
19
|
+
server = self.connection.servers.get(id)
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
unless server
|
22
|
+
puts ui.error("Unable to locate server: #{id}")
|
23
|
+
exit 1
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
if server.ready?
|
27
|
+
puts ui.error("Server is already started")
|
28
|
+
exit 1
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
if server.start
|
32
|
+
puts ui.color("Started server: #{id}", :cyan)
|
33
|
+
exit 0
|
34
|
+
else
|
35
|
+
puts ui.error("Start server failed")
|
36
|
+
exit 1
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
39
|
+
end
|
38
40
|
end
|
39
41
|
end
|
@@ -1,39 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentServerStop < Knife
|
3
6
|
|
4
|
-
|
5
|
-
class JoyentServerStop < Chef::Knife
|
7
|
+
include Knife::JoyentBase
|
6
8
|
|
7
|
-
|
9
|
+
banner 'knife joyent server stop <server_id>'
|
8
10
|
|
9
|
-
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
10
16
|
|
11
|
-
|
12
|
-
unless name_args.size === 1
|
13
|
-
show_usage
|
14
|
-
exit 1
|
15
|
-
end
|
16
|
-
|
17
|
-
id = name_args.first
|
17
|
+
id = name_args.first
|
18
18
|
|
19
|
-
|
19
|
+
server = self.connection.servers.get(id)
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
unless server
|
22
|
+
puts ui.error("Unable to locate server: #{id}")
|
23
|
+
exit 1
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
if server.stopped?
|
27
|
+
puts ui.error("Server #{id} is already stopped")
|
28
|
+
exit 1
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
if server.stop
|
32
|
+
puts ui.color("Stopped server: #{id}", :cyan)
|
33
|
+
exit 0
|
34
|
+
else
|
35
|
+
puts ui.error("Failed to stop server")
|
36
|
+
exit 1
|
37
|
+
end
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentSnapshotCreate < Knife
|
5
6
|
|
6
|
-
include
|
7
|
+
include Knife::JoyentBase
|
7
8
|
|
8
9
|
banner 'knife joyent snapshot create <server> <snapshot_name>'
|
9
10
|
|
@@ -25,19 +26,19 @@ module KnifeJoyent
|
|
25
26
|
:created => snapshot.created
|
26
27
|
})
|
27
28
|
exit 0
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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)
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
rescue => e
|
39
|
+
puts ui.error('Unexpected Error Occured:' + e.message)
|
35
40
|
exit 1
|
36
41
|
end
|
37
|
-
rescue => e
|
38
|
-
puts ui.error('Unexpected Error Occured:' + e.message)
|
39
|
-
exit 1
|
40
42
|
end
|
41
|
-
|
42
43
|
end
|
43
44
|
end
|
@@ -1,41 +1,42 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentSnapshotDelete < Knife
|
5
6
|
|
6
|
-
|
7
|
+
include Knife::JoyentBase
|
7
8
|
|
8
|
-
|
9
|
+
banner 'knife joyent snapshot delete <server> <snapshot_name>'
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def run
|
12
|
+
unless name_args.size == 2
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
17
|
+
server = name_args[0]
|
18
|
+
ssname = name_args[1]
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
exit 1
|
26
|
-
rescue Excon::Errors::Conflict => e
|
27
|
-
if e.response && e.response.body.kind_of?(String)
|
28
|
-
error = MultiJson.decode(e.response.body)
|
29
|
-
puts ui.error(error['message'])
|
20
|
+
snapshot = self.connection.snapshots.get(server, ssname)
|
21
|
+
snapshot.destroy
|
22
|
+
puts ui.color("Deleted snapshot #{snapshot.name}", :cyan)
|
23
|
+
exit 0
|
24
|
+
rescue Excon::Errors::NotFound => e
|
25
|
+
puts ui.error("Snapshot #{ssname} on server #{server} not found")
|
30
26
|
exit 1
|
31
|
-
|
32
|
-
|
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
|
+
rescue => e
|
37
|
+
puts ui.error('Unexpected Error Occured:' + e.message)
|
33
38
|
exit 1
|
34
39
|
end
|
35
|
-
rescue => e
|
36
|
-
puts ui.error('Unexpected Error Occured:' + e.message)
|
37
|
-
exit 1
|
38
40
|
end
|
39
|
-
|
40
41
|
end
|
41
42
|
end
|
@@ -1,44 +1,45 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentSnapshotList < Knife
|
3
6
|
|
4
|
-
|
5
|
-
class JoyentSnapshotList < Chef::Knife
|
7
|
+
include Knife::JoyentBase
|
6
8
|
|
7
|
-
|
9
|
+
banner "knife joyent snapshot list <server_id>"
|
8
10
|
|
9
|
-
|
11
|
+
def run
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
exit 1
|
16
|
-
end
|
13
|
+
unless name_args.size == 1
|
14
|
+
show_usage
|
15
|
+
exit 1
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
server = name_args.first
|
19
|
+
|
20
|
+
snapshots = [
|
21
|
+
ui.color('ID', :bold),
|
22
|
+
ui.color('State', :bold),
|
23
|
+
ui.color('Created', :bold),
|
24
|
+
]
|
25
|
+
|
26
|
+
self.connection.snapshots.all(server).each do |s|
|
27
|
+
snapshots << ui.color(s.name, :bold)
|
28
|
+
snapshots << case s.state
|
29
|
+
when "queued" then
|
30
|
+
ui.color(s.state, :yellow)
|
31
|
+
when "success" then
|
32
|
+
ui.color(s.state, :green)
|
33
|
+
else
|
34
|
+
ui.color(s.state, :red)
|
35
|
+
end
|
36
|
+
snapshots << s.created.to_s
|
35
37
|
end
|
36
|
-
snapshots << s.created.to_s
|
37
|
-
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
puts ui.list(snapshots, :uneven_columns_across, 3)
|
40
|
+
rescue Fog::Compute::Joyent::Errors::NotFound
|
41
|
+
puts ui.error("Server #{server} not found.")
|
42
|
+
end
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
@@ -1,38 +1,40 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentTagCreate < Knife
|
5
6
|
|
6
|
-
|
7
|
+
include Knife::JoyentBase
|
7
8
|
|
8
|
-
|
9
|
+
banner "knife joyent tag create <server_id> <tag> <value>"
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
def run
|
12
|
+
server = name_args[0]
|
13
|
+
tagkey = name_args[1]
|
14
|
+
tagvalue = name_args[2]
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
unless server || tagkey || tagvalue
|
17
|
+
show_usage
|
18
|
+
exit 1
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
tags = [
|
22
|
+
ui.color('Name', :bold),
|
23
|
+
ui.color('Value', :bold),
|
24
|
+
]
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
self.connection.servers.get(server).add_tags({tagkey => tagvalue}).each do |k, v|
|
27
|
+
tags << k
|
28
|
+
tags << v
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
puts ui.color("Updated tags for #{server}", :cyan)
|
32
|
+
puts ui.list(tags, :uneven_columns_across, 2)
|
33
|
+
exit 0
|
34
|
+
rescue Excon::Errors::NotFound => e
|
35
|
+
puts ui.error("Server #{server} not found")
|
36
|
+
exit 1
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -1,62 +1,64 @@
|
|
1
|
-
require
|
1
|
+
require 'chef/knife/joyent_base'
|
2
2
|
|
3
|
-
|
4
|
-
class
|
3
|
+
class Chef
|
4
|
+
class Knife
|
5
|
+
class JoyentTagDelete < Knife
|
5
6
|
|
6
|
-
|
7
|
+
include Knife::JoyentBase
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
banner ["knife joyent tag delete <server_id> <tag>",
|
10
|
+
"knife joyent tag delete <server_id> -A"].join("\n")
|
10
11
|
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
option :all,
|
14
|
+
:short => "-A",
|
15
|
+
:long => "--all",
|
16
|
+
:boolean => true,
|
17
|
+
:description => "delete all tags on the machine"
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
def run
|
20
|
+
server_id = name_args[0]
|
21
|
+
tagname = name_args[1]
|
22
|
+
all = config[:all]
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
begin
|
29
|
-
server = self.connection.servers.get(server_id)
|
30
|
-
rescue Excon::Errors::NotFound => e
|
31
|
-
puts ui.error("Server #{server_id} not found")
|
32
|
-
exit 1
|
33
|
-
end
|
24
|
+
if !server_id || (all == false && !tagname) || (all && tagname)
|
25
|
+
show_usage
|
26
|
+
exit 1
|
27
|
+
end
|
34
28
|
|
35
|
-
if all
|
36
|
-
server.delete_all_tags
|
37
|
-
puts ui.color("Deleted all tags for #{server_id}", :cyan)
|
38
|
-
exit 0
|
39
|
-
else
|
40
29
|
begin
|
41
|
-
server.
|
30
|
+
server = self.connection.servers.get(server_id)
|
42
31
|
rescue Excon::Errors::NotFound => e
|
43
|
-
puts ui.error("
|
32
|
+
puts ui.error("Server #{server_id} not found")
|
44
33
|
exit 1
|
45
34
|
end
|
46
35
|
|
47
|
-
|
48
|
-
|
49
|
-
ui.color(
|
50
|
-
|
36
|
+
if all
|
37
|
+
server.delete_all_tags
|
38
|
+
puts ui.color("Deleted all tags for #{server_id}", :cyan)
|
39
|
+
exit 0
|
40
|
+
else
|
41
|
+
begin
|
42
|
+
server.delete_tag(tagname)
|
43
|
+
rescue Excon::Errors::NotFound => e
|
44
|
+
puts ui.error("Tag #{tagname} on server #{server_id} not found")
|
45
|
+
exit 1
|
46
|
+
end
|
51
47
|
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
tags = [
|
49
|
+
ui.color('Name', :bold),
|
50
|
+
ui.color('Value', :bold),
|
51
|
+
]
|
52
|
+
|
53
|
+
server.reload.tags.each do |k, v|
|
54
|
+
tags << k
|
55
|
+
tags << v
|
56
|
+
end
|
57
|
+
puts ui.color("Deleted tag #{tagname} for #{server_id}", :cyan)
|
58
|
+
puts ui.list(tags, :uneven_columns_across, 2)
|
55
59
|
end
|
56
|
-
|
57
|
-
puts ui.list(tags, :uneven_columns_across, 2)
|
60
|
+
exit 0
|
58
61
|
end
|
59
|
-
exit 0
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|