Commit 8996b587 by Máhonfai Bálint

Don't throw exception when user not found

Return a list of missing users, and create VMs for the existing users instead of throwing an exception.
parent 617234f7
Pipeline #1148 passed with stage
in 0 seconds
......@@ -442,16 +442,16 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
@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.
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 = []
user_id = None
try:
for user_id in users:
missing_users = []
for user_id in users:
try:
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)
except User.DoesNotExist:
missing_users.append(user_id)
instances = []
for user in user_instances:
......@@ -459,7 +459,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
instance.deploy(user=user)
instances.append(instance)
return instances
return missing_users
def clean(self, *args, **kwargs):
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
......
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