- if opts.memtotal != None:
- total = int(opts.memtotal)
- if total == -1:
- x.ram_quota_total = None
- else:
- x.ram_quota_total = total
-
- if opts.memsingle != None:
- single = int(opts.memsingle)
- if single == -1:
- x.ram_quota_single = None
- else:
- x.ram_quota_single = single
-
- if opts.disktotal != None:
- total = int(opts.disktotal)
- if total == -1:
- x.disk_quota_total = None
- else:
- x.disk_quota_total = total
-
- if opts.disksingle != None:
- single = int(opts.disksingle)
- if single == -1:
- x.disk_quota_single = None
- else:
- x.disk_quota_single = single
-
- if opts.vmstotal != None:
- total = int(opts.vmstotal)
- if total == -1:
- x.vms_quota_total = None
- else:
- x.vms_quota_total = total
-
- if opts.vmsactive != None:
- active = int(opts.vmsactive)
- if active == -1:
- x.vms_quota_active = None
- else:
- x.vms_quota_active = active
+ for resource, scope in [('ram', 'total'), ('ram', 'single'),
+ ('disk', 'total'), ('disk', 'single'),
+ ('vms', 'total'), ('vms', 'active')]:
+ opt = getattr(opts, resource+scope)
+ if opt is not None:
+ val = int(opt)
+ setattr(x, resource+'_quota_'+scope, val if val >= 0 else None)