rhc 1.3.8 → 1.4.7

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.
@@ -370,9 +370,8 @@ describe RHC::Commands::Cartridge do
370
370
  end
371
371
  end
372
372
 
373
- =begin
374
- # Commenting this out for US2438
375
373
  describe 'cartridge storage' do
374
+ let!(:rest_client){ MockRestClient.new }
376
375
  let(:cmd_base) { ['cartridge', 'storage'] }
377
376
  let(:std_args) { ['-a', 'app1', '--noprompt', '--config', 'test.conf', '-l', 'test@test.foo', '-p', 'password'] | (@extra_args || []) }
378
377
  let(:cart_type) { ['mock_cart-1'] }
@@ -393,7 +392,7 @@ describe RHC::Commands::Cartridge do
393
392
 
394
393
  context 'when run for a non-existent cartridge' do
395
394
  let(:arguments) { cmd_base | ['bogus_cart'] | std_args }
396
- it { fail_with_message("Cartridge bogus_cart can't be found in application", 154) }
395
+ it { fail_with_message("There are no cartridges that match 'bogus_cart'.", 154) }
397
396
  end
398
397
 
399
398
  context 'when run with -c flag' do
@@ -458,5 +457,4 @@ describe RHC::Commands::Cartridge do
458
457
  end
459
458
  end
460
459
  end
461
- =end
462
460
  end
@@ -139,19 +139,28 @@ describe RHC::Commands::PortForward do
139
139
  end
140
140
 
141
141
  context 'when port forwarding a scaled app with ports to forward' do
142
+ let(:haproxy_host_1) { '127.0.0.1' }
143
+ let(:haproxy_host_2) { '127.0.0.2' }
144
+ let(:mongo_host) { '51125bb94a-test907742.dev.rhcloud.com' }
145
+ let(:ipv6_host) { '::1' }
142
146
  before(:each) do
143
147
  Net::SSH.should_receive(:start).with(@uri.host, @uri.user).and_yield(@ssh).twice
144
- @ssh.should_receive(:exec!).with("rhc-list-ports").and_yield(nil, :stderr, "httpd -> 127.0.0.1:8080\nhttpd -> 127.0.0.2:8080")
148
+ @ssh.should_receive(:exec!).with("rhc-list-ports").
149
+ and_yield(nil, :stderr, "httpd -> #{haproxy_host_1}:8080\nhttpd -> #{haproxy_host_2}:8080\nmongodb -> #{mongo_host}:35541\nmysqld -> #{ipv6_host}:3306")
145
150
  forward = mock(Net::SSH::Service::Forward)
146
151
  @ssh.should_receive(:forward).at_least(3).times.and_return(forward)
147
152
  if mac?
148
- forward.should_receive(:local).with(8080, '127.0.0.1', 8080)
149
- forward.should_receive(:local).with(8080, '127.0.0.2', 8080).and_raise(Errno::EADDRINUSE)
150
- forward.should_receive(:local).with(8081, '127.0.0.2', 8080)
153
+ forward.should_receive(:local).with(8080, haproxy_host_1, 8080)
154
+ forward.should_receive(:local).with(8080, haproxy_host_2, 8080).and_raise(Errno::EADDRINUSE)
155
+ forward.should_receive(:local).with(8081, haproxy_host_2, 8080)
156
+ forward.should_receive(:local).with(35541, mongo_host, 35541)
157
+ forward.should_receive(:local).with(3306, ipv6_host, 3306)
151
158
  else
152
- forward.should_receive(:local).with('127.0.0.1', 8080, '127.0.0.1', 8080)
153
- forward.should_receive(:local).with('127.0.0.2', 8080, '127.0.0.2', 8080).and_raise(Errno::EADDRINUSE)
154
- forward.should_receive(:local).with('127.0.0.2', 8081, '127.0.0.2', 8080)
159
+ forward.should_receive(:local).with(haproxy_host_1, 8080, haproxy_host_1, 8080)
160
+ forward.should_receive(:local).with(haproxy_host_2, 8080, haproxy_host_2, 8080).and_raise(Errno::EADDRINUSE)
161
+ forward.should_receive(:local).with(haproxy_host_2, 8081, haproxy_host_2, 8080)
162
+ forward.should_receive(:local).with(mongo_host, 35541, mongo_host, 35541)
163
+ forward.should_receive(:local).with(ipv6_host, 3306, ipv6_host, 3306)
155
164
  end
