71 |
71 |
Quantity and import/export limit will get default values. Example:
|
72 |
72 |
|
73 |
73 |
--set-capacity 6119a50b-cbc7-42c0-bafc-4b6570e3f6ac cyclades.vm 10
|
|
74 |
|
|
75 |
The special value of 'default' sets the user setting to the default.
|
74 |
76 |
"""
|
75 |
77 |
|
76 |
78 |
option_list = BaseCommand.option_list + (
|
... | ... | |
83 |
85 |
metavar='<uuid or email> <resource> <capacity>',
|
84 |
86 |
nargs=3,
|
85 |
87 |
help="Set capacity for a specified user/resource pair"),
|
|
88 |
|
86 |
89 |
make_option('-f', '--no-confirm',
|
87 |
90 |
action='store_true',
|
88 |
91 |
default=False,
|
... | ... | |
125 |
128 |
else:
|
126 |
129 |
raise CommandError('Please specify user by uuid or email')
|
127 |
130 |
|
|
131 |
if capacity != 'default':
|
|
132 |
try:
|
|
133 |
capacity = int(capacity)
|
|
134 |
except ValueError:
|
|
135 |
m = "Please specify capacity as a decimal integer or 'default'"
|
|
136 |
raise CommandError(m)
|
|
137 |
|
128 |
138 |
args = AddResourceArgs(resource=resource,
|
129 |
139 |
capacity=capacity,
|
130 |
140 |
quantity=0,
|
... | ... | |
133 |
143 |
)
|
134 |
144 |
|
135 |
145 |
try:
|
136 |
|
quota = user.get_resource_policy(resource)
|
|
146 |
quota, default_capacity = user.get_resource_policy(resource)
|
137 |
147 |
except Resource.DoesNotExist:
|
138 |
148 |
raise CommandError("No such resource: %s" % resource)
|
139 |
149 |
|
140 |
|
current = quota.capacity if quota is not None else None
|
|
150 |
current = quota.capacity if quota is not None else 'default'
|
141 |
151 |
|
142 |
152 |
if not force:
|
143 |
153 |
self.stdout.write("user: %s (%s)\n" % (user.uuid, user.username))
|
|
154 |
self.stdout.write("default capacity: %s\n" % default_capacity)
|
144 |
155 |
self.stdout.write("current capacity: %s\n" % current)
|
145 |
156 |
self.stdout.write("new capacity: %s\n" % capacity)
|
146 |
157 |
self.stdout.write("Confirm? (y/n) ")
|
... | ... | |
149 |
160 |
self.stdout.write("Aborted.\n")
|
150 |
161 |
return
|
151 |
162 |
|
152 |
|
try:
|
153 |
|
user.add_resource_policy(*args)
|
154 |
|
except Exception as e:
|
155 |
|
raise CommandError("Failed to add policy: %s" % e)
|
|
163 |
if capacity == 'default':
|
|
164 |
try:
|
|
165 |
service, sep, name = resource.partition('.')
|
|
166 |
q = AstakosUserQuota.objects.get(
|
|
167 |
user=user,
|
|
168 |
resource__service__name=service,
|
|
169 |
resource__name=name)
|
|
170 |
q.delete()
|
|
171 |
except Exception as e:
|
|
172 |
import traceback
|
|
173 |
traceback.print_exc()
|
|
174 |
raise CommandError("Failed to remove policy: %s" % e)
|
|
175 |
else:
|
|
176 |
try:
|
|
177 |
user.add_resource_policy(*args)
|
|
178 |
except Exception as e:
|
|
179 |
raise CommandError("Failed to add policy: %s" % e)
|
156 |
180 |
|
157 |
181 |
def import_from_file(self, location):
|
158 |
182 |
try:
|