Commit 54a4ad92 by Szeberényi Imre

Merge branch 'mass_create_for_users' into 'master'

Mass create for users

See merge request !415
parents 48308ff9 81054e66
Pipeline #1151 passed with stage
in 0 seconds
# Copyright 2014 Budapest University of Technology and Economics (BME IK)
# This file is part of CIRCLE Cloud.
# CIRCLE is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# CIRCLE is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <>.
from import BaseCommand
from vm.models import Instance, InstanceTemplate
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('template_id', type=int)
def handle(self, *args, **options):
template = InstanceTemplate.objects.get(id=options['template_id'])
with open(options['users_path']) as f:
users =
missing_users = Instance.mass_create_for_users(template, users)
if len(missing_users) > 0:
self.stdout.write('These users do not exist:')
for user in missing_users:
......@@ -439,6 +439,28 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
return [cls.create(cps, disks, networks, req_traits, tags)
for cps in customized_params]
def mass_create_for_users(cls, template, users, **kwargs):
Create and deploy an instance of a template for each user
in a list of users. Returns the user IDs of missing users.
user_instances = []
missing_users = []
for user_id in users:
except User.DoesNotExist:
instances = []
for user in user_instances:
instance = cls.create_from_template(template, user, **kwargs)
return missing_users
def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
super(Instance, self).clean(*args, **kwargs)
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