Class: Fog::Orchestration::OpenStack::Mock

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fog/openstack/orchestration.rb', line 42

def initialize(options={})
  @openstack_username = options[:openstack_username]
  @openstack_auth_uri = URI.parse(options[:openstack_auth_url])

  @current_tenant = options[:openstack_tenant]

  @auth_token = Fog::Mock.random_base64(64)
  @auth_token_expiration = (Time.now.utc + 86400).iso8601

  management_url = URI.parse(options[:openstack_auth_url])
  management_url.port = 8774
  management_url.path = '/v1'
  @openstack_management_url = management_url.to_s

  identity_public_endpoint = URI.parse(options[:openstack_auth_url])
  identity_public_endpoint.port = 5000
  @openstack_identity_public_endpoint = identity_public_endpoint.to_s
end

Instance Attribute Details

#auth_tokenObject (readonly)

Returns the value of attribute auth_token.



25
26
27
# File 'lib/fog/openstack/orchestration.rb', line 25

def auth_token
  @auth_token
end

#auth_token_expirationObject (readonly)

Returns the value of attribute auth_token_expiration.



26
27
28
# File 'lib/fog/openstack/orchestration.rb', line 26

def auth_token_expiration
  @auth_token_expiration
end

#current_tenantObject (readonly)

Returns the value of attribute current_tenant.



28
29
30
# File 'lib/fog/openstack/orchestration.rb', line 28

def current_tenant
  @current_tenant
end

#current_userObject (readonly)

Returns the value of attribute current_user.



27
28
29
# File 'lib/fog/openstack/orchestration.rb', line 27

def current_user
  @current_user
end

Class Method Details

.dataObject



30
31
32
33
34
35
36
# File 'lib/fog/openstack/orchestration.rb', line 30

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :stacks => {}
    }
  end
end

.resetObject



38
39
40
# File 'lib/fog/openstack/orchestration.rb', line 38

def self.reset
  @data = nil
end

Instance Method Details

#create_stack(stack_name, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fog/openstack/requests/orchestration/create_stack.rb', line 35

def create_stack(stack_name, options = {})
  stack_id = Fog::Mock.random_hex(32)
  stack = self.data[:stacks][stack_id] = {
    'id' => stack_id,
    'stack_name' => stack_name,
    'links' => [],
    'description' => options[: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"}]}
  response
end

#credentialsObject



69
70
71
72
73
74
75
# File 'lib/fog/openstack/orchestration.rb', line 69

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

#dataObject



61
62
63
# File 'lib/fog/openstack/orchestration.rb', line 61

def data
  self.class.data["#{@openstack_username}-#{@current_tenant}"]
end

#delete_stack(stack_name, stack_id) ⇒ Object



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

def delete_stack(stack_name, stack_id)
  self.data[:stacks].delete(stack_id)

  response = Excon::Response.new
  response.status = 204
  response.body = {}
  response
end

#list_stacks(options = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/fog/openstack/requests/orchestration/list_stacks.rb', line 38

def list_stacks(options = {})
  stacks = self.data[:stacks].values

  Excon::Response.new(
    :body   => { 'stacks' => stacks },
    :status => 200
  )
end

#reset_dataObject



65
66
67
# File 'lib/fog/openstack/orchestration.rb', line 65

def reset_data
  self.class.data.delete("#{@openstack_username}-#{@current_tenant}")
end

#update_stack(stack_name, options = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/fog/openstack/requests/orchestration/update_stack.rb', line 32

def update_stack(stack_name, options = {})
  response = Excon::Response.new
  response.status = 202
  response.body = {}
  response
end