fog-oraclecloud 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/oraclecloud/database.rb +28 -2
  3. data/lib/fog/oraclecloud/models/database/backup.rb +37 -0
  4. data/lib/fog/oraclecloud/models/database/backups.rb +30 -0
  5. data/lib/fog/oraclecloud/models/database/instance.rb +63 -2
  6. data/lib/fog/oraclecloud/models/database/patch.rb +34 -0
  7. data/lib/fog/oraclecloud/models/database/patches.rb +18 -0
  8. data/lib/fog/oraclecloud/models/database/recoveries.rb +26 -0
  9. data/lib/fog/oraclecloud/models/database/recovery.rb +43 -0
  10. data/lib/fog/oraclecloud/models/database/server.rb +28 -0
  11. data/lib/fog/oraclecloud/models/database/servers.rb +18 -0
  12. data/lib/fog/oraclecloud/models/database/snapshot.rb +60 -0
  13. data/lib/fog/oraclecloud/models/database/snapshots.rb +22 -0
  14. data/lib/fog/oraclecloud/requests/database/backup_instance.rb +42 -0
  15. data/lib/fog/oraclecloud/requests/database/create_instance.rb +20 -0
  16. data/lib/fog/oraclecloud/requests/database/create_snapshot.rb +50 -0
  17. data/lib/fog/oraclecloud/requests/database/delete_snapshot.rb +26 -0
  18. data/lib/fog/oraclecloud/requests/database/get_instance.rb +7 -0
  19. data/lib/fog/oraclecloud/requests/database/get_snapshot.rb +44 -0
  20. data/lib/fog/oraclecloud/requests/database/list_backups.rb +37 -0
  21. data/lib/fog/oraclecloud/requests/database/list_patches.rb +51 -0
  22. data/lib/fog/oraclecloud/requests/database/list_recoveries.rb +38 -0
  23. data/lib/fog/oraclecloud/requests/database/list_servers.rb +27 -0
  24. data/lib/fog/oraclecloud/requests/database/list_snapshots.rb +27 -0
  25. data/lib/fog/oraclecloud/requests/database/recover_instance.rb +80 -0
  26. data/lib/fog/oraclecloud/requests/database/scale_instance.rb +40 -0
  27. data/lib/fog/oraclecloud/version.rb +1 -1
  28. data/tests/requests/database_tests.rb +165 -0
  29. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfdb853230afc1e89dba20e81a39ef494234917f
4
- data.tar.gz: 757d5807cbb9f31ec133be9821a51d6b0b6c8cff
3
+ metadata.gz: a4517e556687acd69faa9807cc250d1830eb0624
4
+ data.tar.gz: 86091d93411468a2face694fffbf86f883919910
5
5
  SHA512:
6
- metadata.gz: 060f7511d4454b87de04176b24488db21088b81a1568faeee3920499af9a928f6f0138f75d36e369e1f401c9641a0c57a0f252f0931faf4fee18cc4da0535e6f
7
- data.tar.gz: 83395c4a62880b05ff56f18c854538a8c2df526489e2965fb060ff2a65ea0055f4221dbba70c6677a98811c67ba0d01603113bdcf0e09417396c6ed1d9c71070
6
+ metadata.gz: e9741aad0ade9bb060e7011f675c51bb9d12a1c56067abc405600b4d1057bc4d32c87e85a0fad0bee43300cfe3700a78fbacc03dcb4089156b814b098e6d0e03
7
+ data.tar.gz: 8f3c6713655cb0f9f4594a752c396350bb9807b99ddd2174b1252d2673b7fed020e087dfa2ba2672a327185e4248ec92d9a9635f3e7a77257eb5b86bd9493108
@@ -6,12 +6,33 @@ module Fog
6
6
  model_path 'fog/oraclecloud/models/database'
7
7
  model :instance
8
8
  collection :instances
9
+ model :backup
10
+ collection :backups
11
+ model :recovery
12
+ collection :recoveries
13
+ model :snapshot
14
+ collection :snapshots
15
+ model :server
16
+ collection :servers
17
+ model :patch
18
+ collection :patches
9
19
 
10
20
  request_path 'fog/oraclecloud/requests/database'
11
21
  request :list_instances
12
22
  request :get_instance
13
23
  request :create_instance
14
24
  request :delete_instance
25
+ request :list_backups
26
+ request :list_recoveries
27
+ request :list_snapshots
28
+ request :get_snapshot
29
+ request :create_snapshot
30
+ request :delete_snapshot
31
+ request :list_servers
32
+ request :scale_instance
33
+ request :backup_instance
34
+ request :recover_instance
35
+ request :list_patches
15
36
 
16
37
  class Real
17
38
 
@@ -66,9 +87,14 @@ module Fog
66
87
 
67
88
  def self.data
