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

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/openstack/orchestration.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/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/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_metadata.rb,
lib/fog/openstack/requests/orchestration/show_resource_template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/openstack/orchestration.rb', line 88

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.



71
72
73
# File 'lib/fog/openstack/orchestration.rb', line 71

def auth_token
  @auth_token
end

#auth_token_expirationObject (readonly)

Returns the value of attribute auth_token_expiration.



72
73
74
# File 'lib/fog/openstack/orchestration.rb', line 72

def auth_token_expiration
  @auth_token_expiration
end

#current_tenantObject (readonly)

Returns the value of attribute current_tenant.



74
75
76
# File 'lib/fog/openstack/orchestration.rb', line 74

def current_tenant
  @current_tenant
end

#current_userObject (readonly)

Returns the value of attribute current_user.



73
74
75
# File 'lib/fog/openstack/orchestration.rb', line 73

def current_user
  @current_user
end

Class Method Details

.dataObject



76
77
78
79
80
81
82
# File 'lib/fog/openstack/orchestration.rb', line 76

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

.resetObject



84
85
86
# File 'lib/fog/openstack/orchestration.rb', line 84

def self.reset
  @data = nil
end

Instance Method Details

#create_stack(arg1, arg2 = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fog/openstack/requests/orchestration/create_stack.rb', line 41

def create_stack(arg1, arg2 = nil)
  if arg1.is_a?(Hash)
    # Normal use: create_stack(options)
    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})[/]")
    options = {
      :stack_name => arg1
    }.merge(arg2.nil? ? {} : arg2)
  end

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

#credentialsObject



115
116
117
118
119
120
121
# File 'lib/fog/openstack/orchestration.rb', line 115

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



107
108
109
# File 'lib/fog/openstack/orchestration.rb', line 107

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

#delete_stack(arg1, arg2 = nil) ⇒ 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/delete_stack.rb', line 35

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

  self.data[:stacks].delete(stack_id)

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

#get_stack_template(stack) ⇒ Object



15
16
# File 'lib/fog/openstack/requests/orchestration/get_stack_template.rb', line 15

def get_stack_template(stack)
end

#list_resource_typesObject



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

def list_resource_types
  resources = self.data[:resource_types].values

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

#list_resources(stack) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/fog/openstack/requests/orchestration/list_resources.rb', line 12

def list_resources(stack)
  resources = self.data[:resources].values

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

#list_stack_dataObject



16
17
18
19
20
21
22
23
# File 'lib/fog/openstack/requests/orchestration/list_stack_data.rb', line 16

def list_stack_data
  stacks = self.data[:stacks].values

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

#list_stack_eventsObject



12
13
14
15
16
17
18
19
# File 'lib/fog/openstack/requests/orchestration/list_stack_events.rb', line 12

def list_stack_events
  events = self.data[:events].values

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

#reset_dataObject



111
112
113
# File 'lib/fog/openstack/orchestration.rb', line 111

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

#show_event_details(stack, event) ⇒ Object



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

def show_event_details(stack, event)
  events = self.data[:events].values

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

#show_resource_data(stack_name, stack_id, resource_name) ⇒ Object



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

def show_resource_data(stack_name, stack_id, resource_name)
  resources = self.data[:resources].values

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

#show_resource_metadata(stack, resource_name) ⇒ Object



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

def (stack, resource_name)
  resources = self.data[:resources].values

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

#show_resource_template(name) ⇒ Object



15
16
# File 'lib/fog/openstack/requests/orchestration/show_resource_template.rb', line 15

def show_resource_template(name)
end

#show_stack_details(name, id) ⇒ Object



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

def show_stack_details(name, id)
  stack = self.data[:stack].values

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

#update_stack(arg1, arg2 = nil, arg3 = nil) ⇒ Object



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

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

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