fog-openstack 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a3a52ccf8ef9aec1efe22b6cee7d6cfa6ca1a28
4
- data.tar.gz: 29297c4505150b3a29f696dfd31620369b8d6544
3
+ metadata.gz: a5ef3d5e9db5c4a3630e0f142fb5969346b249a2
4
+ data.tar.gz: 86a67a59a76c82967d7f834c8d0c4fce73391ec1
5
5
  SHA512:
6
- metadata.gz: ca9f9563a28b33ed86c16ff22c7c37be97a63c67898c408918b2f054478304252628d10260174e8a786d56d65773c2e2d2e622b49e4c93b1477e59eb4f4dff59
7
- data.tar.gz: eedee34b9856b255b2996071a6f8d907221d135d44ecec5b46f5c18593dc4300f5bb02d5f805e7c1e8e9e3fcd90550efd2a5426ed22e87103d406770a061471c
6
+ metadata.gz: 064950f848ead6d4791df03194d7b991dd793c8717c42beb0e383f400339560f6633e379709c1dd6239876172f60ef4f8c18eae906e3446ea7c405933193cce8
7
+ data.tar.gz: 4ac6a0c3d149c410d9bbbda237fe14b4d6ab862b4a29a3dc92e4ce96860ce3fc9eb4b6e788d3c93a2be34bd2311ccd87d02ec4d28a0233594e1fdcefbc3d553a
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_dependency 'fog-core', '>= 1.37'
22
+ spec.add_dependency 'fog-core', '>= 1.38'
23
23
  spec.add_dependency 'fog-json', '>= 1.0'
24
24
  spec.add_dependency 'fog-xml', '>= 0.1'
25
25
  spec.add_dependency 'ipaddress', '>= 0.8'
data/lib/fog/openstack.rb CHANGED
@@ -365,6 +365,7 @@ module Fog
365
365
  auth_token = options[:openstack_auth_token] || options[:unscoped_token]
366
366
  uri = options[:openstack_auth_uri]
367
367
  omit_default_port = options[:openstack_auth_omit_default_port]
368
+ cache_ttl = options[:openstack_cache_ttl] || 0
368
369
 
369
370
  connection = Fog::Core::Connection.new(uri.to_s, false, connection_options)
370
371
  request_body = {:auth => {}}
@@ -420,7 +421,7 @@ module Fog
420
421
 
421
422
  path = (uri.path and not uri.path.empty?) ? uri.path : 'v3'
422
423
 
423
- response, expires = @@token_cache[{body: request_body, path: path}]
424
+ response, expires = @@token_cache[{:body => request_body, :path => path}] if cache_ttl > 0
424
425
 
425
426
  unless response && expires > Time.now