68
89
  @data ||= {
69
- :instances => {},
90
+ :instances => {},
91
+ :snapshots => {},
92
+ :servers => {},
93
+ :backups => {},
94
+ :recoveries => {},
70
95
  :deleted_at => {},
71
- :created_at => {}
96
+ :created_at => {},
97
+ :maintenance_at => {}
72
98
  }
73
99
  end
74
100
 
@@ -0,0 +1,37 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Backup < Fog::Model
7
+ identity :db_tag, :aliases=>'dbTag'
8
+
9
+ attribute :backup_complete_date, :aliases=>'backupCompleteDate'
10
+ attribute :status
11
+ attribute :database_id
12
+
13
+ def completed?
14
+ status == "COMPLETED"
15
+ end
16
+
17
+ private
18
+
19
+ # Had to override reload as we need to pass the database_id
20
+ def reload
21
+ requires :identity, :database_id
22
+
23
+ data = begin
24
+ collection.get(database_id, identity)
25
+ rescue Excon::Errors::SocketError
26
+ nil
27
+ end
28
+ return unless data
29
+
30
+ new_attributes = data.attributes
31
+ merge_attributes(new_attributes)
32
+ self
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Backups < Fog::Collection
7
+
8
+ model Fog::OracleCloud::Database::Backup
9
+
10
+ def all(db_name)
11
+ data = service.list_backups(db_name).body['backupList']
12
+ load(data)
13
+ end
14
+
15
+ # There is no get service for backups in the Oracle Cloud
16
+ # Call the list and extract the backup given a tag
17
+ def get(db_name, tag)
18
+ data = {}
19
+ service.list_backups(db_name).body['backupList'].each { |b|
20
+ if b['dbTag'] == tag then
21
+ data = b
22
+ end
23
+ }
24
+ new(data)
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -39,8 +39,6 @@ module Fog
39
39
  attribute :compute_site_name
40
40
 
41
41
  # The following are only used to create an instance and are not returned in the list action
42
- attribute :level
43
- attribute :subscriptionType
44
42
  attribute :vmPublicKey
45
43
  attribute :parameters
46
44
 
@@ -75,6 +73,69 @@ module Fog
75
73
  service.delete_instance(service_name).body
76
74
  end
77
75
 
76
+ def scale(shape)
77
+ requires :service_name
78
+ service.scale_instance(service_name, :shape=>shape).body
79
+ end
80
+
81
+ def add_storage(size)
82
+ requires :service_name
83
+ service.scale_instance(service_name, :additional_storage=>size).body
84
+ end
85
+
86
+ def expand_storage(size, type=nil)
87
+ requires :service_name
88
+ if type.nil? then type = 'data' end
89
+ if type == 'backup' then type ='fra' end
90
+ service.scale_instance(service_name, :additional_storage=>size, :usage=>type).body
91
+ end
92
+
93
+ def snapshots
94
+ requires :service_name
95
+ service.snapshots.all(service_name)
96
+ end
97
+
98
+ def get_snapshot(snapshot_name)
99
+ requires :service_name
100
+ service.snapshots.get(service_name, snapshot_name)
101
+ end
102
+
103
+ def servers
104
+ requires :service_name
105
+ service.servers.all(service_name)
106
+ end
107
+
108
+ def backup
109
+ requires :service_name
110
+ service.backup_instance(service_name)
111
+ end
112
+
113
+ def backups
114
+ requires :service_name
115
+ service.backups.all(service_name)
116
+ end
117
+
118
+ def recover(type, value)
119
+ # Valid types are 'scn', 'tag' or 'timestamp'
120
+ requires :service_name
121
+ service.recover_instance(service_name, type, value)
122
+ end
123
+
124
+ def recover_latest
125
+ requires :service_name
126
+ service.recover_instance(service_name)
127
+ end
128
+
129
+ def recoveries
130
+ requires :service_name
131
+ service.recoveries.all(service_name)
132
+ end
133
+
134
+ def patches
135
+ requires :service_name
136
+ service.patches.all(service_name)
137
+ end
138
+
78
139
  private
79
140
 
80
141
  def create
