Skip to content

Commit 735112e

Browse files
Merge pull request #1741 from caberos/issue1739
add vs user-access command
2 parents 0707fdb + 345ae1f commit 735112e

File tree

7 files changed

+93
-23
lines changed

7 files changed

+93
-23
lines changed

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
('virtual:capacity', 'SoftLayer.CLI.virt.capacity:cli'),
5353
('virtual:placementgroup', 'SoftLayer.CLI.virt.placementgroup:cli'),
5454
('virtual:migrate', 'SoftLayer.CLI.virt.migrate:cli'),
55+
('virtual:access', 'SoftLayer.CLI.virt.access:cli'),
5556
('virtual:monitoring', 'SoftLayer.CLI.virt.monitoring:cli'),
5657

5758
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),

SoftLayer/CLI/virt/access.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""Get user access details a virtual server."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import formatting
9+
10+
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Get user access details a virtual server."""
16+
17+
vsi = SoftLayer.VSManager(env.client)
18+
access_logs = vsi.browser_access_log(identifier)
19+
20+
table = formatting.KeyValueTable(['Username', 'Source IP', 'Port', 'Date', 'Event', 'Message'])
21+
for log in access_logs:
22+
table.add_row([log.get('username'), log.get('sourceIp'), log.get('sourcePort'), log.get('createDate'),
23+
log.get('eventType'), log.get('message')])
24+
25+
env.fout(table)

SoftLayer/fixtures/SoftLayer_Virtual_Guest.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
'item': {'description': '2 GB'},
318318
'hourlyRecurringFee': '.06',
319319
'recurringFee': '42'
320-
},
320+
},
321321
'template': {'maxMemory': 2048}
322322
},
323323
{
@@ -920,3 +920,23 @@
920920
"createDate": "2021-03-22T13:15:31-06:00",
921921
"id": 1234567
922922
}
923+
924+
getBrowserConsoleAccessLogs = [
925+
{
926+
"createDate": "2022-03-07T05:32:23-06:00",
927+
"eventType": "CONNECTED",
928+
"id": 509636,
929+
"message": "User connected",
930+
"sourceIp": "44.200.9.0",
931+
"sourcePort": 47097,
932+
"username": "testuser@ibm.com@ibm.com"
933+
},
934+
{
935+
"createDate": "2022-03-07T07:58:27-06:00",
936+
"eventType": "CONNECTED",
937+
"id": 509024,
938+
"message": "User connected",
939+
"sourceIp": "44.200.9.0",
940+
"sourcePort": 41185,
941+
"username": "testuser@ibm.com"
942+
}]

SoftLayer/managers/vs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,3 +1447,14 @@ def attach_portable_storage(self, vs_id, portable_id):
14471447
disk_id, id=vs_id)
14481448

14491449
return result
1450+
1451+
def browser_access_log(self, identifier):
1452+
"""A virtual guest’s browser access logs.
1453+
1454+
:param int identifier: Virtual server id.
1455+
1456+
1457+
:return: SoftLayer_Virtual_BrowserConsoleAccessLog.
1458+
"""
1459+
mask = 'createDate,eventType,id,message,sourceIp,sourcePort,username'
1460+
return self.client.call('SoftLayer_Virtual_Guest', 'getBrowserConsoleAccessLogs', mask=mask, id=identifier)

docs/cli/vs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ If no timezone is specified, IMS local time (CST) will be assumed, which might n
275275
:prog: virtual monitoring
276276
:show-nested:
277277

278+
.. click:: SoftLayer.CLI.virt.access:cli
279+
:prog: virtual access
280+
:show-nested:
281+
278282
Manages the migration of virutal guests. Supports migrating virtual guests on Dedicated Hosts as well.
279283

280284
Reserved Capacity

tests/CLI/modules/vs/vs_tests.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -345,19 +345,19 @@ def test_dns_sync_both(self, confirm_mock):
345345
'getResourceRecords')
346346
getResourceRecords.return_value = []
347347
createAargs = ({
348-
'type': 'a',
349-
'host': 'vs-test1',
350-
'domainId': 12345, # from SoftLayer_Account::getDomains
351-
'data': '172.16.240.2',
352-
'ttl': 7200
353-
},)
348+
'type': 'a',
349+
'host': 'vs-test1',
350+
'domainId': 12345, # from SoftLayer_Account::getDomains
351+
'data': '172.16.240.2',
352+
'ttl': 7200
353+
},)
354354
createPTRargs = ({
355-
'type': 'ptr',
356-
'host': '2',
357-
'domainId': 123456,
358-
'data': 'vs-test1.test.sftlyr.ws',
359-
'ttl': 7200
360-
},)
355+
'type': 'ptr',
356+
'host': '2',
357+
'domainId': 123456,
358+
'data': 'vs-test1.test.sftlyr.ws',
359+
'ttl': 7200
360+
},)
361361

362362
result = self.run_command(['vs', 'dns-sync', '100'])
363363

@@ -400,12 +400,12 @@ def test_dns_sync_v6(self, confirm_mock):
400400
}
401401
}
402402
createV6args = ({
403-
'type': 'aaaa',
404-
'host': 'vs-test1',
405-
'domainId': 12345,
406-
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
407-
'ttl': 7200
408-
},)
403+
'type': 'aaaa',
404+
'host': 'vs-test1',
405+
'domainId': 12345,
406+
'data': '2607:f0d0:1b01:0023:0000:0000:0000:0004',
407+
'ttl': 7200
408+
},)
409409
guest.return_value = test_guest
410410
result = self.run_command(['vs', 'dns-sync', '--aaaa-record', '100'])
411411
self.assert_no_fail(result)
@@ -957,3 +957,7 @@ def test_last_transaction_empty(self):
957957
mock.return_value = vg_return
958958
result = self.run_command(['vs', 'detail', '100'])
959959
self.assert_no_fail(result)
960+
961+
def test_user_access(self):
962+
result = self.run_command(['vs', 'access', '100'])
963+
self.assert_no_fail(result)

tests/managers/vs/vs_tests.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,10 +939,10 @@ def test_edit_full(self):
939939

940940
self.assertEqual(result, True)
941941
args = ({
942-
'hostname': 'new-host',
943-
'domain': 'new.sftlyr.ws',
944-
'notes': 'random notes',
945-
},)
942+
'hostname': 'new-host',
943+
'domain': 'new.sftlyr.ws',
944+
'notes': 'random notes',
945+
},)
946946
self.assert_called_with('SoftLayer_Virtual_Guest', 'editObject',
947947
identifier=100,
948948
args=args)
@@ -1325,3 +1325,8 @@ def test_authorize_storage_empty(self):
13251325
def test_authorize_portable_storage(self):
13261326
options = self.vs.attach_portable_storage(1234, 1234567)
13271327
self.assertEqual(1234567, options['id'])
1328+
1329+
def test_browser_access_log(self):
1330+
result = self.vs.browser_access_log(1234)
1331+
self.assertTrue(result)
1332+
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBrowserConsoleAccessLogs', identifier=1234)

0 commit comments

Comments
 (0)