fog-oraclecloud 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +12 -10
  3. data/Gemfile +4 -4
  4. data/LICENSE +20 -20
  5. data/README.md +153 -153
  6. data/Rakefile +2 -2
  7. data/bin/console +14 -14
  8. data/bin/setup +8 -8
  9. data/fog-oracle.gemspec +32 -31
  10. data/lib/fog/oraclecloud.rb +29 -29
  11. data/lib/fog/oraclecloud/compute.rb +184 -184
  12. data/lib/fog/oraclecloud/database.rb +129 -129
  13. data/lib/fog/oraclecloud/java.rb +123 -115
  14. data/lib/fog/oraclecloud/models/compute/image.rb +43 -43
  15. data/lib/fog/oraclecloud/models/compute/image_list.rb +39 -39
  16. data/lib/fog/oraclecloud/models/compute/image_lists.rb +22 -22
  17. data/lib/fog/oraclecloud/models/compute/images.rb +22 -22
  18. data/lib/fog/oraclecloud/models/compute/instance.rb +74 -69
  19. data/lib/fog/oraclecloud/models/compute/instances.rb +22 -22
  20. data/lib/fog/oraclecloud/models/compute/object_plan.rb +16 -16
  21. data/lib/fog/oraclecloud/models/compute/object_plans.rb +12 -12
  22. data/lib/fog/oraclecloud/models/compute/orchestration.rb +89 -89
  23. data/lib/fog/oraclecloud/models/compute/orchestrations.rb +20 -20
  24. data/lib/fog/oraclecloud/models/compute/security_application.rb +42 -42
  25. data/lib/fog/oraclecloud/models/compute/security_applications.rb +22 -22
  26. data/lib/fog/oraclecloud/models/compute/security_list.rb +26 -26
  27. data/lib/fog/oraclecloud/models/compute/security_lists.rb +22 -22
  28. data/lib/fog/oraclecloud/models/compute/security_rule.rb +41 -41
  29. data/lib/fog/oraclecloud/models/compute/security_rules.rb +22 -22
  30. data/lib/fog/oraclecloud/models/compute/ssh_key.rb +37 -37
  31. data/lib/fog/oraclecloud/models/compute/ssh_keys.rb +22 -22
  32. data/lib/fog/oraclecloud/models/compute/volume.rb +47 -47
  33. data/lib/fog/oraclecloud/models/compute/volumes.rb +20 -20
  34. data/lib/fog/oraclecloud/models/database/backup.rb +37 -37
  35. data/lib/fog/oraclecloud/models/database/backups.rb +30 -30
  36. data/lib/fog/oraclecloud/models/database/instance.rb +331 -331
  37. data/lib/fog/oraclecloud/models/database/instances.rb +25 -25
  38. data/lib/fog/oraclecloud/models/database/patch.rb +34 -34
  39. data/lib/fog/oraclecloud/models/database/patches.rb +18 -18
  40. data/lib/fog/oraclecloud/models/database/recoveries.rb +26 -26
  41. data/lib/fog/oraclecloud/models/database/recovery.rb +43 -43
  42. data/lib/fog/oraclecloud/models/database/server.rb +28 -28
  43. data/lib/fog/oraclecloud/models/database/servers.rb +18 -18
  44. data/lib/fog/oraclecloud/models/database/snapshot.rb +60 -60
  45. data/lib/fog/oraclecloud/models/database/snapshots.rb +22 -22
  46. data/lib/fog/oraclecloud/models/java/database.rb +17 -17
  47. data/lib/fog/oraclecloud/models/java/databases.rb +17 -17
  48. data/lib/fog/oraclecloud/models/java/instance.rb +269 -265
  49. data/lib/fog/oraclecloud/models/java/instances.rb +23 -23
  50. data/lib/fog/oraclecloud/models/java/server.rb +62 -62
  51. data/lib/fog/oraclecloud/models/java/servers.rb +25 -25
  52. data/lib/fog/oraclecloud/models/soa/instance.rb +163 -163
  53. data/lib/fog/oraclecloud/models/soa/instances.rb +54 -54
  54. data/lib/fog/oraclecloud/models/storage/container.rb +33 -33
  55. data/lib/fog/oraclecloud/models/storage/containers.rb +24 -24
  56. data/lib/fog/oraclecloud/models/storage/object.rb +27 -27
  57. data/lib/fog/oraclecloud/models/storage/objects.rb +27 -27
  58. data/lib/fog/oraclecloud/requests/compute/create_image.rb +30 -30
  59. data/lib/fog/oraclecloud/requests/compute/create_image_list.rb +27 -27
  60. data/lib/fog/oraclecloud/requests/compute/create_instance.rb +53 -53
  61. data/lib/fog/oraclecloud/requests/compute/create_orchestration.rb +82 -82
  62. data/lib/fog/oraclecloud/requests/compute/create_security_application.rb +28 -28
  63. data/lib/fog/oraclecloud/requests/compute/create_security_rule.rb +29 -29
  64. data/lib/fog/oraclecloud/requests/compute/create_ssh_key.rb +46 -46
  65. data/lib/fog/oraclecloud/requests/compute/create_volume.rb +28 -28
  66. data/lib/fog/oraclecloud/requests/compute/delete_image.rb +19 -19
  67. data/lib/fog/oraclecloud/requests/compute/delete_image_list.rb +19 -19
  68. data/lib/fog/oraclecloud/requests/compute/delete_instance.rb +33 -33
  69. data/lib/fog/oraclecloud/requests/compute/delete_orchestration.rb +36 -36
  70. data/lib/fog/oraclecloud/requests/compute/delete_security_application.rb +20 -20
  71. data/lib/fog/oraclecloud/requests/compute/delete_security_rule.rb +20 -20
  72. data/lib/fog/oraclecloud/requests/compute/delete_ssh_key.rb +32 -32
  73. data/lib/fog/oraclecloud/requests/compute/get_image.rb +21 -21
  74. data/lib/fog/oraclecloud/requests/compute/get_image_list.rb +21 -21
  75. data/lib/fog/oraclecloud/requests/compute/get_instance.rb +45 -45
  76. data/lib/fog/oraclecloud/requests/compute/get_orchestration.rb +39 -39
  77. data/lib/fog/oraclecloud/requests/compute/get_security_application.rb +20 -20
  78. data/lib/fog/oraclecloud/requests/compute/get_security_rule.rb +20 -20
  79. data/lib/fog/oraclecloud/requests/compute/get_ssh_key.rb +39 -39
  80. data/lib/fog/oraclecloud/requests/compute/list_image_lists.rb +29 -29
  81. data/lib/fog/oraclecloud/requests/compute/list_images.rb +16 -16
  82. data/lib/fog/oraclecloud/requests/compute/list_instances.rb +28 -28
  83. data/lib/fog/oraclecloud/requests/compute/list_orchestrations.rb +28 -28
  84. data/lib/fog/oraclecloud/requests/compute/list_security_applications.rb +21 -21
  85. data/lib/fog/oraclecloud/requests/compute/list_security_lists.rb +16 -16
  86. data/lib/fog/oraclecloud/requests/compute/list_security_rules.rb +21 -21
  87. data/lib/fog/oraclecloud/requests/compute/list_ssh_keys.rb +29 -29
  88. data/lib/fog/oraclecloud/requests/compute/list_volumes.rb +16 -16
  89. data/lib/fog/oraclecloud/requests/compute/start_orchestration.rb +39 -39
  90. data/lib/fog/oraclecloud/requests/compute/stop_orchestration.rb +39 -39
  91. data/lib/fog/oraclecloud/requests/compute/update_image.rb +27 -27
  92. data/lib/fog/oraclecloud/requests/compute/update_image_list.rb +27 -27
  93. data/lib/fog/oraclecloud/requests/compute/update_orchestration.rb +80 -80
  94. data/lib/fog/oraclecloud/requests/compute/update_ssh_key.rb +49 -49
  95. data/lib/fog/oraclecloud/requests/database/backup_instance.rb +45 -45
  96. data/lib/fog/oraclecloud/requests/database/create_instance.rb +101 -101
  97. data/lib/fog/oraclecloud/requests/database/create_snapshot.rb +50 -50
  98. data/lib/fog/oraclecloud/requests/database/delete_instance.rb +26 -26
  99. data/lib/fog/oraclecloud/requests/database/delete_snapshot.rb +26 -26
  100. data/lib/fog/oraclecloud/requests/database/get_instance.rb +62 -62
  101. data/lib/fog/oraclecloud/requests/database/get_instance_from_job.rb +31 -31
  102. data/lib/fog/oraclecloud/requests/database/get_snapshot.rb +43 -43
  103. data/lib/fog/oraclecloud/requests/database/list_backups.rb +39 -39
  104. data/lib/fog/oraclecloud/requests/database/list_instances.rb +29 -29
  105. data/lib/fog/oraclecloud/requests/database/list_patches.rb +51 -51
  106. data/lib/fog/oraclecloud/requests/database/list_recoveries.rb +40 -40
  107. data/lib/fog/oraclecloud/requests/database/list_servers.rb +27 -27
  108. data/lib/fog/oraclecloud/requests/database/list_snapshots.rb +27 -27
  109. data/lib/fog/oraclecloud/requests/database/recover_instance.rb +83 -83
  110. data/lib/fog/oraclecloud/requests/database/scale_instance.rb +40 -40
  111. data/lib/fog/oraclecloud/requests/java/create_instance.rb +156 -87
  112. data/lib/fog/oraclecloud/requests/java/delete_instance.rb +37 -37
  113. data/lib/fog/oraclecloud/requests/java/get_instance.rb +43 -43
  114. data/lib/fog/oraclecloud/requests/java/get_server.rb +42 -42
  115. data/lib/fog/oraclecloud/requests/java/list_instances.rb +29 -29
  116. data/lib/fog/oraclecloud/requests/java/list_servers.rb +30 -30
  117. data/lib/fog/oraclecloud/requests/java/scale_a_node.rb +45 -45
  118. data/lib/fog/oraclecloud/requests/java/scale_in_a_cluster.rb +35 -35
  119. data/lib/fog/oraclecloud/requests/java/scale_out_a_cluster.rb +38 -38
  120. data/lib/fog/oraclecloud/requests/soa/create_instance.rb +71 -71
  121. data/lib/fog/oraclecloud/requests/soa/delete_instance.rb +35 -35
  122. data/lib/fog/oraclecloud/requests/soa/get_instance.rb +42 -42
  123. data/lib/fog/oraclecloud/requests/soa/get_job_status.rb +22 -22
  124. data/lib/fog/oraclecloud/requests/soa/list_instances.rb +29 -29
  125. data/lib/fog/oraclecloud/requests/storage/create_container.rb +41 -41
  126. data/lib/fog/oraclecloud/requests/storage/delete_container.rb +15 -15
  127. data/lib/fog/oraclecloud/requests/storage/get_container.rb +63 -63
  128. data/lib/fog/oraclecloud/requests/storage/list_containers.rb +27 -27
  129. data/lib/fog/oraclecloud/soa.rb +106 -106
  130. data/lib/fog/oraclecloud/storage.rb +98 -98
  131. data/lib/fog/oraclecloud/version.rb +5 -5
  132. data/tests/helper.rb +5 -3
  133. data/tests/helpers/mock_helper.rb +14 -14
  134. data/tests/requests/compute_tests.rb +9 -9
  135. data/tests/requests/database_tests.rb +241 -241
  136. data/tests/requests/instance_tests.rb +68 -61
  137. data/tests/requests/java_tests.rb +149 -109
  138. data/tests/requests/orchestrations_tests.rb +90 -90
  139. data/tests/requests/soa_tests.rb +151 -151
  140. data/tests/requests/ssh_keys_tests.rb +53 -53
  141. data/tests/requests/storage_tests.rb +54 -54
  142. metadata +17 -3
