knife-joyent 0.0.5 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/knife-joyent.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $:.unshift File.expand_path("../lib", __FILE__)
3
3
  require 'knife-joyent/version'
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -34,11 +34,11 @@ module KnifeJoyent
34
34
  :description => 'path to ssh private key for signature auth',
35
35
  :proc => Proc.new {|key| Chef::Config[:knife][:joyent_keyfile] = key }
36
36
 
37
- option :joyent_url,
37
+ option :joyent_api_url,
38
38
  :short => "-L JOYENT_API_URL",
39
39
  :long => "--joyent-api-url JOYENT_API_URL",
40
40
  :description => "Joyent API URL",
41
- :proc => Proc.new {|key| Chef::Config[:knife][:joyent_url] = key }
41
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_api_url] = key }
42
42
  end
43
43
 
44
44
  def connection
@@ -49,7 +49,7 @@ module KnifeJoyent
49
49
  :joyent_password => Chef::Config[:knife][:joyent_password],
50
50
  :joyent_keyname => Chef::Config[:knife][:joyent_keyname],
51
51
  :joyent_keyfile => Chef::Config[:knife][:joyent_keyfile],
52
- :joyent_url => Chef::Config[:knife][:joyent_url]
52
+ :joyent_url => Chef::Config[:knife][:joyent_api_url]
53
53
  )
54
54
  end
55
55
  end
@@ -3,35 +3,160 @@ module KnifeJoyent
3
3
 
4
4
  include KnifeJoyent::Base
5
5
 
6
+ deps do
7
+ require 'chef/knife/bootstrap'
8
+ Chef::Knife::Bootstrap.load_deps
9
+ require 'fog'
10
+ require 'socket'
11
+ require 'net/ssh/multi'
12
+ require 'readline'
13
+ require 'chef/json_compat'
14
+ end
15
+
6
16
  banner 'knife joyent server create (options)'
7
17
 
18
+ # mixlib option parsing
8
19
  option :name,
9
20
  :long => '--name <name>',
10
21
  :description => 'name for this machine'
11
22
 
12
23
  option :package,
13
- :long => '--flavor <name>',
24
+ :short => '-f FLAVOR_NAME',
25
+ :long => '--flavor FLAVOR_NAME',
14
26
  :description => 'specify flavor/package for the server'
15
27
 
16
28
  option :dataset,
17
- :short => '--image <id>',
29
+ :short => '-I IMAGE_ID',
30
+ :long => '--image IMAGE_ID',
18
31
  :description => 'specify image for the server'
19
32
 
33
+ option :run_list,
34
+ :short => "-r RUN_LIST",
35
+ :long => "--run-list RUN_LIST",
36
+ :description => "Comma separated list of roles/recipes to apply",
37
+ :proc => lambda { |o| o.split(/[\s,]+/) },
38
+ :default => []
39
+
40
+ option :ssh_user,
41
+ :short => "-x USERNAME",
42
+ :long => "--ssh-user USERNAME",
43
+ :description => "The ssh username",
44
+ :default => "root"
45
+
46
+ option :identity_file,
47
+ :short => "-i IDENTITY_FILE",
48
+ :long => "--identity-file IDENTITY_FILE",
49
+ :description => "The SSH identity file used for authentication"
50
+
51
+ option :chef_node_name,
52
+ :short => "-N NAME",
53
+ :long => "--node-name NAME",
54
+ :description => "The Chef node name for your new node"
55
+
56
+ option :prerelease,
57
+ :long => "--prerelease",
58
+ :description => "Install the pre-release chef gems"
59
+
60
+ option :distro,
61
+ :short => "-d DISTRO",
62
+ :long => "--distro DISTRO",
63
+ :description => "Bootstrap a distro using a template",
64
+ :proc => Proc.new { |d| Chef::Config[:knife][:distro] = d },
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
+
74
+ option :no_host_key_verify,
75
+ :long => "--no-host-key-verify",
76
+ :description => "Disable host key verification",
77
+ :boolean => true,
78
+ :default => false
79
+
80
+ # wait for ssh to come up
81
+ def tcp_test_ssh(hostname)
82
+ tcp_socket = TCPSocket.new(hostname, 22)
83
+ readable = IO.select([tcp_socket], nil, nil, 5)
84
+ if readable
85
+ Chef::Log.debug("sshd accepting connections on #{hostname}, banner is #{tcp_socket.gets}")
86
+ yield
87
+ true
88
+ else
89
+ false
90
+ end
91
+ rescue Errno::ETIMEDOUT
92
+ false
93
+ rescue Errno::EPERM
94
+ false
95
+ rescue Errno::ECONNREFUSED
96
+ sleep 2
97
+ false
98
+ rescue Errno::EHOSTUNREACH
99
+ sleep 2
100
+ false
101
+ ensure
102
+ tcp_socket && tcp_socket.close
103
+ end
104
+
105
+
106
+ # Run Chef bootstrap script
107
+ def bootstrap_for_node(server)
108
+ bootstrap = Chef::Knife::Bootstrap.new
109
+ Chef::Log.debug("Bootstrap name_args = [ #{server.ips.last} ]")
110
+ bootstrap.name_args = [ server.ips.last ]
111
+ Chef::Log.debug("Bootstrap run_list = #{config[:run_list]}")
112
+ bootstrap.config[:run_list] = config[:run_list]
113
+ Chef::Log.debug("Bootstrap ssh_user = #{config[:ssh_user]}")
114
+ bootstrap.config[:ssh_user] = config[:ssh_user]
115
+ Chef::Log.debug("Bootstrap identity_file = #{config[:identity_file]}")
116
+ bootstrap.config[:identity_file] = config[:identity_file]
117
+ Chef::Log.debug("Bootstrap chef_node_name = #{config[:chef_node_name]}")
118
+ bootstrap.config[:chef_node_name] = config[:chef_node_name] || server.id
119
+ Chef::Log.debug("Bootstrap prerelease = #{config[:prerelease]}")
120
+ bootstrap.config[:prerelease] = config[:prerelease]
121
+ Chef::Log.debug("Bootstrap distro = #{config[:distro]}")
122
+ bootstrap.config[:distro] = config[:distro]
123
+ #Chef::Log.debug("Bootstrap use_sudo = #{config[:use_sudo]}")
124
+ #bootstrap.config[:use_sudo] = true
125
+ Chef::Log.debug("Bootstrap environment = #{config[:environment]}")
126
+ bootstrap.config[:environment] = config[:environment]
127
+ Chef::Log.debug("Bootstrap no_host_key_verify = #{config[:no_host_key_verify]}")
128
+ bootstrap.config[:no_host_key_verify] = config[:no_host_key_verify]
129
+
130
+ bootstrap
131
+ end
132
+
133
+ # Go
20
134
  def run
