-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from tzumainn/event-command
Add event list command
- Loading branch information
Showing
7 changed files
with
244 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# 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. | ||
|
||
import logging | ||
|
||
from osc_lib.command import command | ||
from osc_lib import utils as oscutils | ||
|
||
from esileapclient.v1.event import Event as EVENT_RESOURCE | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class ListEvent(command.Lister): | ||
"""List events.""" | ||
|
||
log = logging.getLogger(__name__ + ".ListEvent") | ||
|
||
def get_parser(self, prog_name): | ||
parser = super(ListEvent, self).get_parser(prog_name) | ||
|
||
parser.add_argument( | ||
'--project', | ||
dest='project_id', | ||
required=False, | ||
help="Show all events associated with given project ID or name.") | ||
parser.add_argument( | ||
'--last-event-id', | ||
dest='last_event_id', | ||
required=False, | ||
help="Show events after this event ID.") | ||
parser.add_argument( | ||
'--last-notification-time', | ||
dest='last_event_time', | ||
required=False, | ||
help="Show events after this notification time.") | ||
parser.add_argument( | ||
'--event-type', | ||
dest='event_type', | ||
required=False, | ||
help="Show events matching this event type.") | ||
parser.add_argument( | ||
'--resource-type', | ||
dest='resource_type', | ||
required=False, | ||
help="Show events matching this resource type.") | ||
parser.add_argument( | ||
'--resource-uuid', | ||
dest='resource_uuid', | ||
required=False, | ||
help="Show events matching this resource ID or name.") | ||
|
||
return parser | ||
|
||
def take_action(self, parsed_args): | ||
client = self.app.client_manager.lease | ||
|
||
filters = { | ||
'lessee_or_owner_id': parsed_args.project_id, | ||
'last_event_id': parsed_args.last_event_id, | ||
'last_event_time': parsed_args.last_event_time, | ||
'event_type': parsed_args.event_type, | ||
'resource_type': parsed_args.resource_type, | ||
'resource_uuid': parsed_args.resource_uuid, | ||
} | ||
|
||
data = client.event.list(filters) | ||
columns = EVENT_RESOURCE.fields.keys() | ||
labels = EVENT_RESOURCE.fields.values() | ||
|
||
return (labels, | ||
(oscutils.get_item_properties(s, columns) for s in 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
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,69 @@ | ||
import copy | ||
|
||
from esileapclient.osc.v1 import event | ||
from esileapclient.tests.unit.osc.v1 import base | ||
from esileapclient.tests.unit.osc.v1 import fakes | ||
|
||
|
||
class TestEvent(base.TestESILeapCommand): | ||
|
||
def setUp(self): | ||
super(TestEvent, self).setUp() | ||
|
||
self.client_mock = self.app.client_manager.lease | ||
self.client_mock.reset_mock() | ||
|
||
|
||
class TestEventList(TestEvent): | ||
|
||
def setUp(self): | ||
super(TestEventList, self).setUp() | ||
|
||
self.client_mock.event.list.return_value = [ | ||
base.FakeResource(copy.deepcopy(fakes.EVENT)) | ||
] | ||
self.cmd = event.ListEvent(self.app, None) | ||
|
||
def test_event_list(self): | ||
arglist = [] | ||
verifylist = [] | ||
|
||
parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||
columns, data = self.cmd.take_action(parsed_args) | ||
|
||
filters = { | ||
'lessee_or_owner_id': parsed_args.project_id, | ||
'last_event_id': parsed_args.last_event_id, | ||
'last_event_time': parsed_args.last_event_time, | ||
'event_type': parsed_args.event_type, | ||
'resource_type': parsed_args.resource_type, | ||
'resource_uuid': parsed_args.resource_uuid, | ||
} | ||
|
||
self.client_mock.event.list.assert_called_with(filters) | ||
|
||
collist = [ | ||
"ID", | ||
"Event Type", | ||
"Event Time", | ||
"Object Type", | ||
"Object UUID", | ||
"Resource Type", | ||
"Resource UUID", | ||
"Lessee ID", | ||
"Owner ID", | ||
] | ||
|
||
self.assertEqual(collist, list(columns)) | ||
|
||
datalist = ((fakes.event_id, | ||
fakes.event_type, | ||
fakes.event_time, | ||
fakes.object_type, | ||
fakes.lease_uuid, | ||
fakes.lease_resource_type, | ||
fakes.lease_resource_uuid, | ||
fakes.lease_project_id, | ||
fakes.lease_owner_id, | ||
),) | ||
self.assertEqual(datalist, tuple(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
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,73 @@ | ||
# 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. | ||
|
||
import logging | ||
|
||
from esileapclient.common import base | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Event(base.Resource): | ||
|
||
detailed_fields = { | ||
'id': "ID", | ||
'event_type': "Event Type", | ||
'event_time': "Event Time", | ||
'object_type': "Object Type", | ||
'object_uuid': "Object UUID", | ||
'resource_type': "Resource Type", | ||
'resource_uuid': "Resource UUID", | ||
'lessee_id': "Lessee ID", | ||
'owner_id': "Owner ID", | ||
} | ||
|
||
fields = { | ||
'id': "ID", | ||
'event_type': "Event Type", | ||
'event_time': "Event Time", | ||
'object_type': "Object Type", | ||
'object_uuid': "Object UUID", | ||
'resource_type': "Resource Type", | ||
'resource_uuid': "Resource UUID", | ||
'lessee_id': "Lessee ID", | ||
'owner_id': "Owner ID", | ||
} | ||
|
||
_creation_attributes = ['id', 'event_type', 'event_time', | ||
'object_type', 'object_uuid', | ||
'resource_type', 'resource_uuid', | ||
'lessee_id', 'owner_id'] | ||
|
||
def __repr__(self): | ||
return "<Event %s>" % self._info | ||
|
||
|
||
class EventManager(base.Manager): | ||
resource_class = Event | ||
_resource_name = 'events' | ||
|
||
def list(self, filters, os_esileap_api_version=None): | ||
"""Retrieve a list of events. | ||
:returns: A list of events. | ||
""" | ||
|
||
resource_id = '' | ||
|
||
url_variables = EventManager._url_variables(filters) | ||
url = self._path(resource_id) + url_variables | ||
|
||
events = self._list(url, | ||
os_esileap_api_version=os_esileap_api_version) | ||
|
||
if type(events) is list: | ||
return events |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openstacksdk<1.3.0 | ||
pbr!=2.1.0,>=2.0.0 # Apache-2.0 | ||
python-openstackclient>=3.18.0 | ||
six>=1.12.0 | ||
six>=1.12.0 |
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