Class: Fog::OracleCloud::Database::Mock
- Inherits:
-
Object
- Object
- Fog::OracleCloud::Database::Mock
- Defined in:
- lib/fog/oraclecloud/database.rb,
lib/fog/oraclecloud/requests/database/get_instance.rb,
lib/fog/oraclecloud/requests/database/get_snapshot.rb,
lib/fog/oraclecloud/requests/database/list_backups.rb,
lib/fog/oraclecloud/requests/database/list_patches.rb,
lib/fog/oraclecloud/requests/database/list_servers.rb,
lib/fog/oraclecloud/requests/database/list_instances.rb,
lib/fog/oraclecloud/requests/database/list_snapshots.rb,
lib/fog/oraclecloud/requests/database/scale_instance.rb,
lib/fog/oraclecloud/requests/database/backup_instance.rb,
lib/fog/oraclecloud/requests/database/create_instance.rb,
lib/fog/oraclecloud/requests/database/create_snapshot.rb,
lib/fog/oraclecloud/requests/database/delete_instance.rb,
lib/fog/oraclecloud/requests/database/delete_snapshot.rb,
lib/fog/oraclecloud/requests/database/list_recoveries.rb,
lib/fog/oraclecloud/requests/database/recover_instance.rb
Class Method Summary collapse
Instance Method Summary collapse
- #backup_instance(service_name) ⇒ Object
- #create_instance(config, options) ⇒ Object
- #create_snapshot(name, description, database_id) ⇒ Object
- #data ⇒ Object
- #delete_instance(name) ⇒ Object
- #delete_snapshot(db_name, snapshot_name) ⇒ Object
- #get_instance(name) ⇒ Object
- #get_snapshot(db_name, snapshot_name) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_backups(db_name) ⇒ Object
- #list_instances ⇒ Object
- #list_patches(db_name) ⇒ Object
- #list_recoveries(db_name) ⇒ Object
- #list_servers(db_name) ⇒ Object
- #list_snapshots(db_name) ⇒ Object
- #password ⇒ Object
- #recover_instance(service_name, type = nil, value = nil) ⇒ Object
- #scale_instance(name, options = {}) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
90 91 92 93 94 |
# File 'lib/fog/oraclecloud/database.rb', line 90 def initialize(={}) @username = [:oracle_username] @password = [:oracle_password] @identity_domain = [:oracle_domain] end |
Class Method Details
.data ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/fog/oraclecloud/database.rb', line 104 def self.data @data ||= { :instances => {}, :snapshots => {}, :servers => {}, :backups => {}, :recoveries => {}, :deleted_at => {}, :created_at => {}, :maintenance_at => {} } end |
.reset ⇒ Object
117 118 119 |
# File 'lib/fog/oraclecloud/database.rb', line 117 def self.reset @data = nil end |
Instance Method Details
#backup_instance(service_name) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fog/oraclecloud/requests/database/backup_instance.rb', line 22 def backup_instance(service_name) response = Excon::Response.new if !self.data[:backups][service_name].is_a? Array self.data[:backups][service_name] = [] end self.data[:backups][service_name].push({ 'backupCompleteDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'), 'dbTag'=>'TAG' + Time.now.strftime('%Y%m%dT%H%M%S'), 'status'=>'IN PROGRESS', 'database_id'=>service_name }) if !self.data[:created_at][:backups] self.data[:created_at][:backups] = {} self.data[:created_at][:backups][service_name] = [] end self.data[:created_at][:backups][service_name].push(Time.now) response.status = 202 response end |
#create_instance(config, options) ⇒ Object
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fog/oraclecloud/requests/database/create_instance.rb', line 50 def create_instance(config, ) response = Excon::Response.new data = { 'serviceName' => config[:service_name], 'shape' => config[:shape], 'edition' => config[:edition], 'version' => config[:version], 'status' => 'In Progress', 'charset' => 'AL32UTF8', 'ncharset' => 'AL16UTF16', 'pdbName' => 'pdb1', # Note this is only valid for 12c instances. Too hard to fix for mocking 'timezone' => 'UTC', 'totalSharedStorage' => [:usable_storage], 'domainName' => @identity_domain, 'creation_date'=>Time.now.strftime('%Y-%b-%dT%H:%M:%S'), 'serviceType'=>'DBaaS', 'creator'=>@username } .merge(config.select {|key, value| [:description, :level, :subscription_type].include?(key) }) .merge(.select {|key, value| [:backup_destination, :failover_database, :cloud_storage_container, :is_rac, :ncharset, :pdb_name, :sid, :timezone].include?(key) }) self.data[:instances][config[:service_name]] = data self.data[:created_at][config[:service_name]] = Time.now # Also create some compute nodes node = { "status"=>"Running", "creation_job_id"=>"5495118", "creation_time"=>"Tue Jun 28 23:52:45 UTC 2016", "created_by"=>"dbaasadmin", "shape"=>"oc4", "sid"=>"ORCL1", "pdbName"=>"PDB1", "listenerPort"=> 1521, "connect_descriptor"=>"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=db12c-xp-rac2)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=db12c-xp-rac1)(PORT=1521))(LOAD_BALANCE=ON)(FAILOVER=ON))(CONNECT_DATA=(SERVICE_NAME=PDB1.usexample.oraclecloud.internal)))", "connect_descriptor_with_public_ip"=>"(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=129.144.23.176)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=129.144.23.112)(PORT=1521))(LOAD_BALANCE=ON)(FAILOVER=ON))(CONNECT_DATA=(SERVICE_NAME=PDB1.usexample.oraclecloud.internal)))", "initialPrimary"=> true, "storageAllocated"=> 97280, "reservedIP"=>"129.144.23.112", "hostname"=>"db12c-xp-rac1" } self.data[:servers][config[:service_name]] = [node] response.status = 202 response end |
#create_snapshot(name, description, database_id) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fog/oraclecloud/requests/database/create_snapshot.rb', line 26 def create_snapshot(name, description, database_id) response = Excon::Response.new data = { 'name' => name, 'description' => description, 'creationTime' => Time.now, 'clonedServicesSize' => 1, 'status'=>'In Progress', 'database_id'=>database_id, 'clonedServices'=>[{ 'clonedServiceName'=>'ClonedService1', 'clonedServiceCreationTime'=> Time.now }] } if !self.data[:snapshots].key?(database_id) then self.data[:snapshots][database_id] = {} end self.data[:snapshots][database_id][name] = data self.data[:created_at][name] = Time.now response.status = 202 response end |
#data ⇒ Object
121 122 123 |
# File 'lib/fog/oraclecloud/database.rb', line 121 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 |
#delete_snapshot(db_name, snapshot_name) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/fog/oraclecloud/requests/database/delete_snapshot.rb', line 16 def delete_snapshot(db_name, snapshot_name) response = Excon::Response.new self.data[:snapshots][db_name][snapshot_name]['status'] = 'Terminating' self.data[:deleted_at][snapshot_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 41 42 43 44 45 46 47 |
# 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 when 'Maintenance' info = self.data[:maintenance_at][name] if Time.now - info['time'] >= Fog::Mock.delay self.data[:instances][name]['status'] = 'Running' self.data[:instances][name][info['attribute']] = info['value'] self.data[:maintenance_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 |
#get_snapshot(db_name, snapshot_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_snapshot.rb', line 17 def get_snapshot(db_name, snapshot_name) response = Excon::Response.new if snapshot = self.data[:snapshots][db_name][snapshot_name] case snapshot['status'] when 'Terminating' if Time.now - self.data[:deleted_at][snapshot_name] >= Fog::Mock.delay self.data[:deleted_at].delete(snapshot_name) self.data[:snapshots][db_name].delete(snapshot_name) end when 'In Progress' if Time.now - self.data[:created_at][snapshot_name] >= Fog::Mock.delay self.data[:snapshots][db_name][snapshot_name]['status'] = 'Succeeded' snapshot = self.data[:snapshots][db_name][snapshot_name] self.data[:created_at].delete(snapshot_name) end end response.status = 200 response.body = snapshot response else raise Fog::OracleCloud::Database::NotFound.new("Snapshot #{snapshot_name} for #{db_name} does not exist"); end end |
#list_backups(db_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fog/oraclecloud/requests/database/list_backups.rb', line 16 def list_backups(db_name) response = Excon::Response.new if !self.data[:backups][db_name] then self.data[:backups][db_name] = [] end backups = self.data[:backups][db_name] backups.each_with_index { |b, i| if b['status'] = 'IN PROGRESS' then if Time.now - self.data[:created_at][:backups][db_name][i] >= Fog::Mock.delay self.data[:created_at][:backups][db_name].delete(i) self.data[:backups][db_name][i]['status'] = 'COMPLETED' b = self.data[:backups][db_name][i] end end } response.body = { 'backupList' => backups } response end |
#list_instances ⇒ Object
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 |
#list_patches(db_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fog/oraclecloud/requests/database/list_patches.rb', line 16 def list_patches(db_name) response = Excon::Response.new # Fake a patch response.body = { 'availablePatches' => [{ "patchId"=>"23054246-SE", "patchNumber"=>"Patch_12.1.0.2.160719_SE", "patchCategory"=>"DB", "patchSeverity"=>"Normal", "includesConfigUpgrade"=>false, "patchDescription"=>"DB 12.1.0.2.160719 Jul 2016 PSU Standard Edition image", "patchReleaseUrl"=>"https://support.oracle.com/epmos/faces/PatchDetail?patchId=23054246", "serviceType"=>"DBaaS", "serviceVersion"=>"12.1.0.2", "releaseDate"=>"2016-07-16T01:40:00.000+0000", "entryDate"=>"2016-10-07T20:57:33.121+0000", "entryUserId"=>"OCLOUD9_SM_PLATFORM_APPID", "patchType"=>"PSU", "requiresRestart"=> true, "serviceTypeVersions"=>"ANY", "isDeleted"=> false, "isCustomerVisible"=> false, "isAutoApply"=> false, "induceDownTime"=> false, "displayName"=>"12.1.0.2.160719", "releaseVersion"=>"12.1.0.2.160719", "serviceEditions"=>"SE", }] } response end |
#list_recoveries(db_name) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/oraclecloud/requests/database/list_recoveries.rb', line 16 def list_recoveries(db_name) response = Excon::Response.new if !self.data[:recoveries][db_name] then self.data[:recoveries][db_name] = [] end recoveries = self.data[:recoveries][db_name] recoveries.each_with_index { |r, i| if r['status'] = 'IN PROGRESS' then if Time.now - self.data[:created_at][:recoveries][db_name][i] >= Fog::Mock.delay self.data[:created_at][:recoveries][db_name].delete(i) self.data[:recoveries][db_name][i]['status'] = 'COMPLETED' self.data[:recoveries][db_name][i]['recoveryCompleteDate'] = Time.now.strftime('%d-%b-%Y %H:%M:%S UTC') b = self.data[:backups][db_name][i] end end } response.body = { 'recoveryList' => recoveries } response end |
#list_servers(db_name) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fog/oraclecloud/requests/database/list_servers.rb', line 16 def list_servers(db_name) response = Excon::Response.new servers = self.data[:servers][db_name] response.body = servers response end |
#list_snapshots(db_name) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/fog/oraclecloud/requests/database/list_snapshots.rb', line 16 def list_snapshots(db_name) response = Excon::Response.new snapshots = self.data[:snapshots][db_name].values response.body = snapshots response end |
#password ⇒ Object
100 101 102 |
# File 'lib/fog/oraclecloud/database.rb', line 100 def password @password end |
#recover_instance(service_name, type = nil, value = nil) ⇒ Object
24 25 26 27 28 29 30 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 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/fog/oraclecloud/requests/database/recover_instance.rb', line 24 def recover_instance(service_name, type=nil, value=nil) response = Excon::Response.new if !self.data[:recoveries][service_name].is_a? Array then self.data[:recoveries][service_name] = [] end if !self.data[:created_at][:recoveries] self.data[:created_at][:recoveries] = {} self.data[:created_at][:recoveries][service_name] = [] end # Find the backup first backups = self.data[:backups][service_name] backup = nil if type == 'tag' then backup = backups.find { |b| b['dbTag'] = value } elsif type == 'timestamp' then # Too hard to do this logic in mock. Just return the latest backup = backups.last elsif type.nil? then # Default to searching for the latest backup = backups.last end if backup.nil? then response.status = 500 else if type == 'tag' then self.data[:recoveries][service_name].push({ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'), 'status'=>'IN PROGRESS', 'dbTag'=>value, 'database_id' => service_name }) self.data[:created_at][:recoveries][service_name].push(Time.now) elsif type == 'timestamp' then self.data[:recoveries][service_name].push({ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'), 'status'=>'IN PROGRESS', 'timestamp'=>value.strftime('%d-%b-%Y %H:%M:%S'), 'database_id' => service_name }) self.data[:created_at][:recoveries][service_name].push(Time.now) elsif type.nil? then self.data[:recoveries][service_name].push({ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'), 'status'=>'IN PROGRESS', 'latest'=>true, 'database_id' => service_name }) self.data[:created_at][:recoveries][service_name].push(Time.now) end response.status = 202 end response end |
#scale_instance(name, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/oraclecloud/requests/database/scale_instance.rb', line 24 def scale_instance(name, ={}) response = Excon::Response.new self.data[:instances][name]['status'] = 'Maintenance' info = { 'time'=> Time.now } if ([:shape]) then info['attribute'] = 'shape' info['value'] = [:shape] end self.data[:maintenance_at][name] = info response.status = 202 response end |
#username ⇒ Object
96 97 98 |
# File 'lib/fog/oraclecloud/database.rb', line 96 def username @username end |