Skip to content

Commit 478c3e5

Browse files
CSS Cluster class update and fixed wait_for_cluster method (#424)
CSS Cluster class update and fixed wait_for_cluster method Reviewed-by: Anton Sidelnikov
1 parent b988dd9 commit 478c3e5

23 files changed

+796
-547
lines changed

doc/source/sdk/guides/css.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ parameters.
2929
:class:`~otcextensions.sdk.css.v1.cluster.Cluster`.
3030

3131
.. literalinclude:: ../examples/css/create_cluster.py
32-
:lines: 16-44
32+
:lines: 16-55
3333

3434
Get CSS Cluster
3535
^^^^^^^^^^^^^^^
@@ -48,7 +48,7 @@ This interface is used to find a CSS cluster by id or name.
4848
:class:`~otcextensions.sdk.css.v1.cluster.Cluster`.
4949

5050
.. literalinclude:: ../examples/css/find_cluster.py
51-
:lines: 16-24
51+
:lines: 16-23
5252

5353
Restart CSS Cluster
5454
^^^^^^^^^^^^^^^^^^^

examples/css/create_cluster.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,38 @@
1818
openstack.enable_logging(True)
1919
conn = openstack.connect(cloud='otc')
2020

21-
2221
attrs = {
23-
'name': 'ES-Test',
22+
'name': 'test-cluster',
23+
'datastore': {'type': 'elasticsearch', 'version': '7.10.2'},
2424
'instanceNum': 3,
25-
'datastore': {
26-
'type': 'elasticsearch',
27-
'version': '7.6.2'
25+
'httpsEnable': False,
26+
'diskEncryption': {
27+
'systemEncrypted': '0',
2828
},
2929
'instance': {
3030
'availability_zone': 'eu-de-01',
3131
'flavorRef': 'css.xlarge.2',
32-
'volume': {
33-
'volume_type': 'COMMON',
34-
'size': 100
35-
},
36-
32+
'volume': {'volume_type': 'COMMON', 'size': 100},
3733
'nics': {
38-
'vpcId': 'vpcId',
39-
'netId': 'netId',
40-
'securityGroupId': 'securityGroupId'
41-
}
42-
},
43-
'httpsEnable': 'false',
44-
'diskEncryption': {
45-
'systemEncrypted': '0',
34+
"vpcId": "router-id",
35+
"netId": "network-id",
36+
"securityGroupId": "security-group-id",
37+
},
4638
},
47-
'tags': [{'key': "key0", 'value': "value0"},
48-
{'key': "key1", 'value': "value1"},
49-
{'key': "key2", 'value': "value2"},
50-
{'key': "key3", 'value': "value3"}],
39+
'tags': [
40+
{'key': "key0", 'value': "value0"},
41+
{'key': "key1", 'value': "value1"},
42+
],
5143
'backupStrategy': {
5244
'period': "00:00 GMT+03:00",
5345
'prefix': 'backup',
5446
'keepday': 1,
5547
'bucket': 'css-test-0',
5648
'agency': 'test-css',
57-
'basePath': 'css'
49+
'basePath': 'css',
5850
},
5951
}
60-
result = conn.css.create_cluster(**attrs)
52+
cluster = conn.css.create_cluster(**attrs)
53+
conn.css.wait_for_cluster(cluster)
54+
result = conn.css.get_cluster(cluster)
6155
print(result)

examples/css/create_cluster_opensearch.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# License for the specific language governing permissions and limitations
1212
# under the License.
1313
"""
14-
Create CSS Cluster
14+
Create CSS Cluster (opensearch)
1515
"""
1616
import openstack
1717

@@ -23,39 +23,40 @@
2323
'name': 'opensearch_test',
2424
'instanceNum': 3,
2525
'datastore': {
26-
'type': 'elasticsearch',
27-
'version': 'Opensearch_1.3.6'
26+
'type': 'opensearch',
27+
'version': '1.3.6',
2828
},
2929
'instance': {
3030
'availability_zone': 'eu-de-01',
3131
'flavorRef': 'css.xlarge.2',
3232
'volume': {
3333
'volume_type': 'COMMON',
34-
'size': 100
34+
'size': 100,
3535
},
36-
3736
'nics': {
38-
'vpcId': 'vpcId',
39-
'netId': 'netId',
40-
'securityGroupId': 'securityGroupId'
41-
}
37+
'vpcId': 'VPC-ID',
38+
'netId': 'Network-ID',
39+
'securityGroupId': 'SecurityGroup-ID',
40+
},
4241
},
4342
'httpsEnable': 'false',
4443
'diskEncryption': {
4544
'systemEncrypted': '0',
4645
},
47-
'tags': [{'key': "key0", 'value': "value0"},
48-
{'key': "key1", 'value': "value1"},
49-
{'key': "key2", 'value': "value2"},
50-
{'key': "key3", 'value': "value3"}],
46+
'tags': [
47+
{'key': "key0", 'value': "value0"},
48+
{'key': "key1", 'value': "value1"},
49+
],
5150
'backupStrategy': {
5251
'period': "00:00 GMT+01:00",
5352
'prefix': 'backup',
5453
'keepday': 1,
5554
'bucket': 'css-backup-1663481103064',
5655
'agency': 'test_agency',
57-
'basePath': 'css'
56+
'basePath': 'css',
5857
},
5958
}
6059
result = conn.css.create_cluster(**attrs)
61-
print(result)
60+
conn.css.wait_for_cluster(result)
61+
cluster = conn.css.get_cluster(result)
62+
print(cluster)

