Repository: softlayer/softlayer-python
Pull request #1628 (2022-04-28 22:23:00)

new command on autoscale delete
[#1627](https://github.com/softlayer/softlayer-python/issues/1627)

**command**
`slcli autoscale delete scalegroupId`


Patch:
diff --git a/SoftLayer/CLI/autoscale/delete.py b/SoftLayer/CLI/autoscale/delete.py
new file mode 100644
index 00000000..34f41ddc
--- /dev/null
+++ b/SoftLayer/CLI/autoscale/delete.py
@@ -0,0 +1,26 @@
+"""Delete autoscale."""
+# :license: MIT, see LICENSE for more details.
+import click
+import SoftLayer
+
+from SoftLayer.CLI import environment
+from SoftLayer.managers.autoscale import AutoScaleManager
+
+
+@click.command()
+@click.argument('identifier')
+@environment.pass_env
+def cli(env, identifier):
+    """Delete this group and destroy all members of it.
+
+    Example: slcli autoscale delete autoscaleId
+
+    """
+
+    autoscale = AutoScaleManager(env.client)
+
+    try:
+        autoscale.delete(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 ac2d5084..a4cdff5c 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -377,7 +377,8 @@
     ('autoscale:scale', 'SoftLayer.CLI.autoscale.scale:cli'),
     ('autoscale:logs', 'SoftLayer.CLI.autoscale.logs:cli'),
     ('autoscale:tag', 'SoftLayer.CLI.autoscale.tag:cli'),
-    ('autoscale:edit', 'SoftLayer.CLI.autoscale.edit:cli')
+    ('autoscale:edit', 'SoftLayer.CLI.autoscale.edit:cli'),
+    ('autoscale:delete', 'SoftLayer.CLI.autoscale.delete:cli'),
 ]
 
 ALL_ALIASES = {
diff --git a/SoftLayer/fixtures/SoftLayer_Scale_Group.py b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
index f04d8f56..909ed88a 100644
--- a/SoftLayer/fixtures/SoftLayer_Scale_Group.py
+++ b/SoftLayer/fixtures/SoftLayer_Scale_Group.py
@@ -455,3 +455,4 @@
 ]
 
 editObject = True
+forceDeleteObject = True
diff --git a/SoftLayer/managers/autoscale.py b/SoftLayer/managers/autoscale.py
index 78fa18e3..772aa40f 100644
--- a/SoftLayer/managers/autoscale.py
+++ b/SoftLayer/managers/autoscale.py
@@ -116,3 +116,13 @@ def edit(self, identifier, template):
         .. _SoftLayer_Scale_Group: https://sldn.softlayer.com/reference/datatypes/SoftLayer_Scale_Group/
         """
         return self.client.call('SoftLayer_Scale_Group', 'editObject', template, id=identifier)
+
+    def delete(self, identifier):
+        """Calls `SoftLayer_Scale_Group::forceDeleteObject()`_
+
+        :param identifier: SoftLayer_Scale_Group id
+
+        .. _SoftLayer_Scale_Group::forceDeleteObject():
+            https://sldn.softlayer.com/reference/services/SoftLayer_Scale_Group/forceDeleteObject/
+        """
+        return self.client.call('SoftLayer_Scale_Group', 'forceDeleteObject', id=identifier)
diff --git a/docs/cli/autoscale.rst b/docs/cli/autoscale.rst
index a3aa3146..5e05c463 100644
--- a/docs/cli/autoscale.rst
+++ b/docs/cli/autoscale.rst
@@ -34,5 +34,9 @@ For making changes to the triggers or the autoscale group itself, see the `Autos
     :prog: autoscale edit
     :show-nested:
 
+.. click:: SoftLayer.CLI.autoscale.delete:cli
+    :prog: autoscale delete
+    :show-nested:
+
 
 .. _Autoscale Portal: https://cloud.ibm.com/classic/autoscale
\ No newline at end of file


Test patch:
diff --git a/tests/CLI/modules/autoscale_tests.py b/tests/CLI/modules/autoscale_tests.py
index cb3cdfdb..5d09209c 100644
--- a/tests/CLI/modules/autoscale_tests.py
+++ b/tests/CLI/modules/autoscale_tests.py
@@ -89,3 +89,7 @@ def test_autoscale_edit_userfile(self, manager):
             result = self.run_command(['autoscale', 'edit', '12345', '--userfile', userfile.name])
         self.assert_no_fail(result)
         manager.assert_called_with('12345', template)
+
+    def test_autoscale_delete(self):
+        result = self.run_command(['autoscale', 'delete', '12345'])
+        self.assert_no_fail(result)
diff --git a/tests/managers/autoscale_tests.py b/tests/managers/autoscale_tests.py
index 6da50540..3d41e621 100644
--- a/tests/managers/autoscale_tests.py
+++ b/tests/managers/autoscale_tests.py
@@ -123,3 +123,7 @@ def test_edit_object(self):
             'editObject',
             args=(template,),
             identifier=12345)
+
+    def test_delete_object(self):
+        self.autoscale.delete(12345)
+        self.assert_called_with('SoftLayer_Scale_Group', 'forceDeleteObject')