capawsext 0.1 → 0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 762e84774e300c85a73a55b0c6aea0c31fcad919
4
- data.tar.gz: 148f79e31294a8ad2d0fae088761a8aa6614ab3e
3
+ metadata.gz: 462db8dd528f2d58989e39afe65e6487081bf2aa
4
+ data.tar.gz: d5870ce98e2533c6eb5f209f5851301b10e3faa3
5
5
  SHA512:
6
- metadata.gz: b694827848eae4a164ce673874358f4b2c4eef31c35ad50bb2532f0ec76b6c81153e4570a632696d1c545765332f29f7c6f8a6b967ceb5a0790d7a82ed175956
7
- data.tar.gz: 859bfeccca344579b30fd280f7603c3e1d576c793829dfde0a5b9498621cde1b24c7c9309ff3fe6aca56ad213083e32095baab9d021aa3c7d284c49c9312c70d
6
+ metadata.gz: 26267629a07b077072df8e3db3098c27f0d96195b21a65963f9fd240c81c1f60810c44d09059094c670feba9ef6ff0e660f12ad1157b16c1ec0cd1524d54601f
7
+ data.tar.gz: d276dfa3f31027c5fdd65ccbde83aa4c61654abebf0881487eb39a2fdf3faabfffe37c0b8ae0fb82052fffa658eaa00bb92aadbb4f09aba349551996604b887d
@@ -0,0 +1,2 @@
1
+ :aws_access_key_id: "mock"
2
+ :aws_secret_access_key: "mock"
@@ -7,8 +7,8 @@ end
7
7
  require 'capawsext/whoec2helper'
8
8
 
9
9
  Capistrano::Configuration.instance(:must_exist).load do
10
- def add_groups
11
- ec2_helper = Ec2Helper.new
10
+ def add_groups(region)
11
+ ec2_helper = Ec2Helper.new(region)
12
12
  groups = ec2_helper.get_groups
