knife-joyent 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/base')
2
+
1
3
  module KnifeJoyent
2
4
  class JoyentServerCreate < Chef::Knife
3
5
 
4
6
  include KnifeJoyent::Base
5
7
 
6
8
  deps do
7
- require 'chef/knife/bootstrap'
8
- Chef::Knife::Bootstrap.load_deps
9
9
  require 'fog'
10
- require 'socket'
11
- require 'net/ssh/multi'
12
10
  require 'readline'
13
11
  require 'chef/json_compat'
12
+ require 'chef/knife/bootstrap'
13
+ Chef::Knife::Bootstrap.load_deps
14
14
  end
15
15
 
16
16
  banner 'knife joyent server create (options)'
@@ -63,14 +63,7 @@ module KnifeJoyent
63
63
  :description => "Bootstrap a distro using a template",
64
64
  :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
65
65
  :default => "chef-full"
66
-
67
- option :environment,
68
- :short => "-E Environment",
69
- :long => "--environment ENVIRONMENT",
70
- :description => "Assign an environment to Chef Node",
71
- :proc => Proc.new { |e| Chef::Config[:environment][:distro] = e },
72
- :default => "_default"
73
-
66
+
74
67
  option :no_host_key_verify,
75
68
  :long => "--no-host-key-verify",
76
69
  :description => "Disable host key verification",
@@ -132,11 +125,12 @@ module KnifeJoyent
132
125
 
133
126
  # Go
134
127
  def run
128
+ puts ui.color("Creating machine #{config[:chef_node_name]}", :cyan)
135
129
  begin
136
130
  server = self.connection.servers.create(:dataset => config[:dataset],
137
131
  :package => config[:package],
138
132
  :name => config[:name])
139
-
133
+ server.wait_for { print "."; ready? }
140
134
  rescue => e
141
135
  Chef::Log.debug("e: #{e}")
142
136
  if e.response && e.response.body.kind_of?(String)
@@ -147,8 +141,14 @@ module KnifeJoyent
147
141
  raise
148
142
  end
149
143
  end
150
-
151
- puts ui.color("Created machine: #{server.id}", :cyan)
144
+
145
+ puts ui.color("Created machine:", :cyan)
146
+ msg("ID", server.id.to_s)
147
+ msg("Name", server.name)
148
+ msg("State", server.state)
149
+ msg("Type", server.type)
150
+ msg("Dataset", server.dataset)
151
+ msg("IP's", server.ips)
152
152
  puts ui.color("attempting to bootstrap on #{server.ips.last}", :cyan)
153
153
 
154
154
  print(".") until tcp_test_ssh(server.ips.last) {
@@ -158,6 +158,11 @@ module KnifeJoyent
158
158
  bootstrap_for_node(server).run
159
159
  exit 0
160
160
  end
161
-
161
+
162
+ def msg(label, value = nil)
163
+ if value && !value.empty?
164
+ puts "#{ui.color(label, :cyan)}: #{value}"
165
+ end
166
+ end
162
167
  end
163
168
  end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/base')
2
+
3
+ require 'chef/api_client'
4
+
5
+ module KnifeJoyent
6
+ class JoyentServerDelete < Chef::Knife
7
+
8
+ include KnifeJoyent::Base
9
+
10
+ banner 'knife joyent server delete <server_id>'
11
+
12
+ def run
13
+ unless name_args.size === 1
14
+ show_usage
15
+ exit 1
16
+ end
17
+
18
+ id = name_args.first
19
+
20
+ server = self.connection.servers.get(id)
21
+
22
+ msg("ID", server.id.to_s)
23
+ msg("Name", server.name)
24
+ msg("State", server.state)
25
+ msg("Type", server.type)
26
+ msg("Dataset", server.dataset)
27
+ msg("IP's", server.ips)
28
+
29
+ unless server
30
+ puts ui.error("Unable to locate server: #{id}")
31
+ exit 1
32
+ end
33
+
34
+ puts "\n"
35
+ confirm("Do you really want to delete this server")
36
+
37
+ puts ui.color("Stopping server...", :cyan)
38
+
39
+ if server.stopped?
40
+ puts ui.color("Server #{id} is already stopped", :cyan)
41
+ else
42
+ if server.stop
43
+ puts ui.color("Server stopped", :cyan)
44
+ else
45
+ puts ui.error("Failed to stop server")
46
+ exit 1
47
+ end
48
+ end
49
+
50
+ server.destroy
51
+ puts ui.color("Deleted server: #{id}", :cyan)
52
+
53
+ puts "\n"
54
+ confirm("Delete client and node for #{server.name}?")
55
+
56
+ node = Chef::Node.load(server.name)
57
+ puts "deleting node #{node.name}"
58
+ node.destroy
59
+ ui.warn("Deleted node named #{node.name}")
60
+
61
+ client = Chef::ApiClient.load(server.name)
62
+ puts "deleting client #{client.name}"
63
+ client.destroy
64
+ ui.warn("Deleted client named #{client.name}")
65
+ end
66
+
67
+ def msg(label, value)
68
+ if value && !value.empty?
69
+ puts "#{ui.color(label, :cyan)}: #{value}"
70
+ end
71
+ end
72
+ end
73
+ end
@@ -29,11 +29,12 @@ module KnifeJoyent
29
29
  servers << case s.state
30
30
  when 'running'
31
31
  ui.color(s.state, :green)
32
- when 'stopping'
33
- when 'provisioning'
32
+ when 'stopping', 'provisioning'
34
33
  ui.color(s.state, :yellow)
35
34
  when 'stopped'
36
35
  ui.color(s.state, :red)
36
+ else
37
+ ui.color('unknown', :red)
37
38
  end
38
39
 
39
40
  servers << s.type
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/base')
2
+
1
3
  module KnifeJoyent
2
4
  class JoyentSnapshotCreate < Chef::Knife
3
5
 
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/base')
2
+
1
3
  module KnifeJoyent
2
4
  class JoyentSnapshotDelete < Chef::Knife
3
5
 
@@ -1,3 +1,3 @@
1
1
  module KnifeJoyent
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-joyent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
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: 2012-07-17 00:00:00.000000000 Z
12
+ date: 2012-09-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
@@ -65,6 +65,7 @@ files:
65
65
  - lib/chef/knife/joyent_key_delete.rb
66
66
  - lib/chef/knife/joyent_key_list.rb
67
67
  - lib/chef/knife/joyent_server_create.rb
68
+ - lib/chef/knife/joyent_server_delete.rb
68
69
  - lib/chef/knife/joyent_server_list.rb
69
70
  - lib/chef/knife/joyent_server_reboot.rb
70
71
  - lib/chef/knife/joyent_server_resize.rb