Skip to content

Commit 4bad4e6

Browse files
Merge branch 'master' of github.com:softlayer/softlayer-python
2 parents 392c387 + 00e6a06 commit 4bad4e6

18 files changed

+342
-21
lines changed

SoftLayer/CLI/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
class OptionHighlighter(RegexHighlighter):
2424
"""Provides highlighter regex for the Command help"""
2525
highlights = [
26-
r"(?P<switch>\-\w)", # single options like -v
26+
r"(?P<switch>^\-\w)", # single options like -v
2727
r"(?P<option>\-\-[\w\-]+)", # long options like --verbose
2828
r"(?P<default_option>\[[^\]]+\])", # anything between [], usually default options
2929

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Create a user hardware 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 hardware notification entry."""
18+
19+
hardware = SoftLayer.HardwareManager(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 = hardware.add_notification(identifier, user)
27+
table.add_row([notification['id'], notification['hardware']['fullyQualifiedDomainName'],
28+
notification['user']['username'], notification['user']['email'],
29+
notification['user']['firstName'], notification['user']['lastName']])
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+
hardware = SoftLayer.HardwareManager(env.client)
18+
19+
notifications = hardware.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['hardware']['fullyQualifiedDomainName'], notification['hardware']['hostname'],
27+
notification['user']['username'], notification['user']['email'],
28+
notification['user']['firstName'], notification['user']['lastName']])
29+
30+
env.fout(table)

SoftLayer/CLI/routes.py

Lines changed: 4 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'),
@@ -292,6 +294,8 @@
292294
('hardware:upgrade', 'SoftLayer.CLI.hardware.upgrade:cli'),
293295
('hardware:sensor', 'SoftLayer.CLI.hardware.sensor:cli'),
294296
('hardware:monitoring', 'SoftLayer.CLI.hardware.monitoring:cli'),
297+
('hardware:notifications', 'SoftLayer.CLI.hardware.notifications:cli'),
298+
('hardware:add-notification', 'SoftLayer.CLI.hardware.add_notification:cli'),
295299

296300
('securitygroup', 'SoftLayer.CLI.securitygroup'),
297301
('securitygroup:list', 'SoftLayer.CLI.securitygroup.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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
findByHardwareId = [
2+
{
3+
'hardwareId': 147258,
4+
'id': 1232569,
5+
'userId': 3698,
6+
'hardware': {
7+
'accountId': 963258,
8+
'domain': 'testedit.com',
9+
'fullyQualifiedDomainName': 'testslcli.testedit.com',
10+
'hostname': 'bardcabero',
11+
'id': 1403539,
12+
'notes': 'My golang note',
13+
'provisionDate': '2020-04-27T16:10:56-06:00',
14+
},
15+
'user': {
16+
'accountId': 307608,
17+
'email': 'cgallo@us.ibm.com',
18+
'firstName': 'CHRISTOPHER',
19+
'id': 167758,
20+
'lastName': 'GALLO',
21+
'username': 'SL307608',
22+
}
23+
},
24+
{
25+
'hardwareId': 1403539,
26+
'id': 1408587,
27+
'userId': 9734826,
28+
'hardware': {
29+
'accountId': 963258,
30+
'domain': 'testedit.com',
31+
'fullyQualifiedDomainName': 'testslcli.testedit.com',
32+
'hostname': 'bardcabero',
33+
'id': 1403539,
34+
'notes': 'My golang note',
35+
'provisionDate': '2020-04-27T16:10:56-06:00',
36+
},
37+
'user': {
38+
'accountId': 307608,
39+
'email': 'Brian.Flores@ibm.com',
40+
'firstName': 'Brian',
41+
'id': 9734826,
42+
'lastName': 'Flores',
43+
'username': '307608_brian.flores@ibm.com',
44+
}
45+
}
46+
]
47+
48+
createObject = {
49+
'hardwareId': 1403539,
50+
'id': 1408593,
51+
'userId': 7650493,
52+
'hardware': {
53+
'accountId': 307608,
54+
'domain': 'testedit.com',
55+
'fullyQualifiedDomainName': 'bardcabero.testedit.com',
56+
'hostname': 'bardcabero',
57+
'id': 1403539,
58+
'notes': 'My golang note',
59+
60+
},
61+
'user': {
62+
'accountId': 307608,
63+
'email': 'daniel.cabero@jalasoft.com',
64+
'firstName': 'daniel',
65+
'id': 7650493,
66+
'lastName': 'cabero',
67+
'username': 'sl307608-dcabero'
68+
69+
}
70+
}
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/hardware.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,16 @@ def get_sensors(self, hardware_id):
10921092
"""Returns Hardware sensor data"""
10931093
return self.client.call('Hardware', 'getSensorData', id=hardware_id)
10941094

1095+
def get_notifications(self, hardware_id):
1096+
"""Returns all hardware notifications."""
1097+
return self.client.call('SoftLayer_User_Customer_Notification_Hardware', 'findByHardwareId', hardware_id)
1098+
1099+
def add_notification(self, hardware_id, user_id):
1100+
"""Create a user hardware notification entry"""
1101+
1102+
template = {"hardwareId": hardware_id, "userId": user_id}
1103+
return self.client.call('SoftLayer_User_Customer_Notification_Hardware', 'createObject', template)
1104+
10951105

10961106
def _get_bandwidth_key(items, hourly=True, no_public=False, location=None):
10971107
"""Picks a valid Bandwidth Item, returns the KeyName"""

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)

0 commit comments

Comments
 (0)