Filter jobs by client or custom filters
Resolves bug: 1562015 Change-Id: Ib887226c53d747ae36bef0dea7ade6a7a5e37531
This commit is contained in:
parent
f933fec8a1
commit
3d261d1354
|
@ -79,7 +79,8 @@ class FreezerShell(App):
|
|||
)
|
||||
|
||||
def build_option_parser(self, description, version):
|
||||
parser = super(FreezerShell, self).build_option_parser(description, version)
|
||||
parser = super(FreezerShell, self).build_option_parser(description,
|
||||
version)
|
||||
parser.add_argument(
|
||||
'--os-auth-url',
|
||||
dest='os_auth_url',
|
||||
|
|
|
@ -90,6 +90,9 @@ class ActionList(Lister):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
if parsed_args.search:
|
||||
parsed_args.search = {"match": [{"_all": parsed_args.search}, ], }
|
||||
|
||||
actions = self.app.client.actions.list(
|
||||
limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
from pprint import pformat
|
||||
|
@ -35,10 +36,11 @@ class BackupShow(ShowOne):
|
|||
|
||||
def take_action(self, parsed_args):
|
||||
# due to the fact that a backup_id is composed of several strings
|
||||
# some of them may include a slash "/" so it will never find the correct
|
||||
# backup, so the workaround for this version is to use the backup_uuid as
|
||||
# a filter for the search. this won't work when the user wants to delete a
|
||||
# backup, but that functionality is yet to be provided by the api.
|
||||
# some of them may include a slash "/" so it will never find the
|
||||
# correct backup, so the workaround for this version is to use the
|
||||
# backup_uuid as a filter for the search. this won't work when the
|
||||
# user wants to delete a backup, but that functionality is yet to be
|
||||
# provided by the api.
|
||||
search = {"match": [{"backup_uuid": parsed_args.backup_uuid}, ], }
|
||||
backup = self.app.client.backups.list(search=search)
|
||||
|
||||
|
@ -88,11 +90,19 @@ class BackupList(Lister):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
if parsed_args.search:
|
||||
parsed_args.search = {"match": [{"_all": parsed_args.search}, ], }
|
||||
|
||||
backups = self.app.client.backups.list(limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
search=parsed_args.search)
|
||||
return (('Backup ID', 'Backup UUID'),
|
||||
((backup.get('backup_id'),
|
||||
backup.get('backup_uuid'),
|
||||
) for backup in backups))
|
||||
return (('Backup UUID', 'Hostname', 'Path to backup', 'Created at',
|
||||
'Level'),
|
||||
((b.get('backup_uuid'),
|
||||
b.get('backup_metadata', {}).get('hostname'),
|
||||
b.get('backup_metadata', {}).get('path_to_backup'),
|
||||
datetime.datetime.fromtimestamp(
|
||||
int(b.get('backup_metadata',{}).get('time_stamp'))),
|
||||
b.get('backup_metadata', {}).get('curr_backup_level')
|
||||
) for b in backups))
|
||||
|
||||
|
|
|
@ -83,6 +83,9 @@ class ClientList(Lister):
|
|||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
if parsed_args.search:
|
||||
parsed_args.search = {"match": [{"_all": parsed_args.search}, ], }
|
||||
|
||||
clients = self.app.client.clients.list(limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
search=parsed_args.search)
|
||||
|
|
|
@ -89,19 +89,42 @@ class JobList(Lister):
|
|||
parser.add_argument(
|
||||
'--search',
|
||||
dest='search',
|
||||
default='',
|
||||
default={},
|
||||
help='Define a filter for the query',
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--client', '-C',
|
||||
dest='client_id',
|
||||
default='',
|
||||
help='Get jobs for a specific client',
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
jobs = self.app.client.jobs.list_all(
|
||||
limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
search=parsed_args.search
|
||||
)
|
||||
|
||||
return (('Job ID', 'Description', '# Actions', 'Result', 'Event', 'Session ID'),
|
||||
if parsed_args.search:
|
||||
parsed_args.search = {"match": [{"_all": parsed_args.search}, ], }
|
||||
|
||||
if parsed_args.client_id:
|
||||
jobs = self.app.client.jobs.list(
|
||||
limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
search=parsed_args.search,
|
||||
client_id=parsed_args.client_id
|
||||
)
|
||||
else:
|
||||
jobs = self.app.client.jobs.list_all(
|
||||
limit=parsed_args.limit,
|
||||
offset=parsed_args.offset,
|
||||
search=parsed_args.search
|
||||
)
|
||||
|
||||
if not jobs:
|
||||
print('No jobs')
|
||||
|
||||
return (('Job ID', 'Description', '# Actions', 'Result', 'Event',
|
||||
'Session ID'),
|
||||
((job.get('job_id'),
|
||||
job.get('description'),
|
||||
len(job.get('job_actions', [])),
|
||||
|
|
Loading…
Reference in New Issue