awscli 0.0.3

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.
Files changed (44) hide show
  1. checksums.yaml +15 -0
  2. data/README.rdoc +5 -0
  3. data/Rakefile +44 -0
  4. data/bin/awscli +32 -0
  5. data/features/awscli.feature +8 -0
  6. data/features/step_definitions/awscli_steps.rb +6 -0
  7. data/features/support/env.rb +15 -0
  8. data/lib/awscli.rb +44 -0
  9. data/lib/awscli/cli.rb +21 -0
  10. data/lib/awscli/cli/ec2.rb +23 -0
  11. data/lib/awscli/cli/ec2/ami.rb +46 -0
  12. data/lib/awscli/cli/ec2/ebs.rb +85 -0
  13. data/lib/awscli/cli/ec2/eip.rb +56 -0
  14. data/lib/awscli/cli/ec2/instances.rb +195 -0
  15. data/lib/awscli/cli/ec2/keypairs.rb +60 -0
  16. data/lib/awscli/cli/ec2/monitoring.rb +35 -0
  17. data/lib/awscli/cli/ec2/placement.rb +42 -0
  18. data/lib/awscli/cli/ec2/reservedinstmng.rb +45 -0
  19. data/lib/awscli/cli/ec2/secgroups.rb +66 -0
  20. data/lib/awscli/cli/ec2/spot.rb +81 -0
  21. data/lib/awscli/cli/ec2/subnet.rb +43 -0
  22. data/lib/awscli/cli/ec2/tags.rb +45 -0
  23. data/lib/awscli/cli/ec2/vmmng.rb +17 -0
  24. data/lib/awscli/cli/ec2/vpc.rb +42 -0
  25. data/lib/awscli/cli/ec2/vpc/connections.rb +0 -0
  26. data/lib/awscli/cli/ec2/vpc/cust_gateways.rb +0 -0
  27. data/lib/awscli/cli/ec2/vpc/dhcp.rb +51 -0
  28. data/lib/awscli/cli/ec2/vpc/internet_gateways.rb +58 -0
  29. data/lib/awscli/cli/ec2/vpc/net_interfaces.rb +75 -0
  30. data/lib/awscli/cli/ec2/vpc/network_acls.rb +29 -0
  31. data/lib/awscli/cli/ec2/vpc/priv_gatewats.rb +0 -0
  32. data/lib/awscli/cli/ec2/vpc/route_tables.rb +0 -0
  33. data/lib/awscli/cli/s3.rb +12 -0
  34. data/lib/awscli/cli/s3/directories.rb +82 -0
  35. data/lib/awscli/cli/s3/files.rb +77 -0
  36. data/lib/awscli/connection.rb +55 -0
  37. data/lib/awscli/ec2.rb +790 -0
  38. data/lib/awscli/errors.rb +64 -0
  39. data/lib/awscli/helper.rb +8 -0
  40. data/lib/awscli/s3.rb +108 -0
  41. data/lib/awscli/version.rb +3 -0
  42. data/test/default_test.rb +14 -0
  43. data/test/test_helper.rb +9 -0
  44. metadata +182 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NDMxM2Y2YmNlMjQ2M2Q4YWI2ODQzMDBiNWE5ODZiOWYzZDYwNjFhMQ==
