-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,787 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
'''DCS Backup v1 action implementations''' | ||
import logging | ||
|
||
from osc_lib import utils | ||
from osc_lib.command import command | ||
|
||
from otcextensions.common import sdk_utils | ||
|
||
from otcextensions.i18n import _ | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def _get_columns(item): | ||
column_map = { | ||
} | ||
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) | ||
|
||
|
||
class ListBackup(command.Lister): | ||
_description = _('List backups of a single DCS instance') | ||
columns = ('id', 'name', 'progress', 'status', 'error_code') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(ListBackup, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('Name or ID of the instance') | ||
) | ||
parser.add_argument( | ||
'--limit', | ||
metavar='<limit>', | ||
type=int, | ||
help=_('Limit number of records to return.') | ||
) | ||
parser.add_argument( | ||
'--start', | ||
metavar='<start>', | ||
type=int, | ||
help=_('Start number for querying.') | ||
) | ||
parser.add_argument( | ||
'--from_time', | ||
metavar='<yyyyMMddHHmmss>', | ||
help=_('Start time of the period to be queried.') | ||
) | ||
parser.add_argument( | ||
'--to_time', | ||
metavar='<yyyyMMddHHmmss>', | ||
help=_('End time of the period to be queried.') | ||
) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
client = self.app.client_manager.dcs | ||
|
||
query = {} | ||
if parsed_args.limit: | ||
query['limit'] = parsed_args.limit | ||
if parsed_args.start: | ||
query['start'] = parsed_args.start | ||
if parsed_args.from_time: | ||
query['begin_time'] = parsed_args.from_time | ||
if parsed_args.to_time: | ||
query['end_time'] = parsed_args.to_time | ||
|
||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
data = client.backups( | ||
instance={'id': inst.id}, | ||
**query | ||
) | ||
|
||
table = (self.columns, | ||
(utils.get_item_properties( | ||
s, self.columns, | ||
) for s in data)) | ||
return table | ||
|
||
|
||
class DeleteBackup(command.Command): | ||
_description = _('Delete DCS instance backup') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(DeleteBackup, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('ID of the instance.') | ||
) | ||
parser.add_argument( | ||
'backup', | ||
metavar='<backup>', | ||
nargs='+', | ||
help=_('ID of the instance backup to delete.') | ||
) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
|
||
if parsed_args.instance: | ||
client = self.app.client_manager.dcs | ||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
for backup in parsed_args.backup: | ||
client.delete_instance_backup( | ||
backup=backup, | ||
instance_id=inst.id | ||
) | ||
|
||
|
||
class CreateBackup(command.ShowOne): | ||
_description = _('Create a backup of a DCS instance') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(CreateBackup, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('Name or ID of the DCS instance to take backup from.') | ||
) | ||
parser.add_argument( | ||
'--description', | ||
metavar='<description>', | ||
help=_('Description of the backup.') | ||
) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
|
||
client = self.app.client_manager.dcs | ||
|
||
attrs = {} | ||
|
||
if parsed_args.description: | ||
attrs['description'] = parsed_args.description | ||
|
||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
|
||
obj = client.backup_instance( | ||
instance={'id': inst.id}, | ||
**attrs) | ||
|
||
display_columns, columns = _get_columns(obj) | ||
data = utils.get_item_properties(obj, columns) | ||
|
||
return (display_columns, data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
# Licensed under the Apache License, Version 2.0 (the 'License'); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
'''DCS Config params v1 action implementations''' | ||
import logging | ||
import argparse | ||
|
||
from osc_lib import utils | ||
from osc_lib.command import command | ||
|
||
from otcextensions.common import sdk_utils | ||
|
||
from otcextensions.i18n import _ | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def _get_columns(item): | ||
column_map = { | ||
} | ||
return sdk_utils.get_osc_show_columns_for_sdk_resource(item, column_map) | ||
|
||
|
||
class ListInstanceParam(command.Lister): | ||
_description = _('List configurational parameters of a single DCS ' | ||
'instance') | ||
columns = ('id', 'name', 'value', 'default_value') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(ListInstanceParam, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('Name or ID of the instance') | ||
) | ||
|
||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
client = self.app.client_manager.dcs | ||
|
||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
data = client.instance_params( | ||
instance={'id': inst.id}, | ||
) | ||
|
||
table = (self.columns, | ||
(utils.get_item_properties( | ||
s, self.columns, | ||
) for s in data)) | ||
return table | ||
|
||
|
||
class UpdateInstanceParam(command.Command): | ||
_description = _('Update instance configurational parameters') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(UpdateInstanceParam, self).get_parser(prog_name) | ||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('Name or ID of the DCS instance to take backup from.') | ||
) | ||
parser.add_argument( | ||
'--param', | ||
metavar='<id:name:value>', | ||
required=True, | ||
action='append', | ||
help=_('Parameter pair in format ID:NAME:VALUE.') | ||
) | ||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
|
||
client = self.app.client_manager.dcs | ||
|
||
params = [] | ||
|
||
for param in parsed_args.param: | ||
param_parts = param.split(':') | ||
if 3 == len(param_parts): | ||
param_struct = { | ||
'param_id': param_parts[0], | ||
'param_name': param_parts[1], | ||
'param_value': param_parts[2] | ||
} | ||
params.append(param_struct) | ||
else: | ||
msg = _('Cannot parse tag information') | ||
raise argparse.ArgumentTypeError(msg) | ||
|
||
if params: | ||
print('params=%s' % params) | ||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
|
||
return client.update_instance_params( | ||
instance={'id': inst.id}, params=params | ||
) | ||
|
||
|
||
class ShowInstanceParam(command.ShowOne): | ||
_description = _('Show the details of a single instance parameter') | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(ShowInstanceParam, self).get_parser(prog_name) | ||
|
||
parser.add_argument( | ||
'instance', | ||
metavar='<instance>', | ||
help=_('Name or UUID of the instance.') | ||
) | ||
parser.add_argument( | ||
'--param', | ||
metavar='<param>', | ||
required=True, | ||
help=_('ID or name of the parameter.') | ||
) | ||
|
||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
|
||
client = self.app.client_manager.dcs | ||
|
||
inst = client.find_instance(name_or_id=parsed_args.instance, | ||
ignore_missing=False) | ||
data = client.instance_params( | ||
instance={'id': inst.id}, | ||
) | ||
|
||
criteria = parsed_args.param | ||
|
||
found = None | ||
|
||
for param in data: | ||
if param.id == criteria or criteria in param.name: | ||
found = param | ||
break | ||
|
||
if found: | ||
display_columns, columns = _get_columns(found) | ||
data = utils.get_item_properties(found, columns) | ||
|
||
return (display_columns, data) |
Oops, something went wrong.