Skip to content

Commit c50ba73

Browse files
Merge pull request #2056 from softlayer/jayasilan-issue2033
Example and sub feature for slcli firewall monitoring, slcli globalip specific commands #2033
2 parents 28002af + 2d0f9f7 commit c50ba73

File tree

6 files changed

+64
-15
lines changed

6 files changed

+64
-15
lines changed

SoftLayer/CLI/firewall/monitoring.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
@click.argument('identifier')
1414
@environment.pass_env
1515
def cli(env, identifier):
16-
"""Gets bandwidth details for a firewall from the past 30 days."""
16+
"""Gets bandwidth details for a firewall from the past 30 days.
17+
18+
Example::
19+
slcli firewall monitoring vs:12345
20+
"""
1721

1822
mgr = SoftLayer.FirewallManager(env.client)
1923

SoftLayer/CLI/globalip/assign.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
@click.option('--target-id', help='The identifier for the destination resource to route this subnet to. ')
2121
@environment.pass_env
2222
def cli(env, identifier, target, target_id):
23-
"""Assigns the subnet to a target."""
23+
"""Assigns the subnet to a target.
24+
25+
Example::
26+
slcli globalip assign 12345678 9.111.123.456
27+
This command assigns IP address with ID 12345678 to a target device whose IP address is 9.111.123.456
28+
"""
2429

2530
mgr = SoftLayer.NetworkManager(env.client)
2631
mgr.route(identifier, target_types.get(target), target_id)

SoftLayer/CLI/globalip/cancel.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,22 @@
1212

1313
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1414
@click.argument('identifier')
15+
@click.option('-f', '--force', default=False, is_flag=True, help="Force operation without confirmation")
1516
@environment.pass_env
16-
def cli(env, identifier):
17-
"""Cancel global IP."""
17+
def cli(env, identifier, force):
18+
"""Cancel global IP.
19+
20+
Example::
21+
slcli globalip cancel 12345
22+
"""
1823

1924
mgr = SoftLayer.NetworkManager(env.client)
2025
global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
2126
name='global ip')
2227

23-
if not (env.skip_confirmations or formatting.no_going_back(global_ip_id)):
24-
raise exceptions.CLIAbort('Aborted')
28+
if not force:
29+
if not (env.skip_confirmations or
30+
formatting.confirm(f"This will cancel the IP address: {global_ip_id} and cannot be undone. Continue?")):
31+
raise exceptions.CLIAbort('Aborted')
2532

2633
mgr.cancel_global_ip(global_ip_id)

SoftLayer/CLI/globalip/create.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@
1212
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1313
@click.option('-v6', '--ipv6', is_flag=True, help='Order a IPv6 IP')
1414
@click.option('--test', help='test order')
15+
@click.option('-f', '--force', default=False, is_flag=True, help="Force operation without confirmation")
1516
@environment.pass_env
16-
def cli(env, ipv6, test):
17-
"""Creates a global IP."""
17+
def cli(env, ipv6, test, force):
18+
"""Creates a global IP.
19+
20+
Example::
21+
slcli globalip create -v6
22+
This command creates an IPv6 address.
23+
"""
1824

1925
mgr = SoftLayer.NetworkManager(env.client)
2026

2127
version = 4
2228
if ipv6:
2329
version = 6
2430

25-
if not (test or env.skip_confirmations):
26-
if not formatting.confirm("This action will incur charges on your "
27-
"account. Continue?"):
28-
raise exceptions.CLIAbort('Cancelling order.')
31+
if not force:
32+
if not (test or env.skip_confirmations):
33+
if not formatting.confirm("This action will incur charges on your account. Continue?"):
34+
raise exceptions.CLIAbort('Cancelling order.')
2935

3036
result = mgr.add_global_ip(version=version, test_order=test)
3137

SoftLayer/CLI/globalip/list.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
type=click.Choice(['v4', 'v6']))
1515
@environment.pass_env
1616
def cli(env, ip_version):
17-
"""List all global IPs."""
17+
"""List all global IPs.
18+
19+
Example::
20+
slcli globalip list
21+
"""
1822

1923
mgr = SoftLayer.NetworkManager(env.client)
2024

tests/CLI/modules/globalip_tests.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ def test_ip_cancel(self, no_going_back_mock):
3939
no_going_back_mock.return_value = False
4040
result = self.run_command(['globalip', 'cancel', '1'])
4141

42-
self.assertEqual(result.exit_code, 2)
43-
self.assertIsInstance(result.exception, exceptions.CLIAbort)
42+
self.assertEqual(result.exit_code, 0)
4443

4544
def test_ip_list(self):
4645
result = self.run_command(['globalip', 'list', '--ip-version=v4'])
@@ -85,3 +84,27 @@ def test_ip_unassign(self):
8584
result = self.run_command(['globalip', 'unassign', '1'])
8685
self.assert_no_fail(result)
8786
self.assertEqual(result.output, "")
87+
88+
def test_ip_cancel_force(self):
89+
result = self.run_command(['globalip', 'cancel', '1', '--force'])
90+
91+
self.assert_no_fail(result)
92+
self.assertEqual(result.exit_code, 0)
93+
94+
@mock.patch('SoftLayer.CLI.formatting.confirm')
95+
def test_ip_cancel_no_abort(self, confirm_mock):
96+
# Test with confirmation and responding negatively
97+
confirm_mock.return_value = True
98+
result = self.run_command(['globalip', 'cancel', '1'])
99+
100+
self.assert_no_fail(result)
101+
self.assertEqual(result.exit_code, 0)
102+
103+
@mock.patch('SoftLayer.CLI.formatting.confirm')
104+
def test_ip_cancel_abort(self, confirm_mock):
105+
# Test with confirmation and responding negatively
106+
confirm_mock.return_value = False
107+
result = self.run_command(['globalip', 'cancel', '1'])
108+
109+
self.assertEqual(result.exit_code, 2)
110+
self.assertIsInstance(result.exception, exceptions.CLIAbort)

0 commit comments

Comments
 (0)