yun 0.0.3 → 0.0.4
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/.gitignore +1 -0
- data/README.md +63 -0
- data/lib/yun/command.rb +5 -0
- data/lib/yun/commands/node_command.rb +2 -4
- data/lib/yun/commands/yun_command.rb +13 -9
- data/lib/yun/config.rb +4 -0
- data/lib/yun/model/ssh.rb +79 -0
- data/lib/yun/model/ssh_config.rb +17 -0
- data/lib/yun/model.rb +2 -0
- data/lib/yun/templates/chef-solo.rb +3 -0
- data/lib/yun/templates/install_chef.sh +14 -0
- data/lib/yun/version.rb +1 -1
- data/lib/yun.rb +2 -1
- data/spec/yun/model/ssh_config_spec.rb +16 -0
- data/spec/yun/model/ssh_spec.rb +14 -0
- data/spec/yun/version_spec.rb +1 -1
- data/yun.gemspec +11 -0
- metadata +22 -5
data/.gitignore
CHANGED
data/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
yun 云
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
About
|
|
5
|
+
-----
|
|
6
|
+
|
|
7
|
+
`yun` is a command line tool for manage Amazon EC2 environment.
|
|
8
|
+
|
|
9
|
+
It's still working in process. Now it supports `create`, `destroy`,
|
|
10
|
+
`list`, `ssh`, `chef provision` commands.
|
|
11
|
+
|
|
12
|
+
Ruby Gem
|
|
13
|
+
--------
|
|
14
|
+
|
|
15
|
+
Install `yun` by
|
|
16
|
+
|
|
17
|
+
(sudo) gem install yun
|
|
18
|
+
|
|
19
|
+
You can find `yun` in rubygems.org
|
|
20
|
+
|
|
21
|
+
https://rubygems.org/gems/yun
|
|
22
|
+
|
|
23
|
+
How to use
|
|
24
|
+
----------
|
|
25
|
+
|
|
26
|
+
### config file
|
|
27
|
+
After installing `yun`, you need to create a config file `~/.yun`.
|
|
28
|
+
Basically it should contains:
|
|
29
|
+
|
|
30
|
+
:default:
|
|
31
|
+
:aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID
|
|
32
|
+
:aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY
|
|
33
|
+
:region: us-west-1
|
|
34
|
+
:key_name: YOUR_KEY_PAIR_NAME
|
|
35
|
+
:chef_repo: /PATH/TO/YOUR/CHEF_REPO
|
|
36
|
+
|
|
37
|
+
### create EC2 node
|
|
38
|
+
|
|
39
|
+
yun node create NODE_NAME
|
|
40
|
+
|
|
41
|
+
### list all EC2 node
|
|
42
|
+
|
|
43
|
+
yun node list
|
|
44
|
+
|
|
45
|
+
### destroy EC2 node
|
|
46
|
+
|
|
47
|
+
yun node destroy NODE_NAME
|
|
48
|
+
|
|
49
|
+
### ssh to EC2 node
|
|
50
|
+
|
|
51
|
+
yun ssh NODE_NAME
|
|
52
|
+
|
|
53
|
+
### provision EC2 node using chef
|
|
54
|
+
|
|
55
|
+
yun chef NODE_NAME ROLE_NAME
|
|
56
|
+
|
|
57
|
+
Other
|
|
58
|
+
-----
|
|
59
|
+
|
|
60
|
+
Feel free to contact me if you have any problem:
|
|
61
|
+
|
|
62
|
+
* flankerfc at Gmail
|
|
63
|
+
* @冯智超 at Sina Weibo
|
data/lib/yun/command.rb
ADDED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
require 'hirb'
|
|
2
|
-
require 'yun/commands/command_base'
|
|
3
|
-
require 'yun/config'
|
|
4
2
|
|
|
5
3
|
module Yun
|
|
6
4
|
class NodeCommand < Thor
|
|
@@ -16,7 +14,7 @@ module Yun
|
|
|
16
14
|
:type => node.instance_type,
|
|
17
15
|
:image => node.image,
|
|
18
16
|
:ip => node.ip,
|
|
19
|
-
:created_at => node.created_at,
|
|
17
|
+
:created_at => node.created_at.strftime("%Y-%m-%d %H:%M:%S"),
|
|
20
18
|
:state => node.state
|
|
21
19
|
}
|
|
22
20
|
end
|
|
@@ -24,7 +22,7 @@ module Yun
|
|
|
24
22
|
end
|
|
25
23
|
|
|
26
24
|
desc "node create NODE_NAME", "create a node"
|
|
27
|
-
method_option :image, :aliases => "-i", :default => "ami-
|
|
25
|
+
method_option :image, :aliases => "-i", :default => "ami-2e10406b", :desc => "Amazon Machine Image"
|
|
28
26
|
method_option :instance_type, :aliases => "-t", :default => "t1.micro", :desc => "Instance Type"
|
|
29
27
|
def create(node_name)
|
|
30
28
|
attributes = create_attributes node_name, options
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
require 'thor'
|
|
2
|
-
require 'thor/group'
|
|
3
|
-
require 'yun/commands/command_base'
|
|
4
|
-
require 'yun/commands/node_command'
|
|
5
|
-
|
|
6
1
|
module Yun
|
|
7
2
|
class YunCommand < Thor
|
|
8
3
|
|
|
@@ -10,16 +5,25 @@ module Yun
|
|
|
10
5
|
|
|
11
6
|
desc "ssh NODE_NAME", "ssh to a node"
|
|
12
7
|
def ssh node_name
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
ssh_config = SshConfig.new Config.key_name
|
|
9
|
+
node = connection.find node_name
|
|
10
|
+
ssh = Ssh.new node.ip, ssh_config
|
|
15
11
|
|
|
12
|
+
ssh.connect
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
desc "test NODE_NAME, ROLE", "provision node with chef"
|
|
16
|
+
def chef node_name, role
|
|
17
|
+
ssh_config = SshConfig.new Config.key_name
|
|
16
18
|
node = connection.find node_name
|
|
17
|
-
|
|
19
|
+
ssh = Ssh.new node.ip, ssh_config
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
ssh.chef role
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
register NodeCommand, :node, "node SUBCOMMAND", "commands for node"
|
|
25
|
+
|
|
26
|
+
private
|
|
23
27
|
end
|
|
24
28
|
end
|
|
25
29
|
|
data/lib/yun/config.rb
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require 'net/ssh'
|
|
2
|
+
require 'net/scp'
|
|
3
|
+
|
|
4
|
+
module Yun
|
|
5
|
+
class Ssh
|
|
6
|
+
|
|
7
|
+
def initialize host, ssh_config
|
|
8
|
+
@host = host
|
|
9
|
+
@ssh_config = ssh_config
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def connect
|
|
13
|
+
exec "ssh -i #{key_file} #{user}@#{@host}"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def chef role
|
|
17
|
+
Net::SSH.start(@host, user, :keys => [key_file]) do |ssh|
|
|
18
|
+
puts "installing chef"
|
|
19
|
+
remote_command ssh, "bash /tmp/install_chef_file.sh"
|
|
20
|
+
|
|
21
|
+
puts "packaging chef repo"
|
|
22
|
+
tmp_chef_repo_tar = make_chef_repo_tar Config.chef_repo
|
|
23
|
+
|
|
24
|
+
puts "uploading chef repo"
|
|
25
|
+
ssh.scp.upload! tmp_chef_repo_tar, tmp_chef_repo_tar
|
|
26
|
+
ssh.scp.upload! install_chef_file, "/tmp/install_chef_file.sh"
|
|
27
|
+
ssh.scp.upload! chef_config_file, "/tmp/chef-solo.rb"
|
|
28
|
+
remote_command ssh, "echo {\\\"run_list\\\":\\\"role[#{role}]\\\"} > /tmp/node.json"
|
|
29
|
+
|
|
30
|
+
puts "executing chef"
|
|
31
|
+
remote_command ssh, "sudo chef-solo -c /tmp/chef-solo.rb -j /tmp/node.json -r /tmp/chef-solo.tar.gz"
|
|
32
|
+
|
|
33
|
+
puts "**********"
|
|
34
|
+
puts "DONE"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def user
|
|
40
|
+
@ssh_config.user
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def key_file
|
|
44
|
+
@ssh_config.key_file
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def make_chef_repo_tar chef_repo
|
|
48
|
+
tmp_tar = "/tmp/chef-solo.tar.gz"
|
|
49
|
+
Dir.chdir(chef_repo) do
|
|
50
|
+
system "tar -czvf #{tmp_tar} ./cookbooks ./roles"
|
|
51
|
+
end
|
|
52
|
+
tmp_tar
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def install_chef_file
|
|
56
|
+
File.expand_path(File.dirname(__FILE__) + '/../templates/install_chef.sh')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def chef_config_file
|
|
60
|
+
File.expand_path(File.dirname(__FILE__) + '/../templates/chef-solo.rb')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def remote_command(ssh, command)
|
|
64
|
+
ssh.open_channel do |channel|
|
|
65
|
+
channel.exec(command) do |ch, success|
|
|
66
|
+
raise "command failed: #{command}" unless success
|
|
67
|
+
|
|
68
|
+
channel.on_data do |_ch, data|
|
|
69
|
+
$stdout.print data
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
channel.on_extended_data do |_ch, _type, data|
|
|
73
|
+
$stderr.print data
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end.wait
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/yun/model.rb
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
sudo apt-get update
|
|
4
|
+
sudo apt-get install -y --force-yes ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert git-core
|
|
5
|
+
|
|
6
|
+
if test ! -x /usr/bin/gem; then
|
|
7
|
+
cd /tmp
|
|
8
|
+
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
|
|
9
|
+
tar zxf rubygems-1.8.10.tgz
|
|
10
|
+
cd rubygems-1.8.10
|
|
11
|
+
sudo ruby setup.rb --no-format-executable
|
|
12
|
+
fi
|
|
13
|
+
|
|
14
|
+
sudo gem install chef --no-ri --no-rdoc
|
data/lib/yun/version.rb
CHANGED
data/lib/yun.rb
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Yun::SshConfig do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@key_name = 'some_key'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'should construct from config object' do
|
|
10
|
+
ssh_config = Yun::SshConfig.new @key_name
|
|
11
|
+
|
|
12
|
+
ssh_config.user.should == 'ec2-user'
|
|
13
|
+
ssh_config.key_file.should == '~/.ssh/some_key.pem'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
data/spec/yun/version_spec.rb
CHANGED
data/yun.gemspec
CHANGED
|
@@ -21,4 +21,15 @@ Gem::Specification.new do |gem|
|
|
|
21
21
|
gem.add_runtime_dependency 'thor', '>= 0.14.0'
|
|
22
22
|
|
|
23
23
|
gem.add_development_dependency 'rspec', '~> 2.7'
|
|
24
|
+
|
|
25
|
+
gem.post_install_message = <<-MSG
|
|
26
|
+
Thanks for installing yun!
|
|
27
|
+
You need put a config file in your home directory: ~/.yun
|
|
28
|
+
:default:
|
|
29
|
+
:aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID
|
|
30
|
+
:aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY
|
|
31
|
+
:region: us-west-1
|
|
32
|
+
:key_name: YOUR_KEY_PAIR_NAME
|
|
33
|
+
:chef_repo: /PATH/TO/YOUR/CHEF_REPO
|
|
34
|
+
MSG
|
|
24
35
|
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:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease:
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
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: 2011-12-
|
|
18
|
+
date: 2011-12-10 00:00:00 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: fog
|
|
@@ -94,9 +94,11 @@ files:
|
|
|
94
94
|
- .rvmrc
|
|
95
95
|
- Gemfile
|
|
96
96
|
- Gemfile.lock
|
|
97
|
+
- README.md
|
|
97
98
|
- Rakefile
|
|
98
99
|
- bin/yun
|
|
99
100
|
- lib/yun.rb
|
|
101
|
+
- lib/yun/command.rb
|
|
100
102
|
- lib/yun/commands/command_base.rb
|
|
101
103
|
- lib/yun/commands/node_command.rb
|
|
102
104
|
- lib/yun/commands/yun_command.rb
|
|
@@ -105,17 +107,32 @@ files:
|
|
|
105
107
|
- lib/yun/model/connection.rb
|
|
106
108
|
- lib/yun/model/fog_attributes.rb
|
|
107
109
|
- lib/yun/model/node.rb
|
|
110
|
+
- lib/yun/model/ssh.rb
|
|
111
|
+
- lib/yun/model/ssh_config.rb
|
|
112
|
+
- lib/yun/templates/chef-solo.rb
|
|
113
|
+
- lib/yun/templates/install_chef.sh
|
|
108
114
|
- lib/yun/version.rb
|
|
109
115
|
- spec/spec_helper.rb
|
|
110
116
|
- spec/yun/model/connection_spec.rb
|
|
111
117
|
- spec/yun/model/fog_attributes_spec.rb
|
|
112
118
|
- spec/yun/model/node_spec.rb
|
|
119
|
+
- spec/yun/model/ssh_config_spec.rb
|
|
120
|
+
- spec/yun/model/ssh_spec.rb
|
|
113
121
|
- spec/yun/version_spec.rb
|
|
114
122
|
- yun.gemspec
|
|
115
123
|
homepage: https://github.com/flanker/yun
|
|
116
124
|
licenses: []
|
|
117
125
|
|
|
118
|
-
post_install_message:
|
|
126
|
+
post_install_message: |
|
|
127
|
+
Thanks for installing yun!
|
|
128
|
+
You need put a config file in your home directory: ~/.yun
|
|
129
|
+
:default:
|
|
130
|
+
:aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID
|
|
131
|
+
:aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY
|
|
132
|
+
:region: us-west-1
|
|
133
|
+
:key_name: YOUR_KEY_PAIR_NAME
|
|
134
|
+
:chef_repo: /PATH/TO/YOUR/CHEF_REPO
|
|
135
|
+
|
|
119
136
|
rdoc_options: []
|
|
120
137
|
|
|
121
138
|
require_paths:
|