Class: Fog::Event::OpenStack::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/event/openstack.rb,
lib/fog/event/openstack/requests/get_event.rb,
lib/fog/event/openstack/requests/list_events.rb

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
60
61
62
63
64
65
66
# File 'lib/fog/event/openstack.rb', line 42

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

  @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 = 8779
  management_url.path = '/v2'
  @openstack_management_url = management_url.to_s

  @data ||= {:users => {}}
  unless @data[:users].find { |u| u['name'] == options[:openstack_username] }
    id = Fog::Mock.random_numbers(6).to_s
    @data[:users][id] = {
      'id'       => id,
      'name'     => options[:openstack_username],
      'email'    => "#{options[:openstack_username]}@mock.com",
      'tenantId' => Fog::Mock.random_numbers(6).to_s,
      'enabled'  => true
    }
  end
end

Class Method Details

.dataObject



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

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

.resetObject



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

def self.reset
  @data = nil
end

Instance Method Details

#credentialsObject



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

def credentials
  {:provider                 => 'openstack',
   :openstack_auth_url       => @openstack_auth_uri.to_s,
   :openstack_auth_token     => @auth_token,
   :openstack_management_url => @openstack_management_url}
end

#dataObject



68
69
70
# File 'lib/fog/event/openstack.rb', line 68

def data
  self.class.data[@openstack_username]
end

#get_event(_message_id) ⇒ Object



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

def get_event(_message_id)
  response = Excon::Response.new
  response.status = 200
  response.body = {
    'event_type' => 'compute.instance.create',
    'message_id' => 'd646b40dea6347dfb8caee2da1484c56',
  }
  response
end

#list_events(_options = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/fog/event/openstack/requests/list_events.rb', line 30

def list_events(_options = {})
  response = Excon::Response.new
  response.status = 200
  response.body = [{
    'event_type' => 'compute.instance.create',
    'message_id' => 'd646b40dea6347dfb8caee2da1484c56',
  }]
  response
end

#reset_dataObject



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

def reset_data
  self.class.data.delete(@openstack_username)
end