Commit 90a5d98b by Czémán Arnold

dashboard: upgrade init command

Changes:
* Use argparse instead of optparse: https://docs.djangoproject.com/en/1.11/releases/1.10/#features-removed-in-1-10
* convert print to self.stdout.write(), Django documents suggest it: https://docs.djangoproject.com/en/1.11/howto/custom-management-commands/#module-django.core.management
parent dc7f7924
...@@ -32,19 +32,18 @@ logger = logging.getLogger(__name__) ...@@ -32,19 +32,18 @@ logger = logging.getLogger(__name__)
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( def add_arguments(self, parser):
make_option('--force', action="store_true"), parser.add_argument('--force', action="store_true")
make_option('--external-net'), parser.add_argument('--external-net')
make_option('--management-net'), parser.add_argument('--management-net')
make_option('--vm-net'), parser.add_argument('--vm-net')
make_option('--external-if'), parser.add_argument('--external-if')
make_option('--management-if'), parser.add_argument('--management-if')
make_option('--vm-if'), parser.add_argument('--vm-if')
make_option('--datastore-queue'), parser.add_argument('--datastore-queue')
make_option('--firewall-queue'), parser.add_argument('--firewall-queue')
make_option('--admin-user'), parser.add_argument('--admin-user')
make_option('--admin-pass'), parser.add_argument('--admin-pass')
)
def create(self, model, field, **kwargs): def create(self, model, field, **kwargs):
value = kwargs[field] value = kwargs[field]
...@@ -59,14 +58,15 @@ class Command(BaseCommand): ...@@ -59,14 +58,15 @@ class Command(BaseCommand):
# http://docs.saltstack.com/en/latest/ref/states/all/salt.states.cmd.html # http://docs.saltstack.com/en/latest/ref/states/all/salt.states.cmd.html
def print_state(self): def print_state(self):
print "\nchanged=%s" % ("yes" if self.changed else "no") self.stdout.write("\nchanged=%s" % ("yes" if self.changed else "no"))
def handle(self, *args, **options): def handle(self, *args, **options):
self.changed = False self.changed = False
if (DataStore.objects.exists() and Vlan.objects.exists() and if (DataStore.objects.exists() and Vlan.objects.exists() and
not options['force']): not options['force']):
return self.print_state() self.print_state()
return
admin = self.create(User, 'username', username=options['admin_user'], admin = self.create(User, 'username', username=options['admin_user'],
is_superuser=True, is_staff=True) is_superuser=True, is_staff=True)
...@@ -153,4 +153,4 @@ class Command(BaseCommand): ...@@ -153,4 +153,4 @@ class Command(BaseCommand):
direction='out', action='accept', direction='out', action='accept',
foreign_network=vg_net, vlan=man) foreign_network=vg_net, vlan=man)
return self.print_state() self.print_state()
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 sign in to comment