@@ -0,0 +1,34 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Patch < Fog::Model
7
+ identity :id, :aliases=>'patchId'
8
+
9
+ attribute :number, :aliases=>'patchNumber'
10
+ attribute :category, :aliases=>'patchCategory'
11
+ attribute :severity, :aliases=>'patchSeverity'
12
+ attribute :includes_config_upgrade, :aliases=>'includesConfigUpgrade'
13
+ attribute :description, :aliases=>'patchDescription'
14
+ attribute :release_url, :aliases=>'patchReleaseUrl'
15
+ attribute :service_type, :aliases=>'serviceType'
16
+ attribute :service_version, :aliases=>'serviceVersion'
17
+ attribute :release_date, :aliases=>'releaseDate'
18
+ attribute :entry_date, :aliases=>'entryDate'
19
+ attribute :entry_user_id, :aliases=>'entryUserId'
20
+ attribute :patch_type, :aliases=>'patchType'
21
+ attribute :requires_restart, :aliases=>'requiresRestart'
22
+ attribute :is_deleted, :aliases=>'isDeleted'
23
+ attribute :is_customer_visible, :aliases=>'isCustomerVisible'
24
+ attribute :is_auto_apply, :aliases=>'isAutoApply'
25
+ attribute :induce_down_time, :aliases=>'induceDownTime'
26
+ attribute :display_name, :aliases=>'displayName'
27
+ attribute :release_version, :aliases=>'releaseVersion'
28
+ attribute :service_editions, :aliases=>'serviceEditions'
29
+
30
+
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,18 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Patches < Fog::Collection
7
+
8
+ model Fog::OracleCloud::Database::Patch
9
+
10
+ def all(db_name)
11
+ data = service.list_patches(db_name).body['availablePatches']
12
+ load(data)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Recoveries < Fog::Collection
7
+
8
+ model Fog::OracleCloud::Database::Recovery
9
+
10
+ def all(db_name)
11
+ data = service.list_recoveries(db_name).body['recoveryList']
12
+ load(data)
13
+ end
14
+
15
+ # There is no get service for recoveries in the Oracle Cloud
16
+ # Call the list and extract the recovery
17
+ def get(db_name, type=nil, value=nil)
18
+ clean_type = 'dbTag' if type == 'tag'
19
+ clean_type, value = ['latest', true] if type.nil?
20
+ data = service.list_recoveries(db_name).body['recoveryList'].find { |r| r[clean_type] == value }
21
+ new(data)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Recovery < Fog::Model
7
+
8
+ attribute :db_tag, :aliases=>'dbTag'
9
+ attribute :recovery_start_date, :aliases=>'recoveryStartDate'
10
+ attribute :recovery_complete_date, :aliases=>'recoveryCompleteDate'
11
+ attribute :status
12
+ attribute :latest
13
+ attribute :timestamp
14
+ attribute :database_id
15
+
16
+ def completed?
17
+ status == "COMPLETED"
18
+ end
19
+
20
+ private
21
+
22
+ def reload
23
+ requires :database_id
24
+
25
+ data = begin
26
+ if !db_tag.nil? then
27
+ collection.get(database_id, 'tag', db_tag)
28
+ else
29
+ collection.get(database_id)
30
+ end
31
+ rescue Excon::Errors::SocketError
32
+ nil
33
+ end
34
+ return unless data
35
+
36
+ new_attributes = data.attributes
37
+ merge_attributes(new_attributes)
38
+ self
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,28 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Server < Fog::Model
7
+ identity :hostname
8
+
9
+ attribute :connect_descriptor
10
+ attribute :connect_descriptor_with_public_ip
11
+ attribute :created_by
12
+ attribute :creation_job_id
13
+ attribute :creation_time
14
+ attribute :initial_primary, :aliases=>'initialPrimary'
15
+ attribute :listener_port, :aliases=>'listenerPort'
16
+ attribute :pdb_name, :aliases=>'pdbName'
17
+ attribute :reserved_ip, :aliases=>'reservedIP'
18
+ attribute :shape
19
+ attribute :sid
20
+ attribute :status
21
+ attribute :storage_allocated, :aliases=>'storageAllocated'
22
+
23
+ private
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Servers < Fog::Collection
7
+
8
+ model Fog::OracleCloud::Database::Server
9
+
10
+ def all(db_name)
11
+ data = service.list_servers(db_name).body
12
+ load(data)
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,60 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Snapshot < Fog::Model
7
+ identity :name
8
+
9
+ attribute :cloned_services_size, :aliases=>'clonedServicesSize'
10
+ attribute :creation_time, :aliases=>'creationTime'
11
+ attribute :cloned_services, :aliases=>'clonedServices'
12
+ attribute :status
13
+ attribute :description
14
+
15
+ attribute :database_id
16
+
17
+ def completed?
18
+ status == "Succeeded"
19
+ end
20
+
21
+ def deleting?
22
+ status == "Terminating"
23
+ end
24
+
25
+ def save
26
+ create
27
+ end
28
+
29
+ def destroy
30
+ requires :name, :database_id
31
+ service.delete_snapshot(database_id, name).body
32
+ end
33
+
34
+ # Had to override snapshot as we need to pass the database_id
35
+ def reload
36
+ requires :identity, :database_id
37
+
38
+ data = begin
39
+ collection.get(database_id, identity)
40
+ rescue Excon::Errors::SocketError
41
+ nil
42
+ end
43
+
44
+ return unless data
45
+
46
+ new_attributes = data.attributes
47
+ merge_attributes(new_attributes)
48
+ self
49
+ end
50
+
51
+ private
52
+
53
+ def create
54
+ requires :name, :description, :database_id
55
+ data = service.create_snapshot(name, description, database_id)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,22 @@
1
+ require 'fog/core/collection'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Snapshots < Fog::Collection
7
+
8
+ model Fog::OracleCloud::Database::Snapshot
9
+
10
+ def all(db_name)
11
+ data = service.list_snapshots(db_name).body
12
+ load(data)
13
+ end
14
+
15
+ def get(db_name, snapshot_name)
16
+ new(service.get_snapshot(db_name, snapshot_name).body)
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def backup_instance(service_name)
7
+ # Oracle Cloud requires an empty JSON object in the body
8
+ body_data = {}
9
+
10
+ response = request(
11
+ :method => 'POST',
12
+ :expects => 202,
13
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/backups",
14
+ :body => Fog::JSON.encode(body_data),
15
+ )
16
+ response.database_id = service_name
17
+ response
18
+ end
19
+ end
20
+
21
+ class Mock
22
+ def backup_instance(service_name)
23
+ response = Excon::Response.new
24
+
25
+ if !self.data[:backups][service_name].is_a? Array then
26
+ self.data[:backups][service_name] = []
27
+ self.data[:created_at][service_name] = []
28
+ end
29
+ self.data[:backups][service_name].push({
30
+ 'backupCompleteDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'),
31
+ 'dbTag'=>'TAG' + Time.now.strftime('%Y%m%dT%H%M%S'),
32
+ 'status'=>'IN PROGRESS',
33
+ 'database_id'=>service_name
34
+ })
35
+ self.data[:created_at][service_name].push(Time.now)
36
+ response.status = 202
37
+ response
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -47,6 +47,26 @@ module Fog
47
47
 
