Skip to content

Conversation

@fisherma91
Copy link
Contributor

This PR adds the following features to SoftLayer Python:

  • Support for the new return values of SoftLayer_Network_SecurityGroup.addRules(), SoftLayer_Network_SecurityGroup.editRules(), SoftLayer_Network_SecurityGroup.removeRules(), SoftLayer_Network_SecurityGroup. attachNetworkComponents() and SoftLayer_Network_SecurityGroup. detachNetworkComponents()
  • Add abstraction for Event_Log. getAllEventObjectNames()
  • Add the ability to search for Event_Log objects by type, date range, and requestId (Value now returned by the modified SoftLayer_Network_SecurityGroup methods mentioned above)

fisherma91 and others added 15 commits August 23, 2017 14:59
The python api will now output a table with requestIDs for specific calls to security groups apis
Fix unit tests
Fix code style issues
Add functionality to get event logs to slcli
Refactor Event Log Code
Fix Unit Tests
Add Unit Tests
Fix Code Styling
Remove unneeded code left over from refactoring
Fix incorrect package name
Change public facing name to Audit Logs
Add functionality to get event log types
Fix ordering of test expecations to be Actual then Expected
Add functionality to filter by eventName
Add functionality to filter by dates
Add request id search functionality
@rlrossiter rlrossiter self-requested a review February 1, 2018 19:56
@coveralls
Copy link

coveralls commented Feb 1, 2018

Coverage Status

Coverage increased (+0.2%) to 87.152% when pulling 6333687 on fisherma91:security-groups-request-ids into 23dab1e on softlayer:master.

Copy link

@rlrossiter rlrossiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a first pass through the event log side of things, and I think there could be a little shuffling to organize what functions are where to make it a little more usable.

From an interface standpoint, I think you could have 2 functions on the event log manager publicly exposed, get_logs_by_event() and get_logs_by_object() (or break it apart in any way that makes sense) that would contain most of the filter building that currently exists within the CLI.

We can then add a function to either the event log manager that then gets the audit logs for SG operations. Then the sg CLI could have an extra command add it that does the request log querying instead of building SG functionality into the event log CLI.



@click.command()
@click.option('--date_min', '-d',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency, all of these options should be --date-min (dash in middle instead of underscore). As for the args, click automatically changes it for you (so --date-min becomes date_min)

@click.option('--obj_id', '-i',
help="The id of the object we want to get audit logs for")
@click.option('--request_id', '-r',
help="The request id we want to look for. If this is set, we will ignore all other arguments.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather throw an error if they're used together instead of ignoring all other arguments. That way it isn't silently doing something the user may not be aware of

"""Get Audit Logs"""
mgr = SoftLayer.EventLogManager(env.client)

if request_id is not None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So down here you'd add a check for if request_id and any(date_min, date_max, obj_event, ....) and you'd raise a CLIAbort on it

@click.option('--obj_type', '-t',
help="The type of the object we want to get audit logs for")
@click.option('--utc_offset', '-z',
help="UTC Offset for seatching with dates. The default is -0500")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm nervous to force people into -0500. I'd lean more towards if they don't specify it, just leave it at 0.

return filtered_logs


def _parse_date(date_string, utc_offset):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move this to a utility and unit test the heck out of it since this looks a little complex

if date_min and date_max:
request_filter['eventCreateDate'] = {
'operation': 'betweenDate',
'options': [

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are utils for building date filters https://github.com/softlayer/softlayer-python/blob/master/SoftLayer/utils.py#L111. Not sure if that can be used for these as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These won't work for this case, because of where the Event_Log entries are stored.

We need to have a different filter format for it to work.

env.fout(table)


def _build_filter(date_min, date_max, obj_event, obj_id, obj_type, utc_offset):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should get moved to the manager instead of doing all of the legwork in the CLI. That way if people want to find certain event logs when using python, they can borrow this filter building.

:param dict request_filter: filter dict
:returns: List of event logs
"""
results = self.client.call("Event_Log",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a convention standpoint, usually you can just store the event log service on the manager itself. So you'd add self.event_log = client['Event_Log'] to __init__(), and then in these functions you can just do self.event_log.getAllObjects(filter=request_filter)

change date_min to date-min in click args
change date_max to date-max in click args
change how the event log client is initialized
move filter building code into event log manager
set default utc offset to +0000
move date parsing code into utils
add ability to get event logs by type
add ability to get event logs by name
move requestID searching into Security Groups code
Overhaul unit tests
Copy link

@rlrossiter rlrossiter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're getting close. I tried out most of the slcli audit-log command. I still need to try out the slcli sg audit-log to check that as well, but just wanted to post a few of the comments that I had.


self.assertEqual(expected, result)

def test__get_cci_event_logs(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't super important, but it looks like you've got two _ between test and get.

@click.option('--obj_type', '-t',
help="The type of the object we want to get audit logs for")
@click.option('--utc_offset', '-z',
help="UTC Offset for seatching with dates. The default is -0000")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

searching is misspelled here

help='The earliest date we want to search for audit logs in mm/dd/yyyy format.')
@click.option('--date-max', '-D',
help='The latest date we want to search for audit logs in mm/dd/yyyy format.')
@click.option('--obj_event', '-e',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these other options still need to be switched over to use - instead of _ as well

@click.argument('request_id')
@environment.pass_env
def get_by_request_id(env, request_id):
"""Search for event logs by request id"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(venv) ryans-mbp-2:softlayer-python rlrossit$ slcli sg audit-log -h
Usage: slcli sg audit-log [OPTIONS] REQUEST_ID

  Search for event logs by request id

Having it be called sg audit log, with the help text then showing "Search for event logs" is kind of confusing. It looks like throughout most of this PR audit log and event log are being used interchangeably. I'd settle on one of the names, and use it everywhere (file/class names, CLI, etc.)

raise exceptions.CLIAbort("Could not detach network component")

table = formatting.Table(REQUEST_COLUMNS)
table.add_row([success['requestId']])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename the success variable returned from detach, since using it in this situation reads weird. I'd just use ret like all of the other functions are using.

}


def format_event_log_date(date_string, utc):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it kinda surprises me that there are no unit tests for the utils module, but we should probably have some tests for these functions.

@allmightyspiff
Copy link
Member

@fisherma91 have you had a chance to look at Ryan's suggestions?

@fisherma91
Copy link
Contributor Author

@allmightyspiff I have. I've just been heads down with forward development and haven't been able to work in his feedback.

@allmightyspiff
Copy link
Member

going to be finished in #1099

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants