Skip to content

Commit 087ca0d

Browse files
caberoscaberos
authored andcommitted
New Command: virtual notifications
1 parent 2c86f68 commit 087ca0d

File tree

8 files changed

+154
-0
lines changed

8 files changed

+154
-0
lines changed

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
('virtual:migrate', 'SoftLayer.CLI.virt.migrate:cli'),
5555
('virtual:access', 'SoftLayer.CLI.virt.access:cli'),
5656
('virtual:monitoring', 'SoftLayer.CLI.virt.monitoring:cli'),
57+
('virtual:notifications', 'SoftLayer.CLI.virt.notifications:cli'),
58+
('virtual:add-notification', 'SoftLayer.CLI.virt.add_notification:cli'),
5759

5860
('dedicatedhost', 'SoftLayer.CLI.dedicatedhost'),
5961
('dedicatedhost:list', 'SoftLayer.CLI.dedicatedhost.list:cli'),
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Create a user virtual notification entry."""
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+
@click.option('--users', multiple=True,
14+
help='UserId to be notified on monitoring failure.')
15+
@environment.pass_env
16+
def cli(env, identifier, users):
17+
"""Create a user virtual notification entry."""
18+
19+
virtual = SoftLayer.VSManager(env.client)
20+
21+
table = formatting.KeyValueTable(['Id', 'Hostmane', 'Username', 'Email', 'FirstName', 'Lastname'])
22+
table.align['Id'] = 'r'
23+
table.align['Username'] = 'l'
24+
25+
for user in users:
26+
notification = virtual.add_notification(identifier, user)
27+
table.add_row([notification['id'], notification['guest']['fullyQualifiedDomainName'],
28+
notification['user']['username'], notification['user']['email'],
29+
notification['user']['lastName'], notification['user']['firstName']])
30+
31+
env.fout(table)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Get all hardware notifications associated with the passed hardware ID."""
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 all hardware notifications."""
16+
17+
virtual = SoftLayer.VSManager(env.client)
18+
19+
notifications = virtual.get_notifications(identifier)
20+
21+
table = formatting.KeyValueTable(['Domain', 'Hostmane', 'Username', 'Email', 'FirstName', 'Lastname'])
22+
table.align['Domain'] = 'r'
23+
table.align['Username'] = 'l'
24+
25+
for notification in notifications:
26+
table.add_row([notification['guest']['fullyQualifiedDomainName'], notification['guest']['hostname'],
27+
notification['user']['username'], notification['user']['email'],
28+
notification['user']['lastName'], notification['user']['firstName']])
29+
30+
env.fout(table)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
findByGuestId = [
2+
{
3+
'guestId': 100,
4+
'id': 123,
5+
'userId': 147852,
6+
'guest': {
7+
'domain': 'test.support.com',
8+
'fullyQualifiedDomainName': 'adns.test.support.com',
9+
'hostname': 'adns',
10+
'id': 123,
11+
'maxCpu': 4,
12+
'maxCpuUnits': 'CORE',
13+
'maxMemory': 16384,
14+
'startCpus': 4,
15+
'statusId': 1001,
16+
'uuid': 'b395782d-2144-1f9c-0a90-28a7a5160d81',
17+
},
18+
'user': {
19+
'accountId': 147852,
20+
'displayName': 'TESTSUPPORT',
21+
'email': 'testsupport@us.ibm.com',
22+
'firstName': 'test',
23+
'id': 167758,
24+
'lastName': 'support',
25+
'username': 'test',
26+
}
27+
}
28+
]
29+
30+
createObject = {
31+
'guestId': 100,
32+
'id': 123,
33+
'userId': 147852,
34+
'guest': {
35+
'domain': 'test.support.com',
36+
'fullyQualifiedDomainName': 'adns.test.support.com',
37+
'hostname': 'adns',
38+
'id': 123,
39+
'maxCpu': 4,
40+
'maxCpuUnits': 'CORE',
41+
'maxMemory': 16384,
42+
'startCpus': 4,
43+
'statusId': 1001,
44+
'uuid': 'b395782d-2144-1f9c-0a90-28a7a5160d81',
45+
},
46+
'user': {
47+
'accountId': 147852,
48+
'displayName': 'TESTSUPPORT',
49+
'email': 'testsupport@us.ibm.com',
50+
'firstName': 'test',
51+
'id': 167758,
52+
'lastName': 'support',
53+
'username': 'test',
54+
}
55+
}

SoftLayer/managers/vs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,3 +1458,15 @@ def browser_access_log(self, identifier):
14581458
"""
14591459
mask = 'createDate,eventType,id,message,sourceIp,sourcePort,username'
14601460
return self.client.call('SoftLayer_Virtual_Guest', 'getBrowserConsoleAccessLogs', mask=mask, id=identifier)
1461+
1462+
def get_notifications(self, vs_id):
1463+
"""Returns all virtual notifications."""
1464+
return self.client.call('SoftLayer_User_Customer_Notification_Virtual_Guest', 'findByGuestId', vs_id)
1465+
1466+
def add_notification(self, virtual_id, user_id):
1467+
"""Create a user virtual notification entry"""
1468+
1469+
template = {"guestId": virtual_id, "userId": user_id}
1470+
mask = 'user'
1471+
return self.client.call('SoftLayer_User_Customer_Notification_Virtual_Guest',
1472+
'createObject', template, mask=mask)

docs/cli/vs.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ If no timezone is specified, IMS local time (CST) will be assumed, which might n
279279
:prog: virtual access
280280
:show-nested:
281281

282+
.. click:: SoftLayer.CLI.virt.notifications:cli
283+
:prog: virtual notifications
284+
:show-nested:
285+
286+
.. click:: SoftLayer.CLI.virt.add_notification:cli
287+
:prog: virtual add-notification
288+
:show-nested:
289+
282290
Manages the migration of virutal guests. Supports migrating virtual guests on Dedicated Hosts as well.
283291

284292
Reserved Capacity

tests/CLI/modules/vs/vs_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,3 +961,11 @@ def test_last_transaction_empty(self):
961961
def test_user_access(self):
962962
result = self.run_command(['vs', 'access', '100'])
963963
self.assert_no_fail(result)
964+
965+
def test_notifications(self):
966+
result = self.run_command(['vs', 'notifications', '100'])
967+
self.assert_no_fail(result)
968+
969+
def test_add_notification(self):
970+
result = self.run_command(['vs', 'add-notification', '100', '--users', '123456'])
971+
self.assert_no_fail(result)

tests/managers/vs/vs_tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,3 +1330,11 @@ def test_browser_access_log(self):
13301330
result = self.vs.browser_access_log(1234)
13311331
self.assertTrue(result)
13321332
self.assert_called_with('SoftLayer_Virtual_Guest', 'getBrowserConsoleAccessLogs', identifier=1234)
1333+
1334+
def test_notification(self):
1335+
self.vs.get_notifications(100)
1336+
self.assert_called_with('SoftLayer_User_Customer_Notification_Virtual_Guest', 'findByGuestId')
1337+
1338+
def test_add_notification(self):
1339+
self.vs.add_notification(100, 123456)
1340+
self.assert_called_with('SoftLayer_User_Customer_Notification_Virtual_Guest', 'createObject')

0 commit comments

Comments
 (0)