156
165
  @ssh.should_receive(:loop).and_raise(Interrupt.new)
157
166
  end
@@ -8,6 +8,7 @@ require 'highline/import'
8
8
  require 'rhc/config'
9
9
  require 'rhc/helpers'
10
10
  require 'date'
11
+ require 'resolv'
11
12
 
12
13
  describe RHC::Helpers do
13
14
  before(:each) do
@@ -320,6 +321,34 @@ describe RHC::Helpers do
320
321
  subject.fingerprint_for_local_key('1').should be_nil
321
322
  end
322
323
  end
324
+
325
+ context "Resolv helper" do
326
+ let(:resolver) { Object.new }
327
+ let(:existent_host) { 'real_host' }
328
+ let(:nonexistent_host) { 'fake_host' }
329
+
330
+ before :all do
331
+ Resolv::Hosts.stub(:new) { resolver }
332
+ resolver.stub(:getaddress).with(existent_host) { existent_host }
333
+ resolver.stub(:getaddress).with(nonexistent_host){ Resolv::ResolvError }
334
+ end
335
+
336
+ context "when hosts file has the desired host" do
337
+ it "does not raise error" do
338
+ expect {
339
+ subject.hosts_file_contains?(existent_host)
340
+ }.to_not raise_error
341
+ end
342
+ end
343
+
344
+ context "when hosts file does not have the desired host" do
345
+ it "does not raise error" do
346
+ expect {
347
+ subject.hosts_file_contains?(nonexistent_host)
348
+ }.to_not raise_error
349
+ end
350
+ end
351
+ end
323
352
 
324
353
  class OutputTests
325
354
  include RHC::Helpers
@@ -490,6 +519,7 @@ describe RHC::CartridgeHelpers do
490
519
 
491
520
  subject do
492
521
  Class.new(Object) do
522
+ include RHC::Helpers
493
523
  include RHC::CartridgeHelpers
494
524
 
495
525
  def config
@@ -498,26 +528,32 @@ describe RHC::CartridgeHelpers do
498
528
  end.new
499
529
  end
500
530
 
501
- describe '#find_cartridge' do
531
+ describe '#check_cartridges' do
502
532
  let(:cartridges){ [] }
503
533
  let(:find_cartridges){ [] }
504
534
  context "with a generic object" do
505
- let(:rest_obj) do
506
- Object.new.tap do |o|
507
- o.stub(:find_cartridges).and_return(find_cartridges)
508
- o.stub(:cartridges).and_return(cartridges)
509
- end
510
- end
511
- it { expect{ subject.find_cartridge(rest_obj, 'foo') }.should raise_error(RHC::CartridgeNotFoundException, 'Cartridge \'foo\' is not a valid cartridge name.') }
535
+ it { expect{ subject.send(:check_cartridges, 'foo', :from => cartridges) }.should raise_error(RHC::CartridgeNotFoundException, 'There are no cartridges that match \'foo\'.') }
512
536
  end
513
- context "with an Application" do
514
- let(:rest_obj) do
515
- RHC::Rest::Application.new('name' => 'my_app').tap do |o|
516
- o.stub(:find_cartridges).and_return(find_cartridges)
517
- o.stub(:cartridges).and_return(cartridges)
518
- end
519
- end
520
- it { expect{ subject.find_cartridge(rest_obj, 'foo') }.should raise_error(RHC::CartridgeNotFoundException, 'Cartridge \'foo\' cannot be found in application \'my_app\'.') }
537
+ end
538
+ describe '#web_carts_only' do
539
+ it { expect{ subject.send(:web_carts_only).call([]) }.to raise_error(RHC::MultipleCartridgesException, /You must select only a single web/) }
540
+ end
541
+
542
+ describe '#match_cart' do
543
+ context 'with a nil cart' do
544
+ let(:cart){ OpenStruct.new(:name => nil, :description => nil, :tags => nil) }
545
+ it{ subject.send(:match_cart, cart, 'foo').should be_false }
546
+ end
547
+ context 'with simple strings' do
548
+ let(:cart){ OpenStruct.new(:name => 'FOO-more_max any', :description => 'bar', :tags => [:baz]) }
549
+ it{ subject.send(:match_cart, cart, 'foo').should be_true }
550
+ it{ subject.send(:match_cart, cart, 'fo').should be_true }
551
+ it{ subject.send(:match_cart, cart, 'oo').should be_true }
552
+ it{ subject.send(:match_cart, cart, 'bar').should be_true }
553
+ it{ subject.send(:match_cart, cart, 'baz').should be_true }
554
+ it{ subject.send(:match_cart, cart, 'more max').should be_true }
555
+ it{ subject.send(:match_cart, cart, 'foo more max any').should be_true }
556
+ it{ subject.send(:match_cart, cart, 'foo_more max-any').should be_true }
521
557
  end
