kitchen-oci 1.15.1 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,221 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
4
+ #
5
+ # Copyright (C) 2024, Stephen Pearson
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ module Kitchen
20
+ module Driver
21
+ class Oci
22
+ module Models
23
+ # dbaas model
24
+ class Dbaas < Instance # rubocop:disable Metrics/ClassLength
25
+ attr_accessor :launch_details, :database_details, :db_home_details
26
+
27
+ def initialize(config, state, oci, api, action = :create)
28
+ super
29
+ @launch_details = OCI::Database::Models::LaunchDbSystemDetails.new
30
+ @database_details = OCI::Database::Models::CreateDatabaseDetails.new
31
+ @db_home_details = OCI::Database::Models::CreateDbHomeDetails.new
32
+ end
33
+
34
+ def launch
35
+ response = api.dbaas.launch_db_system(launch_instance_details)
36
+ instance_id = response.data.id
37
+
38
+ api.dbaas.get_db_system(instance_id).wait_until(:lifecycle_state, OCI::Database::Models::DbSystem::LIFECYCLE_STATE_AVAILABLE,
39
+ max_interval_seconds: 900, max_wait_seconds: 21_600)
40
+ final_state(state, instance_id)
41
+ end
42
+
43
+ def terminate
44
+ api.dbaas.terminate_db_system(state[:server_id])
45
+ api.dbaas.get_db_system(state[:server_id]).wait_until(:lifecycle_state, OCI::Database::Models::DbSystem::LIFECYCLE_STATE_TERMINATING,
46
+ max_interval_seconds: 900, max_wait_seconds: 21_600)
47
+ end
48
+
49
+ private
50
+
51
+ def launch_instance_details # rubocop:disable Metrics/MethodLength
52
+ # TODO: add support for the #domain property
53
+ compartment_id
54
+ availability_domain
55
+ defined_tags
56
+ shape
57
+ freeform_tags
58
+ names
59
+ cpu_core_count
60
+ create_db_home_details
61
+ subnet_id
62
+ nsg_ids
63
+ pubkey
64
+ initial_data_storage_size_in_gb
65
+ node_count
66
+ license_model
67
+ launch_details
68
+ end
69
+
70
+ def create_db_home_details
71
+ db_version
72
+ db_home_display_name
73
+ database_edition
74
+ db_home_details.database = create_database_details
75
+ launch_details.db_home = db_home_details
76
+ end
77
+
78
+ def create_database_details
79
+ cluster_name
80
+ db_name
81
+ pdb_name
82
+ admin_password
83
+ character_set
84
+ db_workload
85
+ ncharacter_set
86
+ db_backup_config
87
+ end
88
+
89
+ def subnet_id
90
+ launch_details.subnet_id = config[:subnet_id]
91
+ end
92
+
93
+ def nsg_ids
94
+ launch_details.nsg_ids = config[:nsg_ids]
95
+ end
96
+
97
+ def names
98
+ hostname
99
+ display_name
100
+ launch_details
101
+ end
102
+
103
+ def hostname
104
+ # The hostname must begin with an alphabetic character, and can contain alphanumeric characters and hyphens (-).
105
+ # The maximum length of the hostname is 16 characters
106
+ long_name = [hostname_prefix, long_hostname_suffix].compact.join("-")
107
+ trimmed_name = [hostname_prefix[0, 12], random_string(3)].compact.join("-")
108
+ launch_details.hostname = [long_name, trimmed_name].min { |l, t| l.size <=> t.size }
109
+ end
110
+
111
+ def display_name
112
+ # The user-friendly name for the DB system. The name does not have to be unique.
113
+ launch_details.display_name = [config[:hostname_prefix], random_string(4), random_number(2)].compact.join("-")
114
+ end
115
+
116
+ def hostname_prefix
117
+ config[:hostname_prefix]
118
+ end
119
+
120
+ def node_count
121
+ launch_details.node_count = 1
122
+ end
123
+
124
+ def long_hostname_suffix
125
+ [random_string(25 - hostname_prefix.length), random_string(3)].compact.join("-")
126
+ end
127
+
128
+ def pubkey
129
+ result = []
130
+ result << File.readlines(config[:ssh_keypath]).first.chomp
131
+ launch_details.ssh_public_keys = result
132
+ end
133
+
134
+ def cpu_core_count
135
+ launch_details.cpu_core_count = config[:dbaas][:cpu_core_count] ||= 2
136
+ end
137
+
138
+ def license_model
139
+ license = config[:dbaas][:license_model] ||= OCI::Database::Models::DbSystem::LICENSE_MODEL_BRING_YOUR_OWN_LICENSE
140
+ launch_details.license_model = license
141
+ end
142
+
143
+ def initial_data_storage_size_in_gb
144
+ launch_details.initial_data_storage_size_in_gb = config[:dbaas][:initial_data_storage_size_in_gb] ||= 256
145
+ end
146
+
147
+ def dbaas_node(instance_id)
148
+ api.dbaas.list_db_nodes(oci.compartment, db_system_id: instance_id).data
149
+ end
150
+
151
+ def instance_ip(instance_id)
152
+ vnic = dbaas_node(instance_id).select(&:vnic_id).first.vnic_id
153
+ if public_ip_allowed?
154
+ api.network.get_vnic(vnic).data.public_ip
155
+ else
156
+ api.network.get_vnic(vnic).data.private_ip
157
+ end
158
+ end
159
+
160
+ def db_version
161
+ raise "db_version cannot be nil!" if config[:dbaas][:db_version].nil?
162
+
163
+ db_home_details.db_version = config[:dbaas][:db_version]
164
+ end
165
+
166
+ def db_home_display_name
167
+ db_home_details.display_name = ["dbhome", random_number(10)].compact.join
168
+ end
169
+
170
+ def character_set
171
+ database_details.character_set = config[:dbaas][:character_set] ||= "AL32UTF8"
172
+ end
173
+
174
+ def ncharacter_set
175
+ database_details.ncharacter_set = config[:dbaas][:ncharacter_set] ||= "AL16UTF16"
176
+ end
177
+
178
+ def db_workload
179
+ workload = config[:dbaas][:db_workload] ||= OCI::Database::Models::CreateDatabaseDetails::DB_WORKLOAD_OLTP
180
+ database_details.db_workload = workload
181
+ end
182
+
183
+ def admin_password
184
+ database_details.admin_password = config[:dbaas][:admin_password] ||= random_password(%w{# _ -})
185
+ end
186
+
187
+ def db_name
188
+ database_details.db_name = config[:dbaas][:db_name] ||= "dbaas1"
189
+ end
190
+
191
+ def pdb_name
192
+ database_details.pdb_name = config[:dbaas][:pdb_name] ||= "pdb001"
193
+ end
194
+
195
+ def db_backup_config
196
+ database_details.db_backup_config = OCI::Database::Models::DbBackupConfig.new.tap do |l|
197
+ l.auto_backup_enabled = false
198
+ end
199
+ database_details
200
+ end
201
+
202
+ def database_edition
203
+ db_edition = config[:dbaas][:database_edition] ||= OCI::Database::Models::DbSystem::DATABASE_EDITION_ENTERPRISE_EDITION
204
+ launch_details.database_edition = db_edition
205
+ end
206
+
207
+ def cluster_name
208
+ prefix = config[:hostname_prefix].split("-")[0]
209
+ # 11 character limit for cluster_name in DBaaS
210
+ cn = if prefix.length >= 11
211
+ prefix[0, 11]
212
+ else
213
+ [prefix, random_string(10 - prefix.length)].compact.join("-")
214
+ end
215
+ launch_details.cluster_name = cn
216
+ end
217
+ end
218
+ end
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
5
+ #
6
+ # Copyright (C) 2024, Stephen Pearson
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ module Kitchen
21
+ module Driver
22
+ class Oci
23
+ module Models
24
+ # iscsi volume attachment model
25
+ class Iscsi < Blockstorage
26
+ attr_reader :attachment_type
27
+
28
+ def initialize(config, state, oci, api)
29
+ super
30
+ @attachment_type = "iscsi"
31
+ end
32
+
33
+ def attachment_details(volume_details, server_id)
34
+ OCI::Core::Models::AttachIScsiVolumeDetails.new(
35
+ display_name: "#{attachment_type}-#{volume_details.display_name}",
36
+ volume_id: volume_details.id,
37
+ instance_id: server_id
38
+ )
39
+ end
40
+
41
+ def final_volume_attachment_state(response)
42
+ volume_attachment_state.store(:id, response.id)
43
+ volume_attachment_state.store(:display_name, response.display_name)
44
+ volume_attachment_state.store(:iqn_ipv4, response.ipv4)
45
+ volume_attachment_state.store(:iqn, response.iqn)
46
+ volume_attachment_state.store(:port, response.port)
47
+ volume_attachment_state
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Author:: Justin Steele (<justin.steele@oracle.com>)
5
+ #
6
+ # Copyright (C) 2024, Stephen Pearson
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ module Kitchen
21
+ module Driver
22
+ class Oci
23
+ module Models
24
+ # paravirtual attachment model
25
+ class Paravirtual < Blockstorage
26
+ attr_reader :attachment_type
27
+
28
+ def initialize(config, state, oci, api)
29
+ super
30
+ @attachment_type = "paravirtual"
31
+ end
32
+
33
+ def attachment_details(volume_details, server_id)
34
+ OCI::Core::Models::AttachParavirtualizedVolumeDetails.new(
35
+ display_name: "#{attachment_type}-#{volume_details.display_name}",
36
+ volume_id: volume_details.id,
37
+ instance_id: server_id
38
+ )
39
+ end
40
+
41
+ def final_volume_attachment_state(response)
42
+ volume_attachment_state.store(:id, response.id)
43
+ volume_attachment_state.store(:display_name, response.display_name)
44
+ volume_attachment_state
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Author:: Stephen Pearson (<stephen.pearson@oracle.com>)
5
+ #
6
+ # Copyright (C) 2019, Stephen Pearson
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ module Kitchen
21
+ module Driver
22
+ class Oci
23
+ # models definitions
24
+ module Models
25
+ require_relative "instance"
26
+ require_relative "blockstorage"
27
+
28
+ def instance_class(config, state, oci, api, action)
29
+ Oci::Models.const_get(config[:instance_type].capitalize).new(config, state, oci, api, action)
30
+ end
31
+
32
+ def volume_class(type, config, state, oci, api)
33
+ Oci::Models.const_get(volume_attachment_type(type)).new(config, state, oci, api)
34
+ end
35
+
36
+ private
37
+
38
+ def volume_attachment_type(type)
39
+ if type.nil?
40
+ "Paravirtual"
41
+ else
42
+ type.capitalize
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end