Skip to content

Commit

Permalink
Merge pull request #492 from sudorandom/issue-491
Browse files Browse the repository at this point in the history
Fixes issue with skipping confirmations
  • Loading branch information
sudorandom committed Feb 19, 2015
2 parents 2fef3fd + 3f3b3eb commit 6240a96
Show file tree
Hide file tree
Showing 27 changed files with 174 additions and 169 deletions.
6 changes: 3 additions & 3 deletions SoftLayer/CLI/dns/record_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def cli(env, record_id):

manager = SoftLayer.DNSManager(env.client)

if env.skip_confirmations or formatting.no_going_back('yes'):
manager.delete_record(record_id)
else:
if not (env.skip_confirmations or formatting.no_going_back('yes')):
raise exceptions.CLIAbort("Aborted.")

manager.delete_record(record_id)
6 changes: 3 additions & 3 deletions SoftLayer/CLI/dns/zone_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def cli(env, zone):
manager = SoftLayer.DNSManager(env.client)
zone_id = helpers.resolve_id(manager.resolve_ids, zone, name='zone')

if env.skip_confirmations or formatting.no_going_back(zone):
manager.delete_zone(zone_id)
else:
if not (env.skip_confirmations or formatting.no_going_back(zone)):
raise exceptions.CLIAbort("Aborted.")

manager.delete_zone(zone_id)
21 changes: 12 additions & 9 deletions SoftLayer/CLI/firewall/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ def cli(env, identifier):
mgr = SoftLayer.FirewallManager(env.client)
firewall_type, firewall_id = firewall.parse_id(identifier)

if any([env.skip_confirmations,
formatting.confirm("This action will cancel a firewall from your"
"account. Continue?")]):
if firewall_type in ['vs', 'server']:
mgr.cancel_firewall(firewall_id, dedicated=False)
elif firewall_type == 'vlan':
mgr.cancel_firewall(firewall_id, dedicated=True)
return 'Firewall with id %s is being cancelled!' % identifier
else:
if not (env.skip_confirmations or
formatting.confirm("This action will cancel a firewall from your "
"account. Continue?")):
raise exceptions.CLIAbort('Aborted.')

if firewall_type in ['vs', 'server']:
mgr.cancel_firewall(firewall_id, dedicated=False)
elif firewall_type == 'vlan':
mgr.cancel_firewall(firewall_id, dedicated=True)
else:
raise exceptions.CLIAbort('Unknown firewall type: %s' % firewall_type)

