Repository: softlayer/softlayer-python
Pull request #1991 (2023-06-15 15:46:49)

New command `slcli bandwidth pools-edit`
Issue #1989 
```
softlayer-python/ (issue1989) $ slcli bandwidth pools-edit 1234567 --name TestRegionEdited
┌──────────────┬──────────────────┐
│     Name     │      Value       │
├──────────────┼──────────────────┤
│      Id      │     1234567      │
│  Name Pool   │   TestRegionEdited │
│    Region    │ SNG/HKG/OSA/TOK  │
│ Created Date │ 2023-05-31 07:13 │
└──────────────┴──────────────────┘
```


Patch:
diff --git a/SoftLayer/CLI/bandwidth/pools_edit.py b/SoftLayer/CLI/bandwidth/pools_edit.py
new file mode 100644
index 00000000..98f2d08a
--- /dev/null
+++ b/SoftLayer/CLI/bandwidth/pools_edit.py
@@ -0,0 +1,50 @@
+"""Edit bandwidth pool."""
+# :license: MIT, see LICENSE for more details.
+import click
+
+from SoftLayer import BandwidthManager
+from SoftLayer.CLI.command import SLCommand as SLCommand
+from SoftLayer.CLI import environment
+from SoftLayer.CLI import formatting
+from SoftLayer import utils
+
+location_groups = {
+    "SJC/DAL/WDC/TOR/MON": "US/Canada",
+    "AMS/LON/MAD/PAR": "AMS/LON/MAD/PAR",
+    "SNG/HKG/OSA/TOK": "SNG/HKG/JPN",
+    "SYD": "AUS",
+    "MEX": "MEX",
+    "SAO": "BRA",
+    "CHE": "IND",
+    "MIL": "ITA",
+    "SEO": "KOR",
+    "FRA": "FRA"
+}
+
+
+@click.command(cls=SLCommand)
+@click.argument('identifier')
+@click.option('--name', required=True, help="Pool name")
+@environment.pass_env
+def cli(env, identifier, name):
+    """Edit bandwidth pool."""
+
+    manager = BandwidthManager(env.client)
+    bandwidth_pool = manager.edit_pool(identifier, name)
+
+    if bandwidth_pool:
+
+        edited_pool = manager.get_bandwidth_detail(identifier)
+        locations = manager.get_location_group()
+
+        location = next(
+            (location for location in locations if location['id'] == edited_pool.get('locationGroupId')), None)
+
+        region_name = next((key for key, value in location_groups.items() if value == location.get('name')), None)
+
+        table = formatting.KeyValueTable(['Name', 'Value'])
+        table.add_row(['Id', edited_pool.get('id')])
+        table.add_row(['Name Pool', name])
+        table.add_row(['Region', region_name])
+        table.add_row(['Created Date', utils.clean_time(edited_pool.get('createDate'))])
+        env.fout(table)
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index 10bbb3c9..c2e57f03 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -425,6 +425,7 @@
     ('bandwidth:pools', 'SoftLayer.CLI.bandwidth.pools:cli'),
     ('bandwidth:pools-detail', 'SoftLayer.CLI.bandwidth.pools_detail:cli'),
     ('bandwidth:pools-create', 'SoftLayer.CLI.bandwidth.pools_create:cli'),
+    ('bandwidth:pools-edit', 'SoftLayer.CLI.bandwidth.pools_edit:cli'),
 ]
 
 ALL_ALIASES = {
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py b/SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py
index 915cf633..b0145963 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Bandwidth_Version1_Allotment.py
@@ -156,3 +156,5 @@
     "name": "NewRegion",
     "serviceProviderId": 1
 }
+
+editObject = True
diff --git a/SoftLayer/managers/bandwidth.py b/SoftLayer/managers/bandwidth.py
index 55574d8d..8612f3ca 100644
--- a/SoftLayer/managers/bandwidth.py
+++ b/SoftLayer/managers/bandwidth.py
@@ -43,3 +43,29 @@ def create_pool(self, name_pool, id_location_group):
         }
 
         return self.client.call('Network_Bandwidth_Version1_Allotment', 'createObject', template)
+
+    def get_bandwidth_detail(self, identifier):
+        """Gets bandwidth pool detail.
+
+        :returns: bandwidth pool detail
+        """
+        _mask = """activeDetails[allocation],projectedPublicBandwidthUsage, billingCyclePublicBandwidthUsage,
+        hardware[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]],inboundPublicBandwidthUsage,
+        virtualGuests[outboundPublicBandwidthUsage,bandwidthAllotmentDetail[allocation]],
+        bareMetalInstances[outboundBandwidthUsage,bandwidthAllotmentDetail[allocation]]"""
+        return self.client['SoftLayer_Network_Bandwidth_Version1_Allotment'].getObject(id=identifier, mask=_mask)
+
+    def edit_pool(self, identifier, new_name_pool):
+        """Edit bandwidth pool name
+
+        :return: Bandwidth object
+        """
+        actual_bandwidth = self.get_bandwidth_detail(identifier)
+        template = {
+            "accountId": actual_bandwidth.get('accountId'),
+            "bandwidthAllotmentTypeId": actual_bandwidth.get('bandwidthAllotmentTypeId'),
+            "locationGroupId": actual_bandwidth.get('locationGroupId'),
+            "name": new_name_pool
+        }
+
+        return self.client.call('Network_Bandwidth_Version1_Allotment', 'editObject', template, id=identifier)
diff --git a/docs/cli/bandwidth.rst b/docs/cli/bandwidth.rst
index 8560e533..772e5ac1 100644
--- a/docs/cli/bandwidth.rst
+++ b/docs/cli/bandwidth.rst
@@ -19,3 +19,7 @@ bandwidth Commands
 .. click:: SoftLayer.CLI.bandwidth.pools_create:cli
     :prog: bandwidth pools-create
     :show-nested:
+
+.. click:: SoftLayer.CLI.bandwidth.pools_edit:cli
+    :prog: bandwidth pools-edit
+    :show-nested:


Test patch:
diff --git a/tests/CLI/modules/bandwidth_tests.py b/tests/CLI/modules/bandwidth_tests.py
index d4603ad8..bc9d321f 100644
--- a/tests/CLI/modules/bandwidth_tests.py
+++ b/tests/CLI/modules/bandwidth_tests.py
@@ -8,8 +8,6 @@
 
 import json
 
-from pprint import pprint as pp
-
 
 class BandwidthTests(testing.TestCase):
     def test_bandwidth_pools(self):
@@ -31,7 +29,6 @@ def test_bandwidth_summary(self):
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Search', 'advancedSearch')
         json_output = json.loads(result.output)
-        pp(json_output)
         self.assertEqual(5, len(json_output))
         self.assertEqual(100250634, json_output[0]['Id'])
         self.assertEqual('TestRegion', json_output[0]['Pool'])
@@ -51,11 +48,19 @@ def test_create_bandwidth(self):
         self.assert_no_fail(result)
         self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'createObject')
         json_output = json.loads(result.output)
-        pp(json_output)
         self.assertEqual(123456789, json_output['Id'])
         self.assertEqual('NewRegion', json_output['Name Pool'])
         self.assertEqual('SJC/DAL/WDC/TOR/MON', json_output['Region'])
 
+    def test_edit_bandwidth(self):
+        result = self.run_command(['bandwidth', 'pools-edit', '123456', '--name=MexRegionEdited'])
+        self.assert_no_fail(result)
+        self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'editObject')
+        json_output = json.loads(result.output)
+        self.assertEqual(123456, json_output['Id'])
+        self.assertEqual('MexRegionEdited', json_output['Name Pool'])
+        self.assertEqual('MEX', json_output['Region'])
+
 
 def _bandwidth_advanced_search():
     result = [