13
13
  groups.each { |group|
14
14
  task group.to_sym, :desc => "Run the task in all instances of the #{group}" do
@@ -1,3 +1,3 @@
1
1
  module CapAwsExt
2
- VERSION="0.1"
2
+ VERSION="0.2"
3
3
  end
@@ -1,50 +1,25 @@
1
1
  require 'rubygems'
2
2
  require 'fog'
3
3
  require 'colored'
4
- #require File.expand_path(File.dirname(__FILE__) + '/capify-cloud/server')
5
4
 
6
5
  class Ec2Helper
7
6
 
8
- def initialize(cloud_config = "config/cloud.yml")
7
+ def initialize(region, cloud_config = "config/cloud.yml")
9
8
  @cloud_config = YAML.load_file cloud_config
10
9
  @instances =[]
11
- @cloud_providers = @cloud_config[:cloud_providers]
12
- @cloud_providers.each do |cloud_provider|
13
- config = @cloud_config[cloud_provider.to_sym]
14
- config[:provider] = cloud_provider
15
- regions = determine_regions(cloud_provider)
16
- config.delete(:regions)
17
- if regions
18
- regions.each do |region|
19
- config.delete(:region)
20
- config[:region] = region
21
- populate_instances(config)
22
- end
23
- else populate_instances(config)
24
- end
25
- end
26
-
27
- end
28
- def determine_regions(cloud_provider = 'AWS')
29
- regions = @cloud_config[cloud_provider.to_sym][:regions]
30
- end
31
-
32
-
33
- def populate_instances(config)
34
- @fog = Fog::Compute.new(config)
35
- @fog.servers.each {|server| @instances << server }
10
+ populate_instances(region, @cloud_config)
36
11
  end
37
12
 
38
- def get_zoo_srvs_private_dns(group)
39
- zoosrvs = Array.new
40
- instances = get_instances_byrole(group, 'zoo-srv')
41
- instances.each {|instance|
42
- zoosrvs << instance.private_dns_name
43
- }
44
- return zoosrvs
13
+ def populate_instances(region, config)
14
+ #Choose the defualt prover and region
15
+ raise "aws_access_key_id or aws_secret_access_key keys are not present in the config file" if config[:aws_access_key_id].nil? or config[:aws_secret_access_key].nil?
16
+ temp_config = {:provider => 'AWS'}
17
+ config[:region] = region
18
+ @fog = Fog::Compute.new(temp_config.merge!(config))
19
+ @fog.servers.each {|server| @instances << server }
45
20
  end
46
21
 
47
- def get_instances_byrole(group, role)
22
+ def get_instances_role(group, role)
48
23
  ret_instances = Array.new
49
24
  @instances.each {|instance|
50
25
  if not instance.tags['role'].nil? and instance.ready?
@@ -56,22 +31,6 @@ class Ec2Helper
56
31
  return ret_instances
57
32
  end
58
33
 
59
- def get_solr_private_dns(group)
60
- instances = get_instances_byrole(group, 'solr')
61
- return instances[0].private_dns_name if instances.count > 0
62
- end
63
-
64
-
65
- def get_facade_srv_public_dns(group)
66
- instance = get_instances_byrole(group, 'api-srv')
67
- return instance[0].dns_name if instance.count > 0
68
- end
69
-
70
- def get_db_srv_private_dns(group)
71
- instance = get_instances_byrole(group, 'db-srv')
72
- return instance[0].private_dns_name if instance.count > 0
73
- end
74
-
75
34
  def printInstanceDetails()
76
35
  @instances.each_with_index do |instance, i|
77
36
  puts sprintf "%02d: %-20s %-20s %-20s %-20s %-25s %-20s (%s) (%s) (%s)",
@@ -82,47 +41,14 @@ class Ec2Helper
82
41
 
83
42
  end
84
43
 
85
- def get_server_details_by_pri_pub_dns(dns)
86
- details={}
44
+ def get_instance_by_pri_pub_dns(dns)
87
45
  @instances.each { |instance|
88
46
  if instance.private_dns_name == dns or instance.dns_name == dns
89
- details['name']=instance.tags['name_s']
90
- details['orgid']=instance.tags['orgid']
91
- details['group']=instance.tags['group']
92
- details['private_dns_name'] = instance.private_dns_name
93
- details['role'] = instance.tags['role']
94
- details['public_dns_name'] = instance.dns_name
95
- details['id'] = instance.id
96
- details['zone'] = instance.availability_zone
97
- return details
47
+ return instance
98
48
  end
99
49
  }
100
- return details
101
50
  end
102
51
 
103
- def get_server_details_map(isrunning)
104
- servers={}
105
- @instances.each { |instance|
106
- if not isrunning or (isrunning and instance.ready?)
107
- details={}
108
- details['name']=instance.tags['name_s']
109
- details['orgid']=instance.tags['orgid']
110
- details['group']=instance.tags['group']
111
- details['private_dns_name'] = instance.private_dns_name
112
- details['role'] = instance.tags['role']
113
- details['public_dns_name'] = instance.dns_name
114
- details['id'] = instance.id
115
- details['zone'] = instance.availability_zone
116
- details['device_mappings'] = Array.new
117
- instance.block_device_mapping.each { |mapping|
118
- details['device_mappings'] << mapping['deviceName']
119
- }
120
- servers[instance.private_dns_name] = details
121
- end
122
- }
123
- return servers
124
- end
125
-
126
52
  def get_all_stacks
127
53
  stacks = {}
128
54
  @instances.each {|instance|
@@ -137,14 +63,6 @@ class Ec2Helper
137
63
  end
138
64
 
139
65
 
140
- def get_instance_on_dns(dns)
141
- @instances.each { |instance|
142
- if instance.private_dns_name == dns or instance.dns_name == dns
143
- return instance
144
- end
145
- }
146
- end
147
-
148
66
  def get_groups
149
67
  groups = Set.new
150
68
  @instances.each { |instance|
@@ -170,6 +88,34 @@ class Ec2Helper
170
88
  return nil
171
89
  end
172
90
 
91
+ def add_tags(resource_id, tags = {})
92
+ tags.each { |key, value|
93
+ @fog.tags.create(:resource_id => resource_id, :key => key, :value => value)
94
+ }
95
+ end
96
+
97
+ def get_all_instances
98
+ return @instances
99
+ end
100
+
101
+ def lb_unregister_instances(lb_name, instances)
102
+ lb = get_lb(lb_name)
103
+ lb.deregister_instances(instances.map{|i| i.id })
104
+ end
105
+
106
+ def lb_register_instances(lb_name, instances)
107
+ lb = get_lb(lb_name)
108
+ lb.register_instances(instances.map{|i| i.id })
109
+ end
110
+
111
+ private
112
+ def get_lb(lb_name)
113
+ @lbs ||= Fog::AWS::ELB.new(@cloud_config).load_balancers
114
+ lb = @lbs.get(lb_name)
115
+ raise "lb #{lb_name} not found in the region #{@cloud_config[:region]}" if lb.nil?
116
+ return lb
117
+ end
118
+ #Not used.
173
119
  def get_zone(roles, sec_group)
174
120
  zones = Hash["us-west-1b" =>0,"us-west-1c" =>0]
175
121
  @instances.each { |instance|
@@ -186,16 +132,27 @@ class Ec2Helper
186
132
  return min_zone
187
133
  end
188
134
 
189
-
190
- def add_tags(resource_id, tags = {})
191
- tags.each { |key, value|
192
- puts "#{resource_id}, #{key}, #{value}"
193
- @fog.tags.create(:resource_id => resource_id, :key => key, :value => value)
135
+ #Not used anywhere...I just kept this code to check the instance properties to access block_device_mapping
136
+ def get_server_details_map(isrunning)
137
+ servers={}
138
+ @instances.each { |instance|
139
+ if not isrunning or (isrunning and instance.ready?)
140
+ details={}
141
+ details['name']=instance.tags['name_s']
142
+ details['orgid']=instance.tags['orgid']
143
+ details['group']=instance.tags['group']
144
+ details['private_dns_name'] = instance.private_dns_name
145
+ details['role'] = instance.tags['role']
146
+ details['public_dns_name'] = instance.dns_name
147
+ details['id'] = instance.id
148
+ details['zone'] = instance.availability_zone
149
+ details['device_mappings'] = Array.new
150
+ instance.block_device_mapping.each { |mapping|
151
+ details['device_mappings'] << mapping['deviceName']
152
+ }
153
+ servers[instance.private_dns_name] = details
154
+ end
194
155
  }
195
- end
196
-
197
- def get_all_instances
198
- return @instances
199
- end
156
+ return servers
157
+ end
200
158
  end
201
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capawsext
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sumit vij
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-19 00:00:00.000000000 Z
11
+ date: 2013-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -62,6 +62,7 @@ files:
62
62
  - README
63
63
  - capawsext.gemspec
64
64
  - lib/capawsext.rb
65
+ - lib/capawsext/mockcloud.yml
65
66
  - lib/capawsext/tasks.rb
66
67
  - lib/capawsext/version.rb
67
68
  - lib/capawsext/whoec2helper.rb