diff --git a/SoftLayer/CLI/firewall/monitoring.py b/SoftLayer/CLI/firewall/monitoring.py index a76df667a..832f1bd8b 100644 --- a/SoftLayer/CLI/firewall/monitoring.py +++ b/SoftLayer/CLI/firewall/monitoring.py @@ -13,7 +13,11 @@ @click.argument('identifier') @environment.pass_env def cli(env, identifier): - """Gets bandwidth details for a firewall from the past 30 days.""" + """Gets bandwidth details for a firewall from the past 30 days. + + Example:: + slcli firewall monitoring vs:12345 + """ mgr = SoftLayer.FirewallManager(env.client) diff --git a/SoftLayer/CLI/globalip/assign.py b/SoftLayer/CLI/globalip/assign.py index cb91eaf6f..1e793761e 100644 --- a/SoftLayer/CLI/globalip/assign.py +++ b/SoftLayer/CLI/globalip/assign.py @@ -20,7 +20,12 @@ @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.""" + """Assigns the subnet to a target. + + Example:: + slcli globalip assign 12345678 9.111.123.456 + This command assigns IP address with ID 12345678 to a target device whose IP address is 9.111.123.456 + """ mgr = SoftLayer.NetworkManager(env.client) mgr.route(identifier, target_types.get(target), target_id) diff --git a/SoftLayer/CLI/globalip/cancel.py b/SoftLayer/CLI/globalip/cancel.py index f0490500f..0d9394b24 100644 --- a/SoftLayer/CLI/globalip/cancel.py +++ b/SoftLayer/CLI/globalip/cancel.py @@ -12,15 +12,22 @@ @click.command(cls=SoftLayer.CLI.command.SLCommand, ) @click.argument('identifier') +@click.option('-f', '--force', default=False, is_flag=True, help="Force operation without confirmation") @environment.pass_env -def cli(env, identifier): - """Cancel global IP.""" +def cli(env, identifier, force): + """Cancel global IP. + + Example:: + slcli globalip cancel 12345 + """ mgr = SoftLayer.NetworkManager(env.client) global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier, name='global ip') - if not (env.skip_confirmations or formatting.no_going_back(global_ip_id)): - raise exceptions.CLIAbort('Aborted') + if not force: + if not (env.skip_confirmations or + formatting.confirm(f"This will cancel the IP address: {global_ip_id} and cannot be undone. Continue?")): + raise exceptions.CLIAbort('Aborted') mgr.cancel_global_ip(global_ip_id) diff --git a/SoftLayer/CLI/globalip/create.py b/SoftLayer/CLI/globalip/create.py index 7881512a2..8f9def03d 100644 --- a/SoftLayer/CLI/globalip/create.py +++ b/SoftLayer/CLI/globalip/create.py @@ -12,9 +12,15 @@ @click.command(cls=SoftLayer.CLI.command.SLCommand, ) @click.option('-v6', '--ipv6', is_flag=True, help='Order a IPv6 IP') @click.option('--test', help='test order') +@click.option('-f', '--force', default=False, is_flag=True, help="Force operation without confirmation") @environment.pass_env -def cli(env, ipv6, test): - """Creates a global IP.""" +def cli(env, ipv6, test, force): + """Creates a global IP. + + Example:: + slcli globalip create -v6 + This command creates an IPv6 address. + """ mgr = SoftLayer.NetworkManager(env.client) @@ -22,10 +28,10 @@ def cli(env, ipv6, test): if ipv6: version = 6 - if not (test or env.skip_confirmations): - if not formatting.confirm("This action will incur charges on your " - "account. Continue?"): - raise exceptions.CLIAbort('Cancelling order.') + if not force: + if not (test or env.skip_confirmations): + if not formatting.confirm("This action will incur charges on your account. Continue?"): + raise exceptions.CLIAbort('Cancelling order.') result = mgr.add_global_ip(version=version, test_order=test) diff --git a/SoftLayer/CLI/globalip/list.py b/SoftLayer/CLI/globalip/list.py index f38b4fce0..623409387 100644 --- a/SoftLayer/CLI/globalip/list.py +++ b/SoftLayer/CLI/globalip/list.py @@ -14,7 +14,11 @@ type=click.Choice(['v4', 'v6'])) @environment.pass_env def cli(env, ip_version): - """List all global IPs.""" + """List all global IPs. + + Example:: + slcli globalip list + """ mgr = SoftLayer.NetworkManager(env.client) diff --git a/tests/CLI/modules/globalip_tests.py b/tests/CLI/modules/globalip_tests.py index f46bd5ef7..43c5b0f4d 100644 --- a/tests/CLI/modules/globalip_tests.py +++ b/tests/CLI/modules/globalip_tests.py @@ -39,8 +39,7 @@ def test_ip_cancel(self, no_going_back_mock): no_going_back_mock.return_value = False result = self.run_command(['globalip', 'cancel', '1']) - self.assertEqual(result.exit_code, 2) - self.assertIsInstance(result.exception, exceptions.CLIAbort) + self.assertEqual(result.exit_code, 0) def test_ip_list(self): result = self.run_command(['globalip', 'list', '--ip-version=v4']) @@ -85,3 +84,27 @@ def test_ip_unassign(self): result = self.run_command(['globalip', 'unassign', '1']) self.assert_no_fail(result) self.assertEqual(result.output, "") + + def test_ip_cancel_force(self): + result = self.run_command(['globalip', 'cancel', '1', '--force']) + + self.assert_no_fail(result) + self.assertEqual(result.exit_code, 0) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_ip_cancel_no_abort(self, confirm_mock): + # Test with confirmation and responding negatively + confirm_mock.return_value = True + result = self.run_command(['globalip', 'cancel', '1']) + + self.assert_no_fail(result) + self.assertEqual(result.exit_code, 0) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_ip_cancel_abort(self, confirm_mock): + # Test with confirmation and responding negatively + confirm_mock.return_value = False + result = self.run_command(['globalip', 'cancel', '1']) + + self.assertEqual(result.exit_code, 2) + self.assertIsInstance(result.exception, exceptions.CLIAbort)