awscli 0.1.2 → 0.1.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.
@@ -18,22 +18,29 @@ module AwsCli
18
18
 
19
19
  desc 'create', 'create a user'
20
20
  long_desc <<-DESC
21
- Creates a new user in your AWS account. Optionally adds the user to one or more groups, and creates an access key for the user.
21
+ Creates a new user in your AWS account. Optionally adds the user to a group, creates an access key for the user and puts default policy in place.
22
22
  DESC
23
23
  method_option :user_name, :aliases => '-u', :required => true, :desc => 'name of the user to create (do not include path)'
24
- method_option :path, :aliases => '-p', :defualt => '/', :desc => 'optional path to group, defaults to "/"'
24
+ method_option :path, :aliases => '-p', :default => '/', :desc => 'optional path to group, defaults to "/"'
25
25
  method_option :group, :aliases => '-g', :desc => 'name of a group you want to add the user to'
26
- method_option :access_key, :alises => '-k', :desc => 'creates an access key for the user'
26
+ method_option :access_key, :aliases => '-k', :type => :boolean, :default => false, :desc => 'if passed, optionally creates an access key for the user'
27
+ method_option :policy, :aliases => '-l', :type => :boolean, :default => false, :desc => 'if set will not create basic set of access rules for the user, should pass --policy-doc if set'
28
+ method_option :policy_doc, :aliases => '-d', :desc => 'path to the json policy document'
29
+ method_option :password, :aliases => '-a', :type => :boolean, :default => false, :desc => 'assign a generated password for the user'
27
30
  def create
31
+ if options[:policy]
32
+ abort 'Required --policy-doc, if --policy is passed' unless options[:policy_doc]
33
+ end
28
34
  create_iam_object
29
- @iam.create options[:user_name], options[:path]
35
+ @iam.create options
30
36
  end
31
37
 
32
38
  desc 'delete', 'delete existing user'
33
39
  method_option :user_name, :aliases => '-u', :required => true, :desc => 'name of the user to delete (dont include path)'
40
+ method_option :force, :aliases => '-f', :type => :boolean, :default => false, :decs => 'force deletes users login_profile, access_keys, policies if any'
34
41
  def delete
35
42
  create_iam_object
36
- @iam.delete options[:user_name]
43
+ @iam.delete options
37
44
  end
38
45
 
39
46
  desc 'cak', 'create access key for user'
@@ -100,14 +107,18 @@ module AwsCli
100
107
  desc 'passwd [OPTIONS]', 'add/change user password'
101
108
  method_option :user_name, :aliases => '-u', :required => true, :desc => 'name of the user to change password for'
102
109
  method_option :password, :alases => '-p', :desc => 'password for the user'
103
- method_option :genereate, :aliases => '-g', :type => :boolean, :default => false, :desc => 'generates the password'
110
+ method_option :generate, :aliases => '-g', :type => :boolean, :default => false, :desc => 'generates the password'
104
111
  method_option :remove, :aliases => '-r', :type => :boolean, :default => false, :desc => 'remove password for the user'
105
112
  def passwd
106
113
  create_iam_object
107
114
  if options[:remove]
108
115
  @iam.remove_password options[:user_name]
109
116
  else
110
- @iam.assign_password options[:user_name], options[:password], options[:genereate]
117
+ if options[:generate]
118
+ @iam.assign_password options[:user_name], options[:password]
119
+ else
120
+ @iam.generate_password options[:user_name]
121
+ end
111
122
  end
112
123
  end
113
124
 
@@ -4,76 +4,82 @@ module AwsCli
4
4
  require 'awscli/cli/s3'
5
5
  class Files < Thor
6
6
 
7
- desc "list", "list objects(files) in a bucket"
8
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "bucket name to print the contents from"
7
+ desc 'list', 'list objects(files) in a bucket'
8
+ method_option :bucket_name, :aliases => '-b', :required => true, :desc => 'bucket name to print the contents from'
9
+ method_option :prefix, :aliases => '-p', :desc => 'Optionally specify a dir_name to narrow down results'
9
10
  def list
10
11
  create_s3_object
11
- @s3.list options[:bucket_name]
12
+ @s3.list options[:bucket_name], options[:prefix]
12
13
  end
13
14
 
14
- desc "put", "put a file into a bucket"
15
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to upload the file to"
16
- method_option :file_path, :aliases => "-p", :required => true, :desc => "local file path"
15
+ desc 'put', 'put a file into a bucket'
16
+ method_option :bucket_name, :aliases => '-b', :required => true, :desc => 'name of the bucket to upload the file to'
17
+ method_option :file_path, :aliases => '-p', :required => true, :desc => 'local file path'
18
+ method_option :dest_path, :aliases => '-d', :desc => 'optionally specify destination directory path to create'
17
19
  def put
18
20
  create_s3_object
19
- @s3.upload_file options[:bucket_name], options[:file_path]
21
+ if options[:dest_path]
22
+ @s3.upload_file options[:bucket_name], options[:file_path], options[:dest_path]
23
+ else
24
+ @s3.upload_file options[:bucket_name], options[:file_path]
25
+ end
20
26
  end
21
27
 
22
- desc "put_rec", "put a directory recusively into a specified bucket using multiple threads"
23
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to upload the dir to"
24
- method_option :dir_path, :aliases => "-p", :required => true, :desc => "path of the dir to upload"
25
- method_option :dest_path, :aliases => "-d", :desc => "optionally specify destination directory path to create"
26
- method_option :thread_count, :aliases => "-t", :type => :numeric, :default => 5, :desc => "number of threads to use to upload files"
27
- method_option :public, :type => :boolean, :default => false, :desc => "set ACL of files to public"
28
+ desc 'put_rec', 'put a directory recursively into a specified bucket using multiple threads'
29
+ method_option :bucket_name, :aliases => '-b', :required => true, :desc => 'name of the bucket to upload the dir to'
30
+ method_option :dir_path, :aliases => '-p', :required => true, :desc => 'path of the dir to upload'
31
+ method_option :dest_path, :aliases => '-d', :desc => 'optionally specify destination directory path to create'
32
+ method_option :thread_count, :aliases => '-t', :type => :numeric, :default => 5, :desc => 'number of threads to use to upload files'
33
+ method_option :public, :type => :boolean, :default => false, :desc => 'set ACL of files to public'
28
34
  def put_rec
29
35
  create_s3_object
30
36
  @s3.upload_file_rec options
31
37
  end
32
38
 
33
- desc "put_big", "uploads a larger file (> 100 MB) using multipart uploads"
39
+ desc 'put_big', 'uploads a file using multipart uploads'
34
40
  long_desc <<-DESC
35
- Takes in a larger file, split the file into chunks and uploads the parts using amazon multipart uploads and the parts are aggregated at the amazons end.
41
+ Takes in a larger file (> 100MB), split the file into chunks and uploads the parts using amazon multipart uploads and the parts are aggregated at the amazons end.
36
42
  DESC
37
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to upload the parts to"
38
- method_option :file_path, :aliases => "-p", :required => true, :desc => "path of the file to upload"
39
- method_option :tmp_dir, :aliases => "-t", :default => "/tmp", :desc => "path to a temperory location where file will be split into chunks"
40
- method_option :acl, :aliases => "-a", :default => "private", :desc => "ACL to apply, to the object that is created after completing multipart upload, valid options in private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control"
41
- method_option :dest_path, :aliases => "-d", :desc => "optionally specify destination directory path to create"
43
+ method_option :bucket_name, :aliases => '-b', :required => true, :banner => 'NAME', :desc => 'name of the bucket to upload the parts to'
44
+ method_option :file_path, :aliases => '-p', :required => true, :banner => 'PATH', :desc => 'path of the file to upload'
45
+ method_option :tmp_dir, :aliases => '-t', :default => '/tmp', :desc => 'path to a temporary location where file will be split into chunks'
46
+ method_option :acl, :aliases => '-a', :default => 'private', :desc => 'ACL to apply, to the object that is created after completing multipart upload, valid options in private | public-read | public-read-write | authenticated-read | bucket-owner-read | bucket-owner-full-control'
47
+ method_option :dest_path, :aliases => '-d', :desc => 'optionally specify destination directory path to create'
42
48
  def put_big
