Revision 13d2b7f7 tools/snf-admin
b/tools/snf-admin | ||
---|---|---|
56 | 56 |
try: |
57 | 57 |
uid = int(uid) |
58 | 58 |
return models.SynnefoUser.objects.get(id=uid) |
59 |
servers = servers.filter(owner=user) |
|
60 | 59 |
except ValueError: |
61 | 60 |
return None |
62 | 61 |
except models.SynnefoUser.DoesNotExist: |
... | ... | |
72 | 71 |
continue |
73 | 72 |
print '%s: %s' % (key.rjust(margin), val) |
74 | 73 |
|
74 |
def print_item(item): |
|
75 |
print '%d %s' % (item.id, item.name) |
|
76 |
print_dict(item.__dict__, exclude=('id', 'name')) |
|
77 |
|
|
75 | 78 |
def print_items(items, detail=False): |
76 | 79 |
for item in items: |
77 | 80 |
print '%d %s' % (item.id, item.name) |
... | ... | |
120 | 123 |
self.parser.print_help() |
121 | 124 |
|
122 | 125 |
|
126 |
# Server commands |
|
127 |
|
|
123 | 128 |
class ListServers(Command): |
124 | 129 |
group = 'server' |
125 | 130 |
name = 'list' |
... | ... | |
151 | 156 |
print_items(servers, self.detail) |
152 | 157 |
|
153 | 158 |
|
159 |
# User commands |
|
160 |
|
|
154 | 161 |
class ListUsers(Command): |
155 | 162 |
group = 'user' |
156 | 163 |
name = 'list' |
... | ... | |
169 | 176 |
print_items(users, self.detail) |
170 | 177 |
|
171 | 178 |
|
179 |
class ModifyUser(Command): |
|
180 |
group = 'user' |
|
181 |
name = 'modify' |
|
182 |
syntax = '<user id>' |
|
183 |
description = 'modify a user' |
|
184 |
|
|
185 |
def add_options(self, parser): |
|
186 |
parser.add_option('--credit', dest='credit', metavar='VALUE', |
|
187 |
help='set user credits') |
|
188 |
parser.add_option('--invitations', dest='invitations', |
|
189 |
metavar='VALUE', help='set max invitations') |
|
190 |
parser.add_option('--realname', dest='realname', metavar='NAME', |
|
191 |
help='set real name of user') |
|
192 |
parser.add_option('--type', dest='type', metavar='TYPE', |
|
193 |
help='set user type') |
|
194 |
parser.add_option('--username', dest='username', metavar='NAME', |
|
195 |
help='set username') |
|
196 |
|
|
197 |
def main(self, user_id): |
|
198 |
user = get_user(user_id) |
|
199 |
|
|
200 |
if self.credit: |
|
201 |
user.credit = self.credit |
|
202 |
if self.invitations: |
|
203 |
user.max_invitations = self.invitations |
|
204 |
if self.realname: |
|
205 |
user.realname = self.realname |
|
206 |
if self.type: |
|
207 |
allowed = [x[0] for x in models.SynnefoUser.ACCOUNT_TYPE] |
|
208 |
if self.type not in allowed: |
|
209 |
print 'Invalid type' |
|
210 |
return |
|
211 |
user.type = self.type |
|
212 |
if self.username: |
|
213 |
user.name = self.username |
|
214 |
|
|
215 |
user.save() |
|
216 |
print_item(user) |
|
217 |
|
|
218 |
|
|
219 |
# Image commands |
|
220 |
|
|
172 | 221 |
class ListImages(Command): |
173 | 222 |
group = 'image' |
174 | 223 |
name = 'list' |
... | ... | |
214 | 263 |
backend_id=backend_id, |
215 | 264 |
public=self.public) |
216 | 265 |
|
217 |
print_items([image], detail=True)
|
|
266 |
print_item(image)
|
|
218 | 267 |
|
219 | 268 |
|
220 | 269 |
class ModifyImage(Command): |
... | ... | |
249 | 298 |
if self.backend_id: |
250 | 299 |
image.backend_id = self.backend_id |
251 | 300 |
if self.format: |
252 |
image.format = format |
|
301 |
allowed = [x[0] for x in models.Image.FORMATS] |
|
302 |
if self.format not in allowed: |
|
303 |
print 'Invalid format' |
|
304 |
return |
|
305 |
image.format = self.format |
|
253 | 306 |
if self.name: |
254 | 307 |
image.name = self.name |
255 | 308 |
if self.public: |
... | ... | |
257 | 310 |
if self.private: |
258 | 311 |
image.public = False |
259 | 312 |
if self.state: |
313 |
allowed = [x[0] for x in models.Image.IMAGE_STATES] |
|
314 |
if self.state not in allowed: |
|
315 |
print 'Invalid state' |
|
316 |
return |
|
260 | 317 |
image.state = self.state |
261 | 318 |
if self.uid: |
262 | 319 |
image.owner = get_user(self.uid) |
263 | 320 |
|
264 | 321 |
image.save() |
322 |
print_item(image) |
|
265 | 323 |
|
266 | 324 |
|
267 | 325 |
class ModifyImageMeta(Command): |
Also available in: Unified diff