ec2_userdata 1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ec2_userdata.rb +10 -9
  2. metadata +3 -6
data/lib/ec2_userdata.rb CHANGED
@@ -1,29 +1,30 @@
1
1
  require 'net/http'
2
- require 'json/pure'
2
+ require 'json/pure' unless defined?(JSON)
3
+ require 'yaml' unless defined?(YAML)
3
4
 
4
5
  module EC2
5
6
  class UserData
6
7
  def self.[](key)
7
- if @userdata.nil?
8
+ unless defined?(@@userdata)
8
9
  if EC2.ec2? && !use_local_config?
9
10
  logger.info "Running on EC2. Reading user data from http://169.254.169.254/1.0/user-data" if logger
10
- @userdata = get_ec2_userdata
11
+ @@userdata = get_ec2_userdata
11
12
  else
12
13
  logger.info "Reading user data from #{app_root}/config/ec2_userdata.yml." if logger
13
- @userdata = get_local_userdata
14
+ @@userdata = get_local_userdata
14
15
  end
15
16
  end
16
17
 
17
- @userdata[key]
18
+ @@userdata[key]
18
19
  end
19
20
 
20
21
  # Force use of local configuration file even when running on EC2
21
22
  def self.use_local_config!
22
- @use_local_config = true
23
+ @@use_local_config = true
23
24
  end
24
25
 
25
26
  def self.use_local_config?
26
- @use_local_config == true
27
+ @@use_local_config == true
27
28
  end
28
29
 
29
30
  private
@@ -71,9 +72,9 @@ module EC2
71
72
 
72
73
  # Returns true if the current instance is running on the EC2 cloud
73
74
  def self.ec2?
74
- return @running_on_ec2 if @running_on_ec2
75
+ return @@running_on_ec2 if defined?(@@running_on_ec2)
75
76
  raise("nslookup must be in the path") if cmd_exec("which nslookup").blank?
76
- @running_on_ec2 = (cmd_exec("nslookup 169.254.169.254").match(/NXDOMAIN/) || []).size < 1
77
+ @@running_on_ec2 = (cmd_exec("nslookup 169.254.169.254").match(/NXDOMAIN/) || []).size < 1
77
78
  end
78
79
 
79
80
  private
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2_userdata
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
- - 1
9
- version: "1.1"
7
+ - 2
8
+ version: "1.2"
10
9
  platform: ruby
11
10
  authors:
12
11
  - Carl Mercier
@@ -14,7 +13,7 @@ autorequire:
14
13
  bindir: bin
15
14
  cert_chain: []
16
15
 
17
- date: 2010-11-18 00:00:00 -05:00
16
+ date: 2011-01-26 00:00:00 -05:00
18
17
  default_executable:
19
18
  dependencies: []
20
19
 
@@ -43,7 +42,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
42
  requirements:
44
43
  - - ">="
45
44
  - !ruby/object:Gem::Version
46
- hash: 3
47
45
  segments:
48
46
  - 0
49
47
  version: "0"
@@ -52,7 +50,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
50
  requirements:
53
51
  - - ">="
54
52
  - !ruby/object:Gem::Version
55
- hash: 3
56
53
  segments:
57
54
  - 0
58
55
  version: "0"