~awstools-dev/ubuntu/maverick/ec2-ami-tools/maverick

« back to all changes in this revision

Viewing changes to lib/ec2/amitools/deletebundleparameters.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-10-14 08:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20081014083525-c0n69wr7r7aqfb8w
Tags: 1.3-26357-0ubuntu2
* New upstream version.
* Update the debian copyright file.
* Added quilt patch system to make it easier to maintain. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008 Amazon.com, Inc. or its affiliates.  All Rights
 
2
# Reserved.  Licensed under the Amazon Software License (the
 
3
# "License").  You may not use this file except in compliance with the
 
4
# License. A copy of the License is located at
 
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
 
6
# file.  This file is distributed on an "AS IS" BASIS, WITHOUT
 
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
 
8
# the License for the specific language governing permissions and
 
9
# limitations under the License.
 
10
 
 
11
require 'optparse'
 
12
require 'ec2/amitools/version'
 
13
 
 
14
#------------------------------------------------------------------------------#
 
15
 
 
16
class DeleteBundleParameters < OptionParser
 
17
    
 
18
  BUCKET_DESCRIPTION = "The bucket containing the bundled AMI."  
 
19
  MANIFEST_DESCRIPTION = "The path to the unencrypted manifest file."  
 
20
  PREFIX_DESCRIPTION = "The bundled AMI part filename prefix."  
 
21
  USER_DESCRIPTION = "The user's AWS access key ID."  
 
22
  PASS_DESCRIPTION = "The user's AWS secret access key."  
 
23
  DEBUG_DESCRIPTION = "Print debug messages."  
 
24
  HELP_DESCRIPTION = "Display the help message and exit."  
 
25
  MANUAL_DESCRIPTION = "Display the manual and exit."  
 
26
  RETRY_DESCRIPTION = "Automatically retry failed deletes. Use with caution."  
 
27
  URL_DESCRIPTION = "The S3 service URL. Defaults to https://s3.amazonaws.com."  
 
28
  YES_DESCRIPTION = "Automatically answer 'y' without asking."
 
29
  CLEAR_DESCRIPTION = "Delete the bucket if empty. Not done by default"
 
30
  VERSION_DESCRIPTION = "Display the version and copyright notice and then exit."
 
31
  
 
32
  attr_accessor :bucket,
 
33
                :manifest,
 
34
                :prefix,
 
35
                :user,
 
36
                :pass,
 
37
                :debug,
 
38
                :show_help,
 
39
                :manual,
 
40
                :debug,
 
41
                :retry,
 
42
                :url,
 
43
                :yes,
 
44
                :clear
 
45
    
 
46
  #----------------------------------------------------------------------------#
 
47
  
 
48
  class Error < RuntimeError
 
49
    
 
50
    class MissingMandatory < Error
 
51
      def initialize( name )
 
52
        super( "missing mandatory parameter: #{name}" )
 
53
      end
 
54
    end
 
55
    
 
56
    class InvalidValue < Error
 
57
      def initialize( name, value )
 
58
        super( "#{name} value invalid: #{value.to_s}" )
 
59
      end
 
60
    end
 
61
 
 
62
  end
 
63
  
 
64
  #----------------------------------------------------------------------------#
 
65
  
 
66
  def initialize( argv, name )
 
67
    super( argv )
 
68
    
 
69
    @clear = false
 
70
    
 
71
    self.banner = "Usage: #{name} PARAMETERS"
 
72
    
 
73
    #
 
74
    # Mandatory parameters.
 
75
    #
 
76
    separator( "" )
 
77
    separator( "MANDATORY PARAMETERS" )
 
78
    
 
79
    on( '-b', '--bucket BUCKET', String, BUCKET_DESCRIPTION ) do |bucket|
 
80
      @bucket = bucket
 
81
    end
 
82
    
 
83
    on( '-a', '--access-key USER', String, USER_DESCRIPTION ) do |user|
 
84
      @user = user
 
85
    end
 
86
    
 
87
    on( '-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION ) do |pass|
 
88
      @pass = pass
 
89
    end
 
90
    
 
91
    #
 
92
    # Optional parameters.
 
93
    #
 
94
    self.separator( "" )
 
95
    self.separator( "OPTIONAL PARAMETERS" )
 
96
    
 
97
    on( '-m', '--manifest PATH', String, MANIFEST_DESCRIPTION ) do |manifest|
 
98
      raise Error::InvalidValue.new( "--manifest", manifest ) unless ( File::exist?( manifest ) and File::file?( manifest ) )
 
99
      @manifest = manifest
 
100
    end
 
101
    
 
102
    on( '-p', '--prefix PREFIX', String, PREFIX_DESCRIPTION ) do |prefix|
 
103
      @prefix = prefix
 
104
    end
 
105
    
 
106
    on( '--clear', CLEAR_DESCRIPTION ) do
 
107
      @clear = true
 
108
    end
 
109
    
 
110
    on( '--debug', DEBUG_DESCRIPTION ) do
 
111
      @debug = true
 
112
    end
 
113
    
 
114
    on( '--retry', RETRY_DESCRIPTION ) do
 
115
      @retry = true
 
116
    end
 
117
    
 
118
    on( '--url URL', String, URL_DESCRIPTION ) do |url|
 
119
      @url = url
 
120
    end
 
121
    
 
122
    on( '-h', '--help', HELP_DESCRIPTION ) do
 
123
      @show_help = true
 
124
    end
 
125
    
 
126
    on( '--manual', MANUAL_DESCRIPTION ) do
 
127
      @manual = true
 
128
    end
 
129
 
 
130
    on( '-y', '--yes', YES_DESCRIPTION ) do
 
131
      @yes = true
 
132
    end
 
133
    
 
134
    on( '--version', VERSION_DESCRIPTION ) do
 
135
      puts version_copyright_string()
 
136
      exit
 
137
    end
 
138
 
 
139
    #
 
140
    # Parse the command line parameters.
 
141
    #
 
142
    parse!( argv )
 
143
    
 
144
    
 
145
    unless @show_help or @manual
 
146
      #
 
147
      # Verify mandatory parameters.
 
148
      #
 
149
      raise Error::MissingMandatory.new( '--bucket' ) unless @bucket
 
150
      raise Error::MissingMandatory.new( '--manifest or --prefix' ) unless @manifest or @prefix
 
151
      raise Error::MissingMandatory.new( '--access-key' ) unless @user
 
152
      raise Error::MissingMandatory.new( '--secret-key' ) unless @pass
 
153
      
 
154
      #
 
155
      # Set defaults for optional parameters.
 
156
      #
 
157
      @url = 'https://s3.amazonaws.com' unless @url
 
158
    end
 
159
  end
 
160
end