jnewland-capsize 0.5.0 → 0.5.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.
data/README.textile CHANGED
@@ -40,6 +40,11 @@ h2. Tasks
40
40
  Run cap -e <taskname> on any task to get more details
41
41
 
42
42
  * cap ec2:console:output
43
+ * cap ec2:addresses:allocate
44
+ * cap ec2:addresses:associate
45
+ * cap ec2:addresses:disassociate
46
+ * cap ec2:addresses:release
47
+ * cap ec2:addresses:show
43
48
  * cap ec2:images:show
44
49
  * cap ec2:instances:reboot
45
50
  * cap ec2:instances:run
data/lib/capsize/ec2.rb CHANGED
@@ -12,7 +12,7 @@ Capistrano::Configuration.instance.load do
12
12
  Show instance console output.
13
13
  You can view the console of a specific instance by doing one of the following:
14
14
  - define an :instance_id in any Capsize config file with "set :instance_id, 'i-123456'"
15
- - Overide this on the command line with "cap ec2:console:output INSTANCE_ID='i-123456'"
15
+ - Override this on the command line with "cap ec2:console:output INSTANCE_ID='i-123456'"
16
16
  - If neither of these are provided you will be prompted by Capistano for the instance ID you wish to terminate.
17
17
  DESC
18
18
  task :output do
@@ -228,7 +228,7 @@ Capistrano::Configuration.instance.load do
228
228
  Terminate an EC2 instance.
229
229
  You can terminate a specific instance by doing one of the following:
230
230
  - define an :instance_id in deploy.rb with "set :instance_id, 'i-123456'"
231
- - Overide this on the command line with "cap ec2:instances:terminate INSTANCE_ID='i-123456'"
231
+ - Override this on the command line with "cap ec2:instances:terminate INSTANCE_ID='i-123456'"
232
232
  - If neither of these are provided you will be prompted by Capistano for the instance ID you wish to terminate.
233
233
  DESC
234
234
  task :terminate do
@@ -259,7 +259,7 @@ Capistrano::Configuration.instance.load do
259
259
  Reboot an EC2 instance.
260
260
  You can reboot a specific instance by doing one of the following:
261
261
  - define an :instance_id in deploy.rb with "set :instance_id, 'i-123456'"
262
- - Overide this on the command line with "cap ec2:instances:reboot INSTANCE_ID='i-123456'"
262
+ - Override this on the command line with "cap ec2:instances:reboot INSTANCE_ID='i-123456'"
263
263
  - If neither of these are provided you will be prompted by Capistano for the instance ID you wish to reboot.
264
264
  DESC
265
265
  task :reboot do
@@ -510,6 +510,145 @@ Capistrano::Configuration.instance.load do
510
510
 
511
511
  end
512
512
 
513
- end # end namespace :ec2
514
513
 
514
+ # ELASTIC IP (ADDRESSES) TASKS
515
+ #########################################
516
+
517
+ namespace :addresses do
518
+
519
+ desc <<-DESC
520
+ Show and describe elastic IP addresses assigned to your account.
521
+ DESC
522
+ task :show do
523
+ begin
524
+ result = capsize_ec2.describe_addresses()
525
+ rescue Exception => e
526
+ puts "The attempt to show elastic IP addresses failed with error : " + e
527
+ raise e
528
+ end
529
+
530
+ capsize_ec2.print_address_description(result)
531
+ end
532
+
533
+ desc <<-DESC
534
+ Acquire a new elastic IP address for use with your account.
535
+ DESC
536
+ task :allocate do
537
+ begin
538
+ print "Allocating elastic IP address ... "
539
+ $stdout.flush
540
+ response = capsize_ec2.allocate_address()
541
+ puts "success"
542
+ puts "Allocated address: #{response.publicIp}"
543
+ puts ""
544
+ rescue Exception => e
545
+ puts "failed"
546
+ puts "The attempt to allocate an elastic IP addresses failed with error : " + e
547
+ raise e
548
+ end
549
+ end
550
+
551
+ desc <<-DESC
552
+ Release an elastic IP from your account.
553
+ You can release a specific elastic IP by doing one of the following:
554
+ - define a :public_ip in deploy.rb with "set :public_ip, '123.1.2.3'"
555
+ - Override this on the command line with "cap ec2:addresses:release PUBLIC_IP='123.1.2.3'"
556
+ DESC
557
+ task :release do
558
+
559
+ capsize.get(:public_ip)
560
+
561
+ case public_ip
562
+ when nil, ""
563
+ puts "You don't seem to have set a public_ip ..."
564
+ else
565
+ confirm = (Capistrano::CLI.ui.ask("WARNING! Really release elastic IP address \"#{public_ip}\"? (y/N): ").downcase == 'y')
566
+ if confirm
567
+ begin
568
+ response = capsize_ec2.release_address({:public_ip => public_ip})
569
+ puts "The request to release elastic IP address #{public_ip} has been accepted. Monitor the status of the request with 'cap ec2:addresses:show'"
570
+ rescue Exception => e
571
+ puts "The attempt to release the elastic IP address failed with error : " + e
572
+ raise e
573
+ end
574
+ else
575
+ puts "Your address release request has been cancelled."
576
+ end
577
+ end
578
+ end
579
+
580
+
581
+ desc <<-DESC
582
+ Associate an elastic IP address with an instance.
583
+ If the IP address is currently assigned to another instance, the IP address
584
+ is assigned to the new instance.
585
+
586
+ You must supply both a public_ip (this is the elastic IP address you want to assign)
587
+ and an instance_id (this is the instance to which you want to assign the address)
588
+
589
+ You can associate an elastic IP with an instance by doing one of the following:
590
+ - Define these variables in deploy.rb with "set :public_ip, '123.1.2.3'; set :instance_id, 'i-12312312';"
591
+ - Override this on the command line with "cap ec2:addresses:associate PUBLIC_IP='123.1.2.3' INSTANCE_ID='i-12312312'"
592
+ - A combination of the above.
593
+ DESC
594
+ task :associate do
595
+
596
+ capsize.get(:public_ip)
597
+ capsize.get(:instance_id)
598
+
599
+ if !public_ip || public_ip == ''
600
+ puts "You don't seem to have set a public_ip ..."
601
+ elsif !instance_id || instance_id == ''
602
+ puts "You don't seem to have set an instance_id ..."
603
+ else
604
+ #TODO: check if this IP is already assigned to another instance and make
605
+ # the user confirm the new association if that's the case
606
+ begin
607
+ response = capsize_ec2.associate_address(:public_ip => public_ip, :instance_id => instance_id)
608
+ puts "The elastic IP address #{public_ip} has been associated with " +
609
+ "instance #{instance_id}."
610
+ puts "** It may take several minutes for this mapping to take effect."
611
+ rescue Exception => e
612
+ puts "The attempt to associate the elastic IP address failed with error : " + e
613
+ raise e
614
+ end
615
+ end
616
+ end
617
+
618
+
619
+ desc <<-DESC
620
+ Disassociates the specified elastic IP from whatever instance it's
621
+ currently associated with
622
+
623
+ You can disassociate a specific elastic IP by doing one of the following:
624
+ - define a :public_ip in deploy.rb with "set :public_ip, '123.1.2.3'"
625
+ - Override this on the command line with "cap ec2:addresses:disassociate PUBLIC_IP='123.1.2.3'"
626
+ - If neither of these are provided you will be prompted by Capistano for the IP you wish to disassociate.
627
+ DESC
628
+ task :disassociate do
629
+
630
+ capsize.get(:public_ip)
631
+
632
+ case public_ip
633
+ when nil, ""
634
+ puts "You don't seem to have set a public_ip ..."
635
+ else
636
+ confirm = (Capistrano::CLI.ui.ask("WARNING! Really disassociate elastic IP address \"#{public_ip}\"? (y/N): ").downcase == 'y')
637
+ if confirm
638
+ begin
639
+ response = capsize_ec2.disassociate_address({:public_ip => public_ip})
640
+ puts "The elastic IP address #{public_ip} has been disassociated."
641
+ rescue Exception => e
642
+ puts "The attempt to disassociate the elastic IP address failed with error : " + e
643
+ raise e
644
+ end
645
+ else
646
+ puts "Your address disassociation request has been cancelled."
647
+ end
648
+ end
649
+ end
650
+
651
+ end # end namespace :addresses
652
+
653
+ end # end namespace :ec2
515
654
  end # end Capistrano::Configuration.instance.load