522
558
  end
523
559
  end
@@ -56,12 +56,7 @@ describe RHC::Wizard do
56
56
  subject.should_receive(:ssh_key_uploaded?).and_return(true)
57
57
  subject.should_receive(:applications).and_return([app])
58
58
  Net::SSH.should_receive(:start).and_raise(StandardError.new('an_error'))
59
- subject.should_receive(:report_result) do |ssh, msg|
60
- ssh.should be_nil
61
- msg.should match('An SSH connection could not be established')
62
- msg.should match('an_error')
63
- end
64
- subject.send(:test_ssh_connectivity).should be_false
59
+ expect{ subject.send(:test_ssh_connectivity) }.to raise_error(RuntimeError, /An SSH connection could not be established to foo.com/)
65
60
  end
66
61
  end
67
62
 
@@ -55,7 +55,6 @@ class FakeFS::File
55
55
  end
56
56
  end
57
57
 
58
- #include 'mocha'
59
58
  require 'rhc/cli'
60
59
 
61
60
  include WebMock::API
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.8
4
+ version: 1.4.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-28 00:00:00.000000000 Z
12
+ date: 2013-02-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: test-unit
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: commander
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -225,22 +209,6 @@ dependencies:
225
209
  - - ! '>='
226
210
  - !ruby/object:Gem::Version
227
211
  version: '0'
228
- - !ruby/object:Gem::Dependency
229
- name: dnsruby
230
- requirement: !ruby/object:Gem::Requirement
231
- none: false
232
- requirements:
233
- - - ! '>='
234
- - !ruby/object:Gem::Version
235
- version: '0'
236
- type: :development
237
- prerelease: false
238
- version_requirements: !ruby/object:Gem::Requirement
239
- none: false
240
- requirements:
241
- - - ! '>='
242
- - !ruby/object:Gem::Version
243
- version: '0'
244
212
  - !ruby/object:Gem::Dependency
245
213
  name: activesupport
246
214
  requirement: !ruby/object:Gem::Requirement
@@ -261,20 +229,7 @@ description: The client tools for the OpenShift platform that allow for applicat
261
229
  management.
262
230
  email: dev@lists.openshift.redhat.com
263
231
  executables:
264
- - rhc-tail-files
265
- - rhc-domain
266
- - rhc-user-info
267
- - rhc-create-domain
268
- - rhc-ctl-app
269
- - rhc-ctl-domain
270
- - rhc-chk
271
- - rhc-app
272
- - rhc-create-app
273
232
  - rhc
274
- - rhc-sshkey
275
- - rhc-domain-info
276
- - rhc-snapshot
277
- - rhc-port-forward
278
233
  extensions: []
279
234
  extra_rdoc_files: []
280
235
  files:
@@ -330,7 +285,6 @@ files:
330
285
  - lib/rhc/help_formatter.rb
331
286
  - lib/rhc/rest.rb
332
287
  - lib/rhc/helpers.rb
333
- - lib/rhc-common.rb
334
288
  - lib/rhc.rb
335
289
  - lib/rhc/usage_templates/command_syntax_help.erb
336
290
  - lib/rhc/usage_templates/help.erb
@@ -414,20 +368,7 @@ files:
414
368
  - features/lib/rhc_helper/persistable.rb
415
369
  - features/lib/rhc_helper/sshkey.rb
416
370
  - features/README.md
417
- - bin/rhc-tail-files
418
- - bin/rhc-domain
419
- - bin/rhc-user-info
420
- - bin/rhc-create-domain
421
- - bin/rhc-ctl-app
422
- - bin/rhc-ctl-domain
423
- - bin/rhc-chk
424
- - bin/rhc-app
425
- - bin/rhc-create-app
426
371
  - bin/rhc
