Class: Fog::SharedFileSystem::OpenStack::Real

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Core
Defined in:
lib/fog/shared_file_system/openstack.rb,
lib/fog/shared_file_system/openstack/requests/get_quota.rb,
lib/fog/shared_file_system/openstack/requests/get_share.rb,
lib/fog/shared_file_system/openstack/requests/get_limits.rb,
lib/fog/shared_file_system/openstack/requests/list_shares.rb,
lib/fog/shared_file_system/openstack/requests/create_share.rb,
lib/fog/shared_file_system/openstack/requests/delete_share.rb,
lib/fog/shared_file_system/openstack/requests/extend_share.rb,
lib/fog/shared_file_system/openstack/requests/get_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/share_action.rb,
lib/fog/shared_file_system/openstack/requests/shrink_share.rb,
lib/fog/shared_file_system/openstack/requests/update_quota.rb,
lib/fog/shared_file_system/openstack/requests/update_share.rb,
lib/fog/shared_file_system/openstack/requests/list_snapshots.rb,
lib/fog/shared_file_system/openstack/requests/create_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/delete_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/update_snapshot.rb,
lib/fog/shared_file_system/openstack/requests/get_share_network.rb,
lib/fog/shared_file_system/openstack/requests/grant_share_access.rb,
lib/fog/shared_file_system/openstack/requests/list_shares_detail.rb,
lib/fog/shared_file_system/openstack/requests/list_share_networks.rb,
lib/fog/shared_file_system/openstack/requests/revoke_share_access.rb,
lib/fog/shared_file_system/openstack/requests/create_share_network.rb,
lib/fog/shared_file_system/openstack/requests/delete_share_network.rb,
lib/fog/shared_file_system/openstack/requests/update_share_network.rb,
lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb,
lib/fog/shared_file_system/openstack/requests/list_share_access_rules.rb,
lib/fog/shared_file_system/openstack/requests/list_share_networks_detail.rb

Overview

rubocop:enable LineLength, Metrics/MethodLength, Metrics/ClassLength, Metrics/AbcSize

Instance Attribute Summary

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Core

#credentials, #initialize_identity, #reload

Constructor Details

#initialize(options = {}) ⇒ Real

Returns a new instance of Real.



286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/fog/shared_file_system/openstack.rb', line 286

def initialize(options = {})
  @supported_versions     = SUPPORTED_VERSIONS
  @supported_microversion = SUPPORTED_MICROVERSION
  @fixed_microversion     = options[:openstack_shared_file_system_microversion]
  @microversion_key       = 'X-Openstack-Manila-Api-Version'.freeze

  initialize_identity options

  @openstack_service_type  = options[:openstack_service_type] || ['sharev2']
  @openstack_service_name  = options[:openstack_service_name]
  @connection_options      = options[:connection_options] || {}

  authenticate
  set_api_path
  set_microversion

  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Class Method Details

.not_found_classObject



282
283
284
# File 'lib/fog/shared_file_system/openstack.rb', line 282

def self.not_found_class
  Fog::SharedFileSystem::OpenStack::NotFound
end

Instance Method Details

#action_prefixObject



315
316
317
# File 'lib/fog/shared_file_system/openstack.rb', line 315

def action_prefix
  microversion_newer_than?('2.6') ? '' : 'os-'
end

#create_share(protocol, size, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fog/shared_file_system/openstack/requests/create_share.rb', line 5

def create_share(protocol, size, options = {})
  data = {
    'share_proto' => protocol,
    'size'        => size
  }

  vanilla_options = [
    :name, :description, :display_name, :display_description, :share_type, :volume_type, :snapshot_id,
    :is_public, :metadata, :share_network_id, :consistency_group_id, :availability_zone
  ]

  vanilla_options.select { |o| options[o] }.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode('share' => data),
    :expects => 200,
    :method  => 'POST',
    :path    => 'shares'
  )
end

#create_share_network(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fog/shared_file_system/openstack/requests/create_share_network.rb', line 5

def create_share_network(options = {})
  data = {}

  vanilla_options = [
    :name, :description, :neutron_net_id, :neutron_subnet_id, :nova_net_id
  ]

  vanilla_options.select { |o| options[o] }.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode('share_network' => data),
    :expects => 200,
    :method  => 'POST',
    :path    => 'share-networks'
  )
end

#create_snapshot(share_id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/shared_file_system/openstack/requests/create_snapshot.rb', line 5

def create_snapshot(share_id, options = {})
  data = {
    'share_id' => share_id
  }

  vanilla_options = [
    :name, :description, :display_name, :display_description, :force
  ]

  vanilla_options.select { |o| options[o] }.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode('snapshot' => data),
    :expects => 202,
    :method  => 'POST',
    :path    => 'snapshots'
  )
end

#delete_share(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/delete_share.rb', line 5

def delete_share(id)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "shares/#{id}"
  )
end

#delete_share_network(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/delete_share_network.rb', line 5

def delete_share_network(id)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "share-networks/#{id}"
  )
end