21
- if s = self.connection.servers.create(:dataset => config[:dataset],
135
+ begin
136
+ server = self.connection.servers.create(:dataset => config[:dataset],
22
137
  :package => config[:package],
23
138
  :name => config[:name])
24
- puts ui.color("Created machine: #{s.id}", :cyan)
25
- exit 0
26
- end
27
- rescue => 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
- raise
139
+
140
+ rescue => e
141
+ Chef::Log.debug("e: #{e}")
142
+ if e.response && e.response.body.kind_of?(String)
143
+ error = MultiJson.decode(e.response.body)
144
+ puts ui.error(error['message'])
145
+ exit 1
146
+ else
147
+ raise
148
+ end
34
149
  end
150
+
151
+ puts ui.color("Created machine: #{server.id}", :cyan)
152
+ puts ui.color("attempting to bootstrap on #{server.ips.last}", :cyan)
153
+
154
+ print(".") until tcp_test_ssh(server.ips.last) {
155
+ sleep 1
156
+ puts("done")
157
+ }
158
+ bootstrap_for_node(server).run
159
+ exit 0
35
160
  end
36
161
 
37
162
  end
@@ -20,7 +20,9 @@ module KnifeJoyent
20
20
  ui.color('Disk', :bold),
21
21
  ]
22
22
 
23
- self.connection.servers.sort_by(&:name).each do |s|
23
+ self.connection.servers.sort do |a, b|
24
+ (a.name || '') <=> (b.name || '')
25
+ end.each do |s|
24
26
  servers << s.id.to_s
25
27
  servers << s.name
26
28
 
@@ -1,3 +1,3 @@
1
1
  module KnifeJoyent
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,63 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: knife-joyent
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Kevin Chan
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-22 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: fog
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 9
29
- segments:
30
- - 1
31
- - 3
32
- version: "1.3"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: chef
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: chef
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
- requirements:
34
+ requirements:
41
35
  - - ~>
42
- - !ruby/object:Gem::Version
43
- hash: 31
44
- segments:
45
- - 0
46
- - 10
47
- version: "0.10"
36
+ - !ruby/object:Gem::Version
37
+ version: '0.10'
48
38
  type: :runtime
49
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.10'
50
46
  description: Joyent CloudAPI Support for Chef's Knife Command
51
- email:
47
+ email:
52
48
  - kevin@joyent.com
53
49
  executables: []
54
-
55
50
  extensions: []
56
-
57
- extra_rdoc_files:
51
+ extra_rdoc_files:
58
52
  - README.md
59
53
  - LICENSE
60
- files:
54
+ files:
61
55
  - .gitignore
62
56
  - Gemfile
63
57
  - LICENSE
@@ -86,36 +80,26 @@ files:
86
80
  - lib/knife-joyent/version.rb
87
81
  homepage: https://github.com/kevinykchan/knife-joyent
88
82
  licenses: []
89
-
90
83
  post_install_message:
91
84
  rdoc_options: []
92
-
93
- require_paths:
85
+ require_paths:
94
86
  - lib
95
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ required_ruby_version: !ruby/object:Gem::Requirement
96
88
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
94
  none: false
106
- requirements:
107
- - - ">="
108
- - !ruby/object:Gem::Version
109
- hash: 3
110
- segments:
111
- - 0
112
- version: "0"
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
113
99
  requirements: []
114
-
115
100
  rubyforge_project:
116
101
  rubygems_version: 1.8.21
117
102
  signing_key:
118
103
  specification_version: 3
119
104
  summary: Joyent CloudAPI Support for Chef's Knife Command
120
105
  test_files: []
121
-