48
48
  self.data[:instances][service_name] = data
49
49
  self.data[:created_at][service_name] = Time.now
50
+
51
+ # Also create some compute nodes
52
+ node = {
53
+ "status"=>"Running",
54
+ "creation_job_id"=>"5495118",
55
+ "creation_time"=>"Tue Jun 28 23:52:45 UTC 2016",
56
+ "created_by"=>"dbaasadmin",
57
+ "shape"=>"oc4",
58
+ "sid"=>"ORCL1",
59
+ "pdbName"=>"PDB1",
60
+ "listenerPort"=> 1521,
61
+ "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)))",
62
+ "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)))",
63
+ "initialPrimary"=> true,
64
+ "storageAllocated"=> 97280,
65
+ "reservedIP"=>"129.144.23.112",
66
+ "hostname"=>"db12c-xp-rac1"
67
+ }
68
+ self.data[:servers][service_name] = [node]
69
+
50
70
  response.status = 202
51
71
  response
52
72
  end
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def create_snapshot(name, description, database_id)
7
+ body_data = {
8
+ 'name' => name,
9
+ 'description' => description
10
+ }
11
+ body_data = body_data.reject {|key, value| value.nil?}
12
+
13
+ response = request(
14
+ :method => 'POST',
15
+ :expects => 202,
16
+ :path => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/dbaas/instances/#{database_id}/snapshots",
17
+ :body => Fog::JSON.encode(body_data),
18
+ )
19
+ # Store the database reference in the model, so that we can use it later
20
+ response.database_id = service_name
21
+ response
22
+ end
23
+ end
24
+
25
+ class Mock
26
+ def create_snapshot(name, description, database_id)
27
+ response = Excon::Response.new
28
+
29
+ data = {
30
+ 'name' => name,
31
+ 'description' => description,
32
+ 'creationTime' => Time.now,
33
+ 'clonedServicesSize' => 1,
34
+ 'status'=>'In Progress',
35
+ 'database_id'=>database_id,
36
+ 'clonedServices'=>[{
37
+ 'clonedServiceName'=>'ClonedService1',
38
+ 'clonedServiceCreationTime'=> Time.now
39
+ }]
40
+ }
41
+ if !self.data[:snapshots].key?(database_id) then self.data[:snapshots][database_id] = {} end
42
+ self.data[:snapshots][database_id][name] = data
43
+ self.data[:created_at][name] = Time.now
44
+ response.status = 202
45
+ response
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def delete_snapshot(db_name, snapshot_name)
7
+ request(
8
+ :method => 'DELETE',
9
+ :expects => 202,
10
+ :path => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/dbaas/instances/#{db_name}/snapshots/#{snapshot_name}"
11
+ )
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def delete_snapshot(db_name, snapshot_name)
17
+ response = Excon::Response.new
18
+ self.data[:snapshots][db_name][snapshot_name]['status'] = 'Terminating'
19
+ self.data[:deleted_at][snapshot_name] = Time.now
20
+ response.status = 204
21
+ response
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -30,6 +30,13 @@ module Fog
30
30
  instance = self.data[:instances][name]
31
31
  self.data[:created_at].delete(name)
32
32
  end
33
+ when 'Maintenance'
34
+ info = self.data[:maintenance_at][name]
35
+ if Time.now - info['time'] >= Fog::Mock.delay
36
+ self.data[:instances][name]['status'] = 'Running'
37
+ self.data[:instances][name][info['attribute']] = info['value']
38
+ self.data[:maintenance_at].delete(name)
39
+ end
33
40
  end
