Skip to content

Commit

Permalink
Merge pull request #1892 from caberos/issue1889
Browse files Browse the repository at this point in the history
new feature on account hook-delete
  • Loading branch information
allmightyspiff authored Mar 27, 2023
2 parents 77c5057 + 8b0e140 commit 475a3f9
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions SoftLayer/CLI/account/hook_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""Delete a provisioning script"""
# :license: MIT, see LICENSE for more details.

import click
import SoftLayer

from SoftLayer.CLI.command import SLCommand as SLCommand
from SoftLayer.CLI import environment
from SoftLayer.managers.account import AccountManager as AccountManager


@click.command(cls=SLCommand)
@click.argument('identifier')
@environment.pass_env
def cli(env, identifier):
"""Delete a provisioning script"""

manager = AccountManager(env.client)

try:
manager.delete_provisioning(identifier)
click.secho("%s deleted successfully" % identifier, fg='green')
except SoftLayer.SoftLayerAPIError as ex:
click.secho("Failed to delete %s\n%s" % (identifier, ex), fg='red')
1 change: 1 addition & 0 deletions SoftLayer/CLI/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
('account:bandwidth-pools', 'SoftLayer.CLI.account.bandwidth_pools:cli'),
('account:hooks', 'SoftLayer.CLI.account.hooks:cli'),
('account:hook-create', 'SoftLayer.CLI.account.hook_create:cli'),
('account:hook-delete', 'SoftLayer.CLI.account.hook_delete:cli'),

('virtual', 'SoftLayer.CLI.virt'),
('virtual:bandwidth', 'SoftLayer.CLI.virt.bandwidth:cli'),
Expand Down
1 change: 1 addition & 0 deletions SoftLayer/fixtures/SoftLayer_Provisioning_Hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
'uri': 'http://slclitest.com',
'hookType': {}
}
deleteObject = True
9 changes: 9 additions & 0 deletions SoftLayer/managers/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,12 @@ def create_provisioning(self, name, uri):
'uri': uri
}
return self.client.call('SoftLayer_Provisioning_Hook', 'createObject', template)

def delete_provisioning(self, identifier):
"""Delete a provisioning script
param: identifier provisioning script identifier
Returns: boolean
"""
return self.client.call("SoftLayer_Provisioning_Hook", "deleteObject", id=identifier)
4 changes: 4 additions & 0 deletions docs/cli/account.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ Account Commands
.. click:: SoftLayer.CLI.account.hook_create:cli
:prog: account hook-create
:show-nested:

.. click:: SoftLayer.CLI.account.hook_delete:cli
:prog: account hook-delete
:show-nested:
5 changes: 5 additions & 0 deletions tests/CLI/modules/account_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,8 @@ def test_created_provisioning_hook(self):
result = self.run_command(['account', 'hook-create', '--name', 'testslcli', '--uri', 'http://slclitest.com'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

def test_delete_provisioning_hook(self):
result = self.run_command(['account', 'hook-delete', '123456'])
self.assert_no_fail(result)
self.assert_called_with('SoftLayer_Provisioning_Hook', 'deleteObject')
4 changes: 4 additions & 0 deletions tests/managers/account_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,7 @@ def test_get_provisioning_scripts(self):
def test_create_provisioning_scripts(self):
self.manager.create_provisioning('testslcli', 'http://slclitest.com')
self.assert_called_with('SoftLayer_Provisioning_Hook', 'createObject')

def test_delete_provisioning_scripts(self):
self.manager.delete_provisioning(123456)
self.assert_called_with("SoftLayer_Provisioning_Hook", "deleteObject")

0 comments on commit 475a3f9

Please sign in to comment.