yun 0.0.5 → 0.0.6
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/.travis.yml +3 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +36 -8
- data/README.md +28 -4
- data/Rakefile +3 -1
- data/lib/yun/command.rb +1 -0
- data/lib/yun/commands/image_command.rb +19 -0
- data/lib/yun/commands/node_command.rb +12 -1
- data/lib/yun/commands/yun_command.rb +1 -0
- data/lib/yun/config.rb +4 -0
- data/lib/yun/model.rb +1 -0
- data/lib/yun/model/command_executor.rb +9 -0
- data/lib/yun/model/node.rb +9 -0
- data/lib/yun/model/ssh.rb +13 -1
- data/lib/yun/version.rb +1 -1
- data/spec/spec_helper.rb +2 -1
- data/spec/yun/model/node_spec.rb +3 -2
- data/spec/yun/model/ssh_spec.rb +8 -3
- data/spec/yun/version_spec.rb +1 -1
- metadata +7 -4
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,25 +2,48 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
builder (3.0.0)
|
5
|
-
|
6
|
-
|
5
|
+
columnize (0.3.6)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
excon (0.9.6)
|
8
|
+
fog (1.1.2)
|
7
9
|
builder
|
8
|
-
excon (~> 0.
|
10
|
+
excon (~> 0.9.0)
|
9
11
|
formatador (~> 0.2.0)
|
10
12
|
mime-types
|
11
13
|
multi_json (~> 1.0.3)
|
12
14
|
net-scp (~> 1.0.4)
|
13
|
-
net-ssh (
|
15
|
+
net-ssh (>= 2.1.3)
|
14
16
|
nokogiri (~> 1.5.0)
|
15
17
|
ruby-hmac
|
16
18
|
formatador (0.2.1)
|
17
|
-
hirb (0.
|
19
|
+
hirb (0.6.1)
|
20
|
+
linecache (0.46)
|
21
|
+
rbx-require-relative (> 0.0.4)
|
22
|
+
metaclass (0.0.1)
|
18
23
|
mime-types (1.17.2)
|
19
|
-
|
24
|
+
mocha (0.10.5)
|
25
|
+
metaclass (~> 0.0.1)
|
26
|
+
multi_json (1.0.4)
|
20
27
|
net-scp (1.0.4)
|
21
28
|
net-ssh (>= 1.99.1)
|
22
|
-
net-ssh (2.
|
23
|
-
nokogiri (1.5.
|
29
|
+
net-ssh (2.3.0)
|
30
|
+
nokogiri (1.5.2)
|
31
|
+
nyan-cat-formatter (0.0.6)
|
32
|
+
rake (0.9.2.2)
|
33
|
+
rbx-require-relative (0.0.9)
|
34
|
+
rspec (2.8.0)
|
35
|
+
rspec-core (~> 2.8.0)
|
36
|
+
rspec-expectations (~> 2.8.0)
|
37
|
+
rspec-mocks (~> 2.8.0)
|
38
|
+
rspec-core (2.8.0)
|
39
|
+
rspec-expectations (2.8.0)
|
40
|
+
diff-lcs (~> 1.1.2)
|
41
|
+
rspec-mocks (2.8.0)
|
42
|
+
ruby-debug (0.10.4)
|
43
|
+
columnize (>= 0.1)
|
44
|
+
ruby-debug-base (~> 0.10.4.0)
|
45
|
+
ruby-debug-base (0.10.4)
|
46
|
+
linecache (>= 0.3)
|
24
47
|
ruby-hmac (0.4.0)
|
25
48
|
thor (0.14.6)
|
26
49
|
|
@@ -30,4 +53,9 @@ PLATFORMS
|
|
30
53
|
DEPENDENCIES
|
31
54
|
fog (>= 1.0.0)
|
32
55
|
hirb
|
56
|
+
mocha
|
57
|
+
nyan-cat-formatter
|
58
|
+
rake
|
59
|
+
rspec
|
60
|
+
ruby-debug
|
33
61
|
thor
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
yun 云
|
2
2
|
======
|
3
|
+
[](http://travis-ci.org/flanker/yun)
|
3
4
|
|
4
5
|
About
|
5
6
|
-----
|
@@ -25,18 +26,40 @@ How to use
|
|
25
26
|
|
26
27
|
### config file
|
27
28
|
After installing `yun`, you need to create a config file `~/.yun`.
|
28
|
-
Basically it should contains:
|
29
29
|
|
30
|
+
Here is an example configuration:
|
31
|
+
|
32
|
+
#######################################################
|
33
|
+
# Yun Credentials File
|
34
|
+
#
|
30
35
|
:default:
|
31
36
|
:aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID
|
32
37
|
:aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY
|
33
38
|
:region: us-west-1
|
34
39
|
:key_name: YOUR_KEY_PAIR_NAME
|
35
|
-
:chef_repo: /PATH/TO/YOUR/CHEF_REPO
|
40
|
+
:chef_repo: /PATH/TO/YOUR/CHEF_REPO (optional)
|
41
|
+
:os:
|
42
|
+
:ubuntu:
|
43
|
+
:image: ami-cba1fe8e
|
44
|
+
:user: ubuntu
|
45
|
+
:amazon:
|
46
|
+
:image: ami-1bd68a5e
|
47
|
+
:user: ec2-user
|
48
|
+
:windows:
|
49
|
+
:image: ami-ed3768a8
|
50
|
+
:user:
|
51
|
+
:centos:
|
52
|
+
:image: ami-dd2f7298
|
53
|
+
:user: root
|
36
54
|
|
37
55
|
### create EC2 node
|
38
56
|
|
39
|
-
yun node create NODE_NAME
|
57
|
+
yun node create NODE_NAME --os OS_NAME --instance_type INSTANCE_TYPE
|
58
|
+
|
59
|
+
OS_NAME could be os listed in your `~/.yun` configuration file (`ubuntu`,
|
60
|
+
`amazon`, `centos`, etc).
|
61
|
+
|
62
|
+
INSTANCE_TYPE could be `micro`, `small`, etc
|
40
63
|
|
41
64
|
### list all EC2 node
|
42
65
|
|
@@ -60,4 +83,5 @@ Other
|
|
60
83
|
Feel free to contact me if you have any problem:
|
61
84
|
|
62
85
|
* flankerfc at Gmail
|
63
|
-
*
|
86
|
+
* [@fengzhichao](https://twitter.com/#!/fengzhichao)
|
87
|
+
* [@冯智超](http://www.weibo.com/flankerfc)
|
data/Rakefile
CHANGED
data/lib/yun/command.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Yun
|
2
|
+
class ImageCommand < Thor
|
3
|
+
|
4
|
+
include CommandBase
|
5
|
+
|
6
|
+
desc "image list", "list all available images"
|
7
|
+
def list
|
8
|
+
images = Config.images
|
9
|
+
result = images.keys.map do |key|
|
10
|
+
{
|
11
|
+
"image id" => images[key][:image],
|
12
|
+
"os type" => key,
|
13
|
+
"login user" => images[key][:user]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
puts Hirb::Helpers::AutoTable.render result
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -27,11 +27,22 @@ module Yun
|
|
27
27
|
method_option :instance_type, :aliases => "-t", :default => "micro", :desc => "Instance Type"
|
28
28
|
def create(node_name)
|
29
29
|
$stdout.sync = true
|
30
|
+
|
30
31
|
attributes = create_attributes node_name, options
|
32
|
+
|
31
33
|
print "creating node."
|
32
|
-
|
34
|
+
|
35
|
+
node = connection.create attributes do
|
33
36
|
print "."
|
34
37
|
end
|
38
|
+
|
39
|
+
print "node #{node_name} created."
|
40
|
+
print "\nwaiting sshd ready."
|
41
|
+
|
42
|
+
node.wait_for_ssh_ready { print "." }
|
43
|
+
|
44
|
+
print "node #{node_name} is ssh ready."
|
45
|
+
|
35
46
|
puts "\ndone"
|
36
47
|
end
|
37
48
|
|
data/lib/yun/config.rb
CHANGED
data/lib/yun/model.rb
CHANGED
data/lib/yun/model/node.rb
CHANGED
@@ -61,5 +61,14 @@ module Yun
|
|
61
61
|
@server.state == 'terminated'
|
62
62
|
end
|
63
63
|
|
64
|
+
def wait_for_ssh_ready &block
|
65
|
+
ssh_config = SshConfig.new user, key_name
|
66
|
+
ssh = Ssh.new ip, ssh_config
|
67
|
+
@server.wait_for do
|
68
|
+
instance_eval(&block) if block_given?
|
69
|
+
ssh.is_ssh_ready?
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
64
73
|
end
|
65
74
|
end
|
data/lib/yun/model/ssh.rb
CHANGED
@@ -4,15 +4,27 @@ require 'net/scp'
|
|
4
4
|
module Yun
|
5
5
|
class Ssh
|
6
6
|
|
7
|
+
attr_accessor :executor
|
8
|
+
|
7
9
|
def initialize host, ssh_config
|
8
10
|
@host = host
|
9
11
|
@ssh_config = ssh_config
|
12
|
+
self.executor = Yun::CommandExecutor.new
|
10
13
|
end
|
11
14
|
|
12
15
|
def connect
|
13
16
|
ssh_command = "ssh -i #{key_file} #{user}@#{@host}"
|
14
17
|
puts ssh_command
|
15
|
-
|
18
|
+
executor.sys_exec ssh_command
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_ssh_ready?
|
22
|
+
tcp_socket = TCPSocket.new(@host, 22)
|
23
|
+
IO.select([tcp_socket], nil, nil, 10)
|
24
|
+
rescue Exception
|
25
|
+
false
|
26
|
+
ensure
|
27
|
+
tcp_socket && tcp_socket.close
|
16
28
|
end
|
17
29
|
|
18
30
|
def chef role
|
data/lib/yun/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/yun/model/node_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'fog/aws/models/compute/server'
|
2
3
|
|
3
4
|
describe Yun::Node do
|
4
5
|
|
@@ -46,7 +47,7 @@ describe Yun::Node do
|
|
46
47
|
|
47
48
|
end
|
48
49
|
|
49
|
-
context 'node
|
50
|
+
context 'node creation' do
|
50
51
|
|
51
52
|
before do
|
52
53
|
attributes = { :tags => { "name" => 'test node' } }
|
@@ -61,7 +62,7 @@ describe Yun::Node do
|
|
61
62
|
|
62
63
|
end
|
63
64
|
|
64
|
-
context 'destroy' do
|
65
|
+
context 'node destroy' do
|
65
66
|
|
66
67
|
before do
|
67
68
|
@connection = Yun::Connection.new options
|
data/spec/yun/model/ssh_spec.rb
CHANGED
@@ -3,12 +3,17 @@ require 'spec_helper'
|
|
3
3
|
describe Yun::Ssh do
|
4
4
|
|
5
5
|
before do
|
6
|
-
|
6
|
+
ssh_config = Yun::SshConfig.new "user", "test_key"
|
7
|
+
@ssh = Yun::Ssh.new "127.0.0.1", ssh_config
|
8
|
+
@fake_executor = mock 'executor'
|
9
|
+
@ssh.executor = @fake_executor
|
7
10
|
end
|
8
11
|
|
9
12
|
it 'should execute the correct ssh command' do
|
10
|
-
|
13
|
+
expected_command = "ssh -i ~/.ssh/test_key.pem user@127.0.0.1"
|
14
|
+
@fake_executor.expects(:sys_exec).with(expected_command).returns(true)
|
11
15
|
|
12
|
-
|
16
|
+
@ssh.connect.should be_true
|
13
17
|
end
|
18
|
+
|
14
19
|
end
|
data/spec/yun/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Feng Zhichao
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-04-15 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fog
|
@@ -92,6 +92,7 @@ extra_rdoc_files: []
|
|
92
92
|
files:
|
93
93
|
- .gitignore
|
94
94
|
- .rvmrc
|
95
|
+
- .travis.yml
|
95
96
|
- Gemfile
|
96
97
|
- Gemfile.lock
|
97
98
|
- README.md
|
@@ -100,10 +101,12 @@ files:
|
|
100
101
|
- lib/yun.rb
|
101
102
|
- lib/yun/command.rb
|
102
103
|
- lib/yun/commands/command_base.rb
|
104
|
+
- lib/yun/commands/image_command.rb
|
103
105
|
- lib/yun/commands/node_command.rb
|
104
106
|
- lib/yun/commands/yun_command.rb
|
105
107
|
- lib/yun/config.rb
|
106
108
|
- lib/yun/model.rb
|
109
|
+
- lib/yun/model/command_executor.rb
|
107
110
|
- lib/yun/model/connection.rb
|
108
111
|
- lib/yun/model/fog_attributes.rb
|
109
112
|
- lib/yun/model/instance_type.rb
|