34
41
  response.status = 200
35
42
  response.body = instance
@@ -0,0 +1,44 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def get_snapshot(db_name, snapshot_name)
7
+ response = request(
8
+ :expects => 200,
9
+ :method => 'GET',
10
+ :path => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/dbaas/instances/#{db_name}/snapshots/#{snapshot_name}"
11
+ )
12
+ response
13
+ end
14
+ end
15
+
16
+ class Mock
17
+ def get_snapshot(db_name, snapshot_name)
18
+ response = Excon::Response.new
19
+
20
+ if snapshot = self.data[:snapshots][db_name][snapshot_name]
21
+ case snapshot['status']
22
+ when 'Terminating'
23
+ if Time.now - self.data[:deleted_at][snapshot_name] >= Fog::Mock.delay
24
+ self.data[:deleted_at].delete(snapshot_name)
25
+ self.data[:snapshots][db_name].delete(snapshot_name)
26
+ end
27
+ when 'In Progress'
28
+ if Time.now - self.data[:created_at][snapshot_name] >= Fog::Mock.delay
29
+ self.data[:snapshots][db_name][snapshot_name]['status'] = 'Succeeded'
30
+ snapshot = self.data[:snapshots][db_name][snapshot_name]
31
+ self.data[:created_at].delete(snapshot_name)
32
+ end
33
+ end
34
+ response.status = 200
35
+ response.body = snapshot
36
+ response
37
+ else
38
+ raise Fog::OracleCloud::Database::NotFound.new("Snapshot #{snapshot_name} for #{db_name} does not exist");
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,37 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+ def list_backups(db_name)
6
+ response = request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{db_name}/backups"
10
+ )
11
+ response
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_backups(db_name)
17
+ response = Excon::Response.new
18
+
19
+ backups = self.data[:backups][db_name]
20
+ backups.each_with_index { |b, i|
21
+ if b['status'] = 'IN PROGRESS' then
22
+ if Time.now - self.data[:created_at][db_name][i] >= Fog::Mock.delay
23
+ self.data[:created_at][db_name].delete(i)
24
+ self.data[:backups][db_name][i]['status'] = 'COMPLETED'
25
+ b = self.data[:backups][db_name][i]
26
+ end
27
+ end
28
+ }
29
+ response.body = {
30
+ 'backupList' => backups
31
+ }
32
+ response
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,51 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+ def list_patches(db_name)
6
+ response = request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{db_name}/patches"
10
+ )
11
+ response
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_patches(db_name)
17
+ response = Excon::Response.new
18
+
19
+ # Fake a patch
20
+ response.body = {
21
+ 'availablePatches' => [{
22
+ "patchId"=>"23054246-SE",
23
+ "patchNumber"=>"Patch_12.1.0.2.160719_SE",
24
+ "patchCategory"=>"DB",
25
+ "patchSeverity"=>"Normal",
26
+ "includesConfigUpgrade"=>false,
27
+ "patchDescription"=>"DB 12.1.0.2.160719 Jul 2016 PSU Standard Edition image",
28
+ "patchReleaseUrl"=>"https://support.oracle.com/epmos/faces/PatchDetail?patchId=23054246",
29
+ "serviceType"=>"DBaaS",
30
+ "serviceVersion"=>"12.1.0.2",
31
+ "releaseDate"=>"2016-07-16T01:40:00.000+0000",
32
+ "entryDate"=>"2016-10-07T20:57:33.121+0000",
33
+ "entryUserId"=>"OCLOUD9_SM_PLATFORM_APPID",
34
+ "patchType"=>"PSU",
35
+ "requiresRestart"=> true,
36
+ "serviceTypeVersions"=>"ANY",
37
+ "isDeleted"=> false,
38
+ "isCustomerVisible"=> false,
39
+ "isAutoApply"=> false,
40
+ "induceDownTime"=> false,
41
+ "displayName"=>"12.1.0.2.160719",
42
+ "releaseVersion"=>"12.1.0.2.160719",
43
+ "serviceEditions"=>"SE",
44
+ }]
45
+ }
46
+ response
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+ def list_recoveries(db_name)
6
+ response = request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{db_name}/backups/recovery/history"
10
+ )
11
+ response
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_recoveries(db_name)
17
+ response = Excon::Response.new
18
+
19
+ recoveries = self.data[:recoveries][db_name]
20
+ recoveries.each_with_index { |r, i|
21
+ if r['status'] = 'IN PROGRESS' then
22
+ if Time.now - self.data[:created_at][:recoveries][db_name][i] >= Fog::Mock.delay
23
+ self.data[:created_at][:recoveries][db_name].delete(i)
24
+ self.data[:recoveries][db_name][i]['status'] = 'COMPLETED'
25
+ self.data[:recoveries][db_name][i]['recoveryCompleteDate'] = Time.now.strftime('%d-%b-%Y %H:%M:%S UTC')
26
+ b = self.data[:backups][db_name][i]
27
+ end
28
+ end
29
+ }
30
+ response.body = {
31
+ 'recoveryList' => recoveries
32
+ }
33
+ response
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+ def list_servers(db_name)
6
+ response = request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{db_name}/servers"
10
+ )
11
+ response
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_servers(db_name)
17
+ response = Excon::Response.new
18
+
19
+ servers = self.data[:servers][db_name]
20
+
21
+ response.body = servers
22
+ response
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+ def list_snapshots(db_name)
6
+ response = request(
7
+ :expects => 200,
8
+ :method => 'GET',
9
+ :path => "/paas/api/v1.1/instancemgmt/#{@identity_domain}/services/dbaas/instances/#{db_name}/snapshots"
10
+ )
11
+ response
12
+ end
13
+ end
14
+
15
+ class Mock
16
+ def list_snapshots(db_name)
17
+ response = Excon::Response.new
18
+
19
+ snapshots = self.data[:snapshots][db_name].values
20
+
21
+ response.body = snapshots
22
+ response
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,80 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def recover_instance(service_name, type=nil, value=nil)
7
+ if type == 'latest' then body_data = { 'latest' => true } end
8
+ if type == 'tag' then body_data = { 'tag' => value } end
9
+ if type == 'timestamp' then body_data = { 'timestamp' => value } end
10
+ if type == 'scn' then body_data = { 'scn' => value } end
11
+
12
+ response = request(
13
+ :method => 'POST',
14
+ :expects => 202,
15
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{service_name}/backups/recovery",
16
+ :body => Fog::JSON.encode(body_data),
17
+ )
18
+ response.database_id = service_name
19
+ response
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def recover_instance(service_name, type=nil, value=nil)
25
+ response = Excon::Response.new
26
+
27
+ if !self.data[:recoveries][service_name].is_a? Array then
28
+ self.data[:recoveries][service_name] = []
29
+ self.data[:created_at][:recoveries] = {}
30
+ self.data[:created_at][:recoveries][service_name] = []
31
+ end
32
+
33
+ # Find the backup first
34
+ backups = self.data[:backups][service_name]
35
+ backup = nil
36
+ if type == 'tag' then
37
+ backup = backups.find { |b| b['dbTag'] = value }
38
+ elsif type == 'timestamp' then
39
+ # Too hard to do this logic in mock. Just return the latest
40
+ backup = backups.last
41
+ elsif type.nil? then
42
+ # Default to searching for the latest
43
+ backup = backups.last
44
+ end
45
+ if backup.nil? then
46
+ response.status = 500
47
+ else
48
+ if type == 'tag' then
49
+ self.data[:recoveries][service_name].push({
50
+ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'),
51
+ 'status'=>'IN PROGRESS',
52
+ 'dbTag'=>value,
53
+ 'database_id' => service_name
54
+ })
55
+ self.data[:created_at][:recoveries][service_name].push(Time.now)
56
+ elsif type == 'timestamp' then
57
+ self.data[:recoveries][service_name].push({
58
+ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'),
59
+ 'status'=>'IN PROGRESS',
60
+ 'timestamp'=>value.strftime('%d-%b-%Y %H:%M:%S'),
61
+ 'database_id' => service_name
62
+ })
63
+ self.data[:created_at][:recoveries][service_name].push(Time.now)
64
+ elsif type.nil? then
65
+ self.data[:recoveries][service_name].push({
66
+ 'recoveryStartDate'=>Time.now.strftime('%d-%b-%Y %H:%M:%S UTC'),
67
+ 'status'=>'IN PROGRESS',
68
+ 'latest'=>true,
69
+ 'database_id' => service_name
70
+ })
71
+ self.data[:created_at][:recoveries][service_name].push(Time.now)
72
+ end
73
+ response.status = 202
74
+ end
75
+ response
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,40 @@
1
+ module Fog
2
+ module OracleCloud
3
+ class Database
4
+ class Real
5
+
6
+ def scale_instance(name, options={})
7
+ body_data = {
8
+ 'shape' => options[:shape],
9
+ 'additionalStorage' => options[:additional_storage],
10
+ 'usage' => options[:usage]
11
+ }
12
+ body_data = body_data.reject {|key, value| value.nil?}
13
+
14
+ request(
15
+ :method => 'PUT',
16
+ :expects => 202,
17
+ :path => "/paas/service/dbcs/api/v1.1/instances/#{@identity_domain}/#{name}",
18
+ :body => Fog::JSON.encode(body_data),
19
+ )
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def scale_instance(name, options={})
25
+ response = Excon::Response.new
26
+
27
+ self.data[:instances][name]['status'] = 'Maintenance'
28
+ info = { 'time'=> Time.now }
29
+ if (options[:shape]) then
30
+ info['attribute'] = 'shape'
31
+ info['value'] = options[:shape]
32
+ end
33
+ self.data[:maintenance_at][name] = info
34
+ response.status = 202
35
+ response
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module OracleCloud
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -22,7 +22,30 @@ Shindo.tests('Fog::Database[oraclecloud] | database requests', 'database') do
22
22
 
