yun 0.0.4 → 0.0.5
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/lib/yun/commands/node_command.rb +26 -7
- data/lib/yun/commands/yun_command.rb +2 -2
- data/lib/yun/config.rb +8 -0
- data/lib/yun/model.rb +1 -0
- data/lib/yun/model/connection.rb +12 -4
- data/lib/yun/model/fog_attributes.rb +1 -1
- data/lib/yun/model/instance_type.rb +10 -0
- data/lib/yun/model/node.rb +21 -2
- data/lib/yun/model/ssh.rb +7 -4
- data/lib/yun/model/ssh_config.rb +4 -3
- data/lib/yun/version.rb +1 -1
- data/spec/yun/model/instance_type_spec.rb +10 -0
- data/spec/yun/model/ssh_config_spec.rb +3 -2
- data/spec/yun/model/ssh_spec.rb +1 -1
- data/spec/yun/version_spec.rb +1 -1
- metadata +6 -4
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'hirb'
|
2
|
+
require 'pp'
|
2
3
|
|
3
4
|
module Yun
|
4
5
|
class NodeCommand < Thor
|
@@ -12,7 +13,7 @@ module Yun
|
|
12
13
|
:id => node.id,
|
13
14
|
:name => node.name,
|
14
15
|
:type => node.instance_type,
|
15
|
-
:
|
16
|
+
:os => node.os,
|
16
17
|
:ip => node.ip,
|
17
18
|
:created_at => node.created_at.strftime("%Y-%m-%d %H:%M:%S"),
|
18
19
|
:state => node.state
|
@@ -22,25 +23,43 @@ module Yun
|
|
22
23
|
end
|
23
24
|
|
24
25
|
desc "node create NODE_NAME", "create a node"
|
25
|
-
method_option :
|
26
|
-
method_option :instance_type, :aliases => "-t", :default => "
|
26
|
+
method_option :os, :aliases => "-o", :default => "ubuntu", :desc => "OS Name"
|
27
|
+
method_option :instance_type, :aliases => "-t", :default => "micro", :desc => "Instance Type"
|
27
28
|
def create(node_name)
|
29
|
+
$stdout.sync = true
|
28
30
|
attributes = create_attributes node_name, options
|
29
|
-
|
31
|
+
print "creating node."
|
32
|
+
connection.create attributes do
|
33
|
+
print "."
|
34
|
+
end
|
35
|
+
puts "\ndone"
|
30
36
|
end
|
31
37
|
|
32
38
|
desc "node destroy NODE_NAME", "destroy a node"
|
33
39
|
def destroy node_name
|
40
|
+
$stdout.sync = true
|
41
|
+
node = connection.find node_name
|
42
|
+
print "destroy node."
|
43
|
+
node.destroy { print "." }
|
44
|
+
puts "\ndone"
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "node info NODE_NAME", "show a node's info"
|
48
|
+
def info node_name
|
49
|
+
$stdout.sync = true
|
34
50
|
node = connection.find node_name
|
35
|
-
node.
|
51
|
+
pp node.all_info
|
36
52
|
end
|
37
53
|
|
38
54
|
private
|
39
55
|
def create_attributes node_name, options
|
56
|
+
os = options[:os]
|
40
57
|
{
|
41
58
|
"name" => node_name,
|
42
|
-
|
43
|
-
|
59
|
+
"os" => os,
|
60
|
+
"user" => Config.get_user(os),
|
61
|
+
:image => Config.get_image(os),
|
62
|
+
:instance_type => InstanceType.parse(options[:instance_type]),
|
44
63
|
:key_name => Config.key_name
|
45
64
|
}
|
46
65
|
end
|
@@ -5,8 +5,8 @@ module Yun
|
|
5
5
|
|
6
6
|
desc "ssh NODE_NAME", "ssh to a node"
|
7
7
|
def ssh node_name
|
8
|
-
ssh_config = SshConfig.new Config.key_name
|
9
8
|
node = connection.find node_name
|
9
|
+
ssh_config = SshConfig.new node.user, node.key_name
|
10
10
|
ssh = Ssh.new node.ip, ssh_config
|
11
11
|
|
12
12
|
ssh.connect
|
@@ -14,8 +14,8 @@ module Yun
|
|
14
14
|
|
15
15
|
desc "test NODE_NAME, ROLE", "provision node with chef"
|
16
16
|
def chef node_name, role
|
17
|
-
ssh_config = SshConfig.new Config.key_name
|
18
17
|
node = connection.find node_name
|
18
|
+
ssh_config = SshConfig.new node.user, node.key_name
|
19
19
|
ssh = Ssh.new node.ip, ssh_config
|
20
20
|
|
21
21
|
ssh.chef role
|
data/lib/yun/config.rb
CHANGED
@@ -23,6 +23,14 @@ module Yun
|
|
23
23
|
setting[:chef_repo]
|
24
24
|
end
|
25
25
|
|
26
|
+
def self.get_image os_name
|
27
|
+
setting[:os][os_name.to_sym][:image]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.get_user os_name
|
31
|
+
setting[:os][os_name.to_sym][:user]
|
32
|
+
end
|
33
|
+
|
26
34
|
private
|
27
35
|
def self.setting
|
28
36
|
@setting ||= YAML.load_file(config_file)[:default]
|
data/lib/yun/model.rb
CHANGED
data/lib/yun/model/connection.rb
CHANGED
@@ -6,10 +6,13 @@ module Yun
|
|
6
6
|
@servers = Fog::Compute.new(options).servers
|
7
7
|
end
|
8
8
|
|
9
|
-
def create attributes={}
|
9
|
+
def create attributes={}, &block
|
10
10
|
fog_attributes = FogAttributes.new attributes
|
11
11
|
server = @servers.create fog_attributes
|
12
|
-
server.wait_for
|
12
|
+
server.wait_for do
|
13
|
+
instance_eval(&block) if block_given?
|
14
|
+
ready?
|
15
|
+
end
|
13
16
|
Node.new server
|
14
17
|
end
|
15
18
|
|
@@ -20,9 +23,14 @@ module Yun
|
|
20
23
|
end
|
21
24
|
|
22
25
|
def find node_name
|
23
|
-
list.find do |node|
|
24
|
-
node.name == node_name
|
26
|
+
node = list.find do |node|
|
27
|
+
node.name == node_name and not node.is_destroyed?
|
28
|
+
end
|
29
|
+
if node == nil
|
30
|
+
puts "Error: Cannot find node #{node_name}"
|
31
|
+
exit 1
|
25
32
|
end
|
33
|
+
node
|
26
34
|
end
|
27
35
|
|
28
36
|
end
|
data/lib/yun/model/node.rb
CHANGED
@@ -25,6 +25,14 @@ module Yun
|
|
25
25
|
@server.tags["name"]
|
26
26
|
end
|
27
27
|
|
28
|
+
def os
|
29
|
+
@server.tags["os"]
|
30
|
+
end
|
31
|
+
|
32
|
+
def user
|
33
|
+
@server.tags["user"]
|
34
|
+
end
|
35
|
+
|
28
36
|
def state
|
29
37
|
@server.state
|
30
38
|
end
|
@@ -37,9 +45,20 @@ module Yun
|
|
37
45
|
@server.created_at
|
38
46
|
end
|
39
47
|
|
40
|
-
def destroy
|
48
|
+
def destroy &block
|
41
49
|
@server.destroy
|
42
|
-
@server.wait_for
|
50
|
+
@server.wait_for do
|
51
|
+
instance_eval(&block) if block_given?
|
52
|
+
not reload or state == 'terminated'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def all_info
|
57
|
+
@server
|
58
|
+
end
|
59
|
+
|
60
|
+
def is_destroyed?
|
61
|
+
@server.state == 'terminated'
|
43
62
|
end
|
44
63
|
|
45
64
|
end
|
data/lib/yun/model/ssh.rb
CHANGED
@@ -10,14 +10,13 @@ module Yun
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def connect
|
13
|
-
|
13
|
+
ssh_command = "ssh -i #{key_file} #{user}@#{@host}"
|
14
|
+
puts ssh_command
|
15
|
+
exec ssh_command
|
14
16
|
end
|
15
17
|
|
16
18
|
def chef role
|
17
19
|
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
20
|
puts "packaging chef repo"
|
22
21
|
tmp_chef_repo_tar = make_chef_repo_tar Config.chef_repo
|
23
22
|
|
@@ -25,6 +24,10 @@ module Yun
|
|
25
24
|
ssh.scp.upload! tmp_chef_repo_tar, tmp_chef_repo_tar
|
26
25
|
ssh.scp.upload! install_chef_file, "/tmp/install_chef_file.sh"
|
27
26
|
ssh.scp.upload! chef_config_file, "/tmp/chef-solo.rb"
|
27
|
+
|
28
|
+
puts "installing chef"
|
29
|
+
remote_command ssh, "bash /tmp/install_chef_file.sh"
|
30
|
+
|
28
31
|
remote_command ssh, "echo {\\\"run_list\\\":\\\"role[#{role}]\\\"} > /tmp/node.json"
|
29
32
|
|
30
33
|
puts "executing chef"
|
data/lib/yun/model/ssh_config.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
1
|
module Yun
|
2
2
|
class SshConfig
|
3
3
|
|
4
|
-
def initialize key_name
|
4
|
+
def initialize user, key_name
|
5
|
+
@user = user
|
5
6
|
@key_name = key_name
|
6
7
|
end
|
7
8
|
|
8
9
|
def user
|
9
|
-
|
10
|
+
@user
|
10
11
|
end
|
11
12
|
|
12
13
|
def key_file
|
13
14
|
"~/.ssh/#{@key_name}.pem"
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
end
|
17
18
|
end
|
data/lib/yun/version.rb
CHANGED
@@ -3,13 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe Yun::SshConfig do
|
4
4
|
|
5
5
|
before do
|
6
|
+
@user = 'some_user'
|
6
7
|
@key_name = 'some_key'
|
7
8
|
end
|
8
9
|
|
9
10
|
it 'should construct from config object' do
|
10
|
-
ssh_config = Yun::SshConfig.new @key_name
|
11
|
+
ssh_config = Yun::SshConfig.new @user, @key_name
|
11
12
|
|
12
|
-
ssh_config.user.should ==
|
13
|
+
ssh_config.user.should == @user
|
13
14
|
ssh_config.key_file.should == '~/.ssh/some_key.pem'
|
14
15
|
end
|
15
16
|
|
data/spec/yun/model/ssh_spec.rb
CHANGED
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: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
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:
|
18
|
+
date: 2012-01-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fog
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- lib/yun/model.rb
|
107
107
|
- lib/yun/model/connection.rb
|
108
108
|
- lib/yun/model/fog_attributes.rb
|
109
|
+
- lib/yun/model/instance_type.rb
|
109
110
|
- lib/yun/model/node.rb
|
110
111
|
- lib/yun/model/ssh.rb
|
111
112
|
- lib/yun/model/ssh_config.rb
|
@@ -115,6 +116,7 @@ files:
|
|
115
116
|
- spec/spec_helper.rb
|
116
117
|
- spec/yun/model/connection_spec.rb
|
117
118
|
- spec/yun/model/fog_attributes_spec.rb
|
119
|
+
- spec/yun/model/instance_type_spec.rb
|
118
120
|
- spec/yun/model/node_spec.rb
|
119
121
|
- spec/yun/model/ssh_config_spec.rb
|
120
122
|
- spec/yun/model/ssh_spec.rb
|