class Fog::OracleCloud::SOA::Mock

Public Class Methods

data() click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 87
def self.data 
  @data ||= {
    :instances => {},
    :servers => {},
    :deleted_at => {},
    :created_at => {}
  }
end
new(options={}) click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 72
def initialize(options={})
  @username = options[:oracle_username]
  @password = options[:oracle_password]
  @identity_domain   = options[:oracle_domain]
  @region_url = options[:oracle_region] == 'emea' ? 'https://jcs.emea.oraclecloud.com' : 'https://jaas.oraclecloud.com'
end
reset() click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 96
def self.reset
  @data = nil
end

Public Instance Methods

create_instance(config, options) click to toggle source
# File lib/fog/oraclecloud/requests/soa/create_instance.rb, line 31
def create_instance(config, options)
  response = Excon::Response.new

  ip = '192.168.1.1'
  data = {
    'status' => 'In Progress',
    'compute_site_name' => 'EM002_Z11',
    'content_url' => "http://#{ip}",
    'created_by' => @username,
    'creation_job_id' => Random.rand(100000),
    'creation_time'=> Time.now.strftime('%Y-%b-%dT%H:%M:%S'),
    'last_modified_time'=> Time.now.strftime('%Y-%b-%dT%H:%M:%S'),
    'service_id' => Random.rand(100000),
    'service_type' => config[:topology],
    'service_uri'=>"#{@region_url}/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{config[:serviceName]}",
   }
    .merge(config.select {|key, value| [:serviceName, :description, :level, :subscriptionType].include?(key) })
    .merge(options.select {|key, value| [:shape, :version].include?(key) }).collect{|k,v| [k.to_s, v]}.to_h

  self.data[:instances][config[:serviceName]] = data
  self.data[:created_at][config[:serviceName]] = Time.now

  server = {
    "name": "#{data['serviceName'][0,8]}_server_1",
    "shape": data['shape'],
    "nodeType": "WLS",
    "isAdmin": true,
    "hostname": ip,
    "status": "Ready",
    "storageAllocated": 74752,
    "creationDate": Time.now.strftime('%Y-%b-%dT%H:%M:%S')
  }
  self.data[:servers][data['serviceName']] = [server]

  response.status = 202
  response
end
data() click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 100
def data 
  self.class.data
end
delete_instance(name, dba_name, dba_password, options={}) click to toggle source
# File lib/fog/oraclecloud/requests/soa/delete_instance.rb, line 25
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) click to toggle source
# File lib/fog/oraclecloud/requests/soa/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::SOA::NotFound.new("SOA #{name} does not exist");
  end
end
get_job_status(type, job_id) click to toggle source
# File lib/fog/oraclecloud/requests/soa/get_job_status.rb, line 17
def get_job_status(type, job_id)
  ['Creation job succeded']
end
list_instances() click to toggle source
# File lib/fog/oraclecloud/requests/soa/list_instances.rb, line 16
def list_instances
  response = Excon::Response.new

  instances = self.data[:instances].values

  response.body = {
    'services' => instances
  }
  response
end
password() click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 83
def password
  @password
end
username() click to toggle source
# File lib/fog/oraclecloud/soa.rb, line 79
def username
  @username
end