23
23
  test "is built" do
24
24
  db.ready?
25
+ db.shape == 'oc3'
25
26
  end
27
+
28
+ test "scale up instance" do
29
+ db.scale('oc4')
30
+ db.wait_for { ready? }
31
+ db.shape == 'oc4'
32
+ end
33
+
34
+ test "can add extra storage" do
35
+ db.add_storage(1)
36
+ db.wait_for { ready? }
37
+ db.ready?
38
+ end
39
+
40
+ test "can expand storage" do
41
+ db.expand_storage(1)
42
+ db.wait_for { ready? }
43
+ db.ready?
44
+ db.expand_storage(1, 'backup')
45
+ db.wait_for { ready? }
46
+ db.ready?
47
+ end
48
+
26
49
  end
27
50
 
28
51
  tests('#database-read') do
@@ -43,6 +66,146 @@ Shindo.tests('Fog::Database[oraclecloud] | database requests', 'database') do
43
66
  test "should return an instance" do
44
67
  instance.service_name.is_a? String
45
68
  end
69
+ servers = instance.servers
70
+ test "should have compute nodes" do
71
+ servers.is_a? Array
72
+ servers.size >= 1
73
+ servers.first.status.is_a? String
74
+ end
75
+ end
76
+
77
+ tests("#database-backups-create", "create") do
78
+ instance = Fog::OracleCloud[:database].instances.first
79
+ instance.backup()
80
+ test "backup created" do
81
+ backups = instance.backups
82
+ backups.is_a? Array
83
+ backups.first.wait_for { completed? }
84
+ backups.first.completed?
85
+ end
86
+ end
87
+
88
+ tests("#database-backups", "backups") do
89
+ instance = Fog::OracleCloud[:database].instances.first
90
+ backups = instance.backups
91
+ test "should have backups" do
92
+ backups.is_a? Array
93
+ end
94
+ if backups.size >= 1 then
95
+ test "one of them should have completed" do
96
+ backups.size >= 1
97
+ backups.first.completed?
98
+ end
99
+ end
100
+ end
101
+
102
+ tests("#database-recoveries-create", "create") do
103
+ instance = Fog::OracleCloud[:database].instances.first
104
+ tag = instance.backups.first.db_tag
105
+ instance.recover('tag', tag)
106
+ recoveries = instance.recoveries
107
+ test "can recover by tag" do
108
+ recoveries.is_a? Array
109
+ rec = recoveries.find {|r| r.db_tag == tag}
110
+ rec.is_a? Fog::OracleCloud::Database::Recovery
111
+ rec.wait_for { completed? }
112
+ rec.recovery_complete_date.is_a? String
113
+ end
114
+ test "can recover by latest" do
115
+ instance.recover_latest()
116
+ rec = instance.recoveries.find {|r| !r.latest.nil? }
117
+ rec.is_a? Fog::OracleCloud::Database::Recovery
118
+ rec.latest
119
+ rec.wait_for { completed? }
120
+ rec.recovery_complete_date.is_a? String
121
+ end
122
+ test "can recover by timestamp" do
123
+ time = Time.now
124
+ instance.recover('timestamp', time)
125
+ rec = instance.recoveries.find {|r| !r.latest.nil? }
126
+ rec.is_a? Fog::OracleCloud::Database::Recovery
127
+ rec.timestamp == time
128
+ rec.wait_for { completed? }
129
+ rec.recovery_complete_date.is_a? String
130
+ end
131
+ # Need to test SCN. Not sure how to mock test this?
132
+ end
133
+
134
+ tests("#database-recoveries", "recoveries") do
135
+ instances = Fog::OracleCloud[:database].instances
136
+ recs = Fog::OracleCloud[:database].recoveries.all(instances.first.service_name)
137
+ test "might have recoveries" do
138
+ recs.is_a? Array
139
+ end
140
+ if recs.size >= 1 then
141
+ test "one of them should have completed" do
142
+ recs.first.completed?
143
+ end
144
+ end
145
+ end
146
+
147
+ tests("#database-snapshots-create", "create") do
148
+ instances = Fog::OracleCloud[:database].instances
149
+
150
+ snap = Fog::OracleCloud[:database].snapshots.create(
151
+ :name => 'TestSnapshot',
152
+ :description => 'A new snapshot',
153
+ :database_id => instances.first.service_name
154
+ )
155
+ test "can create a snapshot" do
156
+ snap.is_a? Fog::OracleCloud::Database::Snapshot
157
+ end
158
+
159
+ test "is being built" do
160
+ !snap.completed?
161
+ end
162
+ snap.wait_for { completed? }
163
+
164
+ test "is built" do
165
+ snap.completed?
166
+ end
167
+ end
168
+
169
+ tests("#database-snapshots", "snapshots") do
170
+ instances = Fog::OracleCloud[:database].instances
171
+ snaps = instances.first.snapshots
172
+ test "might have snapshots" do
173
+ snaps.is_a? Array
174
+ end
175
+ if snaps.size >= 1 then
176
+ test "one of them should have completed" do
177
+ snaps.first.completed?
178
+ end
179
+ test "can get snapshot" do
180
+ snap = instances.first.get_snapshot(snaps.first.name)
181
+ snap.name.is_a? String
182
+ snap.cloned_services.is_a? Array
183
+ snap.cloned_services.first['clonedServiceName'].is_a? String
184
+ end
185
+ end
186
+ end
187
+
188
+ tests("#database-shapshots-delete", "create") do
189
+ db = Fog::OracleCloud[:database].instances.get('TestDB')
190
+ snap = db.snapshots.first
191
+ snap.destroy()
192
+ snap.wait_for { deleting? }
193
+ tests("should actually delete snapshot").raises(Fog::OracleCloud::Database::NotFound) do
194
+ snap.wait_for { status == 'Stopped' }
195
+ end
196
+ end
197
+
198
+ tests("database-patches") do
199
+ instances = Fog::OracleCloud[:database].instances
200
+ patches = instances.first.patches
201
+ test "should have patches" do
202
+ patches.is_a? Array
203
+ end
204
+ if patches.size >= 1 then
205
+ test "has a patch id" do
206
+ patches.first.id.is_a? String
207
+ end
208
+ end
46
209
  end