43
49
  create_s3_object
44
50
  @s3.multipart_upload options
45
51
  end
46
52
 
47
- desc "get", "get a file from a bucket"
48
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to download the file from"
49
- method_option :file_name, :aliases => "-f", :required => true, :desc => "name of file to download"
50
- method_option :local_path, :aliases => "-p", :required => true, :desc => "local fs path, where to download the file to"
53
+ desc 'get', 'get a file from a bucket'
54
+ method_option :bucket_name, :aliases => '-b', :required => true, :banner => 'NAME', :desc => 'name of the bucket to download the file from'
55
+ method_option :file_name, :aliases => '-f', :required => true, :banner => 'NAME', :desc => 'name of file to download'
56
+ method_option :local_path, :aliases => '-p', :required => true, :banner => 'PATH', :desc => 'local fs path, where to download the file to'
51
57
  def get
52
58
  create_s3_object
53
59
  @s3.download_file options[:bucket_name], options[:file_name], options[:local_path]
54
60
  end
55
61
 
56
- desc "delete", "delete a file from a bucket"
57
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to download the file from"
58
- method_option :file_name, :aliases => "-f", :required => true, :desc => "name of file to download"
62
+ desc 'delete', 'delete a file from a bucket'
63
+ method_option :bucket_name, :aliases => '-b', :required => true, :desc => 'name of the bucket to download the file from'
64
+ method_option :file_name, :aliases => '-f', :required => true, :desc => 'name of file to download'
59
65
  def delete
60
66
  create_s3_object
61
67
  @s3.delete_file options[:bucket_name], options[:file_name]
62
68
  end
63
69
 
64
- desc "copy", "copy object from one bucket to another"
65
- method_option :source_bucket, :aliases => "-s", :required => true, :desc => "source bucket name from where to copy the file"
66
- method_option :source_file, :aliases => "-f", :required => true, :desc => "source file name to copy"
67
- method_option :dest_bucket, :aliases => "-d", :required => true, :desc => "destination bucket name to copy the file to"
68
- method_option :dest_file, :alises => "-r", :required => true, :desc => "destination file name"
70
+ desc 'copy', 'copy object from one bucket to another'
71
+ method_option :source_bucket, :aliases => '-s', :required => true, :banner => 'NAME', :desc => 'source bucket name from where to copy the file'
72
+ method_option :source_file, :aliases => '-f', :required => true, :banner => 'PATH', :desc => 'source file name to copy'
73
+ method_option :dest_bucket, :aliases => '-d', :required => true, :banner => 'NAME', :desc => 'destination bucket name to copy the file to'
74
+ method_option :dest_file, :aliases => '-r', :required => true, :banner => 'PATH', :desc => 'destination file name'
69
75
  def copy
70
76
  create_s3_object
71
77
  @s3.copy_file options[:source_bucket], options[:source_file], options[:dest_bucket], options[:dest_file]
72
78
  end
73
79
 
74
- desc "public_url", "show the public url of a file"
75
- method_option :bucket_name, :aliases => "-b", :required => true, :desc => "name of the bucket to download the file from"
76
- method_option :file_name, :aliases => "-f", :required => true, :desc => "name of file to download"
80
+ desc 'public_url', 'show the public url of a file'
81
+ method_option :bucket_name, :aliases => '-b', :required => true, :desc => 'name of the bucket to download the file from'
82
+ method_option :file_name, :aliases => '-f', :required => true, :desc => 'name of file to download'
77
83
  def public_url
78
84
  create_s3_object
79
85
  @s3.get_public_url options[:bucket_name], options[:file_name]
@@ -83,13 +89,13 @@ module AwsCli
83
89
  private
84
90
 
85
91
  def create_s3_object
86
- puts "S3 Establishing Connetion..."
92
+ puts 'S3 Establishing Connection...'
87
93
  $s3_conn = if parent_options[:region]
88
94
  Awscli::Connection.new.request_s3(parent_options[:region])
89
95
  else
90
96
  Awscli::Connection.new.request_s3
91
97
  end
92
- puts "S3 Establishing Connetion... OK"
98
+ puts 'S3 Establishing Connection... OK'
93
99
  @s3 = Awscli::S3::Files.new($s3_conn)
94
100
  end
95
101
 
@@ -5,67 +5,70 @@ module Awscli
5
5
 
6
6
  def initialize
7
7
  #load env variable AWSCLI_CONFIG_FILE
8
- @@aws_config_file = ENV['AWSCLI_CONFIG_FILE']
9
- unless !@@aws_config_file.nil?
10
- puts "Cannot find config file environment variable"
8
+ @aws_config_file = ENV['AWSCLI_CONFIG_FILE']
9
+ if @aws_config_file.nil?
10
+ puts 'Cannot find config file environment variable'
11
11
  Awscli::Errors.missing_environment_variable
12
12
  end
13
- @@aws_config_file_path = File.expand_path(@@aws_config_file)
14
- unless File.exist?(@@aws_config_file_path)
15
- puts "Cannot locate file #{@@aws_config_file}"
13
+ @aws_config_file_path = File.expand_path(@aws_config_file)
14
+ unless File.exist?(@aws_config_file_path)
15
+ puts "Cannot locate file #{@aws_config_file}"
16
16
  Awscli::Errors.missing_config_file
17
17
  end
18
- @@config = YAML.load(File.read(@@aws_config_file_path))
19
- unless @@config.kind_of?(Hash)
20
- puts "Parse Error"
18
+ @config = YAML.load(File.read(@aws_config_file_path))
19
+ unless @config.kind_of?(Hash)
20
+ puts 'Parse Error'
21
21
  Awscli::Errors.missing_credentials
22
22
  end
23
23
  end
24
24
 
25
- def request_ec2 region=nil
25
+ def request_ec2(region=nil)
26
26
  # => returns AWS Compute connection object
27
- @@config.merge!(:provider => 'AWS')
27
+ @config.merge!(:provider => 'AWS')
28
28
  if region
29
29
  #if user passes a region optionally
30
30
  Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region)
31
- @@config.reject!{ |k| k == 'region' } if @@config['region']
32
- @@config.merge!(:region => region)
31
+ @config.reject!{ |key| key == 'region' } if @config['region']
32
+ @config.merge!(:region => region)
33
33
  else
34
- if @@config['region']
35
- Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@@config['region'])
36
- end
34
+ Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@config['region']) if @config['region']
37
35
  end
38
- Fog::Compute.new(@@config)
36
+ Fog::Compute.new(@config)
39
37
  end
40
38
 
41
- def request_s3 region=nil
39
+ def request_s3(region=nil)
42
40
  # => returns S3 connection object
43
- @@config.merge!(:provider => 'AWS')
44
- if @@config['region']
45
- #remove region
46
- @@config.reject!{ |k| k == "region" }
47
- end
41
+ @config.merge!(:provider => 'AWS')
42
+ @config.reject!{ |key| key == 'region' } if @config['region']
48
43
  #parse optionally passing region
