Class: Fog::AWS::EFS::Real

Inherits:
Object
  • Object
show all
Includes:
CredentialFetcher::ConnectionMethods
Defined in:
lib/fog/aws/efs.rb,
lib/fog/aws/requests/efs/create_file_system.rb,
lib/fog/aws/requests/efs/delete_file_system.rb,
lib/fog/aws/requests/efs/create_mount_target.rb,
lib/fog/aws/requests/efs/delete_mount_target.rb,
lib/fog/aws/requests/efs/describe_file_systems.rb,
lib/fog/aws/requests/efs/describe_mount_targets.rb,
lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb,
lib/fog/aws/requests/efs/describe_mount_target_security_groups.rb

Instance Method Summary collapse

Methods included from CredentialFetcher::ConnectionMethods

#refresh_credentials_if_expired

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fog/aws/efs.rb', line 74

def initialize(options={})
  @connection_options = options[:connection_options] || {}
  @instrumentor       = options[:instrumentor]
  @instrumentor_name  = options[:instrumentor_name] || 'fog.aws.efs'

  @region     = options[:region]     || 'us-east-1'
  @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

Instance Method Details

#_request(body, headers, idempotent, parser, method, path, expects) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/fog/aws/efs.rb', line 141

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?
  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])
  elsif match[:code].match(/(FileSystem|MountTarget)NotFound/)
    raise Fog::AWS::EFS::NotFound.slurp(error, match[:message])
  end
  raise case match[:message]
        when /invalid ((file system)|(mount target)|(security group)) id/i
          Fog::AWS::EFS::NotFound.slurp(error, match[:message])
        when /invalid subnet id/i
          Fog::AWS::EFS::InvalidSubnet.slurp(error, match[:message])
        else
          Fog::AWS::EFS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
        end
end

#create_file_system(creation_token, options = {}) ⇒ Object

Create a new, empty file system docs.aws.amazon.com/efs/latest/ug/API_CreateFileSystem.html

Parameters

  • CreationToken <~String> - String of up to 64 ASCII characters. Amazon EFS uses this to ensure idempotent creation.

  • PerformanceMode <~String> - (Optional) The PerformanceMode of the file system. We recommend generalPurpose performance mode for most file systems. File systems using the maxIO performance mode can scale to higher levels of aggregate throughput and operations per second with a tradeoff of slightly higher latencies for most file operations. This can’t be changed after the file system has been created.

  • Encrypted <~Boolean> - (Optional) A Boolean value that, if true, creates an encrypted file system. When creating an encrypted file system, you have the option of specifying a CreateFileSystem:KmsKeyId for an existing AWS Key Management Service (AWS KMS) customer master key (CMK). If you don’t specify a CMK, then the default CMK for Amazon EFS, /aws/elasticfilesystem, is used to protect the encrypted file system.

  • KmsKeyId <~String> - (Optional) The ID of the AWS KMS CMK to be used to protect the encrypted file system. This parameter is only required if you want to use a non-default CMK. If this parameter is not specified, the default CMK for Amazon EFS is used. This ID can be in one of the following formats:

    • Key ID - A unique identifier of the key, for example, 1234abcd-12ab-34cd-56ef-1234567890ab.

    • ARN - An Amazon Resource Name (ARN) for the key, for example, arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab.

    • Key alias - A previously created display name for a key. For example, alias/projectKey1.

    • Key alias ARN - An ARN for a key alias, for example, arn:aws:kms:us-west-2:444455556666:alias/projectKey1.

    If KmsKeyId is specified, the CreateFileSystem:Encrypted parameter must be set to true.

Returns

  • response<~Excon::Response>

    • body<~Hash>



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aws/requests/efs/create_file_system.rb', line 20

def create_file_system(creation_token, options={})
  params = {
    :path             => "file-systems",
    :method           => 'POST',
    :expects          => 201,
    'CreationToken'   => creation_token,
    'PerformanceMode' => options[:peformance_mode] || 'generalPurpose',
    'Encrypted'       => options[:encrypted] || false
  }
  params[:kms_key_id] = options[:kms_key_id] if options.key?(:kms_key_id)
  request(params)
end

#create_mount_target(file_system_id, subnet_id, options = {}) ⇒ Object

Create a mount target for a specified file system docs.aws.amazon.com/efs/latest/ug/API_CreateMountTarget.html

Parameters

  • FileSystemId <~String> - ID of the file system for which to create the mount target.

  • IpAddress <~String> - Valid IPv4 address within the address range of the specified subnet.

  • SecurityGroups <~Array> - Up to five VPC security group IDs, of the form sg-xxxxxxxx. These must be for the same VPC as subnet specified.

  • SubnetId <~String> - ID of the subnet to add the mount target in.

Returns

  • response<~Excon::Response>

    • body<~Hash>



