Filter jobs by client and/or custom filters
Closes-bug: 1562015 Change-Id: Ib887226c53d747ae36bef0dea7ade6a7a5e37531
This commit is contained in:
parent
5270aa2c66
commit
0a0f24f940
@ -1,4 +1,4 @@
|
|||||||
python-freezerclient Style Commandments
|
python-freezerclient Style Commandments
|
||||||
===============================================
|
=======================================
|
||||||
|
|
||||||
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
|
Read the OpenStack Style Commandments http://docs.openstack.org/developer/hacking/
|
||||||
|
@ -79,7 +79,8 @@ class FreezerShell(App):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def build_option_parser(self, description, version):
|
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(
|
parser.add_argument(
|
||||||
'--os-auth-url',
|
'--os-auth-url',
|
||||||
dest='os_auth_url',
|
dest='os_auth_url',
|
||||||
|
@ -130,3 +130,14 @@ def create_headers_for_request(token):
|
|||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_search(search_term):
|
||||||
|
"""Return a search term that the api can use to query the db
|
||||||
|
:param search_term: string
|
||||||
|
:return: search dict
|
||||||
|
"""
|
||||||
|
if search_term:
|
||||||
|
return {"match": [{"_all": search_term}, ], }
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from cliff.show import ShowOne
|
|||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient.utils import doc_from_json_file
|
||||||
|
from freezerclient.utils import prepare_search
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
@ -90,10 +91,12 @@ class ActionList(Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
search = prepare_search(parsed_args.search)
|
||||||
|
|
||||||
actions = self.app.client.actions.list(
|
actions = self.app.client.actions.list(
|
||||||
limit=parsed_args.limit,
|
limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=parsed_args.search
|
search=search
|
||||||
)
|
)
|
||||||
|
|
||||||
return (('Action ID', 'Name', 'Action',
|
return (('Action ID', 'Name', 'Action',
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
@ -20,6 +21,7 @@ from cliff.lister import Lister
|
|||||||
from cliff.show import ShowOne
|
from cliff.show import ShowOne
|
||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
|
from freezerclient.utils import prepare_search
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
@ -35,10 +37,11 @@ class BackupShow(ShowOne):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
# due to the fact that a backup_id is composed of several strings
|
# 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
|
# some of them may include a slash "/" so it will never find the
|
||||||
# backup, so the workaround for this version is to use the backup_uuid as
|
# correct backup, so the workaround for this version is to use the
|
||||||
# a filter for the search. this won't work when the user wants to delete a
|
# backup_uuid as a filter for the search. this won't work when the
|
||||||
# backup, but that functionality is yet to be provided by the api.
|
# 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}, ], }
|
search = {"match": [{"backup_uuid": parsed_args.backup_uuid}, ], }
|
||||||
backup = self.app.client.backups.list(search=search)
|
backup = self.app.client.backups.list(search=search)
|
||||||
|
|
||||||
@ -88,11 +91,17 @@ class BackupList(Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
search = prepare_search(parsed_args.search)
|
||||||
|
|
||||||
backups = self.app.client.backups.list(limit=parsed_args.limit,
|
backups = self.app.client.backups.list(limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=parsed_args.search)
|
search=search)
|
||||||
return (('Backup ID', 'Backup UUID'),
|
return (('Backup UUID', 'Hostname', 'Path', 'Created at', 'Level'),
|
||||||
((backup.get('backup_id'),
|
((b.get('backup_uuid'),
|
||||||
backup.get('backup_uuid'),
|
b.get('backup_metadata', {}).get('hostname'),
|
||||||
) for backup in backups))
|
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))
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ from cliff.show import ShowOne
|
|||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient.utils import doc_from_json_file
|
||||||
|
from freezerclient.utils import prepare_search
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
@ -83,9 +84,11 @@ class ClientList(Lister):
|
|||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
search = prepare_search(parsed_args.search)
|
||||||
|
|
||||||
clients = self.app.client.clients.list(limit=parsed_args.limit,
|
clients = self.app.client.clients.list(limit=parsed_args.limit,
|
||||||
offset=parsed_args.offset,
|
offset=parsed_args.offset,
|
||||||
search=parsed_args.search)
|
search=search)
|
||||||
|
|
||||||
return (('Client ID', 'uuid', 'hostname', 'description'),
|
return (('Client ID', 'uuid', 'hostname', 'description'),
|
||||||
((client.get('client', {}).get('client_id'),
|
((client.get('client', {}).get('client_id'),
|
||||||
|
@ -23,6 +23,7 @@ from cliff.show import ShowOne
|
|||||||
|
|
||||||
from freezerclient import exceptions
|
from freezerclient import exceptions
|
||||||
from freezerclient.utils import doc_from_json_file
|
from freezerclient.utils import doc_from_json_file
|
||||||
|
from freezerclient.utils import prepare_search
|
||||||
|
|
||||||
|
|
||||||
logging = logging.getLogger(__name__)
|
logging = logging.getLogger(__name__)
|
||||||
@ -89,19 +90,41 @@ class JobList(Lister):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--search',
|
'--search',
|
||||||
dest='search',
|
dest='search',
|
||||||
default='',
|
default={},
|
||||||
help='Define a filter for the query',
|
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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
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'),
|
search = prepare_search(parsed_args.search)
|
||||||
|
|
||||||
|
if parsed_args.client_id:
|
||||||
|
jobs = self.app.client.jobs.list(
|
||||||
|
limit=parsed_args.limit,
|
||||||
|
offset=parsed_args.offset,
|
||||||
|
search=search,
|
||||||
|
client_id=parsed_args.client_id
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
jobs = self.app.client.jobs.list_all(
|
||||||
|
limit=parsed_args.limit,
|
||||||
|
offset=parsed_args.offset,
|
||||||
|
search=search
|
||||||
|
)
|
||||||
|
|
||||||
|
if not jobs:
|
||||||
|
print('No jobs')
|
||||||
|
|
||||||
|
return (('Job ID', 'Description', '# Actions', 'Result', 'Event',
|
||||||
|
'Session ID'),
|
||||||
((job.get('job_id'),
|
((job.get('job_id'),
|
||||||
job.get('description'),
|
job.get('description'),
|
||||||
len(job.get('job_actions', [])),
|
len(job.get('job_actions', [])),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user