stemcell 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/stem CHANGED
@@ -90,6 +90,12 @@ END_OF_BANNER
90
90
  :default => ENV['MACHINE_TYPE'],
91
91
  )
92
92
 
93
+ opt('tags',
94
+ 'tags to apply to image',
95
+ :type => String,
96
+ :default => ENV['TAGS'],
97
+ )
98
+
93
99
  end
94
100
 
95
101
  required_parameters = [
@@ -1,3 +1,3 @@
1
1
  module Stemcell
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/stemcell.rb CHANGED
@@ -29,6 +29,22 @@ module Stemcell
29
29
  @timeout = 120
30
30
  @start_time = Time.new
31
31
 
32
+ @tags = {
33
+ 'Name' => "#{@chef_role}-#{@git_branch}",
34
+ 'Group' => "#{@chef_role}-#{@git_branch}",
35
+ 'created_by' => ENV['USER'],
36
+ 'stemcell' => VERSION,
37
+ }
38
+
39
+ if opts['tags']
40
+ tags = {}
41
+ opts['tags'].split(',').each do |tag_set|
42
+ key, value = tag_set.split('=')
43
+ tags[key] = value
44
+ end
45
+ @tags.merge!(tags)
46
+ end
47
+
32
48
  begin
33
49
  @git_key_contents = File.read(@git_key)
34
50
  rescue Object => e
@@ -57,6 +73,7 @@ module Stemcell
57
73
  File.open('/tmp/user-data', 'w') {|f| f.write(@user_data) }
58
74
  instances = do_launch(opts)
59
75
  wait(instances)
76
+ set_tags(instances)
60
77
  print_run_info(instances)
61
78
  return instances
62
79
  end
@@ -101,7 +118,6 @@ module Stemcell
101
118
  }
102
119
  options.merge!({:availability_zone => opts['avilibility_zone']}) if opts['availability_zone']
103
120
  options.merge!({:count => opts['count']}) if opts['count']
104
- puts "creating instance with options:\n#{options}"
105
121
  instances = @ec2_region.instances.create(options)
106
122
  instances = [instances] unless instances.class == Array
107
123
  instances.each do |instance|
@@ -110,6 +126,12 @@ module Stemcell
110
126
  return instances
111
127
  end
112
128
 
129
+ def set_tags(instances=[])
130
+ instances.each do |instance|
131
+ instance.tags.set(@tags)
132
+ end
133
+ end
134
+
113
135
  def render_template
114
136
  this_file = File.expand_path __FILE__
115
137
  base_dir = File.dirname this_file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stemcell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: