murakumo 0.4.0 → 0.4.1

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.
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'optparse'
5
+ require 'yaml'
6
+
7
+ require 'util/murakumo_ec2_instances'
8
+
9
+ access_key = nil
10
+ secret_key = nil
11
+ endpoint = nil
12
+ instance_id = nil
13
+
14
+ ARGV.options do |opt|
15
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
16
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
17
+ opt.on('-r', '--region REGION') {|v| endpoint = v }
18
+ opt.parse!
19
+
20
+ access_key ||= ENV['AMAZON_ACCESS_KEY_ID']
21
+ secret_key ||= ENV['AMAZON_SECRET_ACCESS_KEY']
22
+
23
+ unless access_key and secret_key
24
+ puts opt.help
25
+ exit 1
26
+ end
27
+ end
28
+
29
+ instances = Murakumo::Util::ec2_instances(access_key, secret_key, endpoint)
30
+
31
+ puts YAML.dump(instances)
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
3
4
  require 'optparse'
5
+
4
6
  require 'util/murakumo_ec2_tags'
5
7
 
6
8
  access_key = nil
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
3
4
  require 'util/murakumo_self_ip_address'
4
5
 
5
6
  puts Murakumo::Util.self_ip_address
@@ -0,0 +1,19 @@
1
+ AMAZON_ACCESS_KEY_ID = '...'
2
+ AMAZON_SECRET_ACCESS_KEY = '...'
3
+
4
+ # get self ip address
5
+ ip_addr = Murakumo::Util.self_ip_address
6
+
7
+ # get hostname
8
+ tags = Murakumo::Util.ec2_tags(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY)
9
+ hostname = tags['Name'] || `curl -s http://169.254.169.254/latest/meta-data/local-hostname`
10
+
11
+ # rewrite host option
12
+ @options['host'] = "#{ip_addr}, #{hostname}"
13
+
14
+ # get instances
15
+ instances = Murakumo::Util.ec2_instances(AMAZON_ACCESS_KEY_ID, AMAZON_SECRET_ACCESS_KEY)
16
+
17
+ # rewrite initial-nodes
18
+ nodes = instances.map {|i| i['ipAddress'] || '' }.select {|i| not i.empty? }
19
+ @options['initial-nodes'] = nodes.join(',') unless nodes.empty?
@@ -1,6 +1,7 @@
1
1
  require 'misc/murakumo_const'
2
2
  require 'util/murakumo_self_ip_address'
3
3
  require 'util/murakumo_ec2_tags'
4
+ require 'util/murakumo_ec2_instances'
4
5
 
5
6
  module Murakumo
6
7
 
@@ -1,5 +1,5 @@
1
1
  module Murakumo
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
 
4
4
  # Priority
5
5
  MASTER = 1
@@ -7,14 +7,24 @@ Net::HTTP.version_1_2
7
7
 
8
8
  module Murakumo
9
9
 
10
- module Util
10
+ class Util
11
11
 
12
12
  class EC2Client
13
13
 
14
14
  API_VERSION = '2011-12-01'
15
15
  SIGNATURE_VERSION = 2
16
16
 
17
- def initialize(accessKeyId, secretAccessKey, endpoint = 'ec2.us-east-1.amazonaws.com', algorithm = :SHA256)
17
+ def initialize(accessKeyId, secretAccessKey, endpoint = nil, algorithm = :SHA256)
18
+ unless endpoint
19
+ local_hostname = Net::HTTP.get('169.254.169.254', '/latest/meta-data/local-hostname')
20
+
21
+ if /\A[^.]+\.([^.]+)\.compute\.internal\Z/ =~ local_hostname
22
+ endpoint = $1
23
+ else
24
+ endpoint = 'us-east-1'
25
+ end
26
+ end
27
+
18
28
  @accessKeyId = accessKeyId
19
29
  @secretAccessKey = secretAccessKey
20
30
  @endpoint = endpoint
@@ -0,0 +1,52 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+
4
+ require 'util/murakumo_ec2_client'
5
+
6
+ module Murakumo
7
+
8
+ class Util
9
+
10
+ def self.ec2_instances(access_key, secret_key, endpoint = nil)
11
+ ec2cli = Murakumo::Util::EC2Client.new(access_key, secret_key, endpoint)
12
+ source = ec2cli.query('DescribeInstances')
13
+ instances = []
14
+
15
+ items = REXML::Document.new(source).get_elements('//instancesSet/item')
16
+ walk_item_list(items, instances)
17
+
18
+ return instances
19
+ end
20
+
21
+ def self.walk_item_list(list, ary)
22
+ list.each do |item|
23
+ hash = {}
24
+ walk_item(item, hash)
25
+ ary << hash
26
+ end
27
+ end
28
+ private_class_method :walk_item_list
29
+
30
+ def self.walk_item(item, hash)
31
+ return unless item.has_elements?
32
+
33
+ item.elements.each do |child|
34
+ if child.has_elements?
35
+ if child.elements.all? {|i| i.name =~ /\Aitem\Z/i }
36
+ hash[child.name] = nested = []
37
+ walk_item_list(child.elements, nested)
38
+ else
39
+ hash[child.name] = nested = {}
40
+ walk_item(child, nested)
41
+ end
42
+ else
43
+ hash[child.name] = child.text
44
+ end
45
+ end
46
+ end
47
+
48
+ private_class_method :walk_item
49
+
50
+ end # Util
51
+
52
+ end # Murakumo
@@ -5,19 +5,9 @@ require 'util/murakumo_ec2_client'
5
5
 
6
6
  module Murakumo
7
7
 
8
- module Util
9
-
10
- def ec2_tags(access_key, secret_key, endpoint = nil, instance_id = nil)
11
- unless endpoint
12
- local_hostname = Net::HTTP.get('169.254.169.254', '/latest/meta-data/local-hostname')
13
-
14
- if /\A[^.]+\.([^.]+)\.compute\.internal\Z/ =~ local_hostname
15
- endpoint = $1
16
- else
17
- endpoint = 'us-east-1'
18
- end
19
- end
8
+ class Util
20
9
 
10
+ def self.ec2_tags(access_key, secret_key, endpoint = nil, instance_id = nil)
21
11
  unless instance_id
22
12
  instance_id = Net::HTTP.get('169.254.169.254', '/latest/meta-data/instance-id')
23
13
  end
@@ -36,8 +26,6 @@ module Murakumo
36
26
  return tags
37
27
  end
38
28
 
39
- module_function :ec2_tags
40
-
41
29
  end # Util
42
30
 
43
31
  end # Murakumo
@@ -1,13 +1,11 @@
1
1
  module Murakumo
2
2
 
3
- module Util
3
+ class Util
4
4
 
5
- def self_ip_address
5
+ def self.self_ip_address
6
6
  `/sbin/ifconfig eth0 | awk -F'[: ]+' '/^eth0/,/^$/{if(/inet addr/) print $4}'`.strip
7
7
  end
8
8
 
9
- module_function :self_ip_address
10
-
11
9
  end # Util
12
10
 
13
11
  end # Murakumo
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: murakumo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - winebarrel
@@ -89,12 +89,14 @@ executables:
89
89
  - murakumo-install-init-script
90
90
  - murakumo-show-ip-address
91
91
  - murakumo-show-ec2-tags
92
+ - murakumo-show-ec2-instances
92
93
  extensions: []
93
94
 
94
95
  extra_rdoc_files: []
95
96
 
96
97
  files:
97
98
  - README
99
+ - bin/murakumo-show-ec2-instances
98
100
  - bin/murakumo
99
101
  - bin/murakumo-show-ec2-tags
100
102
  - bin/murakumo-show-ip-address
@@ -106,6 +108,7 @@ files:
106
108
  - lib/cli/murakumo_initializer_context.rb
107
109
  - lib/cli/mrkmctl_options.rb
108
110
  - lib/misc/murakumo_const.rb
111
+ - lib/util/murakumo_ec2_instances.rb
109
112
  - lib/util/murakumo_ec2_tags.rb
110
113
  - lib/util/murakumo_self_ip_address.rb
111
114
  - lib/util/murakumo_ec2_client.rb
@@ -116,6 +119,7 @@ files:
116
119
  - lib/srv/murakumo_balancer.rb
117
120
  - lib/srv/murakumo_cloud.rb
118
121
  - etc/murakumo.server
122
+ - etc/murakumo-init.rb.for-ec2
119
123
  - etc/murakumo.yml.example
120
124
  - etc/gai.conf.example
121
125
  - etc/murakumo-update-config-for-ec2