Skip to content

Commit 3ab08ee

Browse files
caberoscaberos
authored andcommitted
del-notification commands, rename the commands to notifications-add
1 parent 373a53a commit 3ab08ee

File tree

9 files changed

+49
-6
lines changed

9 files changed

+49
-6
lines changed
File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Remove 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+
9+
10+
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
11+
@click.argument('identifier')
12+
@environment.pass_env
13+
def cli(env, identifier):
14+
"""Remove a user hardware notification entry."""
15+
16+
hardware = SoftLayer.HardwareManager(env.client)
17+
18+
result = hardware.remove_notification(identifier)
19+
20+
if result:
21+
env.fout("The hardware notification instance: {} was deleted.".format(identifier))

SoftLayer/CLI/hardware/notifications.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ def cli(env, identifier):
1818

1919
notifications = hardware.get_notifications(identifier)
2020

21-
table = formatting.KeyValueTable(['Domain', 'Hostmane', 'Username', 'Email', 'FirstName', 'Lastname'])
21+
table = formatting.KeyValueTable(['Id', 'Domain', 'Hostmane', 'Username', 'Email', 'FirstName', 'Lastname'])
2222
table.align['Domain'] = 'r'
2323
table.align['Username'] = 'l'
2424

2525
for notification in notifications:
26-
table.add_row([notification['hardware']['fullyQualifiedDomainName'], notification['hardware']['hostname'],
26+
table.add_row([notification['id'],
27+
notification['hardware']['fullyQualifiedDomainName'], notification['hardware']['hostname'],
2728
notification['user']['username'], notification['user']['email'],
2829
notification['user']['firstName'], notification['user']['lastName']])
2930

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@
295295
('hardware:sensor', 'SoftLayer.CLI.hardware.sensor:cli'),
296296
('hardware:monitoring', 'SoftLayer.CLI.hardware.monitoring:cli'),
297297
('hardware:notifications', 'SoftLayer.CLI.hardware.notifications:cli'),
298-
('hardware:add-notification', 'SoftLayer.CLI.hardware.add_notification:cli'),
298+
('hardware:notification-add', 'SoftLayer.CLI.hardware.notification_add:cli'),
299+
('hardware:notification-del', 'SoftLayer.CLI.hardware.notification_delete:cli'),
299300
('hardware:create-credential', 'SoftLayer.CLI.hardware.create_credential:cli'),
300301

301302
('securitygroup', 'SoftLayer.CLI.securitygroup'),

SoftLayer/fixtures/SoftLayer_User_Customer_Notification_Hardware.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,5 @@
6868

6969
}
7070
}
71+
72+
deleteObjects = True

SoftLayer/managers/hardware.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,12 @@ def create_credential(self, template):
11101110
"""Create a password for a software component"""
11111111
return self.client.call('SoftLayer_Software_Component_Password', 'createObject', template)
11121112

1113+
def remove_notification(self, identifier):
1114+
"""Create a password for a software component"""
1115+
1116+
template = [{'id': identifier}]
1117+
return self.client.call('SoftLayer_User_Customer_Notification_Hardware', 'deleteObjects', template)
1118+
11131119

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

docs/cli/hardware.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ This function updates the firmware of a server. If already at the latest version
136136
:prog: hardware notifications
137137
:show-nested:
138138

139-
.. click:: SoftLayer.CLI.hardware.add_notification:cli
140-
:prog: hardware add-notification
139+
.. click:: SoftLayer.CLI.hardware.notification_add:cli
140+
:prog: hardware notification-add
141+
:show-nested:
142+
143+
.. click:: SoftLayer.CLI.hardware.notification_delete:cli
144+
:prog: hardware notification-delete
141145
:show-nested:
142146

143147
.. click:: SoftLayer.CLI.hardware.create_credential:cli

tests/CLI/modules/server_tests.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,11 @@ def test_notifications(self):
10451045
self.assert_no_fail(result)
10461046

10471047
def test_add_notification(self):
1048-
result = self.run_command(['hardware', 'add-notification', '100', '--users', '123456'])
1048+
result = self.run_command(['hardware', 'notification-add', '100', '--users', '123456'])
1049+
self.assert_no_fail(result)
1050+
1051+
def test_notification_delete(self):
1052+
result = self.run_command(['hardware', 'notification-delete', '100'])
10491053
self.assert_no_fail(result)
10501054

10511055
def test_create_credential(self):

tests/managers/hardware_tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,10 @@ def test_add_notification(self):
928928
self.hardware.add_notification(100, 123456)
929929
self.assert_called_with('SoftLayer_User_Customer_Notification_Hardware', 'createObject')
930930

931+
def test_notification_del(self):
932+
self.hardware.remove_notification(100)
933+
self.assert_called_with('SoftLayer_User_Customer_Notification_Hardware', 'deleteObjects')
934+
931935
def test_get_software_component(self):
932936
self.hardware.get_software_components(123456)
933937
self.assert_called_with('SoftLayer_Hardware', 'getSoftwareComponents')

0 commit comments

Comments
 (0)