return 'Firewall with id %s is being cancelled!' % identifier
6 changes: 3 additions & 3 deletions SoftLayer/CLI/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ def confirm(prompt_str, default=False):
:param bool default: Default value to True or False
"""
if default:
prompt = '%s [Y/n]: ' % prompt_str
prompt = '%s [Y/n]' % prompt_str
else:
prompt = '%s [y/N]: ' % prompt_str
prompt = '%s [y/N]' % prompt_str

response = valid_response(prompt, 'y', 'yes', 'yeah', 'yup', 'yolo')

Expand All @@ -211,7 +211,7 @@ def no_going_back(confirmation):

return valid_response(
'This action cannot be undone! '
'Type "%s" or press Enter to abort: ' % confirmation,
'Type "%s" or press Enter to abort' % confirmation,
str(confirmation))


Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/globalip/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cli(env, identifier):
global_ip_id = helpers.resolve_id(mgr.resolve_global_ip_ids, identifier,
name='global ip')

if env.skip_confirmations or formatting.no_going_back(global_ip_id):
mgr.cancel_global_ip(global_ip_id)
else:
if not (env.skip_confirmations or formatting.no_going_back(global_ip_id)):
raise exceptions.CLIAbort('Aborted')

mgr.cancel_global_ip(global_ip_id)
4 changes: 3 additions & 1 deletion SoftLayer/CLI/globalip/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ def cli(env, ipv6, test):
version = 4
if ipv6:
version = 6
if not test and not env.skip_confirmations:

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)

table = formatting.Table(['item', 'cost'])
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/iscsi/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def cli(env, identifier, reason, immediate):
iscsi_mgr = SoftLayer.ISCSIManager(env.client)
iscsi_id = helpers.resolve_id(iscsi_mgr.resolve_ids, identifier, 'iSCSI')

if env.skip_confirmations or formatting.no_going_back(iscsi_id):
iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
else:
if not (env.skip_confirmations or formatting.no_going_back(iscsi_id)):
raise exceptions.CLIAbort('Aborted')

iscsi_mgr.cancel_iscsi(iscsi_id, reason, immediate)
10 changes: 5 additions & 5 deletions SoftLayer/CLI/loadbal/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def cli(env, identifier):

_, loadbal_id = loadbal.parse_id(identifier)

if any([env.skip_confirmations,
if not (env.skip_confirmations or
formatting.confirm("This action will cancel a load balancer. "
"Continue?")]):
mgr.cancel_lb(loadbal_id)
return 'Load Balancer with id %s is being cancelled!' % identifier
else:
"Continue?")):
raise exceptions.CLIAbort('Aborted.')

mgr.cancel_lb(loadbal_id)
return 'Load Balancer with id %s is being cancelled!' % identifier
12 changes: 6 additions & 6 deletions SoftLayer/CLI/loadbal/group_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def cli(env, identifier):

_, group_id = loadbal.parse_id(identifier)

if env.skip_confirmations or formatting.confirm("This action will cancel "
"a service group. "
"Continue?"):
mgr.delete_service_group(group_id)
return 'Service group %s is being deleted!' % identifier
else:
if not (env.skip_confirmations or
formatting.confirm("This action will cancel a service group. "
"Continue?")):
raise exceptions.CLIAbort('Aborted.')

mgr.delete_service_group(group_id)
return 'Service group %s is being deleted!' % identifier
12 changes: 6 additions & 6 deletions SoftLayer/CLI/loadbal/service_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def cli(env, identifier):
mgr = SoftLayer.LoadBalancerManager(env.client)
_, service_id = loadbal.parse_id(identifier)

if env.skip_confirmations or formatting.confirm("This action will cancel "
"a service from your load "
"balancer. Continue?"):
mgr.delete_service(service_id)
return 'Load balancer service %s is being cancelled!' % service_id
else:
if not (env.skip_confirmations or
formatting.confirm("This action will cancel a service from your "
"load balancer. Continue?")):
raise exceptions.CLIAbort('Aborted.')

mgr.delete_service(service_id)
return 'Load balancer service %s is being cancelled!' % service_id
12 changes: 6 additions & 6 deletions SoftLayer/CLI/loadbal/service_toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def cli(env, identifier):
mgr = SoftLayer.LoadBalancerManager(env.client)
_, service_id = loadbal.parse_id(identifier)

if env.skip_confirmations or formatting.confirm("This action will toggle "
"the status on the "
"service. Continue?"):
mgr.toggle_service_status(service_id)
return 'Load balancer service %s status updated!' % identifier
else:
if not (env.skip_confirmations or
formatting.confirm("This action will toggle the status on the "
"service. Continue?")):
raise exceptions.CLIAbort('Aborted.')

mgr.toggle_service_status(service_id)
return 'Load balancer service %s status updated!' % identifier
9 changes: 3 additions & 6 deletions SoftLayer/CLI/server/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ def cli(env, identifier, immediate, comment, reason):
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')

if not comment and not env.skip_confirmations:
comment = env.input("(Optional) Add a cancellation comment:")

if env.skip_confirmations or formatting.no_going_back(hw_id):
mgr.cancel_hardware(hw_id, reason, comment, immediate)
else:
if not (env.skip_confirmations or formatting.no_going_back(hw_id)):
raise exceptions.CLIAbort('Aborted')

mgr.cancel_hardware(hw_id, reason, comment, immediate)
22 changes: 11 additions & 11 deletions SoftLayer/CLI/server/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,20 @@ def cli(env, **args):
return 'Successfully exported options to a template file.'

if do_create:
if env.skip_confirmations or formatting.confirm(
if not (env.skip_confirmations or formatting.confirm(
"This action will incur charges on your account. "
"Continue?"):
result = mgr.place_order(**order)

table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['id', result['orderId']])
table.add_row(['created', result['orderDate']])
output = table
else:
"Continue?")):
raise exceptions.CLIAbort('Aborting dedicated server order.')

result = mgr.place_order(**order)

table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['id', result['orderId']])
table.add_row(['created', result['orderDate']])
output = table

return output


Expand Down
40 changes: 20 additions & 20 deletions SoftLayer/CLI/server/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def power_off(env, identifier):

mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if env.skip_confirmations or formatting.confirm('This will power off the '
'server with id %s '
'Continue?' % hw_id):
env.client['Hardware_Server'].powerOff(id=hw_id)
else:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

env.client['Hardware_Server'].powerOff(id=hw_id)


@click.command()
@click.argument('identifier')
Expand All @@ -38,18 +38,18 @@ def reboot(env, identifier, hard):
hardware_server = env.client['Hardware_Server']
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if env.skip_confirmations or formatting.confirm('This will power off the '
'server with id %s. '
'Continue?' % hw_id):
if hard is True:
hardware_server.rebootHard(id=hw_id)
elif hard is False:
hardware_server.rebootSoft(id=hw_id)
else:
hardware_server.rebootDefault(id=hw_id)
else:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s. '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

if hard is True:
hardware_server.rebootHard(id=hw_id)
elif hard is False:
hardware_server.rebootSoft(id=hw_id)
else:
hardware_server.rebootDefault(id=hw_id)


@click.command()
@click.argument('identifier')
Expand All @@ -71,9 +71,9 @@ def power_cycle(env, identifier):
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')

if env.skip_confirmations or formatting.confirm('This will power off the '
'server with id %s. '
'Continue?' % hw_id):
env.client['Hardware_Server'].powerCycle(id=hw_id)
else:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s. '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

env.client['Hardware_Server'].powerCycle(id=hw_id)
6 changes: 3 additions & 3 deletions SoftLayer/CLI/server/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def cli(env, identifier, postinstall, key):
resolver = SoftLayer.SshKeyManager(env.client).resolve_ids
key_id = helpers.resolve_id(resolver, single_key, 'SshKey')
key_list.append(key_id)
if env.skip_confirmations or formatting.no_going_back(hardware_id):
hardware.reload(hardware_id, postinstall, key_list)
else:
if not (env.skip_confirmations or formatting.no_going_back(hardware_id)):
raise exceptions.CLIAbort('Aborted')

hardware.reload(hardware_id, postinstall, key_list)
10 changes: 5 additions & 5 deletions SoftLayer/CLI/server/rescue.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def cli(env, identifier):
server = SoftLayer.HardwareManager(env.client)
server_id = helpers.resolve_id(server.resolve_ids, identifier, 'hardware')

if env.skip_confirmations or formatting.confirm(
"This action will reboot this server. "
"Continue?"):
if not (env.skip_confirmations or
formatting.confirm("This action will reboot this server. "
"Continue?")):

server.rescue(server_id)
else:
raise exceptions.CLIAbort('Aborted')

server.rescue(server_id)
11 changes: 5 additions & 6 deletions SoftLayer/CLI/server/update_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def cli(env, identifier):

mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if env.skip_confirmations or formatting.confirm('This will power off the '
'server with id %s and '
'update device firmware. '
'Continue?' % hw_id):
mgr.update_firmware(hw_id)
else:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s and '
'update device firmware. Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

mgr.update_firmware(hw_id)
6 changes: 3 additions & 3 deletions SoftLayer/CLI/sshkey/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def cli(env, identifier):
mgr = SoftLayer.SshKeyManager(env.client)

key_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'SshKey')
if env.skip_confirmations or formatting.no_going_back(key_id):
mgr.delete_key(key_id)
else:
if not (env.skip_confirmations or formatting.no_going_back(key_id)):
raise exceptions.CLIAbort('Aborted')

mgr.delete_key(key_id)
7 changes: 4 additions & 3 deletions SoftLayer/CLI/ssl/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def cli(env, identifier):
"""Remove SSL certificate."""

manager = SoftLayer.SSLManager(env.client)
if env.skip_confirmations or formatting.no_going_back('yes'):
manager.remove_certificate(identifier)
raise exceptions.CLIAbort("Aborted.")
if not (env.skip_confirmations or formatting.no_going_back('yes')):
raise exceptions.CLIAbort("Aborted.")

manager.remove_certificate(identifier)
6 changes: 3 additions & 3 deletions SoftLayer/CLI/subnet/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cli(env, identifier):
subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier,
name='subnet')

if env.skip_confirmations or formatting.no_going_back(subnet_id):
mgr.cancel_subnet(subnet_id)
else:
if not (env.skip_confirmations or formatting.no_going_back(subnet_id)):
raise exceptions.CLIAbort('Aborted')

mgr.cancel_subnet(subnet_id)
10 changes: 6 additions & 4 deletions SoftLayer/CLI/subnet/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ def cli(env, network, quantity, vlan_id, ipv6, test):

mgr = SoftLayer.NetworkManager(env.client)

version = 4
if ipv6:
version = 6
if not test and not env.skip_confirmations:
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.')

version = 4
if ipv6:
version = 6

result = mgr.add_subnet(network,
quantity=quantity,
vlan_id=vlan_id,
Expand Down
6 changes: 3 additions & 3 deletions SoftLayer/CLI/virt/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def cli(env, identifier):

vsi = SoftLayer.VSManager(env.client)
vs_id = helpers.resolve_id(vsi.resolve_ids, identifier, 'VS')
if env.skip_confirmations or formatting.no_going_back(vs_id):
vsi.cancel_instance(vs_id)
else:
if not (env.skip_confirmations or formatting.no_going_back(vs_id)):
raise exceptions.CLIAbort('Aborted')

vsi.cancel_instance(vs_id)

0 comments on commit 6240a96

Please sign in to comment.