Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #89 from davehouse/bug1505892_power-cycle-macs-wit…
Browse files Browse the repository at this point in the history
…h-downtime

Bug1505892 power cycle macs with downtime
  • Loading branch information
davehouse authored Nov 9, 2018
2 parents e3bc03b + 1e35735 commit 076f65a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
16 changes: 13 additions & 3 deletions relops_hardware_controller/api/management/commands/reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,19 @@ def handle(self, hostname, job_data, *args, **options):
reboot_args = [ reboot_method ]
reboot_method = 'ipmi'
elif reboot_method == 'snmp_reboot':
if not hasattr(server, 'pdu'):
try:
reboot_args = server['pdu'].rsplit(':', 1)
except KeyError:
# no pdu information
continue
elif reboot_method == 'snmp_rebootdelay':
try:
reboot_args = server['pdu'].rsplit(':', 1)
except KeyError:
# no pdu information
continue
reboot_args = server['pdu'].rsplit(':', 1)
reboot_args.extend(['--delay', 60])
reboot_method = 'snmp_reboot'
elif reboot_method == 'xenapi_reboot':
reboot_args = server['xen']['reboot']
elif reboot_method == 'ilo_reboot':
Expand Down Expand Up @@ -165,5 +175,5 @@ def check(hostname):
elapsed = time.time() - start
return result_template.format(
command=reboot_command,
stdout=stdout.getvalue().rstrip('\n'),
stdout=stdout.getvalue().replace('\n', '\r'),
time=elapsed)
22 changes: 17 additions & 5 deletions relops_hardware_controller/api/management/commands/snmp_reboot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import logging
import subprocess
import time
Expand Down Expand Up @@ -55,15 +54,13 @@ def add_arguments(self, parser):
help='Wait N seconds before turning the power back on.',
)

# Named (required) arguments

# Named (optional) arguments

# Not an snmp option
parser.add_argument(
'--delay',
dest='delay',
default=5,
default=0,
type=int,
help='Wait N seconds before turning the power back on.',
)
Expand Down Expand Up @@ -117,4 +114,19 @@ def handle(self, fqdn, pdu, port, *args, **options):
self.tower, self.infeed, self.outlet = self._parse_port(port)

logger.info("Powercycling {} via {}.".format(fqdn, pdu))
return self.run_cmd(pdu, self.cmds['reboot'], **options)

if options['delay'] > 0:
logger.info('Powering down {} ...'.format(fqdn))
output = self.run_cmd(pdu, self.cmds['off'], **options)

delay_note = ' wait {}s ... '.format(options['delay'])
logger.info(delay_note)
time.sleep(options['delay'])
output += delay_note

logger.info('Powering up {} ...'.format(fqdn))
output += self.run_cmd(pdu, self.cmds['on'], **options)
else:
output = self.run_cmd(pdu, self.cmds['reboot'], **options)

return output

0 comments on commit 076f65a

Please # to comment.