Class: Fog::OracleCloud::Database::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/oraclecloud/database.rb,
lib/fog/oraclecloud/requests/database/get_instance.rb,
lib/fog/oraclecloud/requests/database/list_instances.rb,
lib/fog/oraclecloud/requests/database/create_instance.rb,
lib/fog/oraclecloud/requests/database/delete_instance.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



61
62
63
64
65
# File 'lib/fog/oraclecloud/database.rb', line 61

def initialize(options={})
  @username = options[:oracle_username]
  @password = options[:oracle_password]
  @identity_domain   = options[:oracle_domain]
end

Class Method Details

.dataObject



67
68
69
70
71
72
73
# File 'lib/fog/oraclecloud/database.rb', line 67

def self.data 
  @data ||= {
    :instances => {},
    :deleted_at => {},
    :created_at => {}
  }
end

.resetObject



75
76
77
# File 'lib/fog/oraclecloud/database.rb', line 75

def self.reset
  @data = nil
end

Instance Method Details

#create_instance(service_name, edition, vmPublicKey, shape, version, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fog/oraclecloud/requests/database/create_instance.rb', line 37

def create_instance(service_name, edition, vmPublicKey, shape, version, options={})
  response = Excon::Response.new

   data = {
     'service_name' => service_name,
     'shape' => shape,
     'edition' => edition,
     'version' => version,
     'status' => 'In Progress'
   }.merge(options.select {|key, value| ["description"].include?(key) })

   self.data[:instances][service_name] = data
   self.data[:created_at][service_name] = Time.now
   response.status = 202
   response
end

#dataObject



79
80
81
# File 'lib/fog/oraclecloud/database.rb', line 79

def data 
  self.class.data
end

#delete_instance(name) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/fog/oraclecloud/requests/database/delete_instance.rb', line 16

def delete_instance(name)
  response = Excon::Response.new
  self.data[:instances][name]['status'] = 'Terminating'
  self.data[:deleted_at][name] = Time.now
  response.status = 204
  response
end

#get_instance(name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fog/oraclecloud/requests/database/get_instance.rb', line 17

def get_instance(name)
  response = Excon::Response.new

  if instance = self.data[:instances][name]
    case instance['status']
    when 'Terminating'
      if Time.now - self.data[:deleted_at][name] >= Fog::Mock.delay
        self.data[:deleted_at].delete(name)
        self.data[:instances].delete(name)
      end
    when 'In Progress'
      if Time.now - self.data[:created_at][name] >= Fog::Mock.delay
        self.data[:instances][name]['status'] = 'Running'
        instance = self.data[:instances][name]
        self.data[:created_at].delete(name)
      end
    end
    response.status = 200
    response.body = instance
    response
  else
    raise Fog::OracleCloud::Database::NotFound.new("Database #{name} does not exist");
  end
end

#list_instancesObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/oraclecloud/requests/database/list_instances.rb', line 16

def list_instances
  response = Excon::Response.new

  instances = self.data[:instances].values

  response.body = {
    'services' => instances
  }
  response
end