Adds audit support in client

This commit enables support in the client for the resource event
logging

Implements: blueprint: audit-support

Co-Authored-By: Kanagaraj Manickam <mkr1481@gmail.com>

Change-Id: Ia54aed6720043840b00dd2eb00ca03a2ed92da5e
Depends-On: Change-Id: Ib82be521c5aa8b627e3f34a3696b10508371d3a0
This commit is contained in:
vish 2016-08-01 22:06:57 +00:00
parent 977038a0b3
commit 647baba801
6 changed files with 185 additions and 2 deletions

View File

@ -45,6 +45,7 @@ from tackerclient.common import exceptions as exc
from tackerclient.common import extension as client_extension
from tackerclient.common import utils
from tackerclient.i18n import _
from tackerclient.tacker.v1_0.events import events
from tackerclient.tacker.v1_0 import extension
from tackerclient.tacker.v1_0.nfvo import vim
from tackerclient.tacker.v1_0.vm import vnf
@ -124,6 +125,13 @@ COMMAND_V1 = {
'vim-delete': vim.DeleteVIM,
'vim-list': vim.ListVIM,
'vim-show': vim.ShowVIM,
'events-list': events.ListResourceEvents,
'event-show': events.ShowEvent,
'vnf-events-list': events.ListVNFEvents,
'vim-events-list': events.ListVIMEvents,
'vnfd-events-list': events.ListVNFDEvents,
}
COMMANDS = {'1.0': COMMAND_V1}

View File

@ -49,8 +49,10 @@ def _get_resource_plural(resource, client):
def find_resourceid_by_id(client, resource, resource_id):
resource_plural = _get_resource_plural(resource, client)
obj_lister = getattr(client, "list_%s" % resource_plural)
# perform search by id only if we are passing a valid UUID
match = re.match(UUID_PATTERN, resource_id)
if resource == 'event':
match = resource_id.isdigit() and resource_id != 0
else:
match = re.match(UUID_PATTERN, resource_id)
collection = resource_plural
if match:
data = obj_lister(id=resource_id, fields='id')

View File

@ -0,0 +1,65 @@
# Copyright 2016 Brocade Communications Systems Inc
# All Rights Reserved.
#
#
# 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.
from tackerclient.tacker import v1_0 as tackerV10
_EVENT = "event"
class ListResourceEvents(tackerV10.ListCommand):
"""List events that belong to a given resource.
The supported args are --id, --resource_id, --resource_state,
--resource_type, --event_type
"""
resource = _EVENT
list_columns = ['id', 'resource_type', 'resource_id',
'resource_state', 'event_type',
'timestamp', 'event_details']
class ListVNFEvents(ListResourceEvents):
"""List events that belong to a given VNF.
The supported args are --id, --resource_id, --resource_state, --event_type
"""
resource = "vnf_event"
class ListVNFDEvents(ListResourceEvents):
"""List events that belong to a given VNFD.
The supported args are --id, --resource_id, --resource_state, --event_type
"""
resource = "vnfd_event"
class ListVIMEvents(ListResourceEvents):
"""List events that belong to a given VIM.
The supported args are --id, --resource_id, --resource_state, --event_type
"""
resource = "vim_event"
class ShowEvent(tackerV10.ShowCommand):
"""Show event given the event id."""
resource = _EVENT

View File

@ -0,0 +1,68 @@
# Copyright 2014 Intel Corporation
# All Rights Reserved.
#
#
# 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 sys
from tackerclient.tacker.v1_0.events import events
from tackerclient.tests.unit import test_cli10
API_VERSION = "1.0"
FORMAT = 'json'
TOKEN = 'testtoken'
ENDURL = 'localurl'
class CLITestV10EventJSON(test_cli10.CLITestV10Base):
_EVT_RESOURCE = 'event'
_EVT_RESOURCES = _EVT_RESOURCE + 's'
_VNF_EVT_RESOURCE = "vnf_event"
_VNF_EVT_RESOURCES = _VNF_EVT_RESOURCE + 's'
_VNFD_EVT_RESOURCE = "vnfd_event"
_VNFD_EVT_RESOURCES = _VNFD_EVT_RESOURCE + 's'
_VIM_EVT_RESOURCE = "vim_event"
_VIM_EVT_RESOURCES = _VIM_EVT_RESOURCE + 's'
def setUp(self):
plurals = {'events': 'event', 'vnf_events': 'vnf_event',
'vnfd_events': 'vnfd_event', 'vim_events': 'vim_event'}
super(CLITestV10EventJSON, self).setUp(plurals=plurals)
def test_list_events(self):
cmd = events.ListResourceEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._EVT_RESOURCES, cmd, True)
def test_list_events_pagination(self):
cmd = events.ListResourceEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources_with_pagination(self._EVT_RESOURCES, cmd,
True)
def test_show_event_id(self):
cmd = events.ShowEvent(test_cli10.MyApp(sys.stdout), None)
args = ['--fields', 'id', self.test_id]
self._test_show_resource(self._EVT_RESOURCE, cmd, self.test_id, args,
['id'])
def test_list_vnf_events(self):
cmd = events.ListVNFEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VNF_EVT_RESOURCES, cmd, True)
def test_list_vnfd_events(self):
cmd = events.ListVNFDEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VNFD_EVT_RESOURCES, cmd, True)
def test_list_vim_events(self):
cmd = events.ListVNFDEvents(test_cli10.MyApp(sys.stdout), None)
self._test_list_resources(self._VIM_EVT_RESOURCES, cmd, True)

View File

@ -343,6 +343,9 @@ class Client(ClientBase):
vims_path = '/vims'
vim_path = '/vims/%s'
events_path = '/events'
event_path = '/events/%s'
# API has no way to report plurals, so we have to hard code them
# EXTED_PLURALS = {}
@ -447,3 +450,40 @@ class Client(ClientBase):
@APIParamsCall
def list_vims(self, retrieve_all=True, **_params):
return self.list('vims', self.vims_path, retrieve_all, **_params)
@APIParamsCall
def list_events(self, retrieve_all=True, **_params):
events = self.list('events', self.events_path, retrieve_all,
**_params)
return events
@APIParamsCall
def list_vnf_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vnf'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vnf_events = {}
vnf_events['vnf_events'] = events['events']
return vnf_events
@APIParamsCall
def list_vnfd_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vnfd'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vnfd_events = {}
vnfd_events['vnfd_events'] = events['events']
return vnfd_events
@APIParamsCall
def list_vim_events(self, retrieve_all=True, **_params):
_params['resource_type'] = 'vim'
events = self.list('events', self.events_path, retrieve_all,
**_params)
vim_events = {}
vim_events['vim_events'] = events['events']
return vim_events
@APIParamsCall
def show_event(self, event_id, **_params):
return self.get(self.event_path % event_id, params=_params)