# File lib/fog/openstack/orchestration.rb, line 84 def initialize(options={}) @openstack_auth_token = options[:openstack_auth_token] @auth_token = options[:openstack_auth_token] @openstack_identity_public_endpoint = options[:openstack_identity_endpoint] unless @auth_token missing_credentials = Array.new @openstack_api_key = options[:openstack_api_key] @openstack_username = options[: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 = options[:openstack_tenant] @openstack_auth_uri = URI.parse(options[:openstack_auth_url]) @openstack_management_url = options[:openstack_management_url] @openstack_must_reauthenticate = false @openstack_service_type = options[:openstack_service_type] || ['orchestration'] @openstack_service_name = options[:openstack_service_name] @openstack_identity_service_type = options[:openstack_identity_service_type] || 'identity' @openstack_endpoint_type = options[:openstack_endpoint_type] || 'publicURL' @openstack_region = options[:openstack_region] @connection_options = options[:connection_options] || {} @current_user = options[:current_user] @current_tenant = options[:current_tenant] authenticate @persistent = options[:persistent] || false @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options) end
Create a stack.
stack_name [String] Name of the stack to create.
options [Hash]:
:template_body [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_in_minutes [Integer] Minutes to wait before status is set to CREATE_FAILED
@see docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_CreateStack.html
# File lib/fog/openstack/requests/orchestration/create_stack.rb, line 18 def create_stack(stack_name, options = {}) params = { :stack_name => stack_name }.merge(options) request( :expects => 201, :path => 'stacks', :method => 'POST', :body => Fog::JSON.encode(params) ) end
# File lib/fog/openstack/orchestration.rb, line 120 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 a stack.
@param stack_name [String] Name of the stack to delete. @param stack_id [String] ID of the stack to delete.
@return [Excon::Response]
@see docs.amazonwebservices.com/AWSCloudFormation/latest/APIReference/API_DeleteStack.html
# File lib/fog/openstack/requests/orchestration/delete_stack.rb, line 14 def delete_stack(stack_name, stack_id) request( :expects => 204, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'DELETE' ) end
List stacks.
@param options [Hash]
@return [Excon::Response]
* body [Hash]: * stacks [Array] - Matching stacks * stack [Hash]: * id [String] - * stack_name [String] - * description [String] * links [Array] * stack_status [String] - * stack_status_reason [String] * creation_time [Time] - * updated_time [Time] -
@see docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_ListStacks.html
# File lib/fog/openstack/requests/orchestration/list_stacks.rb, line 25 def list_stacks(options = {}) request( :expects => 200, :path => 'stacks', :method => 'GET', :query => options ) end
# File lib/fog/openstack/orchestration.rb, line 131 def reload @connection.reset end
# File lib/fog/openstack/orchestration.rb, line 135 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
Update a stack.
@param [String] stack_id ID of the stack to update. @param [String] stack_name Name of the stack to update. @param [Hash] options
* :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. * :parameters [Hash] Hash of providers to supply to template.
# File lib/fog/openstack/requests/orchestration/update_stack.rb, line 15 def update_stack(stack_id, stack_name, options = {}) params = { :stack_name => stack_name }.merge(options) request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PUT', :body => Fog::JSON.encode(params) ) end
# File lib/fog/openstack/orchestration.rb, line 174 def authenticate if !@openstack_management_url || @openstack_must_reauthenticate options = { :openstack_api_key => @openstack_api_key, :openstack_username => @openstack_username, :openstack_auth_token => @auth_token, :openstack_auth_uri => @openstack_auth_uri, :openstack_region => @openstack_region, :openstack_tenant => @openstack_tenant, :openstack_service_type => @openstack_service_type, :openstack_service_name => @openstack_service_name, :openstack_identity_service_type => @openstack_identity_service_type, :openstack_endpoint_type => @openstack_endpoint_type } if @openstack_auth_uri.path =~ /\/v2.0\// credentials = Fog::OpenStack.authenticate_v2(options, @connection_options) else credentials = Fog::OpenStack.authenticate_v1(options, @connection_options) end @current_user = credentials[:user] @current_tenant = credentials[:tenant] @openstack_must_reauthenticate = false @auth_token = credentials[:token] @auth_token_expiration = credentials[:expires] @openstack_management_url = credentials[:server_management_url] @openstack_identity_public_endpoint = credentials[:identity_public_endpoint] end uri = URI.parse(@openstack_management_url) @host = uri.host @path, @tenant_id = uri.path.scan(/(\/.*)\/(.*)/).flatten @path.sub!(/\/$/, '') @port = uri.port @scheme = uri.scheme # Not all implementations have identity service in the catalog if @openstack_identity_public_endpoint || @openstack_management_url @identity_connection = Fog::Core::Connection.new( @openstack_identity_public_endpoint || @openstack_management_url, false, @connection_options) end true end