mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[AWS|Glacier] jobs model
This commit is contained in:
parent
9295f3321d
commit
04fb3298ae
4 changed files with 111 additions and 1 deletions
65
lib/fog/aws/models/glacier/job.rb
Normal file
65
lib/fog/aws/models/glacier/job.rb
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class Glacier
|
||||||
|
|
||||||
|
class Job < Fog::Model
|
||||||
|
|
||||||
|
ARCHIVE = 'archive-retrieval'
|
||||||
|
INVENTORY = 'inventory_retrieval'
|
||||||
|
|
||||||
|
identity :id, :aliases => "JobId"
|
||||||
|
attribute :action, :aliases => "Action"
|
||||||
|
attribute :archive_id, :aliases => "ArchiveId"
|
||||||
|
attribute :archive_size, :aliases => "ArchiveSizeInBytes", :type => :integer
|
||||||
|
attribute :completed, :aliases => "Completed", :type => :boolean
|
||||||
|
attribute :completed_at, :aliases => "CompletionDate", :type => :time
|
||||||
|
attribute :created_at, :aliases => "CreationDate", :type => :time
|
||||||
|
attribute :inventory_size, :aliases => "InventorySizeInBytes", :type => :integer
|
||||||
|
attribute :description, :aliases=> "JobDescription"
|
||||||
|
attribute :tree_hash, :aliases=> "SHA256TreeHash"
|
||||||
|
attribute :sns_topic, :aliases => "SNSTopic"
|
||||||
|
attribute :status_code, :aliases=> "StatusCode"
|
||||||
|
attribute :status_message, :aliases=> "StatusMessage"
|
||||||
|
attribute :vault_arn, :aliases=> "VaultARN"
|
||||||
|
attribute :format
|
||||||
|
attribute :type
|
||||||
|
|
||||||
|
|
||||||
|
def ready?
|
||||||
|
completed
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
requires :vault, :type
|
||||||
|
specification = {'Type' => type, 'ArchiveId' => archive_id, 'Format' => format, 'Description' => description, 'SNSTopic' => sns_topic}.reject{|k,v| v.nil?}
|
||||||
|
|
||||||
|
data = connection.initiate_job(vault.id, specification)
|
||||||
|
self.id = data.headers['x-amz-job-id']
|
||||||
|
reload
|
||||||
|
end
|
||||||
|
|
||||||
|
def vault
|
||||||
|
@vault
|
||||||
|
end
|
||||||
|
|
||||||
|
#pass :range => 1..1234 to only retrieve those bytes
|
||||||
|
#pass :io => f to stream the response to that tio
|
||||||
|
def get_output(options={})
|
||||||
|
if io = options.delete(:io)
|
||||||
|
options = options.merge :response_block => lambda {|chunk, remaining_bytes, total_bytes| io.write chunk}
|
||||||
|
end
|
||||||
|
options['Range'] = options.delete :range
|
||||||
|
connection.get_job_output(vault.id, id, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def vault=(new_vault)
|
||||||
|
@vault = new_vault
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
35
lib/fog/aws/models/glacier/jobs.rb
Normal file
35
lib/fog/aws/models/glacier/jobs.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/aws/models/glacier/job'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class Glacier
|
||||||
|
|
||||||
|
class Jobs < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::AWS::Glacier::Job
|
||||||
|
attribute :vault
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = connection.list_jobs(vault.id).body['JobList']
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(key)
|
||||||
|
data = connection.describe_job(vault.id, key).body
|
||||||
|
new(data)
|
||||||
|
rescue Excon::Errors::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def new(attributes = {})
|
||||||
|
requires :vault
|
||||||
|
super({ :vault => vault }.merge!(attributes))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,5 +1,6 @@
|
||||||
require 'fog/core/model'
|
require 'fog/core/model'
|
||||||
require 'fog/aws/models/glacier/archives'
|
require 'fog/aws/models/glacier/archives'
|
||||||
|
require 'fog/aws/models/glacier/jobs'
|
||||||
|
|
||||||
module Fog
|
module Fog
|
||||||
module AWS
|
module AWS
|
||||||
|
@ -23,6 +24,10 @@ module Fog
|
||||||
@archives ||= Fog::AWS::Glacier::Archives.new(:vault => self, :connection => connection)
|
@archives ||= Fog::AWS::Glacier::Archives.new(:vault => self, :connection => connection)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def jobs
|
||||||
|
@jobs ||= Fog::AWS::Glacier::Jobs.new(:vault => self, :connection => connection)
|
||||||
|
end
|
||||||
|
|
||||||
def save
|
def save
|
||||||
requires :id
|
requires :id
|
||||||
data = connection.create_vault(id)
|
data = connection.create_vault(id)
|
||||||
|
|
|
@ -36,7 +36,12 @@ Shindo.tests('AWS::Glacier | models', ['aws', 'glacier']) do
|
||||||
tests('sets id').returns(true) {!archive.id.nil?}
|
tests('sets id').returns(true) {!archive.id.nil?}
|
||||||
archive.destroy
|
archive.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vault = Fog::AWS[:glacier].vaults.create :id => 'Fog-Test-Vault'
|
||||||
|
tests("jobs") do
|
||||||
|
tests('all').returns([]) {vault.jobs}
|
||||||
|
end
|
||||||
|
vault.destroy
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue