def clean(self):
ram = self.cleaned_data.get('ram', None)
cores = self.cleaned_data.get('cores', None)
if cores:
cores = random_sample(range(0, cpu_count()), cores)
cores = ','.join(map(str, cores))
self.cleaned_data['cores'] = cores
else:
cores = cpu_count()
cores = str(list(range(0, cores))).strip('[]').replace(" ", "")
self.cleaned_data['cores'] = cores
if ram:
ram = int(ram)
self.cleaned_data['ram'] = ram
else:
ram = int(DHost.memory('total'))
self.cleaned_data['ram'] = ram
if self.ssh_users:
for ssh_user in self.ssh_users:
user_obj = User.objects.get(email=ssh_user)
if not user_obj.ssh_pub_key:
raise forms.ValidationError("SSH key not found")
return self.cleaned_data
评论列表
文章目录