rig 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,6 +37,9 @@ module Rig
37
37
  r << server.flavor_id.to_s
38
38
  r << server.id.to_s
39
39
  r << server.state.to_s.downcase
40
+ if detailed
41
+ r << server.dns_name
42
+ end
40
43
  rows << r
41
44
  end
42
45
 
@@ -50,6 +53,7 @@ module Rig
50
53
  cols << "Size"
51
54
  cols << "Instance ID"
52
55
  cols << "State"
56
+ cols << "DNS" if detailed
53
57
 
54
58
  print_table(cols, rows)
55
59
  end
@@ -1,10 +1,37 @@
1
1
  require 'rig'
2
+ require 'rest-client'
2
3
 
3
4
  module Rig
4
5
  module Command
5
6
  module Balancer
6
7
  class Main < Abstract
7
8
  self.default_subcommand = 'list'
9
+ subcommand 'test', 'test a load balancer' do
10
+ option %w{-c --count}, "COUNT", "number of times to loop", :default => 100
11
+ option %w{-p --poll}, "POLL", "poll time", :default => 10
12
+ parameter "NAME", "name of the load balancer to test"
13
+
14
+ def execute
15
+ elb = Rig::Model::Balancer.find(name)
16
+ raise "elb #{name} not found" unless elb
17
+
18
+ dns = elb.dns_name
19
+ count.times do |i|
20
+ puts "### loop #{i}"
21
+ ips = `host #{dns}`.split(/\n/).collect { |e| e.split.last }
22
+ ips.each do |ip|
23
+ val = begin
24
+ RestClient.get("http://#{ip}")
25
+ rescue => e
26
+ e.message
27
+ end
28
+ print ".. #{ip} - #{val}"
29
+ puts
30
+ end
31
+ sleep poll
32
+ end
33
+ end
34
+ end
8
35
  end
9
36
  end
10
37
  end
@@ -9,7 +9,7 @@ module Rig
9
9
  records = Rig::Model::Dns.records("#{zone}")
10
10
  rows = []
11
11
  records.each do |record|
12
- rows << [zone, record.type, record.ttl, record.name, record.value]
12
+ rows << [zone, record.type, record.ttl, record.name, [*record.value].join(",")]
13
13
  end
14
14
  print_table(%w{Domain Type TTL Name Value}, rows)
15
15
  end
@@ -5,7 +5,6 @@ module Rig
5
5
  module Command
6
6
  module Environment
7
7
  class Create < Abstract
8
-
9
8
  parameter "NAME", "the name of the environment"
10
9
  parameter "TEMPLATE", "the template to use (solo, multi, etc)", :default => "solo"
11
10
 
@@ -1,15 +1,56 @@
1
1
  require 'rig'
2
+ require 'awesome_print'
2
3
 
3
4
  module Rig
4
5
  module Command
5
6
  module Instance
6
7
  class Create < Abstract
8
+ option %w{-i --image}, "IMAGE", "the image / ami to use, default: your account image"
9
+ option %w{-f --flavor}, "FLAVOR", "the flavor / size to use"
10
+ option %w{-k --keypair}, "KEYPAIR", "the key pair / name to use, default: your account keypair"
11
+ option %w{-g --groups}, "GROUPS", "comma separated list of groups, default: your account groups"
12
+ option %w{-r --region}, "GROUPS", "the region, default: your account region"
13
+ option %w{--add}, :flag, "add this to the existing instances of this role and environment"
14
+ option "--[no-]chef", :flag, "use chef to bootstrap", :default => true
7
15
 
8
16
  parameter "ENVIRONMENT", "the environment this instance should belong to"
9
17
  parameter "ROLE", "the instance role", :default => 'solo'
10
18
 
11
19
  def execute