427
- - bin/rhc-sshkey
428
- - bin/rhc-domain-info
429
- - bin/rhc-snapshot
430
- - bin/rhc-port-forward
431
372
  homepage: https://github.com/openshift/rhc
432
373
  licenses: []
433
374
  post_install_message: ! '===========================================================================
@@ -1,549 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rhc/coverage_helper'
4
-
5
- require 'rhc-common'
6
- require 'base64'
7
-
8
- if ["add-alias", "remove-alias"].include? ARGV[0]
9
- RHC::Helpers.deprecated_command('rhc alias (add|remove)',true)
10
- elsif "snapshot" == ARGV[0]
11
- RHC::Helpers.deprecated_command('rhc snapshot (save|restore)',true)
12
- elsif "tail" == ARGV[0]
13
- RHC::Helpers.deprecated_command('rhc tail',true)
14
- elsif "cartridge" == ARGV[0]
15
- RHC::Helpers.deprecated_command('rhc cartridge (add|remove|status|stop|start|restart|reload)',true)
16
- else
17
- RHC::Helpers.deprecated_command('rhc app (create|delete|show|stop|force-stop|start|restart|reload|tidy)',true)
18
- end
19
-
20
- $embed_mapper = { 'add' => 'configure', 'remove' => 'deconfigure' }
21
-
22
- #
23
- # print help
24
- #
25
- def p_usage(exit_code = 255)
26
- libra_server = get_var('libra_server')
27
- rhlogin = get_var('default_rhlogin') ? "Default: #{get_var('default_rhlogin')}" : "required"
28
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'standalone', false)
29
- puts <<USAGE
30
-
31
- Usage: rhc app (<command> | cartridge <cartridge-action> | --help) [<args>]
32
- Create and manage an OpenShift application.
33
-
34
- List of commands
35
- create Create a new application on OpenShift
36
- show Display information about a user
37
- start Starts the application (includes all cartridges)
38
- stop Stops the application (includes all cartridges)
39
- force-stop Stops all application processes
40
- restart Restart the application
41
- reload Reloads application configuration
42
- status Returns application status
43
- destroy Destroys the application
44
- tidy Garbage collects the git repo and empties log/tmp dirs
45
- add-alias Add a custom domain name for the application
46
- remove-alias Remove a custom domain name for the application
47
- tail Tail the logs of an application
48
- snapshot [save|restore] Saves/Restores an application snapshot to/from a tarball at the location specified using --filepath (default: ./$APPNAME.tar.gz)
49
- cartridge <action> Manage a cartridge running in this application
50
-
51
- List of cartridge actions
52
- list List of supported embedded cartridges
53
- add Add a cartridge to this application
54
- remove Remove a cartridge from this application
55
- stop Stop a cartridge
56
- start Start a cartridge
57
- restart Restart a cartridge
58
- status Returns cartridge status
59
- reload Reloads cartridge configuration
60
-
61
- List of arguments
62
- -l|--rhlogin rhlogin OpenShift login (#{rhlogin})
63
- -p|--password password Password (optional, will prompt)
64
- -a|--app application Application name (alphanumeric - max #{RHC::APP_NAME_MAX_LENGTH} chars) (required)
65
- -t|--type type Type of app to create (#{type_keys}) (required for creating an application)
66
- -c|--cartridge cartridge The embedded cartrige to manage (required for the cartridge command)
67
- -g|--gear-size size The size of the gear for this app ([small|medium], defaults to small)
68
- -s|--scaling Enable scaling for this app
69
- -r|--repo path Git Repo path (defaults to ./$app_name)
70
- -n|--nogit Only create remote space, don't pull it locally
71
- --no-dns Skip DNS check. Must be used in combination with --nogit
72
- -d|--debug Print Debug info
73
- -h|--help Show Usage info
74
- -b|--bypass Bypass warnings (applicable to application destroying only)
75
- -f|--filepath filepath Applicable in case of snapshot and log command
76
- -o|--opts options Options to pass to the server-side (linux based) tail command (applicable to tail command only) (-f is implicit. See the linux tail man page full list of options.) (Ex: --opts '-n 100')
77
- --alias alias Specify server alias (when using add/remove-alias)
78
- --config path Path of alternate config file
79
- --timeout # Timeout, in seconds, for the session
80
- --enable-jenkins [name] Enables builds for your application with Jenkins. You may optionally specify the name of the Jenkins application that is created (default: 'jenkins'). Note that --no-dns is ignored for the creation of the Jenkins application.
81
- USAGE
82
- exit exit_code
83
- end
84
-
85
-
86
- def validate_args(val_type=true, val_cartridge=false, val_timeout=true)
87
-
88
- # If provided a config path, check it
89
- RHC::Config.check_cpath($opt)
90
-
91
- # Pull in configs from files
92
- $libra_server = get_var('libra_server')
93
- debug = get_var('debug') == 'false' ? nil : get_var('debug')
94
-
95
- $opt['rhlogin'] = get_var('default_rhlogin') unless $opt['rhlogin']
96
- p_usage if !RHC::check_rhlogin($opt['rhlogin'])
97
-
98
- p_usage if !RHC::check_app($opt['app'])
99
-
100
- if val_type && !$opt['type']
101
- puts "Application Type is required"
102
- p_usage
103
- end
104
-
105
- if val_cartridge && !$opt['cartridge']
106
- puts "Cartridge name is required"
107
- p_usage
108
- end
109
-
110
- debug = true if $opt.has_key? 'debug'
111
- RHC::debug(debug)
112
-
113
- RHC::timeout($opt["timeout"], get_var('timeout')) if val_timeout
114
- RHC::connect_timeout($opt["timeout"], get_var('timeout')) if val_timeout
115
-
116
- $password = $opt['password'] ? $opt['password'] : RHC::get_password
117
- end
118
-
119
- def create_app
120
- validate_args
121
-
122
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, false)
123
- app_info = user_info['app_info']
124
-
125
- if app_info[$opt['app']]
126
- puts "An application named '#{$opt['app']}' in namespace '#{user_info['user_info']['domains'][0]['namespace']}' already exists"
127
- exit 255
128
- end
129
-
130
- jenkins_app_name = nil
131
- has_jenkins = false
132
- if $opt['enable-jenkins']
133
- app_info.each do |app_name, app|
134
- if app['framework'] == 'jenkins-1.4'
135
- jenkins_app_name = app_name
136
- has_jenkins = true
137
- puts "
138
- Found existing Jenkins application: #{jenkins_app_name}
139
- "
140
- if !$opt['enable-jenkins'].empty?
141
- puts "Ignoring specified Jenkins app name: #{$opt['enable-jenkins']}"
142
- end
143
- end
144
- end
145
- if !has_jenkins
146
- if $opt['type'] =~ /^jenkins-/
147
- has_jenkins = true
148
- if $opt['no-dns']
149
- puts "
150
- The --no-dns option can't be used in conjunction with --enable-jenkins
151
- when creating a #{$opt['type']} application. Either remove the --no-dns
152
- option or first install your #{$opt['type']} application with --no-dns
153
- and then use 'rhc app cartridge add' to embed the Jenkins client.
154
- "
155
- exit 255
156
- end
157
- jenkins_app_name = $opt['app']
158
- puts "
159
- The Jenkins client will be embedded into the Jenkins application
160
- currently being created: '#{$opt['app']}'
161
- "
162
- end
163
- end
164
- if !has_jenkins
165
- if !$opt['enable-jenkins'].empty?
166
- jenkins_app_name = $opt['enable-jenkins']
167
- else
168
- jenkins_app_name = 'jenkins'
169
- end
170
-
171
- if !RHC::check_app(jenkins_app_name)
172
- p_usage
173
- end
174
-
175
- if jenkins_app_name == $opt['app']
176
- puts "You must specify a different name for your application and Jenkins ('#{$opt['app']}')."
177
- exit 100
178
- end
179
-
180
- if app_info.has_key?(jenkins_app_name)
181
- puts "You already have an application named '#{jenkins_app_name}'."
182
- puts "In order to continue you'll need to specify a different name"
183
- puts "with --enable-jenkins or destroy the existing application."
184
- exit 100
185
- end
186
- end
187
- end
188
-
189
- $opt['gear-size']='small' unless $opt['gear-size']
190
-
191
- $opt['repo'] = $opt['app'] unless $opt['repo']
192
-
193
- if @mydebug
194
- puts "
195
- Found a bug? Post to the forum and we'll get right on it.
196
- IRC: #openshift on freenode
197
- Forums: https://openshift.redhat.com/community/forums/openshift
198
-
199
- "
200
- end
201
-
202
- #
203
- # Confirm local git repo exists
204
- #
205
- unless $opt['nogit']
206
- if File.exists?($opt['repo'])
207
- puts "We will not overwrite an existing git repo. Please remove:"
208
- puts " #{File.expand_path($opt['repo'])}"
209
- puts "Then try again."
210
- puts
211
- exit 210
212
- else
213
- begin
214
- # Create the parent directory for the git repo
215
- @git_parent = File.expand_path($opt['repo'] + "/../")
216
- FileUtils.mkdir_p(@git_parent)
217
- rescue Exception => e
218
- puts "Could not write to #{@git_parent}"
219
- puts "Reason: #{e.message}"
220
- puts
221
- puts "Please re-run from a directory you have write access to or specify -r with a"
222
- puts "path you have write access to"
223
- puts
224
- exit 211
225
- end
226
- end
227
- end
228
-
229
- if jenkins_app_name && !has_jenkins
230
- jenkins_app = RHC::create_app($libra_server, RHC::Config.default_proxy, user_info, jenkins_app_name, 'jenkins-1.4', $opt['rhlogin'], $password, nil, false, true, true)
231
- available = RHC::check_app_available(RHC::Config.default_proxy, jenkins_app[:app_name], jenkins_app[:fqdn], jenkins_app[:health_check_path], jenkins_app[:result], jenkins_app[:git_url], nil, true)
232
- if !available
233
- puts "Unable to access your new Jenkins application."
234
- exit 1
235
- end
236
- end
237
-
238
- #
239
- # Create remote application space
240
- #
241
- main_app = RHC::create_app($libra_server, RHC::Config.default_proxy, user_info, $opt['app'], $opt['type'], $opt['rhlogin'], $password, $opt['repo'], $opt['no-dns'], $opt['nogit'], false, $opt['gear-size'], $opt['scaling'])
242
- if jenkins_app_name
243
- puts "Now embedding the jenkins client into '#{$opt['app']}'..."
244
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, 'configure', true, 'jenkins-client-1.4', nil, false)
245
- end
246
-
247
- if $opt['no-dns']
248
- # In case of the no-dns option, the availability check is not made
249
- # This also results in the git information and app creation result not being displayed
250
- # Hence, for this case, we print out the git url and result here
251
- puts "git url: #{main_app[:git_url]}"
252
- if main_app[:result] && !main_app[:result].empty?
253
- puts "#{main_app[:result]}"
254
- end
255
- else
256
- available = RHC::check_app_available(RHC::Config.default_proxy, main_app[:app_name], main_app[:fqdn], main_app[:health_check_path], main_app[:result], main_app[:git_url], $opt['repo'], $opt['nogit'])
257
- if !available
258
- puts "Unable to access your new application."
259
- exit 1
260
- end
261
- end
262
-
263
- end
264
-
265
- def get_args(l)
266
- l.shift
267
- args = ""
268
- l.each do|a|
269
- if (a.to_s.strip.length == 0 || a.to_s.strip.match(/\s/) ); a = "'#{a}'" end
270
- args += " #{a}"
271
- end
272
- args
273
- end
274
-
275
- def show_app
276
- validate_args(false)
277
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, true)
278
-
279
- app_found = false
280
- unless user_info['app_info'].empty?
281
- user_info['app_info'].each do |key, val|
282
- if key == $opt['app']
283
- app_found = true
284
- puts ""
285
- puts "Application Info"
286
- puts "================"
287
- puts key
288
- puts " Framework: #{val['framework']}"
289
- puts " Creation: #{val['creation_time']}"
290
- puts " UUID: #{val['uuid']}"
291
- puts " Git URL: ssh://#{val['uuid']}@#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/~/git/#{key}.git/"
292
- puts " Public URL: http://#{key}-#{user_info['user_info']['domains'][0]['namespace']}.#{user_info['user_info']['rhc_domain']}/"
293
- if val['aliases'] && !val['aliases'].empty?
294
- puts " Aliases: #{val['aliases'].join(', ')}"
295
- end
296
- puts ""
297
- puts " Embedded: "
298
- if val['embedded'] && !val['embedded'].empty?
299
- val['embedded'].each do |embed_key, embed_val|
300
- if embed_val.has_key?('info') && !embed_val['info'].empty?
301
- puts " #{embed_key} - #{embed_val['info']}"
302
- else
303
- puts " #{embed_key}"
304
- end
305
- end
306
- else
307
- puts " None"
308
- end
309
- puts ""
310
-
311
- # there should be a single application with the given app name
312
- break
313
-
314
- end
315
- end
316
- end
317
-
318
- if !app_found
319
- puts
320
- puts "Could not find app '#{$opt['app']}'. Please run 'rhc domain show' to get a list"
321
- puts "of your current running applications"
322
- puts
323
- exit 1
324
- end
325
-
326
- end
327
-
328
- def control_app(command)
329
- validate_args(false)
330
-
331
- if ($opt['alias'] and !(command =~ /-alias$/)) || (command =~ /-alias$/ and ! $opt['alias'])
332
- puts "When specifying alias make sure to use add-alias or remove-alias command"
333
- p_usage
334
- end
335
-
336
- command = "deconfigure" if command == "destroy"
337
-
338
- if !$opt["bypass"] and command == "deconfigure"
339
- # deconfigure is the actual hook called on 'destroy'
340
- # destroy is used for clarity
341
- puts <<WARNING
342
- !!!! WARNING !!!! WARNING !!!! WARNING !!!!
343
- You are about to destroy the #{$opt['app']} application.
344
-
345
- This is NOT reversible, all remote data for this application will be removed.
346
- WARNING
347
-
348
- print "Do you want to destroy this application (y/n): "
349
- begin
350
- agree = gets.chomp
351
- if agree != 'y'
352
- puts "\n"
353
- exit 217
354
- end
355
- rescue Interrupt
356
- puts "\n"
357
- exit 217
358
- end
359
- end
360
-
361
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, command, false, nil, $opt['alias'])
362
- end
363
-
364
- def control_cartridge(command)
365
- validate_args(false, true)
366
-
367
- # override command if it's in the mapper
368
- command = $embed_mapper[command] if $embed_mapper[command]
369
- framework = $opt['cartridge']
370
-
371
- RHC::ctl_app($libra_server, RHC::Config.default_proxy, $opt['app'], $opt['rhlogin'], $password, command, true, framework, $opt['alias'])
372
- end
373
-
374
- def show_embedded_list
375
- libra_server = get_var('libra_server')
376
- puts ""
377
- puts "List of supported embedded cartridges:"
378
- puts ""
379
- type_keys = RHC::get_cartridge_listing(nil, ', ', libra_server, RHC::Config.default_proxy, 'embedded', false)
380
- puts type_keys
381
- puts ""
382
-
383
- # we should always get something back unless there was an error
384
- exit 255 if type_keys.length == 0
385
- exit 0
386
- end
387
-
388
- def save_or_restore_snapshot(command)
389
- validate_args(false, false, true)
390
-
391
- user_info = RHC::get_user_info($libra_server, $opt['rhlogin'], $password, RHC::Config.default_proxy, @mydebug, false)
392
-
393
- app = $opt['app']
394
- $opt['filepath'] = "#{$opt['app']}.tar.gz" unless $opt['filepath']
395
-
396
- unless user_info['app_info'][app]
397
- puts
398
- puts "Could not find app '#{app}'. Please run 'rhc domain show' to get a list"
399
- puts "of your current running applications"
400
- puts
401
- exit 101
402
- end
403
-
404
- app_uuid = user_info['app_info'][app]['uuid']
405
- namespace = user_info['user_info']['domains'][0]['namespace']
406
- rhc_domain = user_info['user_info']['rhc_domain']
407
-
408
- if command == 'save'
409
- status = RHC.snapshot_create rhc_domain, namespace, app, app_uuid, $opt['filepath'], @mydebug
410
- exit status if ! status
411
- else
412
- status = RHC.snapshot_restore rhc_domain, namespace, app, app_uuid, $opt['filepath'], @mydebug
413
- exit status if ! status
414
- end
415
-
416
- end
417
-
418
- begin
419
- argv_c = ARGV.clone
420
-
421
- if ARGV[0] =~ /^create$/
422
- ARGV.shift
423
- opts = GetoptLong.new(
424
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
425
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
426
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
427
- ["--gear-size", "-g", GetoptLong::REQUIRED_ARGUMENT],
428
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
429
- ["--no-dns", GetoptLong::NO_ARGUMENT],
430
- ["--nogit", "-n", GetoptLong::NO_ARGUMENT],
431
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
432
- ["--repo", "-r", GetoptLong::REQUIRED_ARGUMENT],
433
- ["--type", "-t", GetoptLong::REQUIRED_ARGUMENT],
434
- ["--enable-jenkins", GetoptLong::OPTIONAL_ARGUMENT],
435
- ["--scaling", "-s", GetoptLong::OPTIONAL_ARGUMENT],
436
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
437
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
438
- )
439
- elsif ARGV[0] =~ /^(show|start|stop|force-stop|restart|reload|status|destroy|tidy|add-alias|remove-alias|destroy)$/
440
- ARGV.shift
441
- opts = GetoptLong.new(
442
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
443
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
444
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
445
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
446
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
447
- ["--alias", GetoptLong::REQUIRED_ARGUMENT],
448
- ["--bypass", "-b", GetoptLong::NO_ARGUMENT],
449
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
450
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
451
- )
452
- elsif ARGV[0] =~ /^cartridge$/
453
- ARGV.shift
454
- ARGV.shift if ARGV[0] =~ /^(add|remove|stop|start|restart|status|reload|list)$/
455
- opts = GetoptLong.new(
456
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
457
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
458
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
459
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
460
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
461
- ["--cartridge", "-c", GetoptLong::REQUIRED_ARGUMENT],
462
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
463
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
464
- )
465
- elsif ARGV[0] =~ /^tail$/
466
- ARGV.shift
467
- opts = GetoptLong.new(
468
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
469
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
470
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
471
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
472
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
473
- ["--opts", "-o", GetoptLong::REQUIRED_ARGUMENT],
474
- ["--filepath", "-f", GetoptLong::REQUIRED_ARGUMENT],
475
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
476
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
477
- )
478
- elsif ARGV[0] =~ /^snapshot$/
479
- ARGV.shift
480
- ARGV.shift if ARGV[0] =~ /^(save|restore)$/
481
- opts = GetoptLong.new(
482
- ["--debug", "-d", GetoptLong::NO_ARGUMENT],
483
- ["--help", "-h", GetoptLong::NO_ARGUMENT],
484
- ["--rhlogin", "-l", GetoptLong::REQUIRED_ARGUMENT],
485
- ["--password", "-p", GetoptLong::REQUIRED_ARGUMENT],
486
- ["--app", "-a", GetoptLong::REQUIRED_ARGUMENT],
487
- ["--filepath", "-f", GetoptLong::REQUIRED_ARGUMENT],
488
- ["--config", GetoptLong::REQUIRED_ARGUMENT],
489
- ["--timeout", GetoptLong::REQUIRED_ARGUMENT]
490
- )
491
- else
492
- opts = GetoptLong.new(
493
- ["--help", "-h", GetoptLong::NO_ARGUMENT]
494
- )
495
- unless ARGV[0] =~ /^(help|-h|--help)$/
496
- puts "Missing or invalid command!" unless ARGV[0] =~ /^(help|-h|--help)$/
497
- # just exit at this point
498
- # printing the usage description will be handled in the rescue
499
- exit 255
500
- end
501
- end
502
-
503
- $opt = {}
504
- opts.each do |o, a|
505
- $opt[o[2..-1]] = a.to_s
506
- end
507
-
508
- rescue Exception => e
509
- p_usage
510
- end
511
-
512
- p_usage 0 if $opt["help"]
513
-
514
- case argv_c[0]
515
- when "create"
516
- create_app
517
- when "show"
518
- show_app
519
- when "start", "stop", "force-stop", "restart", "reload", "status", "tidy", "add-alias", "remove-alias", "destroy"
520
- control_app(argv_c[0])
521
- when "tail"
522
- system("rhc-tail-files #{get_args argv_c} 2>&1")
523
- exit $?.exitstatus
524
- when "snapshot"
525
- case argv_c[1]
526
- when "save", "restore"
527
- save_or_restore_snapshot(argv_c[1])
528
- else
529
- puts "Missing or invalid snapshot action!"
530
- p_usage
531
- end
532
- when "cartridge"
533
- case argv_c[1]
534
- when "add", "remove", "start", "stop", "restart", "status", "reload"
535
- control_cartridge(argv_c[1])
536
- when "list", nil
537
- show_embedded_list
538
- else
539
- puts "Missing or invalid cartridge action!"
540
- p_usage
541
- end
542
- when "-h", "--help", "help", nil
543
- p_usage 0
544
- else
545
- puts "Invalid command!"
546
- p_usage
547
- end
548
-
549
- exit 0