ec2_name 0.1.0

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 ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg
6
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'right_aws'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2010
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software is furnished to do so,
8
+ subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ Ec2Name
2
+ ===========
3
+
4
+ Quick way to tag the name of the instance so that it shows up on aws console.
5
+
6
+ Setup
7
+ ------------
8
+
9
+ <pre>
10
+ gem install ec2_name
11
+ </pre>
12
+
13
+ Set up a ~/.br-cloud.yml that holds the aws credentials. File should look like this:
14
+
15
+ <pre>
16
+ $ cat ~/.br-cloud.yml
17
+ ---
18
+ :aws_secret_id: XXXXXXX
19
+ :aws_secret_key: XXXXXXXXXXXXXXXXXXXXX
20
+ $
21
+ </pre>
22
+
23
+ Usage
24
+ -------------------
25
+
26
+ If the script is being on an ec2 instance.
27
+
28
+ <pre>
29
+ ec2_name [NAME]
30
+ </pre>
31
+
32
+ If you are running it locally and want to test it.
33
+
34
+ <pre>
35
+ INSTANCE_ID=i-XXXX ec2_name [NAME]
36
+ </pre>
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ # DELETE AFTER USING
4
+ desc "Rename project"
5
+ task :rename do
6
+ name = ENV['NAME'] || File.basename(Dir.pwd)
7
+ camelize = lambda do |str|
8
+ str.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
9
+ end
10
+ dir = Dir['**/ec2_name*']
11
+ begin
12
+ from = dir.pop
13
+ if from
14
+ to = from.split('/')
15
+ to[-1].gsub!('ec2_name', name)
16
+ FileUtils.mv(from, to.join('/'))
17
+ end
18
+ end while dir.length > 0
19
+ Dir["**/*"].each do |path|
20
+ if File.file?(path)
21
+ `sed -i '' 's/ec2_name/#{name}/g' #{path}`
22
+ `sed -i '' 's/Ec2Name/#{camelize.call(name)}/g' #{path}`
23
+ no_space = File.read(path).gsub(/\s+\z/, '')
24
+ File.open(path, 'w') { |f| f.write(no_space) }
25
+ end
26
+ end
27
+ end
data/bin/ec2_name ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path("../../lib/ec2_name", __FILE__)
4
+ Ec2Name.new.run
data/ec2_name.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ root = File.expand_path('../', __FILE__)
3
+ lib = "#{root}/lib"
4
+
5
+ $:.unshift lib unless $:.include?(lib)
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "ec2_name"
9
+ s.version = '0.1.0'
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = ["Tung Nguyen"]
12
+ s.email = ["tongueroo@gmail.com"]
13
+ s.homepage = "http://github.com/tongueroo/ec2_name"
14
+ s.summary = %q{Quick way to tag the name of the instance so that it shows up on aws console}
15
+ s.description = %q{Quick way to tag the name of the instance so that it shows up on aws console.}
16
+
17
+ s.executables = `cd #{root} && git ls-files bin/*`.split("\n").collect { |f| File.basename(f) }
18
+ s.files = `cd #{root} && git ls-files`.split("\n")
19
+ s.require_paths = %w(lib)
20
+ s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
21
+
22
+ s.add_dependency "right_aws"
23
+
24
+ s.add_development_dependency "rspec", "~> 1.0"
25
+ end
data/lib/ec2_name.rb ADDED
@@ -0,0 +1,21 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'right_aws'
4
+ require 'yaml'
5
+
6
+ class Ec2Name
7
+ def run
8
+ @name = ARGV[0]
9
+ if @name.nil?
10
+ fail("ERROR: Need to supply a name. Usage: #{__FILE__} [name]")
11
+ end
12
+
13
+ @config = YAML.load(IO.read("#{ENV['HOME']}/.br-cloud.yml"))
14
+ @ec2 = RightAws::Ec2.new(@config[:aws_secret_id], @config[:aws_secret_key])
15
+
16
+ instance_id = ENV['INSTANCE_ID'] || `curl -s http://169.254.169.254/latest/meta-data/instance-id`
17
+ puts "Creating tag Name #{@name} for instance #{instance_id}"
18
+ @ec2.create_tags(instance_id, 'Name' => @name)
19
+ puts "Created tag Name #{@name} for instance #{instance_id}"
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ec2Name do
4
+ end
@@ -0,0 +1,8 @@
1
+ require "pp"
2
+ require "bundler"
3
+
4
+ Bundler.require(:development)
5
+
6
+ $root = File.expand_path('../../', __FILE__)
7
+
8
+ require "#{$root}/lib/ec2_name"
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ec2_name
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tung Nguyen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: right_aws
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ description: Quick way to tag the name of the instance so that it shows up on aws
47
+ console.
48
+ email:
49
+ - tongueroo@gmail.com
50
+ executables:
51
+ - ec2_name
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/ec2_name
61
+ - ec2_name.gemspec
62
+ - lib/ec2_name.rb
63
+ - spec/ec2_name_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: http://github.com/tongueroo/ec2_name
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.24
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Quick way to tag the name of the instance so that it shows up on aws console
89
+ test_files:
90
+ - spec/ec2_name_spec.rb
91
+ - spec/spec_helper.rb
92
+ has_rdoc: