def initialize(options={})
require 'multi_json'
@openstack_username = options[:openstack_username] || 'admin'
@openstack_tenant = options[:openstack_tenant] || 'admin'
@openstack_auth_uri = URI.parse(options[:openstack_auth_url])
@openstack_management_url = @openstack_auth_uri.to_s
@auth_token = Fog::Mock.random_base64(64)
@auth_token_expiration = (Time.now.utc + 86400).iso8601
@admin_tenant = self.data[:tenants].values.find do |u|
u['name'] == 'admin'
end
if @openstack_tenant
@current_tenant = self.data[:tenants].values.find do |u|
u['name'] == @openstack_tenant
end
unless @current_tenant
@current_tenant_id = Fog::Mock.random_hex(32)
@current_tenant = self.data[:tenants][@current_tenant_id] = {
'id' => @current_tenant_id,
'name' => @openstack_tenant
}
else
@current_tenant_id = @current_tenant['id']
end
else
@current_tenant = @admin_tenant
end
@current_user = self.data[:users].values.find do |u|
u['name'] == @openstack_username
end
@current_tenant_id = Fog::Mock.random_hex(32)
unless @current_user
@current_user_id = Fog::Mock.random_hex(32)
@current_user = self.data[:users][@current_user_id] = {
'id' => @current_user_id,
'name' => @openstack_username,
'email' => "#{@openstack_username}@mock.com",
'tenantId' => Fog::Mock.random_numbers(6).to_s,
'enabled' => true
}
else
@current_user_id = @current_user['id']
end
end