12
- puts "create: env:#{environment} role:#{role}"
20
+ name = role
21
+ # figure out if there are others of this role, if there are add a number to name to distinguish.
22
+ n = "#{name}.#{environment}.env"
23
+ chef = Rig.config[:chef] ? true : false
24
+
25
+ unless flavor
26
+ raise "must specify flavor"
27
+ end
28
+
29
+ o = {
30
+ :image_id => image,
31
+ :flavor_id => flavor,
32
+ :key_name => keypair,
33
+ :groups => groups.split(','),
34
+ :user_data => Rig::Model::Userdata.create(n, role, environment, :chef => chef)
35
+ }
36
+ tags = {'Name' => n, 'Environment' => environment, 'Role' => role}
37
+ server = Rig::Model::Instance.create(o, tags)
38
+ puts "created: #{server.id}"
39
+ rescue => e
40
+ puts "error: #{e.message}"
41
+ raise Clamp::HelpWanted, self
42
+ end
43
+
44
+ def default_image
45
+ Rig.account[:image].is_a?(Hash) ? Rig.account[:image].first.last : Rig.account[:image]
46
+ end
47
+
48
+ def default_keypair
49
+ Rig.account[:keypair]
50
+ end
51
+
52
+ def default_groups
53
+ Rig.account[:groups].join(",")
13
54
  end
14
55
  end
15
56
  end
@@ -6,7 +6,7 @@ module Rig
6
6
  class List < Abstract
7
7
  include Options::ShowAll
8
8
 
9
- option %w{-d --detailed}, :flag, "show more information in table"
9
+ option %w{-l --long}, :flag, "show more information in table"
10
10
  parameter "[ENV]", "environment"
11
11
 
12
12
  def execute
@@ -16,7 +16,7 @@ module Rig
16
16
  filters["tag:Environment"] = env if env
17
17
 
18
18
  list = connection.servers.all(filters)
19
- instance_list(list, detailed?)
19
+ instance_list(list, long?)
20
20
  end
21
21
  end
22
22
  end
@@ -1,9 +1,10 @@
1
1
  module Rig
2
2
  module Command
3
3
  class Ssh < Abstract
4
+ option %w{-u --user}, "USER", "the user to login as", :default => (Rig.config[:ssh][:user] rescue nil)
4
5
  parameter "NAME", "name of the host. <role><#>.<env>, eg: solo1.stable for the first solo role in environment stable"
5
6
  def execute
6
- user = Rig.config[:ssh][:user] rescue nil
7
+ #user = Rig.config[:ssh][:user] rescue nil
7
8
  unless user
8
9
  puts "must set rig:ssh:user in configuration."
9
10
  exit(1)
@@ -23,16 +23,15 @@ module Rig
23
23
  )
24
24
  end
25
25
 
26
- def create(name, value)
26
+ def create(name, value, options={})
27
27
  zone = zone(Rig.get_config(:dns_zone))
28
28
 
29
29
  if IPAddress.valid?(value)
30
30
  #A record
31
- o = {:name => name, :value => value, :type => 'A', :ttl => 86400}
31
+ o = {:name => name, :value => value, :type => 'A', :ttl => 86400}.merge(options)
32
32
  else
33
33
  #CNAME record
34
- #name = name.gsub(/\.#{Rig.get_config(:dns_zone)}/,'')
35
- o = {:name => name, :value => value, :type => 'CNAME', :ttl => 300}
34
+ o = {:name => name, :value => value, :type => 'CNAME', :ttl => 300}.merge(options)
36
35
  end
37
36
  zone.records.create(o)
38
37
  end
@@ -96,22 +96,14 @@ module Rig
96
96
 
97
97
  @balancers << balancer
98
98
 
99
- # set dns for balancer for this role (<role>.<env>.env.inqlabs.com)
100
- # example:
101
- # if there are 3 servers with the harvester role
102
- # in the environment test
103
- # then the dns would be harvester.test.env.inqlabs.com
104
- puts ".. dns: #{role}.#{name}.env.#@zone #{balancer.attributes[:dns_name]}"
105
- Rig::Model::Dns.create("#{role}.#{name}.env.#@zone", balancer.attributes[:dns_name])
106
-
107
99
  # set primary dns for environment (<name>.env.inqlabs.com)
108
100
  # to point to this load balancer
109
101
  if tmpl[:primary]
110
102
  puts ".. primary: #{name}.env.#@zone #{balancer.attributes[:dns_name]}"
