Class: Iravat::IrS3
- Inherits:
-
Object
- Object
- Iravat::IrS3
- Defined in:
- lib/s3/ir_s3.rb
Instance Method Summary collapse
- #create_s3_bucket(username) ⇒ Object
- #delete_s3_bucket(bucketname) ⇒ Object
-
#error_aws(aws, err) ⇒ Object
common error handler for RightScale Lib.
- #get_bucket_name(username) ⇒ Object
- #get_config(xpath) ⇒ Object
-
#initialize ⇒ IrS3
constructor
A new instance of IrS3.
- #list_s3_bucket ⇒ Object
- #load_config ⇒ Object
Constructor Details
#initialize ⇒ IrS3
Returns a new instance of IrS3.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/s3/ir_s3.rb', line 18 def initialize() @logger = IrLogger.new(self.class.name).getLog4rLogger() self.load_config() @aws_access_key_id = self.get_config('/ChipMonkAWSConfigs/AWSAccessKey/AWSAccessKey') @aws_secret_access_key = self.get_config('/ChipMonkAWSConfigs/AWSAccessKey/AWSAccessSecretKey') @s3config = {:server => self.get_config('/ChipMonkAWSConfigs/S3/Server'), # Amazon service host: 's3.amazonaws.com'(default) :port => self.get_config('/ChipMonkAWSConfigs/S3/Port'), # Amazon service port: 80 or 443(default) :protocol => self.get_config('/ChipMonkAWSConfigs/S3/Protocol'), # Amazon service protocol: 'http' or 'https'(default) :multi_thread => self.get_config('/ChipMonkAWSConfigs/S3/MultiThread'), # Multi-threaded (connection per each thread): :logger => IrLogger.new(IRAVAT_RIGHT_SCALE_LOGGER).getLog4rLogger(),} # Defaults to Stdout @name_prefix = self.get_config('/ChipMonkAWSConfigs/S3/NamePrefix') @name_suffix = self.get_config('/ChipMonkAWSConfigs/S3/NameSuffix') @delimeter = self.get_config('/ChipMonkAWSConfigs/S3/Delimeter') end |
Instance Method Details
#create_s3_bucket(username) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/s3/ir_s3.rb', line 60 def create_s3_bucket(username) s3 = RightAws::S3.new(@aws_access_key_id, @aws_secret_access_key,@s3config) bucketname = self.get_bucket_name(username) @logger.info(bucketname) bucket = s3.bucket(bucketname, true) rescue RightAws::AwsError=>err self.error_aws(s3,err) # keymap=bucket.keys.map{|key| key.name} # puts "File list : #{keymap.join(', ')}" end |
#delete_s3_bucket(bucketname) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/s3/ir_s3.rb', line 76 def delete_s3_bucket(bucketname) s3 = RightAws::S3.new(@aws_access_key_id, @aws_secret_access_key,@s3config) bucket = s3.bucket(bucketname) if( bucket.nil?) raise "No Bucket Exist" end #clear objects from bucket bucket.clear() bucket.delete(:force=>false) rescue RightAws::AwsError=>err self.error_aws(s3,err) #Handling the RuntimeError rescue => e @logger.warn(e.) end |
#error_aws(aws, err) ⇒ Object
common error handler for RightScale Lib
39 40 41 42 43 |
# File 'lib/s3/ir_s3.rb', line 39 def error_aws (aws,err) err.errors.each do |e| @logger.error( "#### System Error #### " + err.errors) end end |
#get_bucket_name(username) ⇒ Object
56 57 58 |
# File 'lib/s3/ir_s3.rb', line 56 def get_bucket_name(username) @name_prefix+@delimeter+username+@delimeter+@name_suffix end |
#get_config(xpath) ⇒ Object
13 14 15 |
# File 'lib/s3/ir_s3.rb', line 13 def get_config(xpath) @config.getPathFromXML(xpath) end |
#list_s3_bucket ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/s3/ir_s3.rb', line 46 def list_s3_bucket() s3 = RightAws::S3.new(@aws_access_key_id, @aws_secret_access_key,@s3config) my_bucket_names = s3.buckets.map { |b| b.name} @logger.info("Buckets on S3: #{my_bucket_names.join(', ')}") rescue RightAws::AwsError=>err self.error_aws(s3,err) end |
#load_config ⇒ Object
7 8 9 10 |
# File 'lib/s3/ir_s3.rb', line 7 def load_config() @config = IrAwsConfigManager.new(IRAVAT_AWS_CONFIG_XML_PATH) @config.loadConfigurationFile() end |