Skip to content

Commit 9368332

Browse files
authored
Merge pull request #9 from OpenTelekomCloud/dcs
Dcs
2 parents 5011a0c + 4439db9 commit 9368332

41 files changed

Lines changed: 4199 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc/source/cli/dcs.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
===================================================
2+
Distributed Cache Service (DCS) command-line client
3+
===================================================
4+
5+
The DCS client is the command-line interface (CLI) for
6+
the Distributed Cache Service (DMS) API and its extensions.
7+
8+
For help on a specific `dcs` command, enter:
9+
10+
.. code-block:: console
11+
12+
$ openstack dcs help SUBCOMMAND
13+
14+
.. _dcs_instance:
15+
16+
Instance operations
17+
-------------------
18+
19+
.. autoprogram-cliff:: openstack.dcs.v1
20+
:command: dcs instance *
21+
22+
.. _dcs_stat:
23+
24+
Statistics operations
25+
---------------------
26+
27+
.. autoprogram-cliff:: openstack.dcs.v1
28+
:command: dcs stat *

doc/source/cli/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
load_balancer.rst
99
volume_backup.rst
1010
dms.rst
11+
dcs.rst

doc/source/user/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ control which services can be used.
126126
Cloud Container Engine <proxies/cce>
127127
Volume Backup Service <proxies/volume_backup>
128128
Distributed Message Service <proxies/dms>
129+
Distributed Cache Service <proxies/dcs>
129130

130131
Resource Interface
131132
~~~~~~~~~~~~~~~~~~

doc/source/user/proxies/dcs.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
DCS API
2+
=======
3+
4+
.. automodule:: otcextensions.sdk.dcs.v1._proxy
5+
6+
The Distributed Message Service Class
7+
-------------------------------------
8+
9+
The dcs high-level interface is available through the ``dcs``
10+
member of a :class:`~openstack.connection.Connection` object. The
11+
``dcs`` member will only be added if the
12+
``otcextensions.sdk.register_otc_extensions(conn)`` method is called.
13+
14+
Instance Operations
15+
^^^^^^^^^^^^^^^^^^^
16+
17+
.. autoclass:: otcextensions.sdk.dcs.v1._proxy.Proxy
18+
19+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.instances
20+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.create_instance
21+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.get_instance
22+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.find_instance
23+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.delete_instance
24+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.update_instance
25+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.extend_instance
26+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.start_instance
27+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.restart_instance
28+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.stop_instance
29+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.stop_instance
30+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.stop_instance
31+
32+
Statistics Operations
33+
^^^^^^^^^^^^^^^^^^^^^
34+
35+
.. autoclass:: otcextensions.sdk.dcs.v1._proxy.Proxy
36+
37+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.statistics
38+
39+
Backup Operations
40+
^^^^^^^^^^^^^^^^^
41+
42+
.. autoclass:: otcextensions.sdk.dcs.v1._proxy.Proxy
43+
44+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.backup_instance
45+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.backups
46+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.delete_instance_backup
47+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.restore_instance
48+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.restore_records
49+
50+
Instance Configuration Operations
51+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
52+
53+
.. autoclass:: otcextensions.sdk.dcs.v1._proxy.Proxy
54+
55+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.instance_params
56+
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.update_instance_params

otcextensions/osclient/dcs/__init__.py

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
import logging
14+
15+
from otcextensions import sdk
16+
17+
18+
LOG = logging.getLogger(__name__)
19+
20+
DEFAULT_API_VERSION = '1.0'
21+
API_VERSION_OPTION = 'os_dcs_api_version'
22+
API_NAME = "dcs"
23+
API_VERSIONS = {
24+
"1.0": "openstack.connection.Connection",
25+
"1": "openstack.connection.Connection",
26+
}
27+
28+
29+
def make_client(instance):
30+
"""Returns a DCS proxy"""
31+
32+
conn = instance.sdk_connection
33+
34+
if getattr(conn, 'dcs', None) is None:
35+
LOG.debug('OTC extensions are not registered. Do that now')
36+
sdk.register_otc_extensions(conn)
37+
38+
LOG.debug('DCS client initialized using OpenStack OTC SDK: %s',
39+
conn.dcs)
40+
return conn.dcs
41+
42+
43+
def build_option_parser(parser):
44+
"""Hook to add global options"""
45+
return parser

otcextensions/osclient/dcs/v1/__init__.py

