Commit 6834797e authored by Christos Stavrakakis's avatar Christos Stavrakakis

Modify backend-modify --drained and --offline args

Make backend-modify drained argument as --drained=True|False instead
of --drained and --no-drained. The same for offline.
parent 1a2ffb1a
......@@ -33,7 +33,8 @@
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
from synnefo.management.common import get_backend, check_backend_credentials
from synnefo.management.common import (get_backend, check_backend_credentials,
parse_bool)
class Command(BaseCommand):
......@@ -56,22 +57,16 @@ class Command(BaseCommand):
help="Set backend's password"),
make_option('--drained',
dest='drained',
action='store_true',
default=False,
choices=["True", "False"],
metavar="True|False",
help="Set the backend as drained to exclude from allocation "\
"operations"),
make_option('--no-drained',
dest='drained',
action='store_false'),
make_option('--offline',
dest='offline',
action='store_true',
default=False,
choices=["True", "False"],
metavar="True|False",
help="Set the backend as offline to not communicate in order "\
"to avoid delays"),
make_option('--no-offline',
dest='offline',
action='store_false')
)
def handle(self, *args, **options):
......@@ -81,19 +76,21 @@ class Command(BaseCommand):
backend = get_backend(args[0])
# Ensure fields correspondence with options and Backend model
fields = ('clustername', 'port', 'username', 'password', 'drained',
'offline')
credentials_changed = False
fields = ('clustername', 'port', 'username', 'password')
for field in fields:
value = options.get(field)
if value is not None:
backend.__setattr__(field, value)
credentials_changed = True
credentials = ('clustername', 'port', 'username', 'password')
for field in credentials:
if options.get(field):
if credentials_changed:
# check credentials, if any of them changed!
check_backend_credentials(backend.clustername, backend.port,
backend.username, backend.password)
return
if options['drained']:
backend.drained = parse_bool(options['drained'])
if options['offline']:
backend.offile = parse_bool(options['offline'])
backend.save()
......@@ -52,6 +52,16 @@ def format_bool(b):
return 'YES' if b else 'NO'
def parse_bool(string):
if string == "True":
return True
elif string == "False":
return False
else:
raise Exception("Can not parse string %s to bool" % string)
def format_date(d):
if not d:
return ''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment