Repository: softlayer/softlayer-python
Pull request #1896 (2023-03-30 15:04:33)

Added new command - slcli cdn delete
Issue link: #1895
```
softlayer-python/ (issue1895) $ slcli cdn delete 214030593705200
Cdn with uniqueId: 214030593705200 was deleted.
```


Patch:
diff --git a/SoftLayer/CLI/cdn/delete.py b/SoftLayer/CLI/cdn/delete.py
new file mode 100644
index 00000000..b089e9ef
--- /dev/null
+++ b/SoftLayer/CLI/cdn/delete.py
@@ -0,0 +1,21 @@
+"""Delete a CDN domain mapping."""
+# :license: MIT, see LICENSE for more details.
+
+import click
+
+import SoftLayer
+from SoftLayer.CLI import environment
+
+
+@click.command(cls=SoftLayer.CLI.command.SLCommand, )
+@click.argument('unique_id')
+@environment.pass_env
+def cli(env, unique_id):
+    """Delete a CDN domain mapping."""
+
+    manager = SoftLayer.CDNManager(env.client)
+
+    cdn = manager.delete_cdn(unique_id)
+
+    if cdn:
+        env.fout("Cdn with uniqueId: {} was deleted.".format(unique_id))
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 921ad247..4a0ee59d 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -81,6 +81,7 @@
     ('cdn:origin-list', 'SoftLayer.CLI.cdn.origin_list:cli'),
     ('cdn:origin-remove', 'SoftLayer.CLI.cdn.origin_remove:cli'),
     ('cdn:purge', 'SoftLayer.CLI.cdn.purge:cli'),
+    ('cdn:delete', 'SoftLayer.CLI.cdn.delete:cli'),
 
     ('config', 'SoftLayer.CLI.config'),
     ('config:setup', 'SoftLayer.CLI.config.setup:cli'),
diff --git a/SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping.py b/SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping.py
index e080c40e..7a1c45db 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_CdnMarketplace_Configuration_Mapping.py
@@ -50,3 +50,27 @@
         "cacheKeyQueryRule": "include: test"
     }
 ]
+
+deleteDomainMapping = [
+    {
+        "akamaiCname": "wildcard.appdomain.mdc.edgekey.net",
+        "certificateType": "NO_CERT",
+        "cname": "cdnakayq9fye4t88239.cdn.appdomain.cloud",
+        "createDate": "2023-03-29T07:33:42-06:00",
+        "domain": "www.test.com",
+        "header": "www.header.com",
+        "httpPort": 80,
+        "httpsPort": None,
+        "modifyDate": "2023-03-29T07:33:46-06:00",
+        "originHost": "67.228.227.82",
+        "originType": "HOST_SERVER",
+        "path": "/path/*",
+        "performanceConfiguration": "General web delivery",
+        "protocol": "HTTP",
+        "respectHeaders": False,
+        "serveStale": True,
+        "status": "DELETING",
+        "uniqueId": "303727924488685",
+        "vendorName": "akamai"
+    }
+]
diff --git a/SoftLayer/managers/cdn.py b/SoftLayer/managers/cdn.py
index 1c6597b4..5226e10c 100644
--- a/SoftLayer/managers/cdn.py
+++ b/SoftLayer/managers/cdn.py
@@ -269,3 +269,12 @@ def get_cache_key_query_rule(cache_type, cache):
         cache_result = '%s: %s' % (cache_type, cache['description'])
 
         return cache_result
+
+    def delete_cdn(self, unique_id):
+        """Delete CDN domain mapping for a particular customer.
+
+        :param str unique_id: The unique ID associated with the CDN.
+        :returns: The cdn that is being deleted.
+        """
+
+        return self.cdn_configuration.deleteDomainMapping(unique_id)
diff --git a/docs/cli/cdn.rst b/docs/cli/cdn.rst
index 3b749995..23bd215f 100644
--- a/docs/cli/cdn.rst
+++ b/docs/cli/cdn.rst
@@ -31,3 +31,7 @@ Interacting with CDN
 .. click:: SoftLayer.CLI.cdn.edit:cli
    :prog: cdn edit
    :show-nested:
+
+.. click:: SoftLayer.CLI.cdn.delete:cli
+   :prog: cdn delete
+   :show-nested:


Test patch:
diff --git a/tests/CLI/modules/cdn_tests.py b/tests/CLI/modules/cdn_tests.py
index a7dfa340..759a4b36 100644
--- a/tests/CLI/modules/cdn_tests.py
+++ b/tests/CLI/modules/cdn_tests.py
@@ -123,3 +123,8 @@ def test_edit_cache_by_uniqueId(self):
         self.assert_no_fail(result)
         header_result = json.loads(result.output)
         self.assertEqual('include: test', header_result['Cache key optimization'])
+
+    def test_delete_cdn(self):
+        result = self.run_command(['cdn', 'delete', '123456'])
+        self.assert_no_fail(result)
+        self.assertIn("Cdn with uniqueId: 123456 was deleted.", result.output)
diff --git a/tests/managers/cdn_tests.py b/tests/managers/cdn_tests.py
index b0e641c6..2107d806 100644
--- a/tests/managers/cdn_tests.py
+++ b/tests/managers/cdn_tests.py
@@ -150,3 +150,13 @@ def test_cdn_instance_by_hostname(self):
         self.assert_called_with(
             'SoftLayer_Network_CdnMarketplace_Configuration_Mapping',
             'listDomainMappings',)
+
+    def test_delete_cdn(self):
+        uniqueId = "123465"
+        self.cdn_client.delete_cdn(uniqueId)
+
+        args = (uniqueId,)
+
+        self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping',
+                                'deleteDomainMapping',
+                                args=args)