426
427
  request = {
@@ -433,7 +434,7 @@ module Fog
433
434
  request[:omit_default_port] = omit_default_port unless omit_default_port.nil?
434
435
 
435
436
  response = connection.request(request)
436
- @@token_cache[{body: request_body, path: path}] = response, Time.now + 30 # 30-second TTL, enough for most requests
437
+ @@token_cache[{:body => request_body, :path => path}] = response, Time.now + cache_ttl if cache_ttl > 0
437
438
  end
438
439
 
439
440
  [response.headers["X-Subject-Token"], Fog::JSON.decode(response.body)]
@@ -2,6 +2,7 @@ module Fog
2
2
  module OpenStack
3
3
  module Core
4
4
  attr_accessor :auth_token
5
+ attr_reader :openstack_cache_ttl
5
6
  attr_reader :auth_token_expiration
6
7
  attr_reader :current_user
7
8
  attr_reader :current_user_id
@@ -27,6 +28,8 @@ module Fog
27
28
  @openstack_must_reauthenticate = false
28
29
  @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL'
29
30
 
31
+ @openstack_cache_ttl = options[:openstack_cache_ttl] || 0
32
+
30
33
  unless @auth_token
31
34
  missing_credentials = Array.new
32
35
 
@@ -15,7 +15,7 @@ module Fog
15
15
  :openstack_user_domain_id, :openstack_project_domain_id,
16
16
  :openstack_api_key, :openstack_current_user_id, :openstack_userid, :openstack_username,
17
17
  :current_user, :current_user_id, :current_tenant,
18
- :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches
18
+ :provider, :openstack_identity_prefix, :openstack_endpoint_path_matches, :openstack_cache_ttl
19
19
 
20
20
  model_path 'fog/openstack/models/identity_v3'
21
21
  model :domain
@@ -12,10 +12,16 @@ module Fog
12
12
  Fog::Identity::OpenStack::V3::Project.use_cache(@@cache)
13
13
 
14
14
  def all(options = {})
15
- cached_project, expires = @@cache[{token: service.auth_token, options: options}]
16
- return cached_project if cached_project && expires > Time.now
15
+ if service.openstack_cache_ttl > 0
16
+ cached_project, expires = @@cache[{:token => service.auth_token, :options => options}]
17
+ return cached_project if cached_project && expires > Time.now
18
+ end
19
+
17
20
  project_to_cache = load_response(service.list_projects(options), 'projects')
18
- @@cache[{token: service.auth_token, options: options}] = project_to_cache, Time.now + 30 # 30-second TTL
21
+ if service.openstack_cache_ttl > 0
22
+ @@cache[{:token => service.auth_token, :options => options}] = [project_to_cache,
23
+ Time.now + service.openstack_cache_ttl]
24
+ end
19
25
  return project_to_cache
20
26
  end
21
27
 
@@ -32,8 +38,11 @@ module Fog
32
38
  if options.is_a? Symbol # Deal with a single option being passed on its own
33
39
  options = [options]
34
40
  end
35
- cached_project, expires = @@cache[{token: service.auth_token, id: id, options: options}]
36
- return cached_project if cached_project && expires > Time.now
41
+
42
+ if service.openstack_cache_ttl > 0
43
+ cached_project, expires = @@cache[{:token => service.auth_token, :id => id, :options => options}]
44
+ return cached_project if cached_project && expires > Time.now
45
+ end
37
46
  project_hash = service.get_project(id, options).body['project']
38
47
  top_project = project_from_hash(project_hash, service)
39
48
  if options.include? :subtree_as_list
@@ -42,7 +51,11 @@ module Fog
42
51
  if options.include? :parents_as_list
43
52
  top_project.parents.map! {|proj_hash| project_from_hash(proj_hash['project'], service)}
44
53
  end
45
- @@cache[{token: service.auth_token, id: id, options: options}] = top_project, Time.now + 30 # 30-second TTL
54
+
55
+ if service.openstack_cache_ttl > 0
56
+ @@cache[{:token => service.auth_token, :id => id, :options => options}] = [
57
+ top_project, Time.now + service.openstack_cache_tt]
58
+ end
46
59
  return top_project
47
60
  end
48
61
 
@@ -6,10 +6,10 @@ module Fog
6
6
  data = {
7
7
  'server' => {
8
8
  'flavorRef' => flavor_ref,
9
- 'imageRef' => image_ref,
10
9
  'name' => name
11
10
  }
12
11
  }
12
+ data['server']['imageRef'] = image_ref if image_ref
13
13
 
14
14
  vanilla_options = ['metadata', 'accessIPv4', 'accessIPv6',
15
15
  'availability_zone', 'user_data', 'key_name',
@@ -59,15 +59,12 @@ module Fog
59
59
 
60
60
  if (block_device_mapping = options['block_device_mapping_v2'])
61
61
  data['server']['block_device_mapping_v2'] = [block_device_mapping].flatten.collect do |mapping|
62
- {
63
- 'boot_index' => mapping[:boot_index],
64
- 'delete_on_termination' => mapping[:delete_on_termination],
65
- 'destination_type' => mapping[:destination_type],
66
- 'device_name' => mapping[:device_name],
67
- 'source_type' => mapping[:source_type],
68
- 'uuid' => mapping[:uuid],
69
- 'volume_size' => mapping[:volume_size],
70
- }
62
+ entered_block_device_mapping = {}
63
+ [:boot_index, :delete_on_termination, :destination_type, :device_name, :source_type, :uuid,
64
+ :volume_size].each do |index|
65
+ entered_block_device_mapping[index.to_s] = mapping[index] if mapping.key?(index)
66
+ end
67
+ entered_block_device_mapping
71
68
  end
72
69
  elsif (block_device_mapping = options['block_device_mapping'])
73
70
  data['server']['block_device_mapping'] = [block_device_mapping].flatten.collect do |mapping|
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Openstack
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-openstack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Darby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-19 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.37'
19
+ version: '1.38'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.37'
26
+ version: '1.38'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fog-json
29
29
  requirement: !ruby/object:Gem::Requirement