yun 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ nguage: ruby
2
+ rvm:
3
+ - 1.8.7
data/Gemfile CHANGED
@@ -1,5 +1,13 @@
1
1
  source "http://rubygems.org"
2
2
 
3
+ gem 'rake'
3
4
  gem 'fog', '>= 1.0.0'
4
5
  gem 'hirb'
5
6
  gem 'thor'
7
+
8
+ group :test do
9
+ gem 'rspec'
10
+ gem 'mocha'
11
+ gem 'ruby-debug'
12
+ gem 'nyan-cat-formatter'
13
+ end
@@ -2,25 +2,48 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  builder (3.0.0)
5
- excon (0.7.6)
6
- fog (1.0.0)
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.7.3)
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 (~> 2.1.4)
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.5.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
- multi_json (1.0.3)
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.1.4)
23
- nokogiri (1.5.0)
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
+ [![Build Status](https://secure.travis-ci.org/flanker/yun.png?branch=master)](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
- * @冯智超 at Sina Weibo
86
+ * [@fengzhichao](https://twitter.com/#!/fengzhichao)
87
+ * [@冯智超](http://www.weibo.com/flankerfc)
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  require 'rspec/core/rake_task'
2
- RSpec::Core::RakeTask.new('spec')
2
+ RSpec::Core::RakeTask.new('spec') do |t|
3
+ t.rspec_opts = '--format NyanCatFormatter'
4
+ end
3
5
 
4
6
  task :default => :spec
@@ -2,4 +2,5 @@ require 'thor'
2
2
  require 'thor/group'
3
3
  require 'yun/commands/command_base'
4
4
  require 'yun/commands/node_command'
5
+ require 'yun/commands/image_command'
5
6
  require 'yun/commands/yun_command'
@@ -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
- connection.create attributes do
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
 
@@ -22,6 +22,7 @@ module Yun
22
22
  end
23
23
 
24
24
  register NodeCommand, :node, "node SUBCOMMAND", "commands for node"
25
+ register ImageCommand, :image, "image SUBCOMMAND", "commands for image"
25
26
 
26
27
  private
27
28
  end
@@ -31,6 +31,10 @@ module Yun
31
31
  setting[:os][os_name.to_sym][:user]
32
32
  end
33
33
 
34
+ def self.images
35
+ setting[:os]
36
+ end
37
+
34
38
  private
35
39
  def self.setting
36
40
  @setting ||= YAML.load_file(config_file)[:default]
@@ -1,4 +1,5 @@
1
1
  require 'fog'
2
+ require 'yun/model/command_executor'
2
3
  require 'yun/model/instance_type'
3
4
  require 'yun/model/connection'
4
5
  require 'yun/model/fog_attributes'
@@ -0,0 +1,9 @@
1
+ module Yun
2
+ class CommandExecutor
3
+
4
+ def sys_exec command
5
+ exec command
6
+ end
7
+
8
+ end
9
+ end
@@ -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
@@ -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
- exec ssh_command
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
@@ -1,3 +1,3 @@
1
1
  module Yun
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -1,10 +1,11 @@
1
+ require 'rubygems'
1
2
  require 'rspec'
2
3
  require 'fog'
3
4
  require 'yun'
5
+ require 'mocha'
4
6
 
5
7
  Fog.mock!
6
8
 
7
9
  RSpec.configure do |config|
8
10
  config.color_enabled = true
9
- config.formatter = 'documentation'
10
11
  end
@@ -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 name' do
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
@@ -3,12 +3,17 @@ require 'spec_helper'
3
3
  describe Yun::Ssh do
4
4
 
5
5
  before do
6
- @ssh_config = Yun::SshConfig.new "user", "test_key"
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
- ssh = Yun::Ssh.new "127.0.0.1", @ssh_config
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
- # ssh.connect
16
+ @ssh.connect.should be_true
13
17
  end
18
+
14
19
  end
@@ -3,6 +3,6 @@ require 'yun/version'
3
3
 
4
4
  describe Yun do
5
5
  it 'should return the version' do
6
- Yun::VERSION.should == '0.0.5'
6
+ Yun::VERSION.should == '0.0.6'
7
7
  end
8
8
  end
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
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-01-08 00:00:00 Z
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