Class: Fog::OracleCloud::Java::Mock

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Mock

Returns a new instance of Mock.



62
63
64
65
66
# File 'lib/fog/oraclecloud/java.rb', line 62

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

Class Method Details

.dataObject



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

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

.resetObject



76
77
78
# File 'lib/fog/oraclecloud/java.rb', line 76

def self.reset
  @data = nil
end

Instance Method Details

#create_instance(service_name, cloudStorageContainer, cloudStorageUser, cloudStoragePassword, dbaName, dbaPassword, dbServiceName, shape, version, vmPublicKey, options = {}) ⇒ Object



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

def create_instance(service_name, cloudStorageContainer, cloudStorageUser, cloudStoragePassword, dbaName, dbaPassword, dbServiceName, shape, version, vmPublicKey, options={})
  response = Excon::Response.new

  data = {
    'service_name' => service_name,
    'db_service_name' => dbServiceName,
    'shape' => shape,
    '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



80
81
82
# File 'lib/fog/oraclecloud/java.rb', line 80

def data 
  self.class.data
end

#delete_instance(name, dba_name, dba_password, options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/fog/oraclecloud/requests/java/delete_instance.rb', line 27

def delete_instance(name, dba_name, dba_password, options={})
  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/java/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::Java::NotFound.new("Java #{name} does not exist");
  end
end

#list_instancesObject



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

def list_instances
  response = Excon::Response.new

  instances = self.data[:instances].values

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