47
210
 
48
211
  tests("#database-delete", "create") do
@@ -53,4 +216,6 @@ Shindo.tests('Fog::Database[oraclecloud] | database requests', 'database') do
53
216
  db.wait_for { stopped? }
54
217
  end
55
218
  end
219
+
220
+
56
221
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-oraclecloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Nation
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-25 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -148,8 +148,18 @@ files:
148
148
  - lib/fog/oraclecloud/models/compute/ssh_keys.rb
149
149
  - lib/fog/oraclecloud/models/compute/volume.rb
150
150
  - lib/fog/oraclecloud/models/compute/volumes.rb
151
+ - lib/fog/oraclecloud/models/database/backup.rb
152
+ - lib/fog/oraclecloud/models/database/backups.rb
151
153
  - lib/fog/oraclecloud/models/database/instance.rb
152
154
  - lib/fog/oraclecloud/models/database/instances.rb
155
+ - lib/fog/oraclecloud/models/database/patch.rb
156
+ - lib/fog/oraclecloud/models/database/patches.rb
157
+ - lib/fog/oraclecloud/models/database/recoveries.rb
158
+ - lib/fog/oraclecloud/models/database/recovery.rb
159
+ - lib/fog/oraclecloud/models/database/server.rb
160
+ - lib/fog/oraclecloud/models/database/servers.rb
161
+ - lib/fog/oraclecloud/models/database/snapshot.rb
162
+ - lib/fog/oraclecloud/models/database/snapshots.rb
153
163
  - lib/fog/oraclecloud/models/java/instance.rb
