Commit 617234f7 by Máhonfai Bálint

Add function to mass create VMs for a list of users

parent 6085e2eb
Pipeline #1144 passed with stage
in 0 seconds
...@@ -439,6 +439,28 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -439,6 +439,28 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
return [cls.create(cps, disks, networks, req_traits, tags) return [cls.create(cps, disks, networks, req_traits, tags)
for cps in customized_params] for cps in customized_params]
@classmethod
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.
"""
user_instances = []
user_id = None
try:
for user_id in users:
user_instances.append(User.objects.get(profile__org_id=user_id))
except User.DoesNotExist:
raise Exception("User with id %s doesn't exist" % user_id)
instances = []
for user in user_instances:
instance = cls.create_from_template(template, user, **kwargs)
instance.deploy(user=user)
instances.append(instance)
return instances
def clean(self, *args, **kwargs): def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times() self.time_of_suspend, self.time_of_delete = self.get_renew_times()
super(Instance, self).clean(*args, **kwargs) 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