Skip to content

Commit 4439db9

Browse files
committed
add remaining dcs ops
1 parent 004ed10 commit 4439db9

19 files changed

Lines changed: 1787 additions & 2 deletions

File tree

doc/source/user/proxies/dcs.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,31 @@ Instance Operations
2626
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.start_instance
2727
.. automethod:: otcextensions.sdk.dcs.v1._proxy.Proxy.restart_instance
2828
.. 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
2931

3032
Statistics Operations
3133
^^^^^^^^^^^^^^^^^^^^^
3234

3335
.. autoclass:: otcextensions.sdk.dcs.v1._proxy.Proxy
3436

3537
.. 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
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)
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
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 Config params v1 action implementations'''
14+
import logging
15+
import argparse
16+
17+
from osc_lib import utils
18+
from osc_lib.command import command
19+
20+
from otcextensions.common import sdk_utils
21+
22+
from otcextensions.i18n import _
23+
24+
LOG = logging.getLogger(__name__)
25+
26+
27+
def _get_columns(item):
28+
column_map = {
29+
}
30+
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map)
31+
32+
33+
class ListInstanceParam(command.Lister):
34+
_description = _('List configurational parameters of a single DCS '
35+
'instance')
36+
columns = ('id', 'name', 'value', 'default_value')
37+
38+
def get_parser(self, prog_name):
39+
parser = super(ListInstanceParam, self).get_parser(prog_name)
40+
parser.add_argument(
41+
'instance',
42+
metavar='<instance>',
43+
help=_('Name or ID of the instance')
44+
)
45+
46+
return parser
47+
48+
def take_action(self, parsed_args):
49+
client = self.app.client_manager.dcs
50+
51+
inst = client.find_instance(name_or_id=parsed_args.instance,
52+
ignore_missing=False)
53+
data = client.instance_params(
54+
instance={'id': inst.id},
55+
)
56+
57+
table = (self.columns,
58+
(utils.get_item_properties(
59+
s, self.columns,
60+
) for s in data))
61+
return table
62+
63+
64+
class UpdateInstanceParam(command.Command):
65+
_description = _('Update instance configurational parameters')
66+
67+
def get_parser(self, prog_name):
68+
parser = super(UpdateInstanceParam, self).get_parser(prog_name)
69+
parser.add_argument(
70+
'instance',
71+
metavar='<instance>',
72+
help=_('Name or ID of the DCS instance to take backup from.')
73+
)
74+
parser.add_argument(
75+
'--param',
76+
metavar='<id:name:value>',
77+
required=True,
78+
action='append',
79+
help=_('Parameter pair in format ID:NAME:VALUE.')
80+
)
81+
return parser
82+
83+
def take_action(self, parsed_args):
84+
85+
client = self.app.client_manager.dcs
86+
87+
params = []
88+
89+
for param in parsed_args.param:
90+
param_parts = param.split(':')
91+
if 3 == len(param_parts):
92+
param_struct = {
93+
'param_id': param_parts[0],
94+
'param_name': param_parts[1],
95+
'param_value': param_parts[2]
96+
}
97+
params.append(param_struct)
98+
else:
99+
msg = _('Cannot parse tag information')
100+
raise argparse.ArgumentTypeError(msg)
101+
102+
if params:
103+
print('params=%s' % params)
104+
inst = client.find_instance(name_or_id=parsed_args.instance,
105+
ignore_missing=False)
106+
107+
return client.update_instance_params(
108+
instance={'id': inst.id}, params=params
109+
)
110+
111+
112+
class ShowInstanceParam(command.ShowOne):
113+
_description = _('Show the details of a single instance parameter')
114+
115+
def get_parser(self, prog_name):
116+
parser = super(ShowInstanceParam, self).get_parser(prog_name)
117+
118+
parser.add_argument(
119+
'instance',
120+
metavar='<instance>',
121+
help=_('Name or UUID of the instance.')
122+
)
123+
parser.add_argument(
124+
'--param',
125+
metavar='<param>',
126+
required=True,
127+
help=_('ID or name of the parameter.')
128+
)
129+
130+
return parser
131+
132+
def take_action(self, parsed_args):
133+
134+
client = self.app.client_manager.dcs
135+
136+
inst = client.find_instance(name_or_id=parsed_args.instance,
137+
ignore_missing=False)
138+
data = client.instance_params(
139+
instance={'id': inst.id},
140+
)
141+
142+
criteria = parsed_args.param
143+
144+
found = None
145+
146+
for param in data:
147+
if param.id == criteria or criteria in param.name:
148+
found = param
149+
break
150+
151+
if found:
152+
display_columns, columns = _get_columns(found)
153+
data = utils.get_item_properties(found, columns)
154+
155+
return (display_columns, data)

0 commit comments

Comments
 (0)