49
44
  if region
50
45
  Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region)
51
- @@config.merge!(:region => region)
46
+ @config.merge!(:region => region)
52
47
  end
53
- Fog::Storage.new(@@config)
48
+ Fog::Storage.new(@config)
54
49
  end
55
50
 
56
51
  def request_as
57
52
  # => returns AWS Auto Scaling connection object
58
- #remove region if passed from config
59
- Fog::AWS::AutoScaling.new(@@config)
53
+ Fog::AWS::AutoScaling.new(@config)
60
54
  end
61
55
 
62
56
  def request_iam
63
57
  # => returns AWS IAM object
64
- if @@config['region']
65
- #remove region
66
- @@config.reject!{ |k| k == "region" }
58
+ @config.reject!{ |key| key == 'region' } if @config['region']
59
+ Fog::AWS::IAM.new(@config)
60
+ end
61
+
62
+ def request_emr(region=nil)
63
+ # => returns AWS EMR object
64
+ if region
65
+ Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(region)
66
+ @config.reject!{ |key| key == 'region' } if @config['region']
67
+ @config.merge!(:region => region)
68
+ else
69
+ Awscli::Errors.invalid_region unless Awscli::Instances::REGIONS.include?(@config['region']) if @config['region']
67
70
  end
68
- Fog::AWS::IAM.new(@@config)
71
+ Fog::AWS::EMR.new(@config)
69
72
  end
70
73
 
71
74
  end
@@ -7,26 +7,26 @@ module Awscli
7
7
  # params:
8
8
  # connection: Awscli::Connection.new.request_ec2
9
9
  # extra options hash
10
- def initialize connection, options = {}
11
- @@conn = connection
10
+ def initialize(connection)
11
+ @conn = connection
12
12
  end
13
13
 
14
14
  # list instances from a specified region in a tabular format
15
15
  def list_instances