154
164
  - lib/fog/oraclecloud/models/java/instances.rb
155
165
  - lib/fog/oraclecloud/models/java/server.rb
@@ -197,10 +207,21 @@ files:
197
207
  - lib/fog/oraclecloud/requests/compute/update_image_list.rb
198
208
  - lib/fog/oraclecloud/requests/compute/update_orchestration.rb
199
209
  - lib/fog/oraclecloud/requests/compute/update_ssh_key.rb
210
+ - lib/fog/oraclecloud/requests/database/backup_instance.rb
200
211
  - lib/fog/oraclecloud/requests/database/create_instance.rb
212
+ - lib/fog/oraclecloud/requests/database/create_snapshot.rb
201
213
  - lib/fog/oraclecloud/requests/database/delete_instance.rb
214
+ - lib/fog/oraclecloud/requests/database/delete_snapshot.rb
202
215
  - lib/fog/oraclecloud/requests/database/get_instance.rb
216
+ - lib/fog/oraclecloud/requests/database/get_snapshot.rb
217
+ - lib/fog/oraclecloud/requests/database/list_backups.rb
203
218
  - lib/fog/oraclecloud/requests/database/list_instances.rb
219
+ - lib/fog/oraclecloud/requests/database/list_patches.rb
220
+ - lib/fog/oraclecloud/requests/database/list_recoveries.rb
221
+ - lib/fog/oraclecloud/requests/database/list_servers.rb
222
+ - lib/fog/oraclecloud/requests/database/list_snapshots.rb
223
+ - lib/fog/oraclecloud/requests/database/recover_instance.rb
224
+ - lib/fog/oraclecloud/requests/database/scale_instance.rb
204
225
  - lib/fog/oraclecloud/requests/java/create_instance.rb
205
226
  - lib/fog/oraclecloud/requests/java/delete_instance.rb
206
227
  - lib/fog/oraclecloud/requests/java/get_instance.rb