111
- Rig::Model::Dns.create("#{name}.env.#@zone", balancer.attributes[:dns_name])
103
+ Rig::Model::Dns.create("#{name}.env.#@zone", balancer.attributes[:dns_name], :ttl => 30)
112
104
  end
113
105
  else
114
- #TODO: handle no balancer, but primary - point to server instance
106
+ #TODO: need to support balancer: false, primary: true = point to server instance
115
107
  #if tmpl[:primary]
116
108
  # puts ".. primary #{name}.env.#@zone #{}"
117
109
  #end
@@ -32,8 +32,8 @@ module Rig
32
32
  end
33
33
 
34
34
  def find_by_nick(name)
35
- (role, num, env) = name.match(/(\w+)(\d+)\.(\w+)/)[1..3]
36
- find_by_role_and_environment(role, env).select {|s| s.tags['Name'] =~ /^#{role}#{num}/ }
35
+ (role, env) = name.match(/(\w+)\.(\w+)/)[1..2]
36
+ find_by_role_and_environment(role, env).select {|s| s.tags['Name'] =~ /^#{role}/ }
37
37
  end
38
38
 
39
39
  def create(opts, tags={})
@@ -3,7 +3,7 @@ unless defined?(Rig::Version)
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 1
6
+ TINY = 2
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,116 +1,120 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rig
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Shawn Catanzarite
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-08 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: clamp
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: fog
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: fog
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :runtime
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: ipaddress
50
39
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: ipaddress
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :runtime
61
- version_requirements: *id003
62
- - !ruby/object:Gem::Dependency
63
- name: terminal-table
64
55
  prerelease: false
65
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: terminal-table
64
+ requirement: !ruby/object:Gem::Requirement
66
65
  none: false
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- hash: 3
71
- segments:
72
- - 0
73
- version: "0"
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
74
70
  type: :runtime
75
- version_requirements: *id004
76
- - !ruby/object:Gem::Dependency
77
- name: erubis
78
71
  prerelease: false
79
- requirement: &id005 !ruby/object:Gem::Requirement
72
+ version_requirements: !ruby/object:Gem::Requirement
80
73
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
- version: "0"
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: erubis
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
88
86
  type: :runtime
89
- version_requirements: *id005
90
- - !ruby/object:Gem::Dependency
91
- name: awesome_print
92
87
  prerelease: false
93
- requirement: &id006 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
94
89
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: awesome_print
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
102
  type: :runtime
103
- version_requirements: *id006
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
104
110
  description: Cloud provisioning tool built on ruby fog
105
- email:
111
+ email:
106
112
  - scatanzarite@gmail.com
107
- executables:
113
+ executables:
108
114
  - rig
109
115
  extensions: []
110
-
111
116
  extra_rdoc_files: []
112
-
113
- files:
117
+ files:
114
118
  - .gitignore
115
119
  - Gemfile
116
120
  - LICENSE
@@ -171,37 +175,26 @@ files:
171
175
  - rig.gemspec
172
176
  homepage: https://github.com/shawncatz/rig
173
177
  licenses: []
174
-
175
178
  post_install_message:
176
179
  rdoc_options: []
177
-
178
- require_paths:
180
+ require_paths:
179
181
  - lib
180
- required_ruby_version: !ruby/object:Gem::Requirement
182
+ required_ruby_version: !ruby/object:Gem::Requirement
181
183
  none: false
182
- requirements:
183
- - - ">="
184
- - !ruby/object:Gem::Version
185
- hash: 3
186
- segments:
187
- - 0
188
- version: "0"
189
- required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ! '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
189
  none: false
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- hash: 3
195
- segments:
196
- - 0
197
- version: "0"
190
+ requirements:
191
+ - - ! '>='
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
198
194
  requirements: []
199
-
200
195
  rubyforge_project:
201
- rubygems_version: 1.8.24
196
+ rubygems_version: 1.8.21
202
197
  signing_key:
203
198
  specification_version: 3
204
199
  summary: Cloud provisioning tool built on ruby fog
205
200
  test_files: []
206
-
207
- has_rdoc: