stem 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/stem/cli.rb +15 -2
- data/lib/stem/instance.rb +21 -15
- data/lib/stem/userdata.rb +11 -13
- metadata +3 -3
data/lib/stem/cli.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
|
+
require 'stem/userdata'
|
4
|
+
|
3
5
|
module Stem
|
4
6
|
Version = "0.2.1"
|
5
7
|
|
@@ -15,6 +17,7 @@ module Stem
|
|
15
17
|
|
16
18
|
opts.separator "Examples:"
|
17
19
|
opts.separator " $ stem launch prototype.config prototype-userdata.sh"
|
20
|
+
opts.separator " $ stem launch examples/lxc-server/lxc-server.json examples/lxc-server/"
|
18
21
|
opts.separator " $ stem list"
|
19
22
|
opts.separator " $ stem create ami-name instance-id"
|
20
23
|
|
@@ -58,8 +61,18 @@ module Stem
|
|
58
61
|
|
59
62
|
def launch config_file = nil, userdata_file = nil
|
60
63
|
abort "No config file" unless config_file
|
61
|
-
userdata =
|
62
|
-
|
64
|
+
userdata = case
|
65
|
+
when userdata_file.nil?
|
66
|
+
nil
|
67
|
+
when File.directory?(userdata_file)
|
68
|
+
Userdata.compile(userdata_file)
|
69
|
+
when File.file?(userdata_file)
|
70
|
+
File.new(userdata_file).read
|
71
|
+
else
|
72
|
+
abort 'Unable to interpret userdata object.'
|
73
|
+
end
|
74
|
+
conf = JSON.parse(File.new(config_file).read)
|
75
|
+
instance = Stem::Instance.launch(conf, userdata)
|
63
76
|
puts "New instance ID: #{instance}"
|
64
77
|
end
|
65
78
|
|
data/lib/stem/instance.rb
CHANGED
@@ -93,24 +93,30 @@ module Stem
|
|
93
93
|
lookup[ami["imageId"]] = name
|
94
94
|
end
|
95
95
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
96
|
+
reservations = instances["reservationSet"]
|
97
|
+
unless reservations.nil? or reservations.empty?
|
98
|
+
puts "------------------------------------------"
|
99
|
+
puts "Instances"
|
100
|
+
puts "------------------------------------------"
|
101
|
+
reservations.each do |r|
|
102
|
+
groups = r["groupSet"].map { |g| g["groupId"] }.join(",")
|
103
|
+
r["instancesSet"].each do |i|
|
104
|
+
name = lookup[i["imageId"]]
|
105
|
+
puts "%-15s %-15s %-15s %-20s %s" % [ i["instanceId"], i["ipAddress"] || "no ip", i["instanceState"]["name"], groups, name ]
|
106
|
+
end
|
104
107
|
end
|
105
108
|
end
|
106
109
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
result = swirl.call "DescribeImages", "Owner" => "self"
|
111
|
+
images = result["imagesSet"]
|
112
|
+
unless images.nil? or images.empty?
|
113
|
+
puts "------------------------------------------"
|
114
|
+
puts "AMIs"
|
115
|
+
puts "------------------------------------------"
|
116
|
+
iwidth = images.map { |img| img["name"].length }.max + 1
|
117
|
+
images.each do |img|
|
118
|
+
puts "%-#{iwidth}s %s" % [ img["name"], img["imageId"] ]
|
119
|
+
end
|
114
120
|
end
|
115
121
|
end
|
116
122
|
end
|
data/lib/stem/userdata.rb
CHANGED
@@ -48,22 +48,20 @@ module Stem
|
|
48
48
|
def make_zip_shell
|
49
49
|
# We'll comment outside here, to keep from wasting valuable userdata bytes.
|
50
50
|
# we decompress into /root/userdata, then run userdata.sh
|
51
|
-
header = <<-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
51
|
+
header = <<-SHELL
|
52
|
+
#!/bin/bash
|
53
|
+
exec >> /var/log/userdata.log 2>&1
|
54
|
+
date --utc '+BOOTING %FT%TZ'
|
55
|
+
UD=~/userdata
|
56
|
+
mkdir -p $UD
|
57
|
+
sed '1,/^#### THE END$/ d' "$0" | tar -jx -C $UD
|
58
|
+
cd $UD
|
59
|
+
exec bash userdata.sh
|
60
|
+
#### THE END
|
60
61
|
SHELL
|
61
|
-
|
62
|
+
header + %x{tar --exclude *.stem -cv . | bzip2 --best -}
|
62
63
|
end
|
63
64
|
|
64
|
-
def process_header(shell)
|
65
|
-
shell.gsub(/HEADER_LINES/, (shell.split("\n").size + 1).to_s).gsub(/^ +/,'')
|
66
|
-
end
|
67
65
|
end
|
68
66
|
end
|
69
67
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter van Hardenberg
|