Module: VCAP::Services::Base::ProvisionerV1
- Defined in:
- lib/base/provisioner_v1.rb
Instance Attribute Summary collapse
-
#prov_svcs ⇒ Object
Returns the value of attribute prov_svcs.
Instance Method Summary collapse
- #add_binding_handle(response) ⇒ Object
- #add_instance_handle(response) ⇒ Object
- #delete_binding_handle(binding_handle) ⇒ Object
- #delete_instance_handle(instance_handle) ⇒ Object
- #find_instance_bindings(instance_id) ⇒ Object
- #get_all_binding_handles ⇒ Object
- #get_all_handles ⇒ Object
-
#get_all_instance_handles ⇒ Object
Helpers.
- #get_binding_handle(binding_id) ⇒ Object
- #get_instance_handle(instance_id) ⇒ Object
- #get_instance_id_list(node_id, &blk) ⇒ Object
- #indexing_handles(handles) ⇒ Object
-
#update_handles(handles) ⇒ Object
Updates our internal handle state from external v1 handles, e.g., ccdb handles.
- #verify_handle_format(handle) ⇒ Object
Instance Attribute Details
#prov_svcs ⇒ Object
Returns the value of attribute prov_svcs.
9 10 11 |
# File 'lib/base/provisioner_v1.rb', line 9 def prov_svcs @prov_svcs end |
Instance Method Details
#add_binding_handle(response) ⇒ Object
100 101 102 |
# File 'lib/base/provisioner_v1.rb', line 100 def add_binding_handle(response) @prov_svcs[response[:service_id]] = response end |
#add_instance_handle(response) ⇒ Object
96 97 98 |
# File 'lib/base/provisioner_v1.rb', line 96 def add_instance_handle(response) @prov_svcs[response[:service_id]] = response end |
#delete_binding_handle(binding_handle) ⇒ Object
108 109 110 |
# File 'lib/base/provisioner_v1.rb', line 108 def delete_binding_handle(binding_handle) @prov_svcs.delete(binding_handle[:service_id]) end |
#delete_instance_handle(instance_handle) ⇒ Object
104 105 106 |
# File 'lib/base/provisioner_v1.rb', line 104 def delete_instance_handle(instance_handle) @prov_svcs.delete(instance_handle[:service_id]) end |
#find_instance_bindings(instance_id) ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'lib/base/provisioner_v1.rb', line 112 def find_instance_bindings(instance_id) binding_handles = [] @prov_svcs.each do |_, handle| if handle[:credentials]["name"] == instance_id binding_handles << handle if handle[:service_id] != instance_id end end binding_handles end |
#get_all_binding_handles ⇒ Object
82 83 84 85 86 |
# File 'lib/base/provisioner_v1.rb', line 82 def get_all_binding_handles binding_handles = @prov_svcs.select {|service_id, entity| service_id.to_s != entity[:credentials]["name"]} binding_handles.each {|service_id, handle| yield handle if block_given?} binding_handles end |
#get_all_handles ⇒ Object
122 123 124 |
# File 'lib/base/provisioner_v1.rb', line 122 def get_all_handles @prov_svcs.deep_dup end |
#get_all_instance_handles ⇒ Object
Helpers
76 77 78 79 80 |
# File 'lib/base/provisioner_v1.rb', line 76 def get_all_instance_handles instance_handles = @prov_svcs.select {|service_id, entity| service_id.to_s == entity[:credentials]["name"]} instance_handles.each {|service_id, handle| yield handle if block_given?} instance_handles end |
#get_binding_handle(binding_id) ⇒ Object
92 93 94 |
# File 'lib/base/provisioner_v1.rb', line 92 def get_binding_handle(binding_id) @prov_svcs[binding_id].deep_dup end |
#get_instance_handle(instance_id) ⇒ Object
88 89 90 |
# File 'lib/base/provisioner_v1.rb', line 88 def get_instance_handle(instance_id) @prov_svcs[instance_id].deep_dup end |
#get_instance_id_list(node_id, &blk) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/base/provisioner_v1.rb', line 62 def get_instance_id_list(node_id, &blk) @logger.debug("Get instance id list for migration") id_list = [] @prov_svcs.each do |k, v| id_list << k if (k == v[:credentials]["name"] && node_id == v[:credentials]["node_id"]) end blk.call(success(id_list)) end |
#indexing_handles(handles) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/base/provisioner_v1.rb', line 42 def indexing_handles(handles) # instance handles hash's key is service_id, value is handle # binding handles hash's key is credentials name & username, value is handle ins_handles = {} bin_handles = {} handles.each do |h| if h["service_id"] == h["credentials"]["name"] ins_handles[h["service_id"]] = h else user = h["credentials"]["username"] || h["credentials"]["user"] next unless user key = h["credentials"]["name"] + user bin_handles[key] = h end end [ins_handles, bin_handles] end |
#update_handles(handles) ⇒ Object
Updates our internal handle state from external v1 handles, e.g., ccdb handles
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/base/provisioner_v1.rb', line 13 def update_handles(handles) @logger.info("[#{service_description}] Updating #{handles.size} handles v1") handles.each do |handle| unless verify_handle_format(handle) @logger.warn("Skip not well-formed handle:#{handle}.") next end h = handle.deep_dup @prov_svcs[h['service_id']] = { :configuration => h['configuration'], :credentials => h['credentials'], :service_id => h['service_id'] } end @logger.info("[#{service_description}] Handles updated") end |
#verify_handle_format(handle) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/base/provisioner_v1.rb', line 31 def verify_handle_format(handle) return nil unless handle return nil unless handle.is_a? Hash VCAP::Services::Internal::ServiceHandle.new(handle) true rescue => e @logger.warn("Verify handle #{handle} failed:#{e}") return nil end |