Repository: softlayer/softlayer-python
Pull request #1619 (2022-04-20 20:30:16)

Improved successful response to command - slcli vlan cancel
Main Issue: #1616 
```
softlayer-python/ (issue1616-vlan) $ slcli vlan cancel 123
This action cannot be undone! Type "123" or press Enter to abort: 123
VLAN 123 was cancelled.
```


Patch:
diff --git a/SoftLayer/CLI/account/cancel_item.py b/SoftLayer/CLI/account/cancel_item.py
index 0cc08593..62664344 100644
--- a/SoftLayer/CLI/account/cancel_item.py
+++ b/SoftLayer/CLI/account/cancel_item.py
@@ -15,4 +15,5 @@ def cli(env, identifier):
     manager = AccountManager(env.client)
     item = manager.cancel_item(identifier)
 
-    env.fout(item)
+    if item:
+        env.fout("Item: {} was cancelled.".format(identifier))
diff --git a/SoftLayer/CLI/account/event_detail.py b/SoftLayer/CLI/account/event_detail.py
index 386a4171..2c1ee80c 100644
--- a/SoftLayer/CLI/account/event_detail.py
+++ b/SoftLayer/CLI/account/event_detail.py
@@ -65,9 +65,9 @@ def update_table(event):
     """Formats a basic event update table"""
     update_number = 0
     for update in event.get('updates', []):
-        update_number = update_number + 1
         header = "======= Update #%s on %s =======" % (update_number, utils.clean_time(update.get('startDate')))
         click.secho(header, fg='green')
+        update_number = update_number + 1
         text = update.get('contents')
         # deals with all the \r\n from the API
         click.secho(utils.clean_splitlines(text))
diff --git a/SoftLayer/CLI/account/events.py b/SoftLayer/CLI/account/events.py
index 8d104800..7d4803b4 100644
--- a/SoftLayer/CLI/account/events.py
+++ b/SoftLayer/CLI/account/events.py
@@ -11,14 +11,8 @@
 @click.command()
 @click.option('--ack-all', is_flag=True, default=False,
               help="Acknowledge every upcoming event. Doing so will turn off the popup in the control portal")
-@click.option('--planned', is_flag=True, default=False,
-              help="Show only planned events")
-@click.option('--unplanned', is_flag=True, default=False,
-              help="Show only unplanned events")
-@click.option('--announcement', is_flag=True, default=False,
-              help="Show only announcement events")
 @environment.pass_env
-def cli(env, ack_all, planned, unplanned, announcement):
+def cli(env, ack_all):
     """Summary and acknowledgement of upcoming and ongoing maintenance events"""
 
     manager = AccountManager(env.client)
@@ -27,22 +21,13 @@ def cli(env, ack_all, planned, unplanned, announcement):
     announcement_events = manager.get_upcoming_events("ANNOUNCEMENT")
 
     add_ack_flag(planned_events, manager, ack_all)
-    add_ack_flag(unplanned_events, manager, ack_all)
-    add_ack_flag(announcement_events, manager, ack_all)
-
-    if planned:
-        env.fout(planned_event_table(planned_events))
+    env.fout(planned_event_table(planned_events))
 
-    if unplanned:
-        env.fout(unplanned_event_table(unplanned_events))
-
-    if announcement:
-        env.fout(announcement_event_table(announcement_events))
+    add_ack_flag(unplanned_events, manager, ack_all)
+    env.fout(unplanned_event_table(unplanned_events))
 
-    if not planned and not unplanned and not announcement:
-        env.fout(planned_event_table(planned_events))
-        env.fout(unplanned_event_table(unplanned_events))
-        env.fout(announcement_event_table(announcement_events))
+    add_ack_flag(announcement_events, manager, ack_all)
+    env.fout(announcement_event_table(announcement_events))
 
 
 def add_ack_flag(events, manager, ack_all):
diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py
index 3f58d712..ea9a3d12 100644
--- a/SoftLayer/CLI/globalip/assign.py
+++ b/SoftLayer/CLI/globalip/assign.py
@@ -5,22 +5,17 @@
 
 import SoftLayer
 from SoftLayer.CLI import environment
+from SoftLayer.CLI import helpers
 
-target_types = {'vlan': 'SoftLayer_Network_Vlan',
-                'ip': 'SoftLayer_Network_Subnet_IpAddress',
-                'hardware': 'SoftLayer_Hardware_Server',
-                'vsi': 'SoftLayer_Virtual_Guest'}
 
-
-@click.command(epilog="More information about types and identifiers "
-                      "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
+@click.command()
 @click.argument('identifier')
-@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
-              help='choose the type. vlan, ip, hardware, vsi')
-@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ')
+@click.argument('target')
 @environment.pass_env
-def cli(env, identifier, target, target_id):
-    """Assigns the subnet to a target."""
+def cli(env, identifier, target):
+    """Assigns the global IP to a target."""
 
     mgr = SoftLayer.NetworkManager(env.client)
-    mgr.route(identifier, target_types.get(target), target_id)
+    global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
+                                      name='global ip')
+    mgr.assign_global_ip(global_ip_id, target)
diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py
index ac2d5084..2d5bb9d6 100644
--- a/SoftLayer/CLI/routes.py
+++ b/SoftLayer/CLI/routes.py
@@ -323,7 +323,6 @@
     ('subnet:list', 'SoftLayer.CLI.subnet.list:cli'),
     ('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'),
     ('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'),
-    ('subnet:route', 'SoftLayer.CLI.subnet.route:cli'),
 
     ('tags', 'SoftLayer.CLI.tags'),
     ('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'),