@@ -458,6 +458,41 @@ module Capsize
458
458
 
459
459
  end
460
460
 
461
+ # ELASTIC IP ADDRESS METHODS
462
+ #########################################
463
+
464
+ # returns information about elastic IP addresses owned by the user
465
+ def describe_addresses(options = {})
466
+ amazon = connect()
467
+ options = {:public_ip => []}.merge(options)
468
+ amazon.describe_addresses(:public_ip => options[:public_ip])
469
+ end
470
+
471
+ # allocate an elastic IP address for use with this account
472
+ def allocate_address
473
+ amazon = connect()
474
+ amazon.allocate_address
475
+ end
476
+
477
+ # release an elastic IP address from this account
478
+ def release_address(options)
479
+ amazon = connect()
480
+ amazon.release_address(:public_ip => options[:public_ip])
481
+ end
482
+
483
+ # associate an elastic IP address to an instance
484
+ def associate_address(options)
485
+ amazon = connect()
486
+ amazon.associate_address(:public_ip => options[:public_ip], :instance_id => options[:instance_id])
487
+ end
488
+
489
+ # disassociate an elastic IP address from whatever instance it may be assigned to
490
+ def disassociate_address(options)
491
+ amazon = connect()
492
+ amazon.disassociate_address(:public_ip => options[:public_ip])
493
+ end
494
+
495
+
461
496
  # CAPSIZE HELPER METHODS
462
497
  #########################################
463
498
  # call these from tasks.rb with 'capsize.method_name'
@@ -563,6 +598,21 @@ module Capsize
563
598
  puts "You don't own any running or pending instances"
564
599
  end
565
600
  end
601
+
602
+ # print the result of an describe_addresses
603
+ def print_address_description(result = nil)
604
+ puts "" if result.nil?
605
+ unless result.addressesSet.nil?
606
+ result.addressesSet.item.each do |item|
607
+ puts "addressesSet:publicIp = " + item.publicIp unless item.publicIp.nil?
608
+ puts "addressesSet:instanceId = " + (item.instanceId ? item.instanceId : '(unassociated)')
609
+ puts ""
610
+ end
611
+ else
612
+ puts "You don't have any elastic IP addresses. Run 'cap ec2:addresses:allocate' to acquire one."
613
+ end
614
+ end
615
+
566
616
  end
567
617
  end
568
618
  Capistrano.plugin :capsize_ec2, Capsize::CapsizeEC2
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jnewland-capsize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Newland
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-06-10 00:00:00 -07:00
13
+ date: 2008-07-13 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
122
  requirements: []
123
123
 
124
124
  rubyforge_project: capsize
125
- rubygems_version: 1.0.1
125
+ rubygems_version: 1.2.0
126
126
  signing_key:
127
127
  specification_version: 2
128
128
  summary: Capsize is a Capistrano plugin used to provide an easy way to manage and script interaction with the Amazon EC2 service using the amazon-ec2 Ruby gem.