1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
"""Power commands."""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
from SoftLayer.CLI import helpers
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def power_off(env, identifier, force):
"""Power off an active server."""
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if not force:
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(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--hard/--soft',
default=None,
help="Perform a hard or soft reboot")
@environment.pass_env
def reboot(env, identifier, hard):
"""Reboot an active server."""
hardware_server = env.client['Hardware_Server']
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
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(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def power_on(env, identifier, force):
"""Power on a server."""
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if not force:
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'].powerOn(id=hw_id)
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@environment.pass_env
def power_cycle(env, identifier):
"""Power cycle a server."""
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
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)
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@environment.pass_env
def rescue(env, identifier):
"""Reboot server into a rescue image."""
mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if not (env.skip_confirmations or
formatting.confirm("This action will reboot this server. Continue?")):
raise exceptions.CLIAbort('Aborted')
env.client['Hardware_Server'].bootToRescueLayer(id=hw_id)
|