@@ -1,30 +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
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
@@ -1,331 +1,331 @@
1
- require 'fog/core/model'
2
-
3
- module Fog
4
- module OracleCloud
5
- class Database
6
- class Instance < Fog::Model
7
- identity :service_name, :aliases=>'serviceName'
8
-
9
- attribute :version
10
- attribute :status
11
- attribute :description, :aliases=>'serviceDescription'
12
- attribute :domain_name, :aliases=>'domainName'
13
- attribute :creation_date
14
- attribute :last_modified_time
15
- attribute :created_by, :aliases=>'creator'
16
- attribute :sm_plugin_version
17
- attribute :service_uri
18
- attribute :num_nodes
19
- attribute :level, :aliases=>'serviceLevel'
20
- attribute :edition
21
- attribute :shape
22
- attribute :subscription_type, :aliases=>['subscriptionType', 'subscription']
23
- attribute :creation_job_id
24
- attribute :num_ip_reservations
25
- attribute :backup_destination
26
- attribute :cloud_storage_container, :aliases=>'cloudStorageContainer'
27
- attribute :failover_database
28
- attribute :sid
29
- attribute :pdb_name, :aliases=>'pdbName'
30
- attribute :listenerPort
31
- attribute :timezone
32
- attribute :em_url
33
- attribute :connect_descriptor
34
- attribute :connect_descriptor_with_public_ip
35
- attribute :apex_url
36
- attribute :glassfish_url
37
- attribute :dbaasmonitor_url
38
- attribute :compute_site_name
39
- attribute :charset
40
- attribute :ncharset
41
- attribute :is_rac, :aliases=>['isRac', 'rac_database']
42
- attribute :total_shared_storage, :aliases=>'totalSharedStorage'
43
- attribute :service_type, :aliases=>'serviceType'
44
-
45
- # The following are only used to create an instance and are not returned in the list or get actions
46
- attribute :ssh_key, :aliases=>'vmPublicKeyText'
47
- attribute :admin_password
48
- attribute :cloud_storage_pwd, :aliases=>'cloudStoragePwd'
49
- attribute :cloud_storage_user, :aliases=>'cloudStorageUser'
50
- attribute :cloud_storage_container_if_missing, :aliases=>'cloudStorageContainerIfMissing'
51
- attribute :disaster_recovery, :aliases=>'disasterRecovery'
52
- attribute :golden_gate, :aliases=>'goldenGate'
53
- attribute :usable_storage, :aliases=>'usableStorage'
54
-
55
- def service_name=(value)
56
- if value.include? '_'
57
- raise ArgumentError, "Invalid service name. Names must be less than 50 characters; must start with a letter and can only contain letters, numbers and hyphens (-); can not end with a hyphen"
58
- else
59
- attributes[:service_name] = value
60
- end
61
- end
62
-
63
- def edition=(value)
64
- if %w(SE EE EE_HP EE_EP).include? value then
65
- attributes[:edition]=value
66
- else
67
- raise ArgumentError, "Invalid Edition. Valid values - SE, EE, EE_HP, EE_EP"
68
- end
69
- end
70
-
71
- def level=(value)
72
- if %w(PAAS BASIC).include? value then
73
- attributes[:level]=value
74
- else
75
- raise ArgumentError, "Invalid level. Valid values - PAAS or BASIC"
76
- end
77
- end
78
-
79
- def shape=(value)
80
- if %w(oc3 oc4 oc5 oc6 oc1m oc2m oc3m oc4m).include? value then
81
- attributes[:shape]=value
82
- else
83
- raise ArgumentError, "Invalid Shape. Valid values - oc3, oc4, oc5, oc6, oc1m, oc2m, oc3m or oc4m"
84
- end
85
- end
86
-
87
- def subscription_type=(value)
88
- if %w(HOURLY MONTHLY).include? value then
89
- attributes[:subscription_type]=value
90
- else
91
- raise ArgumentError, "Invalid subscription type. Valid values - HOURLY or MONTHLY"
92
- end
93
- end
94
-
95
- def backup_destination=(value)
96
- if %w(BOTH OSS NONE).include? value then
97
- attributes[:backup_destination]=value
98
- else
99
- raise ArgumentError, "Invalid backup destination. Valid values - BOTH, OSS or NONE"
100
- end
101
- end
102
-
103
- def disaster_recovery=(value)
104
- if %w(yes no).include? value then
105
- attributes[:disaster_recovery]=value
106
- else
107
- raise ArgumentError, "Invalid disaster recovery value"
108
- end
109
- end
110
-
111
- def failover_database=(value)
112
- if value == true
113
- value = 'yes'
114
- elsif value == false || value.nil?
115
- value = 'no'
116
- end
117
- if %w(yes no).include? value then
118
- attributes[:failover_database]=value
119
- else
120
- raise ArgumentError, "Invalid failover database value"
121
- end
122
- end
123
-
124
- def is_rac=(value)
125
- if value == true
126
- value = 'yes'
127
- elsif value == false || value.nil?
128
- value = 'no'
129
- end
130
- if %w(yes no).include? value then
131
- attributes[:is_rac]=value
132
- else
133
- raise ArgumentError, "Invalid is_rac value"
134
- end
135
- end
136
-
137
- def ncharset=(value)
138
- if value.nil? then
139
- attributes[:ncharset] = 'AL16UTF16'
140
- elsif %w(AL16UTF16 UTF8).include? value then
141
- attributes[:ncharset]=value
142
- else
143
- raise ArgumentError, "Invalid ncharset"
144
- end
145
- end
146
-
147
- def usable_storage=(value)
148
- if value.to_f >= 15 && value.to_f <= 1000 then
149
- attributes[:usable_storage]=value
150
- else
151
- raise ArgumentError, "Usable storage value is invalid: #{value.to_f}"
152
- end
153
- end
154
-
155
- def admin_password=(value)
156
- if !value.nil? and (!(value[0] =~ /[[:alpha:]]/) or value.size < 8 or value.size > 30 or !(value =~ /[_#$]/) or !(value =~ /[0-9]/))
157
- raise ArgumentError, "Invalid admin password. Password must be between 8 and 30 characters in length; must start with a letter and can only contain letters, numbers and $, \#, _"
158
- else
159
- attributes[:admin_password] = value
160
- end
161
- end
162
-
163
-
164
- def clean_name
165
- name.sub %r{\/.*\/}, ''
166
- end
167
-
168
- def save
169
- #identity ? update : create
170
- create
171
- end
172
-
173
- def ready?
174
- status == "Running"
175
- end
176
-
177
- def stopping?
178
- status == 'Maintenance' || status == 'Terminating'
179
- end
180
-
181
- def stopped?
182
- status == 'Stopped'
183
- end
184
-
185
- def ip_address
186
- # TODO: Replace with regex
187
- content_url.sub('http://', '')
188
- end
189
-
190
- def destroy
191
- requires :service_name
192
- service.delete_instance(service_name).body
193
- end
194
-
195
- def scale(shape)
196
- requires :service_name
197
- service.scale_instance(service_name, :shape=>shape).body
198
- end
199
-
200
- def add_storage(size)
201
- requires :service_name
202
- service.scale_instance(service_name, :additional_storage=>size).body
203
- end
204
-
205
- def expand_storage(size, type=nil)
206
- requires :service_name
207
- if type.nil? then type = 'data' end
208
- if type == 'backup' then type ='fra' end
209
- service.scale_instance(service_name, :additional_storage=>size, :usage=>type).body
210
- end
211
-
212
- def snapshots
213
- requires :service_name
214
- service.snapshots.all(service_name)
215
- end
216
-
217
- def get_snapshot(snapshot_name)
218
- requires :service_name
219
- service.snapshots.get(service_name, snapshot_name)
220
- end
221
-
222
- def servers
223
- requires :service_name
224
- service.servers.all(service_name)
225
- end
226
-
227
- def backup
228
- requires :service_name
229
- service.backup_instance(service_name)
230
- end
231
-
232
- def backups
233
- requires :service_name
234
- service.backups.all(service_name)
235
- end
236
-
237
- def recover(type, value)
238
- # Valid types are 'scn', 'tag' or 'timestamp'
239
- requires :service_name
240
- service.recover_instance(service_name, type, value)
241
- end
242
-
243
- def recover_latest
244
- requires :service_name
245
- service.recover_instance(service_name)
246
- end
247
-
248
- def recoveries
249
- requires :service_name
250
- service.recoveries.all(service_name)
251
- end
252
-
253
- def patches
254
- requires :service_name
255
- service.patches.all(service_name)
256
- end
257
-
258
- private
259
-
260
- def create
261
- requires :service_name, :edition, :ssh_key, :shape, :version, :admin_password, :backup_destination
262
-
263
- if backup_destination != 'NONE' then
264
- if cloud_storage_container.nil? then
265
- cloud_storage_if_missing = true
266
- stor_name = "#{service_name}_Backup"
267
- else
268
- stor_name = cloud_storage_container
269
- end
270
- stor_user = cloud_storage_user || service.username
271
- stor_pwd = cloud_storage_pwd || service.password
272
- end
273
-
274
- if !disaster_recovery.nil? && (failover_database.nil? || failover_database == 'no') then raise ArgumentError, 'Can\'t set disaster recovery option without failover_database set to \'yes\'' end
275
- if failover_database == 'yes' && golden_gate == 'yes' then raise ArgumentError, 'Can\'t set failover_database and golden_gate both to \'yes\'' end
276
- if is_rac == 'yes' && (failover_database == 'yes' || golden_gate == 'yes') then raise ArgumentError, 'Can\'t set is_rac and failover_database or golden_gate both to \'yes\'' end
277
-
278
- params = {
279
- :service_name => service_name,
280
- :edition => edition,
281
- :ssh_key => ssh_key,
282
- :shape => shape,
283
- :version => version,
284
- :level => level || 'PAAS',
285
- :subscription_type => subscription_type || 'HOURLY',
286
- :description => description
287
- }
288
- options = {
289
- :admin_password => admin_password,
290
- :charset => charset,
291
- :backup_destination => backup_destination,
292
- :cloud_storage_container => stor_name,
293
- :cloud_storage_pwd => stor_pwd,
294
- :cloud_storage_user => stor_user,
295
- :create_storage_container_if_missing => cloud_storage_if_missing,
296
- :disaster_recovery => disaster_recovery,
297
- :failover_database => failover_database,
298
- :golden_gate => golden_gate,
299
- :is_rac => is_rac,
300
- :ncharset => ncharset,
301
- :pdb_name => pdb_name,
302
- :sid => sid || 'ORCL',
303
- :timezone => timezone,
304
- :usable_storage => usable_storage || 25
305
- }
306
- data = service.create_instance(params, options)
307
- # Get the Job Id out of the header
308
- self.creation_job_id = /status\/create\/job\/([0-9]*)/.match(data.headers['Location'])[1]
309
- end
310
-
311
- def reload
312
- requires :identity
313
- data = begin
314
- collection.get(identity)
315
- rescue Excon::Errors::SocketError
316
- nil
317
- rescue Excon::Errors::NotFound
318
- # Try using the creation job id (maybe it was just created)
319
- collection.get_from_job(creation_job_id)
320
- end
321
-
322
- return unless data
323
-
324
- new_attributes = data.attributes
325
- merge_attributes(new_attributes)
326
- self
327
- end
328
- end
329
- end
330
- end
331
- end
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module OracleCloud
5
+ class Database
6
+ class Instance < Fog::Model
7
+ identity :service_name, :aliases=>'serviceName'
8
+
9
+ attribute :version
10
+ attribute :status
11
+ attribute :description, :aliases=>'serviceDescription'
12
+ attribute :domain_name, :aliases=>'domainName'
13
+ attribute :creation_date
14
+ attribute :last_modified_time
15
+ attribute :created_by, :aliases=>'creator'
16
+ attribute :sm_plugin_version
17
+ attribute :service_uri
18
+ attribute :num_nodes
19
+ attribute :level, :aliases=>'serviceLevel'
20
+ attribute :edition
21
+ attribute :shape
22
+ attribute :subscription_type, :aliases=>['subscriptionType', 'subscription']
23
+ attribute :creation_job_id
24
+ attribute :num_ip_reservations
25
+ attribute :backup_destination
26
+ attribute :cloud_storage_container, :aliases=>'cloudStorageContainer'
27
+ attribute :failover_database
28
+ attribute :sid
29
+ attribute :pdb_name, :aliases=>'pdbName'
30
+ attribute :listenerPort
31
+ attribute :timezone
32
+ attribute :em_url
33
+ attribute :connect_descriptor
34
+ attribute :connect_descriptor_with_public_ip
35
+ attribute :apex_url
36
+ attribute :glassfish_url
37
+ attribute :dbaasmonitor_url
38
+ attribute :compute_site_name
39
+ attribute :charset
40
+ attribute :ncharset
41
+ attribute :is_rac, :aliases=>['isRac', 'rac_database']
42
+ attribute :total_shared_storage, :aliases=>'totalSharedStorage'
43
+ attribute :service_type, :aliases=>'serviceType'
44
+
45
+ # The following are only used to create an instance and are not returned in the list or get actions
46
+ attribute :ssh_key, :aliases=>'vmPublicKeyText'
47
+ attribute :admin_password
48
+ attribute :cloud_storage_pwd, :aliases=>'cloudStoragePwd'
49
+ attribute :cloud_storage_user, :aliases=>'cloudStorageUser'
50
+ attribute :cloud_storage_container_if_missing, :aliases=>'cloudStorageContainerIfMissing'
51
+ attribute :disaster_recovery, :aliases=>'disasterRecovery'
52
+ attribute :golden_gate, :aliases=>'goldenGate'
53
+ attribute :usable_storage, :aliases=>'usableStorage'
54
+
55
+ def service_name=(value)
56
+ if value.include? '_'
57
+ raise ArgumentError, "Invalid service name. Names must be less than 50 characters; must start with a letter and can only contain letters, numbers and hyphens (-); can not end with a hyphen"
58
+ else
59
+ attributes[:service_name] = value
60
+ end
61
+ end
62
+
63
+ def edition=(value)
64
+ if %w(SE EE EE_HP EE_EP).include? value then
65
+ attributes[:edition]=value
66
+ else
67
+ raise ArgumentError, "Invalid Edition. Valid values - SE, EE, EE_HP, EE_EP"
68
+ end
69
+ end
70
+
71
+ def level=(value)
72
+ if %w(PAAS BASIC).include? value then
73
+ attributes[:level]=value
74
+ else
75
+ raise ArgumentError, "Invalid level. Valid values - PAAS or BASIC"
76
+ end
77
+ end
78
+
79
+ def shape=(value)
80
+ if %w(oc3 oc4 oc5 oc6 oc1m oc2m oc3m oc4m).include? value then
81
+ attributes[:shape]=value
82
+ else
83
+ raise ArgumentError, "Invalid Shape. Valid values - oc3, oc4, oc5, oc6, oc1m, oc2m, oc3m or oc4m"
84
+ end
85
+ end
86
+
87
+ def subscription_type=(value)
88
+ if %w(HOURLY MONTHLY).include? value then
89
+ attributes[:subscription_type]=value
90
+ else
91
+ raise ArgumentError, "Invalid subscription type. Valid values - HOURLY or MONTHLY"
92
+ end
93
+ end
94
+
95
+ def backup_destination=(value)
96
+ if %w(BOTH OSS NONE).include? value then
97
+ attributes[:backup_destination]=value
98
+ else
99
+ raise ArgumentError, "Invalid backup destination. Valid values - BOTH, OSS or NONE"
100
+ end
101
+ end
102
+
103
+ def disaster_recovery=(value)
104
+ if %w(yes no).include? value then
105
+ attributes[:disaster_recovery]=value
106
+ else
107
+ raise ArgumentError, "Invalid disaster recovery value"
108
+ end
109
+ end
110
+
111
+ def failover_database=(value)
112
+ if value == true
113
+ value = 'yes'
114
+ elsif value == false || value.nil?
115
+ value = 'no'
116
+ end
117
+ if %w(yes no).include? value then
118
+ attributes[:failover_database]=value
119
+ else
120
+ raise ArgumentError, "Invalid failover database value"
121
+ end
122
+ end
123
+
124
+ def is_rac=(value)
125
+ if value == true
126
+ value = 'yes'
127
+ elsif value == false || value.nil?
128
+ value = 'no'
129
+ end
130
+ if %w(yes no).include? value then
131
+ attributes[:is_rac]=value
132
+ else
133
+ raise ArgumentError, "Invalid is_rac value"
134
+ end
135
+ end
136
+
137
+ def ncharset=(value)
138
+ if value.nil? then
139
+ attributes[:ncharset] = 'AL16UTF16'
140
+ elsif %w(AL16UTF16 UTF8).include? value then
141
+ attributes[:ncharset]=value
142
+ else
143
+ raise ArgumentError, "Invalid ncharset"
144
+ end
145
+ end
146
+
147
+ def usable_storage=(value)
148
+ if value.to_f >= 15 && value.to_f <= 1000 then
149
+ attributes[:usable_storage]=value
150
+ else
151
+ raise ArgumentError, "Usable storage value is invalid: #{value.to_f}"
152
+ end
153
+ end
154
+
155
+ def admin_password=(value)
156
+ if !value.nil? and (!(value[0] =~ /[[:alpha:]]/) or value.size < 8 or value.size > 30 or !(value =~ /[_#$]/) or !(value =~ /[0-9]/))
157
+ raise ArgumentError, "Invalid admin password. Password must be between 8 and 30 characters in length; must start with a letter and can only contain letters, numbers and $, \#, _"
158
+ else
159
+ attributes[:admin_password] = value
160
+ end
161
+ end
162
+
163
+
164
+ def clean_name
165
+ name.sub %r{\/.*\/}, ''
166
+ end
167
+
168
+ def save
169
+ #identity ? update : create
170
+ create
171
+ end
172
+
173
+ def ready?
174
+ status == "Running"
175
+ end
176
+
177
+ def stopping?
178
+ status == 'Maintenance' || status == 'Terminating'
179
+ end
180
+
181
+ def stopped?
182
+ status == 'Stopped'
183
+ end
184
+
185
+ def ip_address
186
+ # TODO: Replace with regex
187
+ content_url.sub('http://', '')
188
+ end
189
+
190
+ def destroy
191
+ requires :service_name
192
+ service.delete_instance(service_name).body
193
+ end
194
+
195
+ def scale(shape)
196
+ requires :service_name
197
+ service.scale_instance(service_name, :shape=>shape).body
198
+ end
199
+
200
+ def add_storage(size)
201
+ requires :service_name
202
+ service.scale_instance(service_name, :additional_storage=>size).body
203
+ end
204
+
205
+ def expand_storage(size, type=nil)
206
+ requires :service_name
207
+ if type.nil? then type = 'data' end
208
+ if type == 'backup' then type ='fra' end
209
+ service.scale_instance(service_name, :additional_storage=>size, :usage=>type).body
210
+ end
211
+
212
+ def snapshots
213
+ requires :service_name
214
+ service.snapshots.all(service_name)
215
+ end
216
+
217
+ def get_snapshot(snapshot_name)
218
+ requires :service_name
219
+ service.snapshots.get(service_name, snapshot_name)
220
+ end
221
+
222
+ def servers
223
+ requires :service_name
224
+ service.servers.all(service_name)
225
+ end
226
+
227
+ def backup
228
+ requires :service_name
229
+ service.backup_instance(service_name)
230
+ end
231
+
232
+ def backups
233
+ requires :service_name
234
+ service.backups.all(service_name)
235
+ end
236
+
237
+ def recover(type, value)
238
+ # Valid types are 'scn', 'tag' or 'timestamp'
239
+ requires :service_name
240
+ service.recover_instance(service_name, type, value)
241
+ end
242
+
243
+ def recover_latest
244
+ requires :service_name
245
+ service.recover_instance(service_name)
246
+ end
247
+
248
+ def recoveries
249
+ requires :service_name
250
+ service.recoveries.all(service_name)
251
+ end
252
+
253
+ def patches
254
+ requires :service_name
255
+ service.patches.all(service_name)
256
+ end
257
+
258
+ private
259
+
260
+ def create
261
+ requires :service_name, :edition, :ssh_key, :shape, :version, :admin_password, :backup_destination
262
+
263
+ if backup_destination != 'NONE' then
264
+ if cloud_storage_container.nil? then
265
+ cloud_storage_if_missing = true
266
+ stor_name = "#{service_name}_Backup"
267
+ else
268
+ stor_name = cloud_storage_container
269
+ end
270
+ stor_user = cloud_storage_user || service.username
271
+ stor_pwd = cloud_storage_pwd || service.password
272
+ end
273
+
274
+ if !disaster_recovery.nil? && (failover_database.nil? || failover_database == 'no') then raise ArgumentError, 'Can\'t set disaster recovery option without failover_database set to \'yes\'' end
275
+ if failover_database == 'yes' && golden_gate == 'yes' then raise ArgumentError, 'Can\'t set failover_database and golden_gate both to \'yes\'' end
276
+ if is_rac == 'yes' && (failover_database == 'yes' || golden_gate == 'yes') then raise ArgumentError, 'Can\'t set is_rac and failover_database or golden_gate both to \'yes\'' end
277
+
278
+ params = {
279
+ :service_name => service_name,
280
+ :edition => edition,
281
+ :ssh_key => ssh_key,
282
+ :shape => shape,
283
+ :version => version,
284
+ :level => level || 'PAAS',
285
+ :subscription_type => subscription_type || 'HOURLY',
286
+ :description => description
287
+ }
288
+ options = {
289
+ :admin_password => admin_password,
290
+ :charset => charset,
291
+ :backup_destination => backup_destination,
292
+ :cloud_storage_container => stor_name,
293
+ :cloud_storage_pwd => stor_pwd,
294
+ :cloud_storage_user => stor_user,
295
+ :create_storage_container_if_missing => cloud_storage_if_missing,
296
+ :disaster_recovery => disaster_recovery,
297
+ :failover_database => failover_database,
298
+ :golden_gate => golden_gate,
299
+ :is_rac => is_rac,
300
+ :ncharset => ncharset,
301
+ :pdb_name => pdb_name,
302
+ :sid => sid || 'ORCL',
303
+ :timezone => timezone,
304
+ :usable_storage => usable_storage || 25
305
+ }
306
+ data = service.create_instance(params, options)
307
+ # Get the Job Id out of the header
308
+ self.creation_job_id = /status\/create\/job\/([0-9]*)/.match(data.headers['Location'])[1]
309
+ end
310
+
311
+ def reload
312
+ requires :identity
313
+ data = begin
314
+ collection.get(identity)
315
+ rescue Excon::Errors::SocketError
316
+ nil
317
+ rescue Excon::Errors::NotFound
318
+ # Try using the creation job id (maybe it was just created)
319
+ collection.get_from_job(creation_job_id)
320
+ end
321
+
322
+ return unless data
323
+
324
+ new_attributes = data.attributes
325
+ merge_attributes(new_attributes)
326
+ self
327
+ end
328
+ end
329
+ end
330
+ end
331
+ end