Whitespace-only changes.
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Licensed under the Apache License, Version 2.0 (the 'License'); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
#
13+
'''DCS Backup v1 action implementations'''
14+
import logging
15+
16+
from osc_lib import utils
17+
from osc_lib.command import command
18+
19+
from otcextensions.common import sdk_utils
20+
21+
from otcextensions.i18n import _
22+
23+
LOG = logging.getLogger(__name__)
24+
25+
26+
def _get_columns(item):
27+
column_map = {
28+
}
29+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
30+
31+
32+
class ListBackup(command.Lister):
33+
_description = _('List backups of a single DCS instance')
34+
columns = ('id', 'name', 'progress', 'status', 'error_code')
35+
36+
def get_parser(self, prog_name):
37+
parser = super(ListBackup, self).get_parser(prog_name)
38+
parser.add_argument(
39+
'instance',
40+
metavar='<instance>',
41+
help=_('Name or ID of the instance')
42+
)
43+
parser.add_argument(
44+
'--limit',
45+
metavar='<limit>',
46+
type=int,
47+
help=_('Limit number of records to return.')
48+
)
49+
parser.add_argument(
50+
'--start',
51+
metavar='<start>',
52+
type=int,
53+
help=_('Start number for querying.')
54+
)
55+
parser.add_argument(
56+
'--from_time',
57+
metavar='<yyyyMMddHHmmss>',
58+
help=_('Start time of the period to be queried.')
59+
)
60+
parser.add_argument(
61+
'--to_time',
62+
metavar='<yyyyMMddHHmmss>',
63+
help=_('End time of the period to be queried.')
64+
)
65+
return parser
66+
67+
def take_action(self, parsed_args):
68+
client = self.app.client_manager.dcs
69+
70+
query = {}
71+
if parsed_args.limit:
72+
query['limit'] = parsed_args.limit
73+
if parsed_args.start:
74+
query['start'] = parsed_args.start
75+
if parsed_args.from_time:
76+
query['begin_time'] = parsed_args.from_time
77+
if parsed_args.to_time:
78+
query['end_time'] = parsed_args.to_time
79+
80+
inst = client.find_instance(name_or_id=parsed_args.instance,
81+
ignore_missing=False)
82+
data = client.backups(
83+
instance={'id': inst.id},
84+
**query
85+
)
86+
87+
table = (self.columns,
88+
(utils.get_item_properties(
89+
s, self.columns,
90+
) for s in data))
91+
return table
92+
93+
94+
class DeleteBackup(command.Command):
95+
_description = _('Delete DCS instance backup')
96+
97+
def get_parser(self, prog_name):
98+
parser = super(DeleteBackup, self).get_parser(prog_name)
99+
parser.add_argument(
100+
'instance',
101+
metavar='<instance>',
102+
help=_('ID of the instance.')
103+
)
104+
parser.add_argument(
105+
'backup',
106+
metavar='<backup>',
107+
nargs='+',
108+
help=_('ID of the instance backup to delete.')
109+
)
110+
return parser
111+
112+
def take_action(self, parsed_args):
113+
114+
if parsed_args.instance:
115+
client = self.app.client_manager.dcs
116+
inst = client.find_instance(name_or_id=parsed_args.instance,
117+
ignore_missing=False)
118+
for backup in parsed_args.backup:
119+
client.delete_instance_backup(
120+
backup=backup,
121+
instance_id=inst.id
122+
)
123+
124+
125+
class CreateBackup(command.ShowOne):
126+
_description = _('Create a backup of a DCS instance')
127+
128+
def get_parser(self, prog_name):
129+
parser = super(CreateBackup, self).get_parser(prog_name)
130+
parser.add_argument(
131+
'instance',
132+
metavar='<instance>',
133+
help=_('Name or ID of the DCS instance to take backup from.')
134+
)
135+
parser.add_argument(
136+
'--description',
137+
metavar='<description>',
138+
help=_('Description of the backup.')
139+
)
140+
return parser
141+
142+
def take_action(self, parsed_args):
143+
144+
client = self.app.client_manager.dcs
145+
146+
attrs = {}
147+
148+
if parsed_args.description:
149+
attrs['description'] = parsed_args.description
150+
151+
inst = client.find_instance(name_or_id=parsed_args.instance,
152+
ignore_missing=False)
153+
154+
obj = client.backup_instance(
155+
instance={'id': inst.id},
156+
**attrs)
157+
158+
display_columns, columns = _get_columns(obj)
159+
data = utils.get_item_properties(obj, columns)
160+
161+
return (display_columns, data)

0 commit comments

Comments
 (0)