Class: Fog::Orchestration::OpenStack::Real
- Inherits:
-
Object
- Object
- Fog::Orchestration::OpenStack::Real
- Defined in:
- lib/fog/openstack/orchestration.rb,
lib/fog/openstack/requests/orchestration/list_stacks.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
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
-
#create_stack(stack_name, options = {}) ⇒ Object
Create a stack.
- #credentials ⇒ Object
-
#delete_stack(stack_name, stack_id) ⇒ Excon::Response
Delete a stack.
-
#initialize(options = {}) ⇒ Real
constructor
A new instance of Real.
-
#list_stacks(options = {}) ⇒ Excon::Response
List stacks.
- #reload ⇒ Object
- #request(params) ⇒ Object
-
#update_stack(stack_id, stack_name, options = {}) ⇒ Object
Update a stack.
Constructor Details
#initialize(options = {}) ⇒ Real
Returns a new instance of Real.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/fog/openstack/orchestration.rb', line 84 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.
79 80 81 |
# File 'lib/fog/openstack/orchestration.rb', line 79 def auth_token @auth_token end |
#auth_token_expiration ⇒ Object (readonly)
Returns the value of attribute auth_token_expiration.
80 81 82 |
# File 'lib/fog/openstack/orchestration.rb', line 80 def auth_token_expiration @auth_token_expiration end |
#current_tenant ⇒ Object (readonly)
Returns the value of attribute current_tenant.
82 83 84 |
# File 'lib/fog/openstack/orchestration.rb', line 82 def current_tenant @current_tenant end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
81 82 83 |
# File 'lib/fog/openstack/orchestration.rb', line 81 def current_user @current_user end |
Instance Method Details
#create_stack(stack_name, options = {}) ⇒ Object
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
-
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fog/openstack/requests/orchestration/create_stack.rb', line 18 def create_stack(stack_name, = {}) params = { :stack_name => stack_name }.merge() request( :expects => 201, :path => 'stacks', :method => 'POST', :body => Fog::JSON.encode(params) ) end |
#credentials ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# 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_stack(stack_name, stack_id) ⇒ Excon::Response
Delete a stack.
14 15 16 17 18 19 20 |
# 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(options = {}) ⇒ Excon::Response
List stacks.
25 26 27 28 29 30 31 32 |
# File 'lib/fog/openstack/requests/orchestration/list_stacks.rb', line 25 def list_stacks( = {}) request( :expects => 200, :path => 'stacks', :method => 'GET', :query => ) end |
#reload ⇒ Object
131 132 133 |
# File 'lib/fog/openstack/orchestration.rb', line 131 def reload @connection.reset end |
#request(params) ⇒ Object
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 165 166 167 168 169 170 |
# 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_stack(stack_id, stack_name, options = {}) ⇒ Object
Update a stack.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/openstack/requests/orchestration/update_stack.rb', line 15 def update_stack(stack_id, stack_name, = {}) params = { :stack_name => stack_name }.merge() request( :expects => 202, :path => "stacks/#{stack_name}/#{stack_id}", :method => 'PUT', :body => Fog::JSON.encode(params) ) end |