examples/css/create_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
attrs = {
2323
"name": "snapshot_001",
2424
"indices": "myindex1,myindex2",
25-
"description": ""
25+
"description": "",
2626
}
2727

2828
result = conn.css.create_snapshot(cluster_id, **attrs)

examples/css/extend_cluster_nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"grow": [
2424
{"type": "ess-master", "nodesize": 2, "disksize": 0},
2525
{"type": "ess", "nodesize": 0, "disksize": 60},
26-
{"type": "ess-client", "nodesize": 1, "disksize": 0}
26+
{"type": "ess-client", "nodesize": 1, "disksize": 0},
2727
]
2828
}
2929
conn.css.extend_cluster_nodes(cluster_id, **attrs)

examples/css/find_cluster.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@
1919
conn = openstack.connect(cloud='otc')
2020

2121
name_or_id = 'css-test-1'
22-
resp = conn.css.find_cluster(
23-
name_or_id, ignore_missing=False)
22+
resp = conn.css.find_cluster(name_or_id, ignore_missing=False)
2423
print(resp)

examples/css/restore_snapshot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
attrs = {
2222
"targetCluster": "target-cluster-uuid",
23-
"indices": "myindex1,myindex2"
23+
"indices": "myindex1,myindex2",
2424
}
2525

2626
cluster_id = 'cluster-uuid'

examples/css/set_snapshot_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
# Set Cluster Snapshot Configuration with custom bucket & agency.
2727
attrs = {
2828
"bucket": "css-backup-1626212749424",
29-
"agency": "css_obs_agency"
29+
"agency": "css_obs_agency",
3030
}
3131
conn.css.set_snapshot_configuration(cluster_id, **attrs)

examples/css/set_snapshot_policy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"prefix": "snapshot",
2323
"period": "16:00 GMT+08:00",
2424
"keepday": 7,
25-
"enable": "true"
25+
"enable": "true",
2626
}
2727

2828
cluster_id = 'cluster-uuid'

otcextensions/common/cli_utils.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,35 @@ def human_readable(self):
3232
self._value = self._value / 1000
3333
timestamp = datetime.datetime.fromtimestamp(self._value)
3434
timezone_offset = datetime.timezone(
35-
datetime.timedelta(hours=gmt_offset))
35+
datetime.timedelta(hours=gmt_offset)
36+
)
3637
timestamp_gmt = timestamp.astimezone(timezone_offset)
3738

3839
# Format the timestamp as a string with the timezone offset
3940
timezone_offset_str = timestamp_gmt.strftime('%z')
40-
timezone_offset_formatted = \
41+
timezone_offset_formatted = (
4142
f'GMT{timezone_offset_str[:3]}:{timezone_offset_str[3:]}'
42-
return timestamp_gmt.strftime(
43-
'%Y-%m-%d %H:%M:%S ') + timezone_offset_formatted
43+
)
44+
return (
45+
timestamp_gmt.strftime('%Y-%m-%d %H:%M:%S ')
46+
+ timezone_offset_formatted
47+
)
4448
# Format GMT+1 timestamp as string
4549

4650

4751
class YamlFormat(cliff_columns.FormattableColumn):
4852
def remove_null_values(self, data):
4953
if isinstance(data, dict):
50-
if 'record_delimiter' in data.keys() and \
51-
'\n' in data['record_delimiter']:
54+
if (
55+
'record_delimiter' in data.keys()
56+
and '\n' in data['record_delimiter']
57+
):
5258
data['record_delimiter'] = '\\n'
5359
return {
54-
k: self.remove_null_values(v) for k,
55-
v in data.items() if v is not None}
60+
k: self.remove_null_values(v)
61+
for k, v in data.items()
62+
if v is not None
63+
}
5664
elif isinstance(data, list):
5765
return [self.remove_null_values(v) for v in data if v is not None]
5866
else:
@@ -61,6 +69,6 @@ def remove_null_values(self, data):
6169
def human_readable(self):
6270
data = self._value
6371
if type(data) not in (dict, list):
64-
data = self._value.to_dict(original_names=True, computed=False)
72+
data = self._value.to_dict(computed=False)
6573
data = self.remove_null_values(data)
6674
return yaml.dump(data, width=100)

0 commit comments

Comments
 (0)