Class: Fog::Orchestration::OpenStack::Real
- Inherits:
-
Object
- Object
- Fog::Orchestration::OpenStack::Real
- Defined in:
- lib/fog/openstack/orchestration.rb,
lib/fog/openstack/requests/orchestration/build_info.rb,
lib/fog/openstack/requests/orchestration/create_stack.rb,
lib/fog/openstack/requests/orchestration/delete_stack.rb,
lib/fog/openstack/requests/orchestration/update_stack.rb,
lib/fog/openstack/requests/orchestration/abandon_stack.rb,
lib/fog/openstack/requests/orchestration/preview_stack.rb,
lib/fog/openstack/requests/orchestration/list_resources.rb,
lib/fog/openstack/requests/orchestration/list_stack_data.rb,
lib/fog/openstack/requests/orchestration/list_stack_events.rb,
lib/fog/openstack/requests/orchestration/validate_template.rb,
lib/fog/openstack/requests/orchestration/get_stack_template.rb,
lib/fog/openstack/requests/orchestration/show_event_details.rb,
lib/fog/openstack/requests/orchestration/show_resource_data.rb,
lib/fog/openstack/requests/orchestration/show_stack_details.rb,
lib/fog/openstack/requests/orchestration/list_resource_types.rb,
lib/fog/openstack/requests/orchestration/list_resource_events.rb,
lib/fog/openstack/requests/orchestration/show_resource_schema.rb,
lib/fog/openstack/requests/orchestration/show_resource_metadata.rb,
lib/fog/openstack/requests/orchestration/show_resource_template.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.
Instance Method Summary collapse
- #abandon_stack(stack) ⇒ Object
- #build_info ⇒ Object
-
#create_stack(arg1, arg2 = nil) ⇒ Object
Create a stack.
- #credentials ⇒ Object
-
#delete_stack(arg1, arg2 = nil) ⇒ Excon::Response
Delete a stack.
- #get_stack_template(stack) ⇒ Object
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
- #list_resource_events(stack, resource, options = {}) ⇒ Object
- #list_resource_types ⇒ Object
- #list_resources(stack, options = {}) ⇒ Object
- #list_stack_data(options = {}) ⇒ Object
- #list_stack_events(stack, options = {}) ⇒ Object
- #preview_stack(options = {}) ⇒ Object
- #reload ⇒ Object
- #request(params) ⇒ Object
- #show_event_details(stack, resource, event_id) ⇒ Object
- #show_resource_data(stack_name, stack_id, resource_name) ⇒ Object
- #show_resource_metadata(stack, resource_name) ⇒ Object
- #show_resource_schema(name) ⇒ Object
- #show_resource_template(name) ⇒ Object
- #show_stack_details(name, id) ⇒ Object
-
#update_stack(arg1, arg2 = nil, arg3 = nil) ⇒ Object
Update a stack.
- #validate_template(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/fog/openstack/orchestration.rb', line 130 def initialize(={}) @openstack_auth_token = [:openstack_auth_token] @auth_token = [:openstack_auth_token] @openstack_identity_public_endpoint = [:openstack_identity_endpoint] unless @auth_token missing_credentials = Array.new @openstack_api_key = [:openstack_api_key] @openstack_username = [:openstack_username] missing_credentials << :openstack_api_key unless @openstack_api_key missing_credentials << :openstack_username unless @openstack_username raise ArgumentError, "Missing required arguments: #{missing_credentials.join(', ')}" unless missing_credentials.empty? end @openstack_tenant = [:openstack_tenant] @openstack_auth_uri = URI.parse([:openstack_auth_url]) @openstack_management_url = [:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_type = [:openstack_service_type] || ['orchestration'] @openstack_service_name = [:openstack_service_name] @openstack_identity_service_type = [:openstack_identity_service_type] || 'identity' @openstack_endpoint_type = [:openstack_endpoint_type] || 'publicURL' @openstack_region = [:openstack_region] @connection_options = [:connection_options] || {} @current_user = [:current_user] @current_tenant = [:current_tenant] authenticate @persistent = [:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end |
Instance Attribute Details
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
125 126 127 |
# File 'lib/fog/openstack/orchestration.rb', line 125 def auth_token @auth_token end |
#auth_token_expiration ⇒ Object (readonly)
Returns the value of attribute auth_token_expiration.
126 127 128 |
# File 'lib/fog/openstack/orchestration.rb', line 126 def auth_token_expiration @auth_token_expiration end |
#current_tenant ⇒ Object (readonly)
Returns the value of attribute current_tenant.
128 129 130 |
# File 'lib/fog/openstack/orchestration.rb', line 128 def current_tenant @current_tenant end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
127 128 129 |
# File 'lib/fog/openstack/orchestration.rb', line 127 def current_user @current_user end |
Instance Method Details
#abandon_stack(stack) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/abandon_stack.rb', line 5 def abandon_stack(stack) request( :expects => [200], :method => 'DELETE', :path => "stacks/#{stack.stack_name}/#{stack.id}/abandon" ) end |
#build_info ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/build_info.rb', line 5 def build_info request( :expects => [200], :method => 'GET', :path => 'build_info' ) end |
#create_stack(arg1, arg2 = nil) ⇒ Object
Create a stack.
-
options [Hash]:
-
:stack_name [String] Name of the stack to create.
-
:template [String] Structure containing the template body.
or (one of the two Template parameters is required)
-
:template_url [String] URL of file containing the template body.
-
:disable_rollback [Boolean] Controls rollback on stack creation failure, defaults to false.
-
:parameters [Hash] Hash of providers to supply to template
-
:timeout_mins [Integer] Minutes to wait before status is set to CREATE_FAILED
-
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/openstack/requests/orchestration/create_stack.rb', line 19 def create_stack(arg1, arg2 = nil) if arg1.is_a?(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 request( :expects => 201, :path => 'stacks', :method => 'POST', :body => Fog::JSON.encode() ) end |
#credentials ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/fog/openstack/orchestration.rb', line 166 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, :openstack_region => @openstack_region, :current_user => @current_user, :current_tenant => @current_tenant } end |
#delete_stack(arg1, arg2 = nil) ⇒ Excon::Response
Delete a stack.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fog/openstack/requests/orchestration/delete_stack.rb', line 13 def delete_stack(arg1, arg2 = nil) if arg1.is_a?(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 request( :expects => 204, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'DELETE' ) end |
#get_stack_template(stack) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/get_stack_template.rb', line 5 def get_stack_template(stack) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/template", :expects => 200 ) end |
#list_resource_events(stack, resource, options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/fog/openstack/requests/orchestration/list_resource_events.rb', line 5 def list_resource_events(stack, resource, ={}) uri = "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events" request(:method => 'GET', :path => uri, :expects => 200, :query => ) end |
#list_resource_types ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/list_resource_types.rb', line 5 def list_resource_types request( :method => 'GET', :path => "resource_types", :expects => 200 ) end |
#list_resources(stack, options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/fog/openstack/requests/orchestration/list_resources.rb', line 5 def list_resources(stack, ={}) uri = "stacks/#{stack.stack_name}/#{stack.id}/resources" request(:method => 'GET', :path => uri, :expects => 200, :query => ) end |
#list_stack_data(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/openstack/requests/orchestration/list_stack_data.rb', line 5 def list_stack_data(={}) request( :method => 'GET', :path => 'stacks', :expects => 200, :query => ) end |
#list_stack_events(stack, options = {}) ⇒ Object
5 6 7 8 |
# File 'lib/fog/openstack/requests/orchestration/list_stack_events.rb', line 5 def list_stack_events(stack, ={}) uri = "stacks/#{stack.stack_name}/#{stack.id}/events" request(:method => 'GET', :path => uri, :expects => 200, :query => ) end |
#preview_stack(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/openstack/requests/orchestration/preview_stack.rb', line 5 def preview_stack( = {}) request( :body => Fog::JSON.encode(), :expects => [200], :method => 'POST', :path => 'stacks/preview' ) end |
#reload ⇒ Object
177 178 179 |
# File 'lib/fog/openstack/orchestration.rb', line 177 def reload @connection.reset end |
#request(params) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/fog/openstack/orchestration.rb', line 181 def request(params) begin response = @connection.request(params.merge({ :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Auth-Token' => @auth_token, 'X-Auth-User' => @openstack_username, 'X-Auth-Key' => @openstack_api_key }.merge!(params[:headers] || {}), :path => "#{@path}/#{@tenant_id}/#{params[:path]}", :query => params[:query] })) rescue Excon::Errors::Unauthorized => error if error.response.body != 'Bad username or password' # token expiration @openstack_must_reauthenticate = true authenticate retry else # Bad Credentials raise error end rescue Excon::Errors::HTTPStatusError => error raise case error when Excon::Errors::NotFound Fog::Compute::OpenStack::NotFound.slurp(error) else error end end if !response.body.empty? and response.get_header('Content-Type') =~ /application\/json/ then response.body = Fog::JSON.decode(response.body) end response end |
#show_event_details(stack, resource, event_id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_event_details.rb', line 5 def show_event_details(stack, resource, event_id) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource.resource_name}/events/#{event_id}", :expects => 200 ) end |
#show_resource_data(stack_name, stack_id, resource_name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_resource_data.rb', line 5 def show_resource_data(stack_name, stack_id, resource_name) request( :method => 'GET', :path => "stacks/#{stack_name}/#{stack_id}/resources/#{resource_name}", :expects => 200 ) end |
#show_resource_metadata(stack, resource_name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_resource_metadata.rb', line 5 def (stack, resource_name) request( :method => 'GET', :path => "stacks/#{stack.stack_name}/#{stack.id}/resources/#{resource_name}/metadata", :expects => 200 ) end |
#show_resource_schema(name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_resource_schema.rb', line 5 def show_resource_schema(name) request( :method => 'GET', :path => "resource_types/#{name}", :expects => 200 ) end |
#show_resource_template(name) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_resource_template.rb', line 5 def show_resource_template(name) request( :method => 'GET', :path => "resource_types/#{name}/template", :expects => 200 ) end |
#show_stack_details(name, id) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/fog/openstack/requests/orchestration/show_stack_details.rb', line 5 def show_stack_details(name, id) request( :method => 'GET', :path => "stacks/#{name}/#{id}", :expects => 200 ) end |
#update_stack(arg1, arg2 = nil, arg3 = nil) ⇒ Object
Update a stack.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/openstack/requests/orchestration/update_stack.rb', line 14 def update_stack(arg1, arg2 = nil, arg3 = nil) if arg1.is_a?(Stack) # Normal use, update_stack(stack, options = {}) stack = arg1 stack_name = stack.stack_name stack_id = stack.id params = 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 params = { :stack_name => stack_name }.merge(arg3.nil? ? {} : arg3) end request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PUT', :body => Fog::JSON.encode(params) ) end |
#validate_template(options = {}) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/fog/openstack/requests/orchestration/validate_template.rb', line 5 def validate_template( = {}) request( :body => Fog::JSON.encode(), :expects => [200], :method => 'POST', :path => 'validate' ) end |