diff --git a/SoftLayer/CLI/subnet/route.py b/SoftLayer/CLI/subnet/route.py
deleted file mode 100644
index e4d4acd4..00000000
--- a/SoftLayer/CLI/subnet/route.py
+++ /dev/null
@@ -1,26 +0,0 @@
-"""allows you to change the route of your Account Owned subnets."""
-# :license: MIT, see LICENSE for more details.
-
-import click
-
-import SoftLayer
-from SoftLayer.CLI import environment
-
-target_types = {'vlan': 'SoftLayer_Network_Vlan',
-                'ip': 'SoftLayer_Network_Subnet_IpAddress',
-                'hardware': 'SoftLayer_Hardware_Server',
-                'vsi': 'SoftLayer_Virtual_Guest'}
-
-
-@click.command(epilog="More information about types and identifiers "
-                      "on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
-@click.argument('identifier')
-@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
-              help='choose the type. vlan, ip, hardware, vsi')
-@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ')
-@environment.pass_env
-def cli(env, identifier, target, target_id):
-    """Assigns the subnet to a target."""
-
-    mgr = SoftLayer.NetworkManager(env.client)
-    mgr.route(identifier, target_types.get(target), target_id)
diff --git a/SoftLayer/CLI/virt/edit.py b/SoftLayer/CLI/virt/edit.py
index a72caa58..93f9c669 100644
--- a/SoftLayer/CLI/virt/edit.py
+++ b/SoftLayer/CLI/virt/edit.py
@@ -54,11 +54,16 @@ def cli(env, identifier, domain, userfile, tag, hostname, userdata,
 
     vsi = SoftLayer.VSManager(env.client)
     vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
-    if not vsi.edit(vs_id, **data):
-        raise exceptions.CLIAbort("Failed to update virtual server")
+
+    if vsi.edit(vs_id, **data):
+        for key, value in data.items():
+            if value is not None:
+                env.fout("The {} of virtual server instance: {} was updated.".format(key, vs_id))
 
     if public_speed is not None:
-        vsi.change_port_speed(vs_id, True, int(public_speed))
+        if vsi.change_port_speed(vs_id, True, int(public_speed)):
+            env.fout("The public speed of virtual server instance: {} was updated.".format(vs_id))
 
     if private_speed is not None:
-        vsi.change_port_speed(vs_id, False, int(private_speed))
+        if vsi.change_port_speed(vs_id, False, int(private_speed)):
+            env.fout("The private speed of virtual server instance: {} was updated.".format(vs_id))
diff --git a/SoftLayer/CLI/vlan/cancel.py b/SoftLayer/CLI/vlan/cancel.py
index 35f5aa0f..3470c059 100644
--- a/SoftLayer/CLI/vlan/cancel.py
+++ b/SoftLayer/CLI/vlan/cancel.py
@@ -25,10 +25,11 @@ def cli(env, identifier):
         raise exceptions.CLIAbort(reasons)
     item = mgr.get_vlan(identifier).get('billingItem')
     if item:
-        mgr.cancel_item(item.get('id'),
-                        True,
-                        'Cancel by cli command',
-                        'Cancel by cli command')
+        if mgr.cancel_item(item.get('id'),
+                           True,
+                           'Cancel by cli command',
+                           'Cancel by cli command'):
+            env.fout("VLAN {} was cancelled.".format(identifier))
     else:
         raise exceptions.CLIAbort(
             "VLAN is an automatically assigned and free of charge VLAN,"
diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
index 9ecf8164..ac3b9d74 100644
--- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
+++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py
@@ -44,4 +44,3 @@
 editNote = True
 setTags = True
 cancel = True
-route = True
diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py
index d1d4e8f8..0f550ec3 100644
--- a/SoftLayer/managers/network.py
+++ b/SoftLayer/managers/network.py
@@ -506,7 +506,7 @@ def list_subnets(self, identifier=None, datacenter=None, version=0,
         kwargs['iter'] = True
         return self.client.call('Account', 'getSubnets', **kwargs)
 
-    def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **kwargs):
+    def list_vlans(self, datacenter=None, vlan_number=None, name=None, **kwargs):
         """Display a list of all VLANs on the account.
 
         This provides a quick overview of all VLANs including information about
@@ -523,8 +523,6 @@ def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **
         """
         _filter = utils.NestedDict(kwargs.get('filter') or {})
 
-        _filter['networkVlans']['id'] = utils.query_filter_orderby()
-
         if vlan_number:
             _filter['networkVlans']['vlanNumber'] = (
                 utils.query_filter(vlan_number))
@@ -542,10 +540,7 @@ def list_vlans(self, datacenter=None, vlan_number=None, name=None, limit=100, **
             kwargs['mask'] = DEFAULT_VLAN_MASK
 
         kwargs['iter'] = True
-        if limit > 0:
-            return self.account.getNetworkVlans(mask=kwargs['mask'], filter=_filter.to_dict(), limit=limit)
-        else:
-            return self.account.getNetworkVlans(mask=kwargs['mask'], filter=_filter.to_dict(), iter=True)
+        return self.account.getNetworkVlans(**kwargs)
 
     def list_securitygroups(self, **kwargs):
         """List security groups."""
@@ -829,13 +824,3 @@ def get_closed_pods(self):
         mask = """mask[name, datacenterLongName, frontendRouterId, capabilities, datacenterId, backendRouterId,
                 backendRouterName, frontendRouterName]"""
         return self.client.call('SoftLayer_Network_Pod', 'getAllObjects', mask=mask, filter=closing_filter)
-
-    def route(self, subnet_id, type_serv, target):
-        """Assigns a subnet to a specified target.
-
-        :param int subnet_id: The ID of the global IP being assigned
-        :param string type_serv: The type service to assign
-        :param string target: The instance to assign
-        """
-        return self.client.call('SoftLayer_Network_Subnet', 'route',
-                                type_serv, target, id=subnet_id, )
diff --git a/docs/cli/subnet.rst b/docs/cli/subnet.rst
index 7d22b824..38bda428 100644
--- a/docs/cli/subnet.rst
+++ b/docs/cli/subnet.rst
@@ -30,6 +30,3 @@ Subnets
 .. click:: SoftLayer.CLI.subnet.edit_ip:cli
     :prog: subnet edit-ip
     :show-nested:
-.. click:: SoftLayer.CLI.subnet.route:cli
-    :prog: subnet route
-    :show-nested:


Test patch:
diff --git a/tests/CLI/modules/globalip_tests.py b/tests/CLI/modules/globalip_tests.py
index f46bd5ef..e12b7c3f 100644
--- a/tests/CLI/modules/globalip_tests.py
+++ b/tests/CLI/modules/globalip_tests.py
@@ -15,7 +15,7 @@
 class DnsTests(testing.TestCase):
 
     def test_ip_assign(self):
-        result = self.run_command(['globalip', 'assign', '1'])
+        result = self.run_command(['globalip', 'assign', '1', '127.0.0.1'])
 
         self.assert_no_fail(result)
         self.assertEqual(result.output, "")
diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py
index 03166c9f..65a4cc5c 100644
--- a/tests/CLI/modules/subnet_tests.py
+++ b/tests/CLI/modules/subnet_tests.py
@@ -184,9 +184,3 @@ def test_cancel(self, confirm_mock):
     def test_cancel_fail(self):
         result = self.run_command(['subnet', 'cancel', '1234'])
         self.assertEqual(result.exit_code, 2)
-
-    def test_route(self):
-        result = self.run_command(['subnet', 'route', '1'])
-
-        self.assert_no_fail(result)
-        self.assertEqual(result.exit_code, 0)
diff --git a/tests/CLI/modules/vs/vs_tests.py b/tests/CLI/modules/vs/vs_tests.py
index 4ae31fd6..99fafc0b 100644
--- a/tests/CLI/modules/vs/vs_tests.py
+++ b/tests/CLI/modules/vs/vs_tests.py
@@ -609,7 +609,13 @@ def test_edit(self):
                                    '100'])
 
         self.assert_no_fail(result)
-        self.assertEqual(result.output, '')
+        expected_output = '"The userdata of virtual server instance: 100 was updated."\n' \
+                          + '"The hostname of virtual server instance: 100 was updated."\n' \
+                          + '"The domain of virtual server instance: 100 was updated."\n' \
+                          + '"The tags of virtual server instance: 100 was updated."\n' \
+                          + '"The public speed of virtual server instance: 100 was updated."\n' \
+                          + '"The private speed of virtual server instance: 100 was updated."\n'
+        self.assertEqual(result.output, expected_output)
 
         self.assert_called_with(
             'SoftLayer_Virtual_Guest', 'editObject',
diff --git a/tests/managers/network_tests.py b/tests/managers/network_tests.py
index 8d256961..a578fd60 100644
--- a/tests/managers/network_tests.py
+++ b/tests/managers/network_tests.py
@@ -360,14 +360,13 @@ def test_list_vlans_with_filters(self):
         self.assertEqual(result, fixtures.SoftLayer_Account.getNetworkVlans)
         _filter = {
             'networkVlans': {
-                'id': {
-                    'operation': 'orderBy',
-                    'options': [
-                           {'name': 'sort', 'value': ['ASC']}]},
+                'primaryRouter': {
+                    'datacenter': {
+                        'name': {'operation': '_= dal00'}},
+                },
                 'vlanNumber': {'operation': 5},
                 'name': {'operation': '_= primary-vlan'},
-                'primaryRouter': {
-                      'datacenter': {'name': {'operation': '_= dal00'}}}}
+            },
         }
         self.assert_called_with('SoftLayer_Account', 'getNetworkVlans',
                                 filter=_filter)
@@ -629,7 +628,3 @@ def test_vlan_edit(self):
     def test_get_all_pods(self):
         self.network.get_pods()
         self.assert_called_with('SoftLayer_Network_Pod', 'getAllObjects')
-
-    def test_route(self):
-        self.network.route('SoftLayer_Hardware_Server', 123456, 100)
-        self.assert_called_with('SoftLayer_Network_Subnet', 'route')