Class: Fog::OracleCloud::Java::Mock
- Inherits:
-
Object
- Object
- Fog::OracleCloud::Java::Mock
- Defined in:
- lib/fog/oraclecloud/java.rb,
lib/fog/oraclecloud/requests/java/get_instance.rb,
lib/fog/oraclecloud/requests/java/list_servers.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
- #create_instance(config, options) ⇒ Object
- #data ⇒ Object
- #delete_instance(name, dba_name, dba_password, options = {}) ⇒ Object
- #get_instance(name) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_instances ⇒ Object
- #list_servers(db_name) ⇒ Object
- #password ⇒ Object
- #region_url ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
71 72 73 74 75 76 |
# File 'lib/fog/oraclecloud/java.rb', line 71 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
90 91 92 93 94 95 96 97 |
# File 'lib/fog/oraclecloud/java.rb', line 90 def self.data @data ||= { :instances => {}, :servers => {}, :deleted_at => {}, :created_at => {} } end |
.reset ⇒ Object
99 100 101 |
# File 'lib/fog/oraclecloud/java.rb', line 99 def self.reset @data = nil end |
Instance Method Details
#create_instance(config, options) ⇒ Object
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fog/oraclecloud/requests/java/create_instance.rb', line 32 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'), 'db_info' => "#{options[:dbServiceName]}:1521/#{options[:pdbName] || 'PDB1'}.#{@identity_domain}.oraclecloud.internal", 'deletion_job_id' => 0, 'domainMode'=>'DEVELOPMENT', 'fmw_control_url'=> "https://#{ip}:#{options[:adminPort] || 7002}/em", 'last_modified_time'=> Time.now.strftime('%Y-%b-%dT%H:%M:%S'), 'num_ip_reservations'=> 2, # Can't rely on this number in mocking mode 'num_nodes'=>[:managedServerCount], 'otd_provisioned'=>[:provisionOTD] || 'no', 'psm_plugin_version'=>"16.3.5-532", 'secure_content_url' => "https://#{ip}", 'service_type'=>'jaas', 'service_uri'=>"#{@region_url}/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{config[:serviceName]}", 'wls_admin_url'=> "https://#{ip}:#{options[:adminPort] || 7002}/console", 'wls_deployment_channel_port' => [:deploymentChannelPort] || 9001, 'wlsVersion'=>'12.2.1.0.160419' } .merge(config.select {|key, value| [:serviceName, :description, :level, :subscriptionType].include?(key) }) .merge(.select {|key, value| [:clusterName, :dbServiceName, :edition, :shape, :version].include?(key) }).collect{|k,v| [k.to_s, v]}.to_h if data['clusterName'].nil? then data['clusterName'] = data['serviceName'][0,8] + "_cluster" end if data['domainName'].nil? then data['domainName'] = data['serviceName'][0,8] + "_domain" end self.data[:instances][config[:serviceName]] = data self.data[:created_at][config[:serviceName]] = Time.now server = { "clusterName": data['clusterName'] || data['serviceName'][0,8] + "_cluster", "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
103 104 105 |
# File 'lib/fog/oraclecloud/java.rb', line 103 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, ={}) 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_instances ⇒ Object
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 |
#list_servers(db_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fog/oraclecloud/requests/java/list_servers.rb', line 16 def list_servers(db_name) response = Excon::Response.new servers = self.data[:servers][db_name] response.body = { 'servers' => servers } response end |
#password ⇒ Object
82 83 84 |
# File 'lib/fog/oraclecloud/java.rb', line 82 def password @password end |
#region_url ⇒ Object
86 87 88 |
# File 'lib/fog/oraclecloud/java.rb', line 86 def region_url @region_url end |
#username ⇒ Object
78 79 80 |
# File 'lib/fog/oraclecloud/java.rb', line 78 def username @username end |