16
- @@conn.servers.table([:id, :dns_name, :flavor_id, :groups, :image_id, :key_name, :private_ip_address,
16
+ @conn.servers.table([:id, :dns_name, :flavor_id, :groups, :image_id, :key_name, :private_ip_address,
17
17
  :public_ip_address, :root_device_type, :security_group_ids, :state, :tags])
18
18
  end
19
19
 
20
20
  # list available instance types
21
21
  def list_flavors
22
- @@conn.flavors.table
22
+ @conn.flavors.table
23
23
  end
24
24
 
25
25
  # describe instance attributes - returns information about an attribute of an instance. You can get information
26
26
  # only one attribute per call.
27
- # Avaliable attributes to request: instanceType, kernel, ramdisk, userData, disableApiTermination, instanceInitiatedShutdownBehavior,
27
+ # Available attributes to request: instanceType, kernel, ramdisk, userData, disableApiTermination, instanceInitiatedShutdownBehavior,
28
28
  # rootDeviceName, blockDeviceMapping, sourceDestCheck, groupSet
29
- def describe_instance_attribute instance_id, request
29
+ def describe_instance_attribute(instance_id, request)
30
30
  valid_requests = %w(architecture ami_launch_index availability_zone block_device_mapping network_interfaces client_token
31
31
  dns_name ebs_optimized groups flavor_id iam_instance_profile image_id instance_initiated_shutdown_behavior
32
32
  kernel_id key_name created_at monitoring placement_group platform private_dns_name private_ip_address
@@ -34,14 +34,14 @@ module Awscli
34
34
  tenancy tags user_data vpc_id volumes username)
35
35
  #more options
36
36
  #:monitor=, :username=, :private_key=, :private_key_path=, :public_key=, :public_key_path=, :username, :private_key_path, :private_key, :public_key_path, :public_key, :scp, :scp_upload, :scp_download, :ssh, :ssh_port, :sshable?
37
- response = @@conn.servers.get(instance_id)
37
+ response = @conn.servers.get(instance_id)
38
38
  abort "Invalid Attribute, available attributes to request: #{valid_requests}" unless valid_requests.include?(request)
39
- abort "InstanceId Not found :#{instance_id}, Available instnaces #{@@conn.servers.map { |x| x.id }}" unless response
39
+ abort "InstanceId Not found :#{instance_id}, Available instnaces #{@conn.servers.map { |x| x.id }}" unless response
40
40
  puts "#{request}: #{response.send(request)}"
41
41
  end
42
42
 
43
43
  # modifies an attribute of an instance
44
- def modify_instance_attribute instance_id, attributename, attributevalue
44
+ def modify_instance_attribute(instance_id, attributename, attributevalue)
45
45
  attrs_lookup = {
46
46
  'isize' => 'InstanceType',
47
47
  'kernel' => 'Kernel',
@@ -53,36 +53,36 @@ module Awscli
53
53
  'group_id' => 'GroupId'
54
54
  }
55
55
  valid_attributes = %w(InstanceType Kernel Ramdisk UserData DisableApiTermination InstanceInitiatedShutdownBehavior SourceDestCheck GroupId)
56
- response = @@conn.servers.get(instance_id)
57
- abort "InstanceId Not found :#{instance_id}, Available instnaces #{@@conn.servers.map { |x| x.id }}" unless response
56
+ response = @conn.servers.get(instance_id)
57
+ abort "InstanceId Not found :#{instance_id}, Available instnaces #{@conn.servers.map { |x| x.id }}" unless response
58
58
  abort "Instance should be in stopped state to modify its attributes" if response.state != 'stopped'
59
59
  puts "#{instance_id}, #{attributename}, #{attributevalue}"
60
60
  if attrs_lookup[attributename] == 'GroupId' #handle groupid which is array
61
61
  puts "#{instance_id}, #{attrs_lookup[attributename]} => #{attributevalue}"
62
- @@conn.modify_instance_attribute(instance_id, attrs_lookup[attributename] => attributevalue)
62
+ @conn.modify_instance_attribute(instance_id, attrs_lookup[attributename] => attributevalue)
63
63
  else
64
64
  puts "#{instance_id}, #{attrs_lookup[attributename]}.Value => #{attributevalue}"
65
- @@conn.modify_instance_attribute(instance_id, "#{attrs_lookup[attributename]}.Value" => attributevalue)
65
+ @conn.modify_instance_attribute(instance_id, "#{attrs_lookup[attributename]}.Value" => attributevalue)
66
66
  end
67
67
  end
68
68
 
69
69
  # reset instance attribute
70
- def reset_instance_attribute instance_id, attribute
71
- end
70
+ #def reset_instance_attribute(instance_id, attribute)
71
+ #end
72
72
 
73
73
  #create a single instance with options passed
74
- def create_instance options
74
+ def create_instance(options)
75
75
  #validate required options
76
- puts "Validating Options ..."
77
- abort "Invalid Key: #{options[:key_name]}" unless @@conn.key_pairs.get(options[:key_name])
76
+ puts 'Validating Options ...'
77
+ abort "Invalid Key: #{options[:key_name]}" unless @conn.key_pairs.get(options[:key_name])
78
78
  options[:groups].each do |sg|
79
- abort "Invalid Group: #{sg}" unless @@conn.security_groups.get(sg)
79
+ abort "Invalid Group: #{sg}" unless @conn.security_groups.get(sg)
80
80
  end
81
- abort "Invalid AMI: #{options[:image_id]}" unless @@conn.images.get(options[:image_id])
82
- abort "Invalid Instance Flavor: #{options[:flavor_id]}" unless @@conn.flavors.get(options[:flavor_id])
81
+ abort "Invalid AMI: #{options[:image_id]}" unless @conn.images.get(options[:image_id])
82
+ abort "Invalid Instance Flavor: #{options[:flavor_id]}" unless @conn.flavors.get(options[:flavor_id])
83
83
  #validate optional options
84
84
  if options[:availability_zone]
85
- available_zones = @@conn.describe_availability_zones.body['availabilityZoneInfo'].map { |az| az['zoneName'] }
85
+ available_zones = @conn.describe_availability_zones.body['availabilityZoneInfo'].map { |az| az['zoneName'] }
86
86
  abort "Invalid AvailabilityZone: #{options[:availability_zone]}" unless available_zones.include?(options[:availability_zone])
87
87
  end
88
88
  opts = Marshal.load(Marshal.dump(options))
@@ -109,7 +109,7 @@ module Awscli
109
109
  mapping['Ebs.VolumeSize'] = volume_size if !volume_size.nil? && !volume_size.empty?
110
110
  mapping['Ebs.DeleteOnTermination'] = delete_on_termination if !delete_on_termination.nil? && !delete_on_termination.empty?
111
111
  else
112
- abort "Cannot validate block_device"
112
+ abort 'Cannot validate block_device'
113
113
  end
114
114
  block_device_mapping << mapping
115
115
  end
@@ -118,110 +118,110 @@ module Awscli
118
118
  opts.merge!(:block_device_mapping => block_device_mapping)
119
119
  end
120
120
  wait_for_server = options[:wait_for] && opts.reject! { |k| k == 'wait_for' }
121
- puts "Validating Options ... OK"
122
- puts "Creating Server"
123
- server = @@conn.servers.create(opts)
121
+ puts 'Validating Options ... OK'
122
+ puts 'Creating Server'
123
+ server = @conn.servers.create(opts)
124
124
  #wait for server to get created and return public_dns
125
125
  if wait_for_server
126
- print "Waiting for server to get created "
126
+ print 'Waiting for server to get created'
127
127
  server.wait_for { print "."; ready? }
128
128
  puts
129
129
  puts "Server dns_name: #{server.dns_name}"
130
130
  end
131
131
  end
132
132
 
133
- # create a new instnace(s)
134
- def run_instances options
135
- end
133
+ ## create a new instance(s)
134
+ #def run_instances options
135
+ #end
136
136
 
137
- # describe instnace status
138
- def describe_instance_status instnace_id
139
- response = @@conn.servers.get(instance_id)
137
+ # describe instance status
138
+ def describe_instance_status(instnace_id)
139
+ response = @conn.servers.get(instance_id)
140
140
  abort "InstanceId Not found :#{instance_id}" unless response
141
141
  puts "Instance #{instance_id} State: #{response.state}"
142
142
  end
143
143
 
144
- # import instance as vm
145
- def import_instance
146
- end
144
+ ## import instance as vm
145
+ #def import_instance
146
+ #end
147
147
 
148
- #@@conn.server.get(instanceid).(:reboot, :save, :setup, :start, :stop)
148
+ #@conn.server.get(instanceid).(:reboot, :save, :setup, :start, :stop)
149
149
  # reboot an instance
150
- def reboot_instance instance_id
151
- response = @@conn.servers.get(instance_id)
150
+ def reboot_instance(instance_id)
151
+ response = @conn.servers.get(instance_id)
152
152
  abort "InstanceId Not found :#{instance_id}" unless response
153
153
  response.reboot
154
154
  puts "Rebooting Instance: #{instance_id}"
155
155
  end
156
156
 
157
157
  # start a stopped instance
158
- def stop_instance instance_id
159
- response = @@conn.servers.get(instance_id)
158
+ def stop_instance(instance_id)
159
+ response = @conn.servers.get(instance_id)
160
160
  abort "InstanceId Not found :#{instance_id}" unless response
161
- abort "Instance should be in running to stop it" if response.state != 'running'
161
+ abort 'Instance should be in running to stop it' if response.state != 'running'
162
162
  response.stop
163
163
  puts "Stopped Instance: #{instance_id}"
164
164
  end
165
165
 
166
166
  # stop a running isntance
167
- def start_instance instance_id
168
- response = @@conn.servers.get(instance_id)
167
+ def start_instance(instance_id)
168
+ response = @conn.servers.get(instance_id)
169
169
  abort "InstanceId Not found :#{instance_id}" unless response
170
- abort "Instance should be stopped to start it" if response.state != 'stopped'
170
+ abort 'Instance should be stopped to start it' if response.state != 'stopped'
171
171
  response.start
172
172
  puts "Starting Instance: #{instance_id}"
173
173
  end
174
174
 
175
175
  # terminates an instance
176
- def terminate_instance instance_id
177
- response = @@conn.servers.get(instance_id)
176
+ def terminate_instance(instance_id)
177
+ response = @conn.servers.get(instance_id)
178
178
  abort "InstanceId Not found :#{instance_id}" unless response
179
179
  unless response.state == 'terminated'
180
180
  response.destroy
181
181
  puts "Terminated Instance: #{instance_id}"
182
182
  else
183
- puts "Instance is already in terminated state"
183
+ puts 'Instance is already in terminated state'
184
184
  end
185
185
  end
186
186
 
187
- def get_console_output instance_id
188
- response = @@conn.get_console_output(instance_id)
187
+ def get_console_output(instance_id)
188
+ response = @conn.get_console_output(instance_id)
189
189
  puts response
190
190
  end
191
191
 
192
192
  end # => EC2
193
193
 
194
194
  class KeyPairs
195
- def initialize connection, options = {}
196
- @@conn = connection
195
+ def initialize(connection)
196
+ @conn = connection
197
197
  end
198
198
 
199
199
  def list_keypairs
200
- @@conn.key_pairs.table
200
+ @conn.key_pairs.table
201
201
  end
202
202
 
203
- def create_keypair options
203
+ def create_keypair(options)
204
204
  #validate keypair
205
205
  Fog.credential = 'awscli'
206
- abort "KeyPair '#{options[:name]}' already exists" if @@conn.key_pairs.get(options[:name])
207
- kp = @@conn.key_pairs.create(options)
206
+ abort "KeyPair '#{options[:name]}' already exists" if @conn.key_pairs.get(options[:name])
207
+ kp = @conn.key_pairs.create(options)
208
208
  puts "Created keypair: #{options[:name]}"
209
209
  p kp.write #save the key to disk
210
210
  end
211
211
 
212
- def delete_keypair keypair
213
- abort "KeyPair '#{keypair}' does not exist" unless @@conn.key_pairs.get(keypair)
214
- @@conn.key_pairs.get(keypair).destroy
212
+ def delete_keypair(keypair)
213
+ abort "KeyPair '#{keypair}' does not exist" unless @conn.key_pairs.get(keypair)
214
+ @conn.key_pairs.get(keypair).destroy
215
215
  puts "Deleted Keypair: #{keypair}"
216
216
  end
217
217
 
218
- def fingerprint keypair
219
- response = @@conn.key_pairs.get(keypair)
218
+ def fingerprint(keypair)
219
+ response = @conn.key_pairs.get(keypair)
220
220
  abort "Cannot find key pair: #{keypair}" unless response
221
221
  puts "Fingerprint for the key (#{keypair}): #{response.fingerprint}"
222
222
  end
223
223
 
224
- def import_keypair options
224
+ def import_keypair(options)
225
225
  #validate if the file exists
226
226
  private_key_path = if options[:private_key_path]
227
227
  File.expand_path(options[:private_key_path])
@@ -237,7 +237,7 @@ module Awscli
237
237
  abort "Cannot find public_key_path: #{public_key_path}" unless File.exist?(public_key_path)
238
238
  #validate if the key pair name exists
239
239
  Fog.credentials = Fog.credentials.merge({ :private_key_path => private_key_path, :public_key_path => public_key_path })
240
- @@conn.import_key_pair(options[:name], IO.read(public_key_path)) if @@conn.key_pairs.get(options[:name]).nil?
240
+ @conn.import_key_pair(options[:name], IO.read(public_key_path)) if @conn.key_pairs.get(options[:name]).nil?
241
241
  puts "Imported KeyPair with name: #{options[:name]} sucessfully, using public_key: #{public_key_path} and private_key: #{private_key_path}"
242
242
  end
243
243
  end # => KP
@@ -247,36 +247,36 @@ module Awscli
247
247
  #Limitations: Ec2-Classic: user can have upto 500 groups
248
248
  # Ec2-VPC: user can have 50 group per VPC
249
249
 
250
- def initialize connection, options = {}
251
- @@conn = connection
250
+ def initialize(connection)
251
+ @conn = connection
252
252
  end
253
253
 
254
- def list_secgroups options
254
+ def list_secgroups(options)
255
255
  if options[:show_ip_permissions]
256
- # @@conn.security_groups.table([:name, :group_id, :ip_permissions])
257
- @@conn.security_groups.each do |sg|
256
+ # @conn.security_groups.table([:name, :group_id, :ip_permissions])
257
+ @conn.security_groups.each do |sg|
258
258
  id = sg.group_id
259
259
  ip_permissions = sg.ip_permissions.to_yaml
260
260
  Formatador.display_line("[green]#{id}[/]")
261
261
  puts "#{ip_permissions}"
262
- puts "================="
262
+ puts '================='
263
263
  end
264
264
  else
265
- @@conn.security_groups.table([:name, :group_id, :description])
265
+ @conn.security_groups.table([:name, :group_id, :description])
266
266
  end
267
267
  end
268
268
 
269
- def authorize_securitygroup options
269
+ def authorize_securitygroup(options)
270
270
  # => Ingress regular traffic -> this action applies to both EC2 and VPC Security Groups
271
271
  # Each rule consists of the protocol, plus cidr range or a source group,
272
272
  #for TCP/UDP protocols you must also specify the dest port or port range
273
273
  #for ICMP, you must specify the icmp type and code (-1 means all types/codes)
274
274
  abort "Expecting Security group id(s) of the form: 'sg-xxxxxx'" unless options[:group_id] =~ /sg-\S{8}/
275
275
  abort "Invalid CIDR format" unless options[:cidr] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(\d|[1-2]\d|3[0-2]))$/
276
- sg = @@conn.security_groups.get_by_id(options[:group_id])
276
+ sg = @conn.security_groups.get_by_id(options[:group_id])
277
277
  abort "Cannot find Security Group with Id: #{sg}" unless sg
278
278
  begin
279
- @@conn.authorize_security_group_ingress(
279
+ @conn.authorize_security_group_ingress(
280
280
  "GroupId" => options[:group_id],
281
281
  "IpProtocol" => options[:protocol_type],
282
282
  "FromPort" => options[:start_port],
@@ -290,12 +290,12 @@ module Awscli
290
290
  end
291
291
  end
292
292
 
293
- def revoke_securitygroup options
293
+ def revoke_securitygroup(options)
294
294
  abort "Expecting Security group id(s) of the form: 'sg-xxxxxx'" unless options[:group_id] =~ /sg-\S{8}/
295
- sg = @@conn.security_groups.get_by_id(options[:group_id])
295
+ sg = @conn.security_groups.get_by_id(options[:group_id])
296
296
  abort "Cannot find Security Group with Id: #{sg}" unless sg
297
297
  begin
298
- response = @@conn.revoke_security_group_ingress(
298
+ response = @conn.revoke_security_group_ingress(
299
299
  "GroupId" => options[:group_id],
300
300
  "IpProtocol" => options[:protocol_type],
301
301
  "FromPort" => options[:start_port],
@@ -308,14 +308,14 @@ module Awscli
308
308
  end
309
309
  end
310
310
 
311
- def create_securitygroup options
312
- abort "Error: Security Group => #{options[:name]} already exists" if @@conn.security_groups.get(options[:name])
313
- @@conn.security_groups.create(options)
311
+ def create_securitygroup(options)
312
+ abort "Error: Security Group => #{options[:name]} already exists" if @conn.security_groups.get(options[:name])
313
+ @conn.security_groups.create(options)
314
314
  puts "Created Security Group: #{options[:name]}"
315
315
  end
316
316
 
317
- def delete_securitygroup options
318
- sg = @@conn.security_groups.get_by_id(options[:group_id])
317
+ def delete_securitygroup(options)
318
+ sg = @conn.security_groups.get_by_id(options[:group_id])
319
319
  abort "Error: Cannot find Security Group with Id: #{sg}" unless sg
320
320
  begin
321
321
  sg.destroy
@@ -328,32 +328,32 @@ module Awscli
328
328
  end # => SG
329
329
 
330
330
  class Eip
331
- def initialize connection, options = {}
332
- @@conn = connection
331
+ def initialize(connection)
332
+ @conn = connection
333
333
  end
334
334
 
335
335
  def list
336
- @@conn.addresses.table
336
+ @conn.addresses.table
337
337
  end
338
338
 
339
339
  def create
340
- eip = @@conn.addresses.create
340
+ eip = @conn.addresses.create
341
341
  puts "Created EIP: #{eip.public_ip}"
342
342
  end
343
343
 
344
- def delete options
344
+ def delete(options)
345
345
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
346
- eip = @@conn.addresses.get(options[:eip])
346
+ eip = @conn.addresses.get(options[:eip])
347
347
  abort "Cannot find IP: #{options[:eip]}" unless eip
348
348
  eip.destroy
349
349
  puts "Deleted EIP: #{eip.public_ip}"
350
350
  end
351
351
 
352
- def associate options
352
+ def associate(options)
353
353
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
354
- eip = @@conn.addresses.get(options[:eip])
354
+ eip = @conn.addresses.get(options[:eip])
355
355
  abort "Cannot find eip: #{options[:eip]}" unless eip
356
- server = @@conn.servers.get(options[:instance_id])
356
+ server = @conn.servers.get(options[:instance_id])
357
357
  abort "Cannot find server with id: #{options[:instance_id]}" unless server
358
358
  begin
359
359
  eip.server = server
@@ -363,25 +363,25 @@ module Awscli
363
363
  end
364
364
  end
365
365
 
366
- def disassociate options
366
+ def disassociate(options)
367
367
  abort "Invalid IP Format" unless options[:eip] =~ /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
368
- abort "Cannot find EIP: #{options[:eip]}" unless @@conn.addresses.get(options[:eip])
369
- @@conn.disassociate_address(options[:eip])
368
+ abort "Cannot find EIP: #{options[:eip]}" unless @conn.addresses.get(options[:eip])
369
+ @conn.disassociate_address(options[:eip])
370
370
  puts "Disassociated EIP: #{options[:eip]}"
371
371
  end
372
372
  end # => Eip
373
373
 
374
374
  class Ami
375
- def initialize connection, options = {}
376
- @@conn = connection
375
+ def initialize(connection)
376
+ @conn = connection
377
377
  end
378
378
 
379
- def list filter
379
+ def list(filter)
380
380
  puts filter
381
381
  if filter.nil?
382
- @@conn.images.all.table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
382
+ @conn.images.all.table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
383
383
  else
384
- data = @@conn.images.all(filter)
384
+ data = @conn.images.all(filter)
385
385
  data.empty? ? puts("No AMI's found for provided filters") : data.table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
386
386
  end
387
387
  end
@@ -420,17 +420,17 @@ module Awscli
420
420
  end
421
421
 
422
422
  def list_amazon
423
- @@conn.images.all('owner-alias' => 'amazon').table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
423
+ @conn.images.all('owner-alias' => 'amazon').table([:architecture, :id, :is_public, :platform, :root_device_type, :state])
424
424
  end
425
425
 
426
426
  def list_self
427
- response = @@conn.describe_images({'Owner' => 'self'}).body['imagesSet']
427
+ response = @conn.describe_images({'Owner' => 'self'}).body['imagesSet']
428
428
  Formatador.display_table(response, ['architecture', 'imageId', 'isPublic', 'name', 'imageState', 'rootDeviceType', 'imageType'])
429
429
  end
430
430
 
431
- def create_image_from_instance options
432
- abort "Invalid Instace: #{options[:instance_id]}" unless @@conn.servers.get(options[:instance_id])
433
- @@conn.create_image(
431
+ def create_image_from_instance(options)
432
+ abort "Invalid Instace: #{options[:instance_id]}" unless @conn.servers.get(options[:instance_id])
433
+ @conn.create_image(
434
434
  options[:instance_id],
435
435
  options[:name],
436
436
  options[:desc],
@@ -439,67 +439,67 @@ module Awscli
439
439
  puts "Created image from instance: #{options[:instance_id]}"
440
440
  end
441
441
 
442
- def deregister image_id
443
- image = @@conn.images.get(image_id)
442
+ def deregister(image_id)
443
+ image = @conn.images.get(image_id)
444
444
  abort "Cannot find image with id: #{image_id}" unless image
445
- @@conn.deregister_image(image_id)
445
+ @conn.deregister_image(image_id)
446
446
  say "De-registerd image: <%= color('#{image_id}', :green) %>"
447
447
  end
448
448
 
449
449
  end # => AMI
450
450
 
451
451
  class Ebs
452
- def initialize connection, options = {}
453
- @@conn = connection
452
+ def initialize(connection)
453
+ @conn = connection
454
454
  end
455
455
 
456
- def list options
456
+ def list(options)
457
457
  unless options[:snapshots]
458
- @@conn.volumes.table([:availability_zone, :delete_on_termination, :device, :id, :server_id, :size, :snapshot_id, :state, :tags, :type])
458
+ @conn.volumes.table([:availability_zone, :delete_on_termination, :device, :id, :server_id, :size, :snapshot_id, :state, :tags, :type])
459
459
  else
460
- @@conn.snapshots.table([:id, :owner_id, :volume_id, :state, :progress, :tags, :description])
460
+ @conn.snapshots.table([:id, :owner_id, :volume_id, :state, :progress, :tags, :description])
461
461
  end
462
462
  end
463
463
 
464
- def create options
465
- @@conn.volumes.create(options)
464
+ def create(options)
465
+ @conn.volumes.create(options)
466
466
  end
467
467
 
468
- def attach_volume options
468
+ def attach_volume(options)
469
469
  #The volume and instance must be in the same Availability Zone.
470
- volume = @@conn.volumes.get(options[:volume_id])
470
+ volume = @conn.volumes.get(options[:volume_id])
471
471
  volume.merge_attributes(:device => options[:device])
472
- server = @@conn.servers.get(options[:instance_id])
472
+ server = @conn.servers.get(options[:instance_id])
473
473
  abort "Cannot find volume: #{options[:volume_id]}" unless volume
474
474
  abort "Cannot find instance: #{options[:instance_id]}" unless server
475
475
  volume.server = server
476
476
  puts "Attached volume: #{options[:volume_id]} to instance: #{options[:instance_id]}"
477
477
  end
478
478
 
479
- def detach_volume options
479
+ def detach_volume(options)
480
480
  #Check if the volume is mounted and show warning regarding data loss
481
- volume = @@conn.volumes.get(options[:volume_id])
481
+ volume = @conn.volumes.get(options[:volume_id])
482
482
  abort "Cannot find volume: #{options[:volume_id]}" unless volume
483
483
  if options[:force]
484
484
  volume.force_detach
485
485
  else
486
- @@conn.detach_volume(options[:volume_id])
486
+ @conn.detach_volume(options[:volume_id])
487
487
  end
488
488
  puts "Detached volume: #{options[:volume_id]}"
489
489
  end
490
490
 
491
- def delete_volume options
492
- vol = @@conn.volumes.get(options[:volume_id])
491
+ def delete_volume(options)
492
+ vol = @conn.volumes.get(options[:volume_id])
493
493
  abort "Cannot find volume #{options[:volume_id]}" unless vol
494
494
  vol.destroy
495
495
  puts "Deleted volume: #{options[:volume_id]}"
496
496
  end
497
497
 
498
498
  def delete_detached
499
- vols = @@conn.volumes.all('status' => 'available')
499
+ vols = @conn.volumes.all('status' => 'available')
500
500
  unless vols.empty?
501
- if agree("Are you sure want to delete all the all volumes that are not in use ? ")
502
- puts "Deleting all volumes which are not in use ..."
501
+ if agree('Are you sure want to delete all the all volumes that are not in use ? ')
502
+ puts 'Deleting all volumes which are not in use ...'
503
503
  vols.each do |vol|
504
504
  vol.destroy
505
505
  end
@@ -509,20 +509,20 @@ module Awscli
509
509
  end
510
510
  end
511
511
 
512
- def create_snapshot options
513
- abort "Cannot find volume: #{options[:volume_id]}" unless @@conn.volumes.get(options[:volume_id])
514
- @@conn.snapshots.create(options)
512
+ def create_snapshot(options)
513
+ abort "Cannot find volume: #{options[:volume_id]}" unless @conn.volumes.get(options[:volume_id])
514
+ @conn.snapshots.create(options)
515
515
  puts "Created snapshot"
516
516
  end
517
517
 
518
- def copy_snapshot options
519
- # abort "Cannot find snapshot: #{options[:snapshot_id]}" unless @@conn.snapshots.get(options[:snapshot_id])
520
- @@conn.copy_snapshot(options[:snapshot_id], options[:source_region])
518
+ def copy_snapshot(options)
519
+ # abort "Cannot find snapshot: #{options[:snapshot_id]}" unless @conn.snapshots.get(options[:snapshot_id])
520
+ @conn.copy_snapshot(options[:snapshot_id], options[:source_region])
521
521
  puts "Copied snapshot"
522
522
  end
523
523
 
524
- def delete_snapshot options
525
- snap = @@conn.snapshots.get(options[:snapshot_id])
524
+ def delete_snapshot(options)
525
+ snap = @conn.snapshots.get(options[:snapshot_id])
526
526
  abort "Cannot find snapshot: #{options[:snapshot_id]}" unless snap
527
527
  snap.destroy
528
528
  puts "Deleted snapshot"
@@ -530,87 +530,87 @@ module Awscli
530
530
  end # => EBS
531
531
 
532
532
  class Monitor
533
- def initialize connection, options = {}
534
- @@conn = connection
533
+ def initialize(connection)
534
+ @conn = connection
535
535
  end
536
536
 
537
- def monitor options
537
+ def monitor(options)
538
538
  options[:instance_ids].each do |instance|
539
- abort "Invalid InstanceId: #{instance}" unless @@conn.servers.get(instance)
539
+ abort "Invalid InstanceId: #{instance}" unless @conn.servers.get(instance)
540
540
  end
541
- @@conn.monitor_instances(options[:instance_ids])
541
+ @conn.monitor_instances(options[:instance_ids])
542
542
  puts "Enabled monitoring for instnaces: #{options[:instance_ids].join(",")}"
543
543
  end
544
544
 
545
- def unmonitor options
545
+ def unmonitor(options)
546
546
  options[:instance_ids].each do |instance|
547
- abort "Invalid InstanceId: #{instance}" unless @@conn.servers.get(instance)
547
+ abort "Invalid InstanceId: #{instance}" unless @conn.servers.get(instance)
548
548
  end
549
- @@conn.unmonitor_instances(options[:instance_ids])
549
+ @conn.unmonitor_instances(options[:instance_ids])
550
550
  puts "Disabled monitoring for instnaces: #{options[:instance_ids].join(",")}"
551
551
  end
552
552
  end # => Monitor
553
553
 
554
554
  class Tags
555
- def initialize connection, options = {}
556
- @@conn = connection
555
+ def initialize(connection)
556
+ @conn = connection
557
557
  end
558
558
 
559
559
  def list
560
- @@conn.tags.table
560
+ @conn.tags.table
561
561
  end
562
562
 
563
- def create options
564
- @@conn.tags.create(options)
565
- puts "Created Tag"
563
+ def create(options)
564
+ @conn.tags.create(options)
565
+ puts 'Created Tag'
566
566
  end
567
567
 
568
- def delete options
569
- @@conn.tags.destroy(options)
570
- puts "Deleted Tag"
568
+ def delete(options)
569
+ @conn.tags.destroy(options)
570
+ puts 'Deleted Tag'
571
571
  end
572
572
  end # => Tags
573
573
 
574
574
  class Placement
575
- def initialize connection, options = {}
576
- @@conn = connection
575
+ def initialize(connection)
576
+ @conn = connection
577
577
  end
578
578
 
579
579
  def list
580
- @@conn.describe_placement_groups
580
+ @conn.describe_placement_groups
581
581
  end
582
582
 
583
- def create options
584
- @@conn.create_placement_group(options[:name], options[:strategy])
583
+ def create(options)
584
+ @conn.create_placement_group(options[:name], options[:strategy])
585
585
  puts "Created a new placement group: #{options[:name]}"
586
586
  end
587
587
 
588
- def delete options
589
- @@conn.delete_placement_group(options[:name])
588
+ def delete(options)
589
+ @conn.delete_placement_group(options[:name])
590
590
  puts "Deleted placement group: #{options[:name]}"
591
591
  end
592
592
  end # => Placement
593
593
 
594
594
  class ReservedInstances
595
- def initialize connection, options = {}
596
- @@conn = connection
595
+ def initialize(connection)
596
+ @conn = connection
597
597
  end
598
598
 
599
- def list filters
599
+ def list(filters)
600
600
  puts filters
601
601
  if filters.nil?
602
- @@conn.describe_reserved_instances.body['reservedInstancesSet']
602
+ @conn.describe_reserved_instances.body['reservedInstancesSet']
603
603
  else
604
- @@conn.describe_reserved_instances(filters).body['reservedInstancesSet']
604
+ @conn.describe_reserved_instances(filters).body['reservedInstancesSet']
605
605
  end
606
606
  end
607
607
 
608
- def list_offerings filters
608
+ def list_offerings(filters)
609
609
  puts filters
610
610
  response = if filters.nil?
611
- @@conn.describe_reserved_instances_offerings.body['reservedInstancesOfferingsSet']
611
+ @conn.describe_reserved_instances_offerings.body['reservedInstancesOfferingsSet']
612
612
  else
613
- @@conn.describe_reserved_instances_offerings(filters).body['reservedInstancesOfferingsSet']
613
+ @conn.describe_reserved_instances_offerings(filters).body['reservedInstancesOfferingsSet']
614
614
  end
615
615
  Formatador.display_table(response)
616
616
  end
@@ -633,30 +633,30 @@ module Awscli
633
633
  Formatador.display_table(filters, [:filter_name, :desc, :availability])
634
634
  end
635
635
 
636
- def purchase options
637
- @@conn.purchase_reserved_instances_offering(options[:reserved_instances_offering_id], options[:instance_count])
636
+ def purchase(options)
637
+ @conn.purchase_reserved_instances_offering(options[:reserved_instances_offering_id], options[:instance_count])
638
638
  end
639
639
  end # => ReservedInstances
640
640
 
641
641
  class Spot
642
- def initialize connection, options = {}
643
- @@conn = connection
642
+ def initialize(connection)
643
+ @conn = connection
644
644
  end
645
645
 
646
646
  def describe_spot_requests
647
- @@conn.spot_requests.table
647
+ @conn.spot_requests.table
648
648
  end
649
649
 
650
650
  def describe_spot_datafeed_subscription
651
- @@conn.describe_spot_datafeed_subscription
651
+ @conn.describe_spot_datafeed_subscription
652
652
  end
653
653
 
654
- def describe_spot_price_history filters
654
+ def describe_spot_price_history(filters)
655
655
  puts filters
656
656
  response = if filters.nil?
657
- @@conn.describe_spot_price_history.body['spotPriceHistorySet']
657
+ @conn.describe_spot_price_history.body['spotPriceHistorySet']
658
658
  else
659
- @@conn.describe_spot_price_history(filters).body['spotPriceHistorySet']
659
+ @conn.describe_spot_price_history(filters).body['spotPriceHistorySet']
660
660
  end
661
661
  Formatador.display_table(response)
662
662
  end
@@ -671,21 +671,21 @@ module Awscli
671
671
  Formatador.display_table(filters, [:filter_name, :desc])
672
672
  end
673
673
 
674
- def create_spot_datafeed_subsription bucket, prefix
675
- @@conn.create_spot_datafeed_subscription(bucket, prefix)
674
+ def create_spot_datafeed_subsription(bucket, prefix)
675
+ @conn.create_spot_datafeed_subscription(bucket, prefix)
676
676
  end
677
677
 
678
678
  def delete_spot_datafeed_subsription
679
- @@conn.delete_spot_datafeed_subscription
679
+ @conn.delete_spot_datafeed_subscription
680
680
  end
681
681
 
682
- def request_spot_instances options
683
- sr = @@conn.spot_requests.create(options)
682
+ def request_spot_instances(options)
683
+ sr = @conn.spot_requests.create(options)
684
684
  puts "Created spot request: #{sr.id}"
685
685
  end
686
686
 
687
- def cancel_spot_instance_requests sid
688
- sr = @@conn.spot_requests.get(sid)
687
+ def cancel_spot_instance_requests(sid)
688
+ sr = @conn.spot_requests.get(sid)
689
689
  abort "Cannot find spot request with id: #{sid}" unless sr
690
690
  sr.destroy
691
691
  puts "Deleted spot request: #{sid}"
@@ -693,21 +693,21 @@ module Awscli
693
693
  end # => Spot
694
694
 
695
695
  class Vpc
696
- def initialize connection, options = {}
697
- @@conn = connection
696
+ def initialize(connection)
697
+ @conn = connection
698
698
  end
699
699
 
700
700
  def list
701
- @@conn.vpcs.table
701
+ @conn.vpcs.table
702
702
  end
703
703
 
704
- def create options
705
- vpc = @@conn.vpcs.create(options)
704
+ def create(options)
705
+ vpc = @conn.vpcs.create(options)
706
706
  puts "Created VPC: #{vpc.id}"
707
707
  end
708
708
 
709
- def delete vpc_id
710
- vpc = @@conn.vpcs.get(vpc_id)
709
+ def delete(vpc_id)
710
+ vpc = @conn.vpcs.get(vpc_id)
711
711
  abort "cannot find vpc: #{vpc_id}" unless vpc
712
712
  vpc.destroy
713
713
  puts "Deleted VPC : #{vpc_id}"
@@ -715,21 +715,21 @@ module Awscli
715
715
  end # => Vpc
716
716
 
717
717
  class Subnet
718
- def initialize connection, options = {}
719
- @@conn = connection
718
+ def initialize(connection)
719
+ @conn = connection
720
720
  end
721
721
 
722
722
  def list
723
- @@conn.subnets.table
723
+ @conn.subnets.table
724
724
  end
725
725
 
726
- def create options
727
- subnet = @@conn.subnets.create(options)
726
+ def create(options)
727
+ subnet = @conn.subnets.create(options)
728
728
  puts "Created Subnet: #{subnet.id}"
729
729
  end
730
730
 
731
- def delete subnet_id
732
- subnet = @@conn.subnets.get(subnet_id)
731
+ def delete(subnet_id)
732
+ subnet = @conn.subnets.get(subnet_id)
733
733
  abort "Cannot find subnet: #{subnet_id}" unless subnet
734
734
  subnet.destroy
735
735
  puts "Deleted subnet: #{subnet_id}"
@@ -737,57 +737,57 @@ module Awscli
737
737
  end # => Subnet
738
738
 
739
739
  class NetworkAcl
740
- def initialize connection, options = {}
741
- @@conn = connection
740
+ def initialize(connection)
741
+ @conn = connection
742
742
  end
743
743
 
744
744
  def list
745
- puts "Listing Network Acls"
745
+ puts 'Listing Network Acls'
746
746
  end
747
747
 
748
748
  end # => NetworkAcl
749
749
 
750
750
  class NetworkInterfaces
751
- def initialize connection, options = {}
752
- @@conn = connection
751
+ def initialize(connection)
752
+ @conn = connection
753
753
  end
754
754
 
755
755
  def list
756
- @@conn.network_interfaces.table
756
+ @conn.network_interfaces.table
757
757
  end
758
758
 
759
- def create options
760
- nic = @@conn.network_interfaces.create(options)
759
+ def create(options)
760
+ nic = @conn.network_interfaces.create(options)
761
761
  puts "Create network interface #{nic.network_interface_id}"
762
762
  end
763
763
 
764
- def delete nic_id
765
- nic = @@conn.network_interfaces.get(nic_id)
764
+ def delete(nic_id)
765
+ nic = @conn.network_interfaces.get(nic_id)
766
766
  abort "Cannot find nic with id: #{nic_id}" unless nic
767
767
  nic.destroy
768
768
  puts "Deleted network interface #{nic_id}"
769
769
  end
770
770
 
771
- def attach nic_id, instance_id, device_index
772
- @@conn.attach_network_interface(nic_id, instance_id, device_index)
771
+ def attach(nic_id, instance_id, device_index)
772
+ @conn.attach_network_interface(nic_id, instance_id, device_index)
773
773
  puts "Attached Network Interface: #{nic_id} to instance: #{instance_id}"
774
774
  end
775
775
 
776
- def deattach attachement_id, force
777
- @@conn.detach_network_interface attachement_id, force
778
- puts "Deattached Network Interface with attachement_id: #{attachement_id}"
776
+ def deattach(attachement_id, force)
777
+ @conn.detach_network_interface attachement_id, force
778
+ puts "Detached Network Interface with attachement_id: #{attachement_id}"
779
779
  end
780
780
 
781
- def modify_attribute options
781
+ def modify_attribute(options)
782
782
  case options[:attribute]
783
783
  when 'description'
784
- @@conn.modify_network_interface_attribute(options[:network_interface_id], 'description', options[:description])
784
+ @conn.modify_network_interface_attribute(options[:network_interface_id], 'description', options[:description])
785
785
  when 'groupSet'
786
- @@conn.modify_network_interface_attribute(options[:network_interface_id], 'groupSet', options[:group_set])
786
+ @conn.modify_network_interface_attribute(options[:network_interface_id], 'groupSet', options[:group_set])
787
787
  when 'sourceDestCheck'
788
- @@conn.modify_network_interface_attribute(options[:network_interface_id], 'sourceDestCheck', options[:source_dest_check])
788
+ @conn.modify_network_interface_attribute(options[:network_interface_id], 'sourceDestCheck', options[:source_dest_check])
789
789
  when 'attachment'
790
- @@conn.modify_network_interface_attribute(options[:network_interface_id], 'attachment', options[:attachment])
790
+ @conn.modify_network_interface_attribute(options[:network_interface_id], 'attachment', options[:attachment])
791
791
  else
792
792
  abort "Invalid attribute: #{options[:attribute]}"
793
793
  end
@@ -795,56 +795,56 @@ module Awscli
795
795
  end # => NetworkInterfaces
796
796
 
797
797
  class InternetGateways
798
- def initialize connection, options = {}
799
- @@conn = connection
798
+ def initialize(connection)
799
+ @conn = connection
800
800
  end
801
801
 
802
802
  def list
803
- @@conn.internet_gateways.table
803
+ @conn.internet_gateways.table
804
804
  end
805
805
 
806
806
  def create
807
- gw = @@conn.internet_gateways.create
807
+ gw = @conn.internet_gateways.create
808
808
  puts "Created Internet Gateway: #{gw.id}"
809
809
  end
810
810
 
811
- def delete gwid
812
- gw = @@conn.internet_gateways.get(gwid)
811
+ def delete(gwid)
812
+ gw = @conn.internet_gateways.get(gwid)
813
813
  gw.destroy
814
814
  puts "Deleted Internet Gateway: #{gwid}"
815
815
  end
816
816
 
817
- def attach gwid, vpcid
818
- @@conn.internet_gateways.attach(gwid, vpcid)
817
+ def attach(gwid, vpcid)
818
+ @conn.internet_gateways.attach(gwid, vpcid)
819
819
  puts "Attached InternetGateway: #{gwid} to VPC: #{vpcid}"
820
820
  end
821
821
 
822
- def deattach gwid, vpcid
823
- @@conn.internet_gateways.deattach(gwid, vpcid)
824
- puts "Deattached InternetGateway: #{gwid} from VPC: #{vpcid}"
822
+ def deattach(gwid, vpcid)
823
+ @conn.internet_gateways.deattach(gwid, vpcid)
824
+ puts "Detached InternetGateway: #{gwid} from VPC: #{vpcid}"
825
825
  end
826
826
  end # => InternetGateways
827
827
 
828
828
  class Dhcp
829
- def initialize connection, options = {}
830
- @@conn = connection
829
+ def initialize(connection)
830
+ @conn = connection
831
831
  end
832
832
 
833
833
  def list
834
- @@conn.dhcp_options.table
834
+ @conn.dhcp_options.table
835
835
  end
836
836
 
837
- def create options
838
- @@conn.dhcp_options.create(options)
837
+ def create(options)
838
+ @conn.dhcp_options.create(options)
839
839
  end
840
840
 
841
- def delete dhcp_id
842
- dhcp = @@conn.dhcp_options(dhcp_id)
841
+ def delete(dhcp_id)
842
+ dhcp = @conn.dhcp_options(dhcp_id)
843
843
  dhcp.destroy
844
844
  end
845
845
 
846
- def associate dhcp_id, vpc_id
847
- @@conn.dhcp_options.attach(dhcp_id, vpc_id)
846
+ def associate(dhcp_id, vpc_id)
847
+ @conn.dhcp_options.attach(dhcp_id, vpc_id)
848
848
  end
849
849
  end # => Dhcp
850
850