2016-10-05 14:29:19 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class EFS < Fog::Service
|
|
|
|
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
|
|
|
|
|
|
|
class FileSystemInUse < Fog::Errors::Error; end
|
2016-10-06 18:52:32 -04:00
|
|
|
class IncorrectFileSystemLifeCycleState < Fog::Errors::Error; end
|
|
|
|
class InvalidSubnet < Fog::Errors::Error; end
|
2016-10-05 14:29:19 -04:00
|
|
|
|
|
|
|
requires :aws_access_key_id, :aws_secret_access_key
|
2016-10-06 18:52:32 -04:00
|
|
|
recognizes :region, :host, :path, :port, :scheme, :persistent, :instrumentor, :instrumentor_name
|
2016-10-05 14:29:19 -04:00
|
|
|
|
|
|
|
model_path 'fog/aws/models/efs'
|
|
|
|
request_path 'fog/aws/requests/efs'
|
|
|
|
|
|
|
|
model :file_system
|
2016-10-06 18:52:32 -04:00
|
|
|
model :mount_target
|
|
|
|
|
2016-10-05 14:29:19 -04:00
|
|
|
collection :file_systems
|
2016-10-06 18:52:32 -04:00
|
|
|
collection :mount_targets
|
2016-10-05 14:29:19 -04:00
|
|
|
|
|
|
|
request :create_file_system
|
2016-10-06 18:52:32 -04:00
|
|
|
request :create_mount_target
|
2016-10-05 14:29:19 -04:00
|
|
|
request :delete_file_system
|
2016-10-06 18:52:32 -04:00
|
|
|
request :delete_mount_target
|
2016-10-05 14:29:19 -04:00
|
|
|
request :describe_file_systems
|
2016-10-07 07:45:04 -04:00
|
|
|
request :describe_mount_target_security_groups
|
2016-10-06 18:52:32 -04:00
|
|
|
request :describe_mount_targets
|
2016-10-07 09:19:28 -04:00
|
|
|
request :modify_mount_target_security_groups
|
2016-10-05 14:29:19 -04:00
|
|
|
|
|
|
|
class Mock
|
2016-10-10 08:46:46 -04:00
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
|
|
|
|
2016-10-05 14:29:19 -04:00
|
|
|
def self.data
|
|
|
|
@data ||= Hash.new do |hash, region|
|
|
|
|
hash[region] = Hash.new do |region_hash, key|
|
|
|
|
region_hash[key] = {
|
2016-10-07 07:45:04 -04:00
|
|
|
:file_systems => {},
|
|
|
|
:mount_targets => {},
|
|
|
|
:security_groups => {}
|
2016-10-05 14:29:19 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.reset
|
|
|
|
@data = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def data
|
|
|
|
self.class.data[@region][@aws_access_key_id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset
|
|
|
|
self.class.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :region
|
|
|
|
|
|
|
|
def initialize(options={})
|
2016-10-10 08:46:46 -04:00
|
|
|
@region = options[:region] || "us-east-1"
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
|
|
end
|
|
|
|
|
|
|
|
def mock_compute
|
2018-09-12 05:34:50 -04:00
|
|
|
@mock_compute ||= Fog::AWS::Compute.new(:aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key, :region => @region)
|
2016-10-05 14:29:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Real
|
|
|
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
|
|
|
|
|
|
|
def initialize(options={})
|
|
|
|
@connection_options = options[:connection_options] || {}
|
|
|
|
@instrumentor = options[:instrumentor]
|
|
|
|
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.efs'
|
|
|
|
|
2016-10-06 18:52:32 -04:00
|
|
|
@region = options[:region] || 'us-east-1'
|
2016-10-05 14:29:19 -04:00
|
|
|
@host = options[:host] || "elasticfilesystem.#{@region}.amazonaws.com"
|
|
|
|
@port = options[:port] || 443
|
|
|
|
@scheme = options[:scheme] || "https"
|
|
|
|
@persistent = options[:persistent] || false
|
|
|
|
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
|
|
|
@version = options[:version] || '2015-02-01'
|
|
|
|
@path = options[:path] || "/#{@version}/"
|
|
|
|
|
|
|
|
setup_credentials(options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def reload
|
|
|
|
@connection.reset
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_credentials(options)
|
|
|
|
@aws_access_key_id = options[:aws_access_key_id]
|
|
|
|
@aws_secret_access_key = options[:aws_secret_access_key]
|
|
|
|
@aws_session_token = options[:aws_session_token]
|
|
|
|
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
|
|
|
|
|
|
|
#global services that have no region are signed with the us-east-1 region
|
|
|
|
#the only exception is GovCloud, which requires the region to be explicitly specified as us-gov-west-1
|
|
|
|
@signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'elasticfilesystem')
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(params)
|
|
|
|
refresh_credentials_if_expired
|
|
|
|
idempotent = params.delete(:idempotent)
|
|
|
|
parser = params.delete(:parser)
|
|
|
|
expects = params.delete(:expects) || 200
|
|
|
|
path = @path + params.delete(:path)
|
|
|
|
method = params.delete(:method) || 'GET'
|
|
|
|
request_body = Fog::JSON.encode(params)
|
|
|
|
|
|
|
|
body, headers = Fog::AWS.signed_params_v4(
|
|
|
|
params,
|
|
|
|
{
|
|
|
|
'Content-Type' => "application/x-amz-json-1.0",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
:host => @host,
|
|
|
|
:path => path,
|
|
|
|
:port => @port,
|
|
|
|
:version => @version,
|
|
|
|
:signer => @signer,
|
|
|
|
:aws_session_token => @aws_session_token,
|
|
|
|
:method => method,
|
|
|
|
:body => request_body
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if @instrumentor
|
|
|
|
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
|
|
|
_request(body, headers, idempotent, parser, method, path, expects)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
_request(body, headers, idempotent, parser, method, path, expects)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def _request(body, headers, idempotent, parser, method, path, expects)
|
|
|
|
response = @connection.request({
|
|
|
|
:body => body,
|
|
|
|
:expects => expects,
|
|
|
|
:idempotent => idempotent,
|
|
|
|
:headers => headers,
|
|
|
|
:method => method,
|
|
|
|
:parser => parser,
|
|
|
|
:path => path
|
|
|
|
})
|
|
|
|
unless response.body.empty?
|
|
|
|
response.body = Fog::JSON.decode(response.body)
|
|
|
|
end
|
|
|
|
response
|
|
|
|
rescue Excon::Errors::HTTPStatusError => error
|
|
|
|
match = Fog::AWS::Errors.match_error(error)
|
|
|
|
raise if match.empty?
|
2016-10-06 18:52:32 -04:00
|
|
|
if match[:code] == "IncorrectFileSystemLifeCycleState"
|
|
|
|
raise Fog::AWS::EFS::IncorrectFileSystemLifeCycleState.slurp(error, match[:message])
|
|
|
|
elsif match[:code] == 'FileSystemInUse'
|
|
|
|
raise Fog::AWS::EFS::FileSystemInUse.slurp(error, match[:message])
|
2016-10-11 08:49:54 -04:00
|
|
|
elsif match[:code].match(/(FileSystem|MountTarget)NotFound/)
|
2016-10-10 16:34:26 -04:00
|
|
|
raise Fog::AWS::EFS::NotFound.slurp(error, match[:message])
|
2016-10-06 18:52:32 -04:00
|
|
|
end
|
2016-10-05 14:29:19 -04:00
|
|
|
raise case match[:message]
|
2016-10-07 07:45:04 -04:00
|
|
|
when /invalid ((file system)|(mount target)|(security group)) id/i
|
2016-10-05 14:29:19 -04:00
|
|
|
Fog::AWS::EFS::NotFound.slurp(error, match[:message])
|
2016-10-06 18:52:32 -04:00
|
|
|
when /invalid subnet id/i
|
|
|
|
Fog::AWS::EFS::InvalidSubnet.slurp(error, match[:message])
|
2016-10-05 14:29:19 -04:00
|
|
|
else
|
|
|
|
Fog::AWS::EFS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|