Class: Fog::OracleCloud::SOA::Mock
- Inherits:
-
Object
- Object
- Fog::OracleCloud::SOA::Mock
- Defined in:
- lib/fog/oraclecloud/soa.rb,
lib/fog/oraclecloud/requests/soa/get_instance.rb,
lib/fog/oraclecloud/requests/soa/get_job_status.rb,
lib/fog/oraclecloud/requests/soa/list_instances.rb,
lib/fog/oraclecloud/requests/soa/create_instance.rb,
lib/fog/oraclecloud/requests/soa/delete_instance.rb
Class Method Summary collapse
Instance Method Summary collapse
- #create_instance(config, options) ⇒ Object
- #data ⇒ Object
- #delete_instance(name, dba_name, dba_password, options = {}) ⇒ Object
- #get_instance(name) ⇒ Object
- #get_job_status(type, job_id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_instances ⇒ Object
- #password ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
72 73 74 75 76 77 |
# File 'lib/fog/oraclecloud/soa.rb', line 72 def initialize(={}) @username = [:oracle_username] @password = [:oracle_password] @identity_domain = [:oracle_domain] @region_url = [:oracle_region] == 'emea' ? 'https://jcs.emea.oraclecloud.com' : 'https://jaas.oraclecloud.com' end |
Class Method Details
.data ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/fog/oraclecloud/soa.rb', line 87 def self.data @data ||= { :instances => {}, :servers => {}, :deleted_at => {}, :created_at => {} } end |
.reset ⇒ Object
96 97 98 |
# File 'lib/fog/oraclecloud/soa.rb', line 96 def self.reset @data = nil end |
Instance Method Details
#create_instance(config, options) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 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 67 |
# File 'lib/fog/oraclecloud/requests/soa/create_instance.rb', line 31 def create_instance(config, ) 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(.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 ⇒ Object
100 101 102 |
# File 'lib/fog/oraclecloud/soa.rb', line 100 def data self.class.data end |
#delete_instance(name, dba_name, dba_password, options = {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/fog/oraclecloud/requests/soa/delete_instance.rb', line 25 def delete_instance(name, dba_name, dba_password, ={}) 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 |
# 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) ⇒ Object
17 18 19 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# 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 ⇒ Object
83 84 85 |
# File 'lib/fog/oraclecloud/soa.rb', line 83 def password @password end |
#username ⇒ Object
79 80 81 |
# File 'lib/fog/oraclecloud/soa.rb', line 79 def username @username end |