Repository: softlayer/softlayer-python
Pull request #1892 (2023-03-23 20:00:25)

new feature on account hook-delete
[#issue1889](https://github.com/softlayer/softlayer-python/issues/1889)

![image](https://user-images.githubusercontent.com/22535437/227337287-22ccb07e-a6dc-41ca-99e8-1b3f51743501.png)



Patch:
diff --git a/SoftLayer/CLI/account/hook_delete.py b/SoftLayer/CLI/account/hook_delete.py
new file mode 100644
index 00000000..c4eda42b
--- /dev/null
+++ b/SoftLayer/CLI/account/hook_delete.py
@@ -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')
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 09a7c54a..921ad247 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -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'),
diff --git a/SoftLayer/fixtures/SoftLayer_Provisioning_Hook.py b/SoftLayer/fixtures/SoftLayer_Provisioning_Hook.py
index 452a1585..86c5756d 100644
--- a/SoftLayer/fixtures/SoftLayer_Provisioning_Hook.py
+++ b/SoftLayer/fixtures/SoftLayer_Provisioning_Hook.py
@@ -5,3 +5,4 @@
                 'uri': 'http://slclitest.com',
                 'hookType': {}
 }
+deleteObject = True
diff --git a/SoftLayer/managers/account.py b/SoftLayer/managers/account.py
index c2386a83..7de4db36 100644
--- a/SoftLayer/managers/account.py
+++ b/SoftLayer/managers/account.py
@@ -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)
diff --git a/docs/cli/account.rst b/docs/cli/account.rst
index c2ac4900..248525cb 100644
--- a/docs/cli/account.rst
+++ b/docs/cli/account.rst
@@ -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:


Test patch:
diff --git a/tests/CLI/modules/account_tests.py b/tests/CLI/modules/account_tests.py
index 60a572b7..71a4ad71 100644
--- a/tests/CLI/modules/account_tests.py
+++ b/tests/CLI/modules/account_tests.py
@@ -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')
diff --git a/tests/managers/account_tests.py b/tests/managers/account_tests.py
index 3fa796b2..a1a9f483 100644
--- a/tests/managers/account_tests.py
+++ b/tests/managers/account_tests.py
@@ -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")