Class: Fog::Orchestration::OpenStack::Real

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(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::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
end

Instance Attribute Details

#auth_tokenObject (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_expirationObject (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_tenantObject (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_userObject (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



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fog/openstack/requests/orchestration/create_stack.rb', line 19

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

#credentialsObject



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.

Parameters:

  • stack_name (String)

    Name of the stack to delete.

  • stack_id (String)

    ID of the stack to delete.

Returns:

  • (Excon::Response)

See Also:



15
16
17
18
19
20
21
# File 'lib/fog/openstack/requests/orchestration/delete_stack.rb', line 15

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.

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (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 Also:



26
27
28
29
30
31
32
33
# File 'lib/fog/openstack/requests/orchestration/list_stacks.rb', line 26

def list_stacks(options = {})
  request(
    :expects  => 200,
    :path => 'stacks',
    :method => 'GET',
    :query => options
  )
end

#reloadObject



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.

Parameters:

  • stack_id (String)

    ID of the stack to update.

  • stack_name (String)

    Name of the stack to update.

  • options (Hash) (defaults to: {})
    • :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.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fog/openstack/requests/orchestration/update_stack.rb', line 16

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