15
16
17
18
19
20
21
22
# File 'lib/fog/aws/requests/efs/create_mount_target.rb', line 15

def create_mount_target(file_system_id, subnet_id, options={})
  request({
    :path          => "mount-targets",
    :method        => "POST",
    'FileSystemId' => file_system_id,
    'SubnetId'     => subnet_id
  }.merge(options))
end

#delete_file_system(id) ⇒ Object

Delete a file system docs.aws.amazon.com/efs/latest/ug/API_DeleteFileSystem.html

Parameters

  • FileSystemId <~String> - ID of the file system you want to delete.

Returns

  • response<~Excon::Response>

    • body - Empty

    • status - 204



13
14
15
16
17
18
19
# File 'lib/fog/aws/requests/efs/delete_file_system.rb', line 13

def delete_file_system(id)
  request({
    :path             => "file-systems/#{id}",
    :method           => 'DELETE',
    :expects          => 204,
  })
end

#delete_mount_target(id) ⇒ Object

Delete a mount target docs.aws.amazon.com/efs/latest/ug/API_DeleteMountTarget.html

Parameters

  • MountTargetId <~String> - ID of the mount target you want to delete

Returns

  • response<~Excon::Response>

    • body - Empty

    • status - 204



13
14
15
16
17
18
19
# File 'lib/fog/aws/requests/efs/delete_mount_target.rb', line 13

def delete_mount_target(id)
  request(
    :path    => "mount-targets/#{id}",
    :method  => "DELETE",
    :expects => 204
  )
end

#describe_file_systems(options = {}) ⇒ Object

Describe all or specified elastic file systems docs.aws.amazon.com/efs/latest/ug/API_DescribeFileSystems.html

Parameters

  • CreationToken <~String> - (Optional) Restricts the list to the file system with this creation token (String). You specify a creation token when you create an Amazon EFS file system.

  • FileSystemId <~String> - (Optional) ID of the file system whose description you want to retrieve (String).

Returns

  • response<~Excon::Response>:

    • body<~Hash>



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aws/requests/efs/describe_file_systems.rb', line 13

def describe_file_systems(options={})
  params = {}
  if options[:marker]
    params['Marker'] = options[:marker]
  end
  if options[:max_records]
    params['MaxRecords'] = options[:max_records]
  end
  if options[:id]
    params['FileSystemId'] = options[:id]
  end
  if options[:creation_token]
    params['CreationToken'] = options[:creation_token]
  end

  request({
    :path => "file-systems"
  }.merge(params))
end

#describe_mount_target_security_groups(mount_target_id) ⇒ Object

Describe mount target security groups docs.aws.amazon.com/efs/latest/ug/API_DescribeMountTargetSecurityGroups.html

Parameters

  • MountTargetId - Id of the mount target for which you want to describe security groups

Returns

  • response<~Excon::Response>

  • body<~Hash>



13
14
15
16
17
# File 'lib/fog/aws/requests/efs/describe_mount_target_security_groups.rb', line 13

def describe_mount_target_security_groups(mount_target_id)
  request(
    :path => "mount-targets/#{mount_target_id}/security-groups"
  )
end

#describe_mount_targets(options = {}) ⇒ Object

Describe all mount targets for a filesystem, or specified mount target docs.aws.amazon.com/efs/latest/ug/API_DescribeMountTargets.html

Parameters

  • FileSystemId<~String> - Id of file system to describe mount targets for. Required unless MountTargetId is specified

  • MountTargetId<~String> - Specific mount target to describe. Required if FileSystemId is not specified

Returns

  • response<~Excon::Response>

    • body<~Hash>



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/aws/requests/efs/describe_mount_targets.rb', line 13

def describe_mount_targets(options={})
  params = {}
  if options[:marker]
    params['Marker'] = options[:marker]
  end
  if options[:max_records]
    params['MaxRecords'] = options[:max_records]
  end
  if options[:id]
    params['MountTargetId'] = options[:id]
  end
  if options[:file_system_id]
    params['FileSystemId'] = options[:file_system_id]
  end

  request({
    :path => "mount-targets"
  }.merge(params))
end

#modify_mount_target_security_groups(id, security_groups) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/aws/requests/efs/modify_mount_target_security_groups.rb', line 5

def modify_mount_target_security_groups(id, security_groups)
  request({
    :path            => "mount-targets/#{id}/security-groups",
    :method          => "PUT",
    :expects         => 204,
    'SecurityGroups' => security_groups
  })
end

#reloadObject



91
92
93
# File 'lib/fog/aws/efs.rb', line 91

def reload
  @connection.reset
end

#request(params) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/fog/aws/efs.rb', line 106

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

#setup_credentials(options) ⇒ Object



95
96
97
98
99
100
101
102
103
104
# File 'lib/fog/aws/efs.rb', line 95

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