#delete_snapshot(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/delete_snapshot.rb', line 5

def delete_snapshot(id)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "snapshots/#{id}"
  )
end

#extend_share(share_id, new_size) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/extend_share.rb', line 5

def extend_share(share_id, new_size)
  action = {
    "#{action_prefix}extend" => {
      'new_size' => new_size
    }
  }
  share_action(share_id, action)
end

#get_limitsObject



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/get_limits.rb', line 5

def get_limits
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'limits'
  )
end

#get_quota(project_id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/get_quota.rb', line 5

def get_quota(project_id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "#{action_prefix}quota-sets/#{project_id}"
  )
end

#get_share(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/get_share.rb', line 5

def get_share(id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "shares/#{id}"
  )
end

#get_share_network(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/get_share_network.rb', line 5

def get_share_network(id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "share-networks/#{id}"
  )
end

#get_snapshot(id) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/fog/shared_file_system/openstack/requests/get_snapshot.rb', line 5

def get_snapshot(id)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "snapshots/#{id}"
  )
end

#grant_share_access(share_id, access_to = '0.0.0.0/0', access_type = 'ip', access_level = 'rw') ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/fog/shared_file_system/openstack/requests/grant_share_access.rb', line 5

def grant_share_access(share_id, access_to = '0.0.0.0/0', access_type = 'ip', access_level = 'rw')
  action = {
    "#{action_prefix}allow_access" => {
      'access_to'    => access_to,
      'access_type'  => access_type,
      'access_level' => access_level
    }
  }
  share_action(share_id, action, 200)
end

#list_share_access_rules(share_id) ⇒ Object



5
6
7
8
9
10
# File 'lib/fog/shared_file_system/openstack/requests/list_share_access_rules.rb', line 5

def list_share_access_rules(share_id)
  action = {
    "#{action_prefix}access_list" => nil
  }
  share_action(share_id, action, 200)
end

#list_share_networks(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_share_networks.rb', line 5

def list_share_networks(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'share_networks',
    :query   => options
  )
end

#list_share_networks_detail(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_share_networks_detail.rb', line 5

def list_share_networks_detail(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'share-networks/detail',
    :query   => options
  )
end

#list_shares(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_shares.rb', line 5

def list_shares(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'shares',
    :query   => options
  )
end

#list_shares_detail(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_shares_detail.rb', line 5

def list_shares_detail(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'shares/detail',
    :query   => options
  )
end

#list_snapshots(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_snapshots.rb', line 5

def list_snapshots(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'snapshots',
    :query   => options
  )
end

#list_snapshots_detail(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/list_snapshots_detail.rb', line 5

def list_snapshots_detail(options = {})
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'snapshots/detail',
    :query   => options
  )
end

#revoke_share_access(share_id, access_id) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/revoke_share_access.rb', line 5

def revoke_share_access(share_id, access_id)
  action = {
    "#{action_prefix}deny_access" => {
      'access_id' => access_id
    }
  }
  share_action(share_id, action)
end

#set_api_pathObject



306
307
308
309
310
311
312
313
# File 'lib/fog/shared_file_system/openstack.rb', line 306

def set_api_path
  unless @path.match(@supported_versions)
    @path = Fog::OpenStack.get_supported_version_path(@supported_versions,
                                                      @openstack_management_uri,
                                                      @auth_token,
                                                      @connection_options)
  end
end

#share_action(id, options = {}, expects_status = 202) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/share_action.rb', line 5

def share_action(id, options = {}, expects_status = 202)
  request(
    :body    => Fog::JSON.encode(options),
    :expects => expects_status,
    :method  => 'POST',
    :path    => "shares/#{id}/action"
  )
end

#shrink_share(share_id, new_size) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/shrink_share.rb', line 5

def shrink_share(share_id, new_size)
  action = {
    "#{action_prefix}shrink" => {
      'new_size' => new_size
    }
  }
  share_action(share_id, action)
end

#update_quota(project_id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/update_quota.rb', line 5

def update_quota(project_id, options = {})
  request(
    :body    => Fog::JSON.encode('quota_set' => options),
    :expects => 200,
    :method  => 'PUT',
    :path    => "#{action_prefix}quota-sets/#{project_id}"
  )
end

#update_share(id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/update_share.rb', line 5

def update_share(id, options = {})
  request(
    :body    => Fog::JSON.encode('share' => options),
    :expects => 200,
    :method  => 'PUT',
    :path    => "shares/#{id}"
  )
end

#update_share_network(id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/update_share_network.rb', line 5

def update_share_network(id, options = {})
  request(
    :body    => Fog::JSON.encode('share_network' => options),
    :expects => 200,
    :method  => 'PUT',
    :path    => "share-networks/#{id}"
  )
end

#update_snapshot(id, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/fog/shared_file_system/openstack/requests/update_snapshot.rb', line 5

def update_snapshot(id, options = {})
  request(
    :body    => Fog::JSON.encode('snapshot' => options),
    :expects => 200,
    :method  => 'PUT',
    :path    => "snapshots/#{id}"
  )
end