5
+ data.tar.gz: !binary |-
6
+ N2FhODA0ZTNiNjI2MzU3MzAwZDhlOGZkYzdiYjZiZTZmMDIyMDY5Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGJjNDAzZjlkZjU4MGQ2MDNjNTI4MzFhZWZmMTJhMzY4YjUxMjFlYjg0NDhh
10
+ YTM5ZWNkMzJjNTNkNGE5YjUwMTg2NjVkMWJjYTQwNDY3ZGM1ZWU3ZWJmODhh
11
+ NWFhNGVmYWVkNDU4ZmJmMTQ2NjcxM2JjMmUyZGNiYTY0ZWNlY2Q=
12
+ data.tar.gz: !binary |-
13
+ ODc3ODcyMmNlOTVlYzY3ZDgyMjY4ZTc3M2ZhOTM5MGYwN2JhYjk3Y2UwZjQ5
14
+ YzlmMTg2NmI2NWRlNTQ1OGFiM2FhMzYxN2ViMzljZTU0OGU3MjFkMWJlZDdk
15
+ N2UzNDA2ZmQ4YzZhMDVkZTcyYWFhMmE2YmE4MGVmYWRmNGVkYWE=
data/README.rdoc ADDED
@@ -0,0 +1,5 @@
1
+ = awscli
2
+
3
+ Amazon Web Service Command Line Interface
4
+
5
+ WIP
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rake/clean'
2
+ require 'rubygems'
3
+ require 'rubygems/package_task'
4
+ require 'rdoc/task'
5
+ require 'cucumber'
6
+ require 'cucumber/rake/task'
7
+ Rake::RDocTask.new do |rd|
8
+ rd.main = "README.rdoc"
9
+ rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*")
10
+ rd.title = 'Your application title'
11
+ end
12
+
13
+ spec = eval(File.read('awscli.gemspec'))
14
+
15
+ Gem::PackageTask.new(spec) do |pkg|
16
+ end
17
+ CUKE_RESULTS = 'results.html'
18
+ CLEAN << CUKE_RESULTS
19
+ desc 'Run features'
20
+ Cucumber::Rake::Task.new(:features) do |t|
21
+ opts = "features --format html -o #{CUKE_RESULTS} --format progress -x"
22
+ opts += " --tags #{ENV['TAGS']}" if ENV['TAGS']
23
+ t.cucumber_opts = opts
24
+ t.fork = false
25
+ end
26
+
27
+ desc 'Run features tagged as work-in-progress (@wip)'
28
+ Cucumber::Rake::Task.new('features:wip') do |t|
29
+ tag_opts = ' --tags ~@pending'
30
+ tag_opts = ' --tags @wip'
31
+ t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}"
32
+ t.fork = false
33
+ end
34
+
35
+ task :cucumber => :features
36
+ task 'cucumber:wip' => 'features:wip'
37
+ task :wip => 'features:wip'
38
+ require 'rake/testtask'
39
+ Rake::TestTask.new do |t|
40
+ t.libs << "test"
41
+ t.test_files = FileList['test/*_test.rb']
42
+ end
43
+
44
+ task :default => [:test,:features]
data/bin/awscli ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #Trap interupt to quit cleanly
4
+ Signal.trap("INT") { exit 1 }
5
+
6
+ #load the path if not loaded previously
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
8
+
9
+ begin
10
+ require "awscli"
11
+ rescue LoadError
12
+ require "rubygems"
13
+ require "awscli"
14
+ end
15
+
16
+ #Start the cli
17
+ begin
18
+ AwsCli::Cli.start
19
+ rescue Interrupt
20
+ puts "Caught Interrupt, Exiting..."
21
+ rescue Excon::Errors::SocketError => e
22
+ puts "Error: Establishing Connection to AWS, #{e}"
23
+ rescue Fog::Compute::AWS::Error
24
+ puts "Error: #{$!}"
25
+ rescue Fog::Compute::AWS::NotFound
26
+ puts "Cannot find Resource: #{$!}"
27
+ rescue Excon::Errors::InternalServerError
28
+ puts "Something went wrong, please try again!."
29
+ puts "Error: #{$!}"
30
+ rescue ArgumentError => e
31
+ puts "Cannot recognize the argument passed, #{e}"
32
+ end
@@ -0,0 +1,8 @@
1
+ Feature: My bootstrapped app kinda works
2
+ In order to get going on coding my awesome app
3
+ I want to have aruba and cucumber setup
4
+ So I don't have to do it myself
5
+
6
+ Scenario: App just runs
7
+ When I get help for "awscli"
8
+ Then the exit status should be 0
@@ -0,0 +1,6 @@
1
+ When /^I get help for "([^"]*)"$/ do |app_name|
2
+ @app_name = app_name
3
+ step %(I run `#{app_name} help`)
4
+ end
5
+
6
+ # Add more step definitions here
@@ -0,0 +1,15 @@
1
+ require 'aruba/cucumber'
2
+
3
+ ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
4
+ LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
5
+
6
+ Before do
7
+ # Using "announce" causes massive warnings on 1.9.2
8
+ @puts = true
9
+ @original_rubylib = ENV['RUBYLIB']
10
+ ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s
11
+ end
12
+
13
+ After do
14
+ ENV['RUBYLIB'] = @original_rubylib
15
+ end
data/lib/awscli.rb ADDED
@@ -0,0 +1,44 @@
1
+ #external dependencies
2
+ begin
3
+ require 'thor'
4
+ require 'thor/group'
5
+ require 'fog'
6
+ require 'highline'
7
+ require 'yaml'
8
+ rescue LoadError
9
+ puts "Failed to load gems: fog, highline, thor"
10
+ exit 1
11
+ end
12
+
13
+ module AwsCli
14
+ # => require all interfaces for awscli/
15
+ require 'awscli/version.rb' #to get version
16
+ require 'awscli/errors'
17
+
18
+ # => first require cli so all subcommands can register
19
+ require 'awscli/cli'
20
+ # => register all subcommands
21
+ #EC2
22
+ require 'awscli/cli/ec2'
23
+ require 'awscli/cli/ec2/instances'
24
+ require 'awscli/cli/ec2/ami'
25
+ require 'awscli/cli/ec2/ebs'
26
+ require 'awscli/cli/ec2/eip'
27
+ require 'awscli/cli/ec2/keypairs'
28
+ require 'awscli/cli/ec2/monitoring'
29
+ require 'awscli/cli/ec2/placement'
30
+ require 'awscli/cli/ec2/reservedinstmng'
31
+ require 'awscli/cli/ec2/secgroups'
32
+ require 'awscli/cli/ec2/spot'
33
+ require 'awscli/cli/ec2/tags'
34
+ require 'awscli/cli/ec2/vmmng'
35
+ require 'awscli/cli/ec2/vpc'
36
+ require 'awscli/cli/ec2/vpc/network_acls'
37
+ require 'awscli/cli/ec2/vpc/net_interfaces'
38
+ require 'awscli/cli/ec2/vpc/internet_gateways'
39
+ require 'awscli/cli/ec2/vpc/dhcp'
40
+ #S3
41
+ require 'awscli/cli/s3'
42
+ require 'awscli/cli/s3/files'
43
+ require 'awscli/cli/s3/directories'
44
+ end
data/lib/awscli/cli.rb ADDED
@@ -0,0 +1,21 @@
1
+ module AwsCli
2
+ #This it the main cli runner class
3
+ #All class_methods should be defined here except for Thor::Groups
4
+ class Cli < ::Thor
5
+
6
+ default_task :help_banner #if no option is passed call help_banner task
7
+ # class_option :config, :banner => "PATH", :type => :string,
8
+ # :desc => 'Configuration file, accepts ENV $AWSCLI_CONFIG_FILE',
9
+ # :default => ENV['AWSCLI_CONFIG_FILE'] || "~/.awscli.yml"
10
+
11
+ desc "help", "help banner"
12
+ def help_banner
13
+ puts <<-HELP.gsub(/^ {8}/, '')
14
+ Amazon Web Services Command Line Interface, Version - #{Awscli::VERSION}
15
+
16
+ HELP
17
+ help #call help
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,23 @@
1
+ module AwsCli
2
+ module CLI
3
+ require 'awscli/cli'
4
+ require 'awscli/connection'
5
+ require 'awscli/ec2'
6
+ class Ec2 < Thor
7
+
8
+ class_option :region, :type => :string, :desc => "region to connect to", :default => 'us-west-1'
9
+
10
+ private
11
+
12
+ def create_ec2_object
13
+ puts "ec2 Establishing Connetion..."
14
+ $ec2_conn = Awscli::Connection.new.request_ec2
15
+ puts $ec2_conn
16
+ puts "ec2 Establishing Connetion... OK"
17
+ @ec2 = Awscli::EC2::EC2.new($ec2_conn)
18
+ end
19
+
20
+ AwsCli::Cli.register AwsCli::CLI::Ec2, :ec2, 'ec2 [COMMAND]', 'Elastic Cloud Compute Interface'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,46 @@
1
+ module AwsCli
2
+ module CLI
3
+ module EC2
4
+ require 'awscli/cli/ec2'
5
+ class Ami < Thor
6
+
7
+ desc "list", "List Images"
8
+ method_option :filter, :aliases => "-f", :type => :hash, :desc => "filter the images based on filters"
9
+ method_option :amazon_owned, :aliases => "-a", :type => :boolean, :default => false, :desc => "lists amazon owned images"
10
+ method_option :show_filters, :aliases => "-s", :type => :boolean, :default => false, :desc => "filters available"
11
+ def list
12
+ create_ec2_object
13
+ if options[:amazon_owned]
14
+ @ec2.list_amazon
15
+ elsif options[:show_filters]
16
+ @ec2.show_filters
17
+ else
18
+ @ec2.list options[:filter]
19
+ end
20
+ end
21
+
22
+ desc "create", "Create a bootable EBS volume AMI, from instance specified"
23
+ method_option :instance_id, :aliases => "-i", :type => :string, :required => true, :desc => "Instance used to create image"
24
+ method_option :name, :aliases => "-n", :type => :string, :default => "awscli_image_#{Time.now.to_i}", :desc => "Name to give image"
25
+ method_option :desc, :aliases => "-d", :type => :string, :default => "awscli_image-created_at-#{Time.now.to_i}", :desc => "Description of image"
26
+ method_option :no_reboot, :aliases => "-r", :type => :boolean, :default => false, :desc => "Optional, whether or not to reboot the image when making the snapshot"
27
+ def create
28
+ create_ec2_object
29
+ @ec2.create_image_from_instance options
30
+ end
31
+
32
+ private
33
+
34
+ def create_ec2_object
35
+ puts "ec2 Establishing Connetion..."
36
+ $ec2_conn = Awscli::Connection.new.request_ec2
37
+ puts "ec2 Establishing Connetion... OK"
38
+ @ec2 = Awscli::EC2::Ami.new($ec2_conn)
39
+ end
40
+
41
+ AwsCli::CLI::Ec2.register AwsCli::CLI::EC2::Ami, :ami, 'ami [COMMAND]', 'EC2 AMI Management'
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,85 @@
1
+ module AwsCli
2
+ module CLI
3
+ module EC2
4
+ require 'awscli/cli/ec2'
5
+ class Ebs < Thor
6
+
7
+ desc "list", "List ELastic Block Storages"
8
+ method_option :snapshots, :aliases => "-s", :type => :boolean, :default => false, :desc => "list snapshots"
9
+ def list
10
+ create_ec2_object
11
+ @ec2.list options
12
+ end
13
+
14
+ desc "create", "Create a EBS Volume"
15
+ method_option :availability_zone, :aliases => "-z", :required => true, :banner => "ZONE", :type => :string, :desc => "Name of the availability zone to create the voulume in"
16
+ method_option :size, :aliases => "-s", :required => true, :type => :numeric, :desc => "Size of the volume to create (in GB)"
17
+ method_option :snapshot_id, :aliases => "-i", :banner => "ID", :type => :string, :desc => "Snapshot ID from which to create volume from"
18
+ method_option :device, :aliases => "-d", :type => :string, :desc => "how the volume is exposed(in unix '/dev/sdx', in windows 'xvdf')"
19
+ def create
20
+ create_ec2_object
21
+ @ec2.create options
22
+ end
23
+
24
+ desc "attach_volume", "Attach a volume to instance"
25
+ method_option :instance_id, :aliases => "-i", :banner => "ID", :type => :string, :desc => "instance id to attach the volume to"
26
+ method_option :volume_id, :aliases => "-v", :banner => "VID", :type => :string, :desc => "volume id to attach"
27
+ method_option :device, :aliases => "-d", :type => :string, :desc => "how the volume is exposed(in unix '/dev/sdx', in windows 'xvdf')"
28
+ def attach_volume
29
+ create_ec2_object
30
+ @ec2.attach_volume options
31
+ end
32
+
33
+ desc "detach_voulme", "Detach a volume from instance"
34
+ method_option :volume_id, :aliases => "-v", :banner => "VID", :type => :string, :desc => "volume id to attach"
35
+ method_option :force, :aliase => "-f", :type => :boolean, :default => false, :desc => "force detaches the volume"
36
+ def detach_volume
37
+ create_ec2_object
38
+ @ec2.detach_volume options
39
+ end
40
+
41
+ desc "delete", "Delete Volume"
42
+ method_option :volume_id, :aliases => "-v", :banner => "VID", :required => true, :type => :string, :desc => "volume id to delete"
43
+ def delete
44
+ #ask if the user is sure about deleting the volume which leads to data loss or can make a snapshot before deleting it
45
+ create_ec2_object
46
+ @ec2.delete_volume options
47
+ end
48
+
49
+ desc "create_snapshot", "Create a snapshot from volume"
50
+ method_option :volume_id, :aliases => "-v", :banner => "VID", :required => true, :type => :string, :desc => "volume to make a snapshot from"
51
+ def create_snapshot
52
+ create_ec2_object
53
+ @ec2.create_snapshot
54
+ end
55
+
56
+ desc "copy_snapshot", "Copy a snapshot to a different region"
57
+ method_option :source_region, :aliases => "-s", :banner => "REGION", :required => true, :type => :string, :desc => "Region to move it from"
58
+ method_option :snapshot_id, :aliases => "-i", :banner => "ID", :required => true, :type => :string, :desc => "Id of the snapshot"
59
+ def copy_snapshot
60
+ create_ec2_object
61
+ @ec2.copy_snapshot
62
+ end
63
+
64
+ desc "delete_snapshot", "Delete SnapShot"
65
+ method_option :snapshot_id, :aliases => "-i", :banner => "ID", :required => true, :type => :string, :desc => "Snapshot Id to delete"
66
+ def delete_snapshot
67
+ create_ec2_object
68
+ @ec2.delete_snapshot options
69
+ end
70
+
71
+ private
72
+
73
+ def create_ec2_object
74
+ puts "ec2 Establishing Connetion..."
75
+ $ec2_conn = Awscli::Connection.new.request_ec2
76
+ puts "ec2 Establishing Connetion... OK"
77
+ @ec2 = Awscli::EC2::Ebs.new($ec2_conn)
78
+ end
79
+
80
+ AwsCli::CLI::Ec2.register AwsCli::CLI::EC2::Ebs, :ebs, 'ebs [COMMAND]', 'EC2 EBS Management'
81
+
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,56 @@
1
+ module AwsCli
2
+ module CLI
3
+ module EC2
4
+ require 'awscli/cli/ec2'
5
+ class Eip < Thor
6
+
7
+ desc "list", "List Elastic IPs"
8
+ def list
9
+ puts "Listing EIPs"
10
+ create_ec2_object
11
+ @ec2.list
12
+ end
13
+
14
+ desc "create", "Create Elastic IP"
15
+ def create
16
+ create_ec2_object
17
+ @ec2.create
18
+ end
19
+
20
+ desc "delete", "Delete Elastic IP"
21
+ method_option :eip, :aliases => "-e", :required => true, :banner => "IP", :type => :string, :desc => "Elastic IP to delete"
22
+ def delete
23
+ create_ec2_object
24
+ @ec2.delete options
25
+ end
26
+
27
+ desc "associate", "Associate EIP with an Instance"
28
+ method_option :eip, :aliases => "-e", :required => true, :banner => "IP", :type => :string, :desc => "Elastic IP to associate"
29
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :type => :string, :desc => "Instance ID to which to associate EIP"
30
+ def associate
31
+ create_ec2_object
32
+ @ec2.associate options
33
+ end
34
+
35
+ desc "disassociate", "Disassociate EIP from an instance"
36
+ method_option :eip, :aliases => "-e", :required => true, :banner => "IP", :type => :string, :desc => "Elastic IP to disassociate"
37
+ def disassociate
38
+ create_ec2_object
39
+ @ec2.disassociate options
40
+ end
41
+
42
+ private
43
+
44
+ def create_ec2_object
45
+ puts "ec2 Establishing Connetion..."
46
+ $ec2_conn = Awscli::Connection.new.request_ec2
47
+ puts "ec2 Establishing Connetion... OK"
48
+ @ec2 = Awscli::EC2::Eip.new($ec2_conn)
49
+ end
50
+
51
+ AwsCli::CLI::Ec2.register AwsCli::CLI::EC2::Eip, :eip, 'eip [COMMAND]', 'EC2 EIP Management'
52
+
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,195 @@
1
+ module AwsCli
2
+ module CLI
3
+ module EC2
4
+ require 'awscli/cli/ec2'
5
+ class Instances < Thor
6
+
7
+ # default_task :list
8
+
9
+ desc "list", "ec2_describe_instances"
10
+ long_desc <<-LONGDESC
11
+ List and describe your instances
12
+ The INSTANCE parameter is the instance ID(s) to describe.
13
+ If unspecified all your instances will be returned.
14
+ LONGDESC
15
+ def list
16
+ puts "Listing Instances"
17
+ create_ec2_object
18
+ # puts parent_options #access awscli/cli/ec2.rb class options
19
+ @ec2.list_instances
20
+ end
21
+
22
+ desc "diatt", "ec2_describe_instance_attribute"
23
+ long_desc <<-LONGDESC
24
+ Describes the specified attribute of the specified instance. You can specify only one attribute at a time.
25
+ \x5
26
+ Available Attributes to Request:
27
+ architecture ami_launch_index availability_zone block_device_mapping network_interfaces client_token
28
+ dns_name ebs_optimized groups flavor_id iam_instance_profile image_id instance_initiated_shutdown_behavior
29
+ kernel_id key_name created_at monitoring placement_group platform private_dns_name private_ip_address
30
+ public_ip_address ramdisk_id root_device_name root_device_type security_group_ids state state_reason subnet_id
31
+ tenancy tags user_data vpc_id volumes username
32
+ LONGDESC
33
+ method_option :id, :aliases => "-i", :banner => "INSTANCEID", :type => :string, :desc => "Id of an instance to modify attribute", :required => true
34
+ method_option :attr, :aliases => "-a", :banner => "ATTR", :type => :string, :desc => "Attribute to modify", :required => true
35
+ def diatt
36
+ create_ec2_object
37
+ @ec2.describe_instance_attribute(options[:id], options[:attr])
38
+ end
39
+
40
+
41
+ desc "miatt", "ec2_modify_instance_attribute"
42
+ long_desc <<-LONGDESC
43
+ Modifies an instance attribute. Only one attribute can be specified per call.
44
+ LONGDESC
45
+ method_option :id, :aliases => "-i", :banner => "INSTANCEID", :type => :string, :desc => "Id of an instance to modify attribute", :required => true
46
+ method_option :isize, :aliases => "-t", :banner => "VALUE", :type => :string, :desc => "Changes the instance type to the specified value."
47
+ method_option :kernel, :aliases => "-k", :banner => "VALUE", :type => :string, :desc => "Changes the instance's kernel to the specified value"
48
+ method_option :ramdisk, :aliases => "-r", :banner => "VALUE", :type => :string, :desc => "Changes the instance's RAM disk to the specified value"
49
+ method_option :userdata, :aliases => "-u", :banner => "VALUE", :type => :string, :desc => "Changes the instance's user data to the specified value"
50
+ method_option :disable_api_term, :aliases => "-d", :banner => "true|false" , :type => :string, :desc => "Changes the instance's DisableApiTermination flag to the specified value. Setting this flag means you can't terminate the instance using the API"
51
+ method_option :inst_shutdown_beh, :aliases => "-s", :banner => "stop|terminate", :type => :string, :desc => "Changes the instance's InstanceInitiatedShutdownBehavior flag to the specified value."
52
+ method_option :source_dest_check, :aliases => "-c", :banner => "true|false" , :type => :string, :desc => "This attribute exists to enable a Network Address Translation (NAT) instance in a VPC to perform NAT. The attribute controls whether source/destination checking is enabled on the instance. A value of true means checking is enabled, and false means checking is disabled"
53
+ method_option :group_id, :aliases => "-g", :banner => "G1, G2, ..", :type => :array, :desc => "This attribute is applicable only to instances running in a VPC. Use this parameter when you want to change the security groups that an instance is in."
54
+ def miatt
55
+ create_ec2_object
56
+ opts = Marshal.load(Marshal.dump(options)) #create a copy of options, as original options hash cannot be modified
57
+ opts.reject!{ |k| k == 'id' } #remove id from opts
58
+ abort "Please pass an attribute by setting respective option" unless opts
59
+ abort "You can only pass one attribute at a time" if opts.size != 1
60
+ opts.each do |k,v|
61
+ puts "calling modify_instance_attribute with: #{options[:id]}, #{k}, #{opts[k]}"
62
+ @ec2.modify_instance_attribute(options[:id], k, opts[k])
63
+ end
64
+
65
+ end
66
+
67
+ desc "riatt", "ec2_reset_instance_attribute"
68
+ long_desc <<-LONGDESC
69
+ Resets an instance attribute to its initial value. Only one attribute can be specified per call.
70
+ LONGDESC
71
+ def riatt
72
+ puts "Not yet Implemented"
73
+ end
74
+
75
+ desc "dins", "ec2_describe_instance_status"
76
+ long_desc <<-LONGDESC
77
+ Describe the status for one or more instances.
78
+ Checks are performed on your instances to determine if they are
79
+ in running order or not. Use this command to see the result of these
80
+ instance checks so that you can take remedial action if possible.
81
+
82
+ There are two types of checks performed: INSTANCE and SYSTEM.
83
+ INSTANCE checks examine the health and reachability of the
84
+ application environment. SYSTEM checks examine the health of
85
+ the infrastructure surrounding your instance.
86
+ LONGDESC
87
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id that needs to be stopped"
88
+ def dins
89
+ create_ec2_object
90
+ @ec2.describe_instance_status options[:instance_id]
91
+ end
92
+
93
+ desc "import", "ec2_import_instance"
94
+ long_desc <<-LONGDESC
95
+ Create an import instance task to import a virtual machine into EC2
96
+ using meta_data from the given disk image. The volume size for the
97
+ imported disk_image will be calculated automatically, unless specified.
98
+ LONGDESC
99
+ def import
100
+ puts "Cannot find it in the *FOG*"
101
+ end
102
+
103
+ desc "reboot", "ec2_reboot_instances"
104
+ long_desc <<-LONGDESC
105
+ Reboot selected running instances.
106
+ The INSTANCE parameter is an instance ID to reboot.
107
+ LONGDESC
108
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id that needs to be stopped"
109
+ def reboot
110
+ create_ec2_object
111
+ @ec2.reboot_instance options[:instance_id]
112
+ end
113
+
114
+ desc "create", "ec2_run_instances"
115
+ long_desc <<-LONGDESC
116
+ Launch an instance of a specified AMI.\x5
117
+ Usage Examples:\x5
118
+ awscli ec2 instances create -i 'ami-xxxxxxx' -b '{:DeviceName => '/dev/sdg', :VirtualName => 'ephemeral0'}' -g 'default' -t 'm1.small' -k 'default' --tags=name:testserver
119
+ LONGDESC
120
+ method_option :image_id, :aliases => "-i", :required => true, :banner => "AMIID", :type => :string, :desc => "Id of machine image to load on instances"
121
+ method_option :availability_zone, :banner => "ZONE", :type => :string, :desc => "Placement constraint for instances"
122
+ method_option :placement_group, :banner => "GROUP", :type => :string, :desc => "Name of existing placement group to launch instance into"
123
+ method_option :tenancy, :banner => "TENANCY", :type => :string, :desc => "Tenancy option in ['dedicated', 'default'], defaults to 'default'"
124
+ method_option :block_device_mapping, :aliases => "-b", :type => :array , :desc => "hashes of device mappings, see help for how to pass values"
125
+ method_option :client_token, :type => :string, :desc => "unique case-sensitive token for ensuring idempotency"
126
+ method_option :groups, :aliases => "-g", :banner => "SG1 SG2 SG3",:type => :array, :default => ["default"], :desc => "Name of security group(s) for instances (not supported for VPC). Default: 'default'"
127
+ method_option :flavor_id, :aliases => "-t",:type => :string, :default => "m1.small", :desc => "Type of instance to boot."
128
+ method_option :kernel_id, :type => :string, :desc => "Id of kernel with which to launch"
129
+ method_option :key_name, :aliases => "-k", :required => true, :type => :string, :desc => "Name of a keypair to add to booting instances"
130
+ method_option :monitoring, :type => :boolean, :default => false, :desc => "Enables monitoring, defaults to false"
131
+ method_option :ramdisk_id, :type => :string, :desc => "Id of ramdisk with which to launch"
132
+ method_option :subnet_id, :type => :string, :desc => "VPC option to specify subnet to launch instance into"
133
+ method_option :user_data, :type => :string, :desc => "Additional data to provide to booting instances"
134
+ method_option :ebs_optimized, :type => :boolean, :default => false, :desc => "Whether the instance is optimized for EBS I/O"
135
+ method_option :vpc_id, :type => :string, :desc => "VPC to connect to"
136
+ method_option :tags, :type => :hash, :default => {'Name' => "awscli-#{Time.now.to_i}"}, :desc => "Tags to identify server"
137
+ method_option :private_ip_address, :banner => "IP",:type => :string, :desc => "VPC option to specify ip address within subnet"
138
+ method_option :wait_for, :aliases => "-w", :type => :boolean, :default => false, :desc => "wait for the server to get created and return public_dns"
139
+ def create
140
+ create_ec2_object
141
+ @ec2.create_instance options
142
+ end
143
+
144
+ desc "start", "ec2_start_instances"
145
+ long_desc <<-LONGDESC
146
+ Start selected running instances.
147
+ LONGDESC
148
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id that needs to be stopped"
149
+ def start
150
+ create_ec2_object
151
+ @ec2.start_instance options[:instance_id]
152
+ end
153
+
154
+ desc "stop", "ec2_stop_instances"
155
+ long_desc <<-LONGDESC
156
+ Stop selected running instances.
157
+ LONGDESC
158
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id that needs to be stopped"
159
+ def stop
160
+ create_ec2_object
161
+ @ec2.stop_instance options[:instance_id]
162
+ end
163
+
164
+ desc "kill", "ec2_terminate_instances"
165
+ long_desc <<-LONGDESC
166
+ Terminate selected running instances
167
+ LONGDESC
168
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id that needs to be stopped"
169
+ def terminate
170
+ create_ec2_object
171
+ @ec2.terminate_instance options[:instance_id]
172
+ end
173
+
174
+ desc "console_output", "Retrieve console output for specified instance"
175
+ method_option :instance_id, :aliases => "-i", :required => true, :banner => "ID", :desc => "instance id to get console output from"
176
+ def console_output
177
+ create_ec2_object
178
+ @ec2.get_console_output options[:instance_id]
179
+ end
180
+
181
+ private
182
+
183
+ def create_ec2_object
184
+ puts "ec2 Establishing Connetion..."
185
+ $ec2_conn = Awscli::Connection.new.request_ec2
186
+ puts "ec2 Establishing Connetion... OK"
187
+ @ec2 = Awscli::EC2::EC2.new($ec2_conn)
188
+ end
189
+
190
+ AwsCli::CLI::Ec2.register AwsCli::CLI::EC2::Instances, :instances, 'instances [COMMAND]', 'EC2 Instance Management'
191
+
192
+ end
193
+ end
194
+ end
195
+ end