Class: Fog::Orchestration::OpenStack::Mock
- Inherits:
-
Object
- Object
- Fog::Orchestration::OpenStack::Mock
- Defined in:
- lib/fog/orchestration/openstack.rb,
lib/fog/orchestration/openstack/requests/list_events.rb,
lib/fog/orchestration/openstack/requests/patch_stack.rb,
lib/fog/orchestration/openstack/requests/create_stack.rb,
lib/fog/orchestration/openstack/requests/delete_stack.rb,
lib/fog/orchestration/openstack/requests/update_stack.rb,
lib/fog/orchestration/openstack/requests/cancel_update.rb,
lib/fog/orchestration/openstack/requests/list_resources.rb,
lib/fog/orchestration/openstack/requests/list_stack_data.rb,
lib/fog/orchestration/openstack/requests/list_stack_events.rb,
lib/fog/orchestration/openstack/requests/get_stack_template.rb,
lib/fog/orchestration/openstack/requests/show_event_details.rb,
lib/fog/orchestration/openstack/requests/show_resource_data.rb,
lib/fog/orchestration/openstack/requests/show_stack_details.rb,
lib/fog/orchestration/openstack/requests/list_resource_types.rb,
lib/fog/orchestration/openstack/requests/list_resource_events.rb,
lib/fog/orchestration/openstack/requests/show_resource_metadata.rb,
lib/fog/orchestration/openstack/requests/show_resource_template.rb,
lib/fog/orchestration/openstack/requests/list_stack_data_detailed.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#auth_token_expiration ⇒ Object
readonly
Returns the value of attribute auth_token_expiration.
-
#current_tenant ⇒ Object
readonly
Returns the value of attribute current_tenant.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel_update(_) ⇒ Object
- #create_stack(arg1, arg2 = nil) ⇒ Object
- #credentials ⇒ Object
- #data ⇒ Object
- #delete_stack(arg1, arg2 = nil) ⇒ Object
- #get_stack_template(stack) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_events(_options = {}) ⇒ Object
- #list_resource_events(_stack, _resource, _options = {}) ⇒ Object
- #list_resource_types ⇒ Object
- #list_resources(_options = {}, _options_deprecated = {}) ⇒ Object
- #list_stack_data(_options = {}) ⇒ Object
- #list_stack_data_detailed(_options = {}) ⇒ Object
- #list_stack_events(_stack, _options = {}) ⇒ Object
- #patch_stack(_stack, _options = {}) ⇒ Object
- #reset_data ⇒ Object
- #show_event_details(_stack, _event) ⇒ Object
- #show_resource_data(_stack_name, _stack_id, _resource_name) ⇒ Object
- #show_resource_metadata(_stack, _resource_name) ⇒ Object
- #show_resource_template(name) ⇒ Object
- #show_stack_details(_name, _id) ⇒ Object
- #update_stack(arg1, arg2 = nil, arg3 = nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/fog/orchestration/openstack.rb', line 95 def initialize( = {}) @openstack_username = [:openstack_username] @openstack_auth_uri = URI.parse([:openstack_auth_url]) @current_tenant = [:openstack_tenant] @auth_token = Fog::Mock.random_base64(64) @auth_token_expiration = (Time.now.utc + 86400).iso8601 management_url = URI.parse([:openstack_auth_url]) management_url.port = 8774 management_url.path = '/v1' @openstack_management_url = management_url.to_s identity_public_endpoint = URI.parse([:openstack_auth_url]) identity_public_endpoint.port = 5000 @openstack_identity_public_endpoint = identity_public_endpoint.to_s end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
78 79 80 |
# File 'lib/fog/orchestration/openstack.rb', line 78 def auth_token @auth_token end |
#auth_token_expiration ⇒ Object (readonly)
Returns the value of attribute auth_token_expiration.
79 80 81 |
# File 'lib/fog/orchestration/openstack.rb', line 79 def auth_token_expiration @auth_token_expiration end |
#current_tenant ⇒ Object (readonly)
Returns the value of attribute current_tenant.
81 82 83 |
# File 'lib/fog/orchestration/openstack.rb', line 81 def current_tenant @current_tenant end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
80 81 82 |
# File 'lib/fog/orchestration/openstack.rb', line 80 def current_user @current_user end |
Class Method Details
.data ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/fog/orchestration/openstack.rb', line 83 def self.data @data ||= Hash.new do |hash, key| hash[key] = { :stacks => {} } end end |
.reset ⇒ Object
91 92 93 |
# File 'lib/fog/orchestration/openstack.rb', line 91 def self.reset @data = nil end |
Instance Method Details
#cancel_update(_) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fog/orchestration/openstack/requests/cancel_update.rb', line 17 def cancel_update(_) response = Excon::Response.new response.status = 200 response.body = {} response end |
#create_stack(arg1, arg2 = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/fog/orchestration/openstack/requests/create_stack.rb', line 54 def create_stack(arg1, arg2 = nil) if arg1.kind_of?(Hash) # Normal use: create_stack(options) = arg1 else # Deprecated: create_stack(stack_name, options = {}) Fog::Logger.deprecation("#create_stack(stack_name, options) is deprecated, use #create_stack(options) instead [light_black](#{caller.first})[/]") = { :stack_name => arg1 }.merge(arg2.nil? ? {} : arg2) end stack_id = Fog::Mock.random_hex(32) stack = data[:stacks][stack_id] = { 'id' => stack_id, 'stack_name' => [:stack_name], 'links' => [], 'description' => [:description], 'stack_status' => 'CREATE_COMPLETE', 'stack_status_reason' => 'Stack successfully created', 'creation_time' => Time.now, 'updated_time' => Time.now } response = Excon::Response.new response.status = 201 response.body = { 'id' => stack_id, 'links' => [{"href" => "http://localhost:8004/v1/fake_tenant_id/stacks/#{[:stack_name]}/#{stack_id}", "rel" => "self"}] } if .key?(:files) response.body['files'] = {'foo.sh' => 'hello'} end if .key?(:template) || .key?(:template_url) file_resolver = Util::RecursiveHotFileLoader.new([:template] || [:template_url], [:files]) response.body['files'] = file_resolver.files unless file_resolver.files.empty? end response end |
#credentials ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/fog/orchestration/openstack.rb', line 122 def credentials {:provider => 'openstack', :openstack_auth_url => @openstack_auth_uri.to_s, :openstack_auth_token => @auth_token, :openstack_management_url => @openstack_management_url, :openstack_identity_endpoint => @openstack_identity_public_endpoint} end |
#data ⇒ Object
114 115 116 |
# File 'lib/fog/orchestration/openstack.rb', line 114 def data self.class.data["#{@openstack_username}-#{@current_tenant}"] end |
#delete_stack(arg1, arg2 = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/fog/orchestration/openstack/requests/delete_stack.rb', line 35 def delete_stack(arg1, arg2 = nil) if arg1.kind_of?(Stack) # Normal use: delete_stack(stack) stack = arg1 stack_name = stack.stack_name stack_id = stack.id else # Deprecated: delete_stack(stack_name, stack_id) Fog::Logger.deprecation("#delete_stack(stack_name, stack_id) is deprecated, use #delete_stack(stack) instead [light_black](#{caller.first})[/]") stack_name = arg1 stack_id = arg2 end data[:stacks].delete(stack_id) response = Excon::Response.new response.status = 204 response.body = {} response end |
#get_stack_template(stack) ⇒ Object
15 16 |
# File 'lib/fog/orchestration/openstack/requests/get_stack_template.rb', line 15 def get_stack_template(stack) end |
#list_events(_options = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fog/orchestration/openstack/requests/list_events.rb', line 35 def list_events( = {}) events = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end |
#list_resource_events(_stack, _resource, _options = {}) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/fog/orchestration/openstack/requests/list_resource_events.rb', line 17 def list_resource_events(_stack, _resource, = {}) events = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end |
#list_resource_types ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fog/orchestration/openstack/requests/list_resource_types.rb', line 16 def list_resource_types resources = data[:resource_types].values Excon::Response.new( :body => {'resource_types' => resources}, :status => 200 ) end |
#list_resources(_options = {}, _options_deprecated = {}) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fog/orchestration/openstack/requests/list_resources.rb', line 35 def list_resources( = {}, = {}) resources = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end |
#list_stack_data(_options = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fog/orchestration/openstack/requests/list_stack_data.rb', line 16 def list_stack_data( = {}) stacks = data[:stacks].values Excon::Response.new( :body => {'stacks' => stacks}, :status => 200 ) end |
#list_stack_data_detailed(_options = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fog/orchestration/openstack/requests/list_stack_data_detailed.rb', line 16 def list_stack_data_detailed( = {}) Excon::Response.new( :body => { 'stacks' => [{"parent" => nil, "disable_rollback" => true, "description" => "No description", "links" => [{"href" => "http://192.0.2.1:8004/v1/ae084f19a7974d5b95703f633e57fd64/stacks/overcloud/9ea5226f-0bb3-40bf-924b-f89ea11bb69c", "rel" => "self"}], "stack_status_reason" => "Stack CREATE completed successfully", "stack_name" => "overcloud", "stack_user_project_id" => "ae084f19a7974d5b95703f633e57fd64", "stack_owner" => "admin", "creation_time" => "2015-06-24T07:19:01Z", "capabilities" => [], "notification_topics" => [], "updated_time" => nil, "timeout_mins" => nil, "stack_status" => "CREATE_COMPLETE", "parameters" => {"Controller-1::SSLKey" => "******", "Compute-1::RabbitClientUseSSL" => "False", "Controller-1::KeystoneSSLCertificate" => "", "Controller-1::CinderLVMLoopDeviceSize" => "5000"}, "id" => "9ea5226f-0bb3-40bf-924b-f89ea11bb69c", "outputs" => [], "template_description" => "No description"}] }, :status => 200 ) end |
#list_stack_events(_stack, _options = {}) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fog/orchestration/openstack/requests/list_stack_events.rb', line 16 def list_stack_events(_stack, = {}) events = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end |
#patch_stack(_stack, _options = {}) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/fog/orchestration/openstack/requests/patch_stack.rb', line 28 def patch_stack(_stack, = {}) response = Excon::Response.new response.status = 202 response.body = {} response end |
#reset_data ⇒ Object
118 119 120 |
# File 'lib/fog/orchestration/openstack.rb', line 118 def reset_data self.class.data.delete("#{@openstack_username}-#{@current_tenant}") end |
#show_event_details(_stack, _event) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/orchestration/openstack/requests/show_event_details.rb', line 15 def show_event_details(_stack, _event) events = data[:events].values Excon::Response.new( :body => {'events' => events}, :status => 200 ) end |
#show_resource_data(_stack_name, _stack_id, _resource_name) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/orchestration/openstack/requests/show_resource_data.rb', line 15 def show_resource_data(_stack_name, _stack_id, _resource_name) resources = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end |
#show_resource_metadata(_stack, _resource_name) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/orchestration/openstack/requests/show_resource_metadata.rb', line 15 def (_stack, _resource_name) resources = data[:resources].values Excon::Response.new( :body => {'resources' => resources}, :status => 200 ) end |
#show_resource_template(name) ⇒ Object
15 16 |
# File 'lib/fog/orchestration/openstack/requests/show_resource_template.rb', line 15 def show_resource_template(name) end |
#show_stack_details(_name, _id) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/fog/orchestration/openstack/requests/show_stack_details.rb', line 15 def show_stack_details(_name, _id) stack = data[:stack].values Excon::Response.new( :body => {'stack' => stack}, :status => 200 ) end |
#update_stack(arg1, arg2 = nil, arg3 = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fog/orchestration/openstack/requests/update_stack.rb', line 54 def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.kind_of?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id = arg2.nil? ? {} : arg2 else # Deprecated, update_stack(stack_id, stack_name, options = {}) Fog::Logger.deprecation("#update_stack(stack_id, stack_name, options) is deprecated, use #update_stack(stack, options) instead [light_black](#{caller.first})[/]") stack_id = arg1 stack_name = arg2 = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end if .key?(:files) response.body['files'] = {'foo.sh' => 'hello'} end if .key?(:template) || .key?(:template_url) file_resolver = Util::RecursiveHotFileLoader.new([:template] || [:template_url], [:files]) response.body['files'] = file_resolver.files unless file_resolver.files.empty? end response = Excon::Response.new response.status = 202 response.body = {} response end |