Commit f03239bb by Máhonfai Bálint

Add an optional argument for an additional admin user

parent 81054e66
Pipeline #1152 passed with stage
in 0 seconds
......@@ -21,14 +21,20 @@ from vm.models import Instance, InstanceTemplate
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('template_id', type=int)
parser.add_argument('-t', '--template', type=int, required=True)
parser.add_argument('-u', '--users', required=True)
parser.add_argument('-a', '--admin')
def handle(self, *args, **options):
template = InstanceTemplate.objects.get(id=options['template_id'])
with open(options['users_path']) as f:
template = InstanceTemplate.objects.get(id=options['template'])
with open(options['users']) as f:
users =
missing_users = Instance.mass_create_for_users(template, users)
missing_users = Instance.mass_create_for_users(
template, users, options['admin']
if len(missing_users) > 0:
self.stdout.write('These users do not exist:')
for user in missing_users:
......@@ -440,7 +440,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
for cps in customized_params]
def mass_create_for_users(cls, template, users, **kwargs):
def mass_create_for_users(cls, template, users, admin=None, **kwargs):
Create and deploy an instance of a template for each user
in a list of users. Returns the user IDs of missing users.
......@@ -453,11 +453,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
except User.DoesNotExist:
instances = []
for user in user_instances:
instance = cls.create_from_template(template, user, **kwargs)
if admin:
instance.set_level(User.objects.get(username=admin), 'owner')
return missing_users
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