Revision ca8f8081
b/tools/snf-admin | ||
---|---|---|
63 | 63 |
return None |
64 | 64 |
|
65 | 65 |
def print_dict(d, exclude=()): |
66 |
if not d: |
|
67 |
return |
|
66 | 68 |
margin = max(len(key) for key in d) + 1 |
67 | 69 |
|
68 | 70 |
for key, val in sorted(d.items()): |
... | ... | |
119 | 121 |
|
120 | 122 |
class ListServers(Command): |
121 | 123 |
category = 'server' |
122 |
name = 'ls'
|
|
124 |
name = 'list'
|
|
123 | 125 |
syntax = '[server id]' |
124 | 126 |
description = 'list servers' |
125 | 127 |
|
... | ... | |
150 | 152 |
|
151 | 153 |
class ListUsers(Command): |
152 | 154 |
category = 'user' |
153 |
name = 'ls'
|
|
155 |
name = 'list'
|
|
154 | 156 |
syntax = '[user id]' |
155 | 157 |
description = 'list users' |
156 | 158 |
|
... | ... | |
168 | 170 |
|
169 | 171 |
class ListImages(Command): |
170 | 172 |
category = 'image' |
171 |
name = 'ls'
|
|
173 |
name = 'list'
|
|
172 | 174 |
syntax = '[image id]' |
173 | 175 |
description = 'list images' |
174 | 176 |
|
... | ... | |
191 | 193 |
description = 'register an image' |
192 | 194 |
|
193 | 195 |
def add_options(self, parser): |
194 |
parser.add_option('-p', action='store_true', dest='public',
|
|
196 |
parser.add_option('--public', action='store_true', dest='public',
|
|
195 | 197 |
default=False, help='make image public') |
196 | 198 |
parser.add_option('-u', dest='uid', metavar='UID', |
197 | 199 |
help='assign image to user with id UID') |
... | ... | |
225 | 227 |
help='set image format') |
226 | 228 |
parser.add_option('-n', dest='name', metavar='NAME', |
227 | 229 |
help='set image name') |
228 |
parser.add_option('-p', action='store_true', dest='public',
|
|
230 |
parser.add_option('--public', action='store_true', dest='public',
|
|
229 | 231 |
default=False, help='make image public') |
230 |
parser.add_option('-r', action='store_true', dest='private',
|
|
232 |
parser.add_option('--nopublic', action='store_true', dest='private',
|
|
231 | 233 |
default=False, help='make image private') |
232 | 234 |
parser.add_option('-s', dest='state', metavar='STATE', |
233 | 235 |
default=False, help='set image state') |
... | ... | |
259 | 261 |
image.save() |
260 | 262 |
|
261 | 263 |
|
264 |
class ModifyImageMeta(Command): |
|
265 |
category = 'image' |
|
266 |
name = 'meta' |
|
267 |
syntax = '<image id> [key[=val]]' |
|
268 |
description = 'get and manipulate image metadata' |
|
269 |
|
|
270 |
def main(self, image_id, arg=''): |
|
271 |
try: |
|
272 |
image = models.Image.objects.get(id=image_id) |
|
273 |
except: |
|
274 |
print 'Image not found' |
|
275 |
return |
|
276 |
|
|
277 |
key, sep, val = arg.partition('=') |
|
278 |
if not sep: |
|
279 |
val = None |
|
280 |
|
|
281 |
if not key: |
|
282 |
metadata = {} |
|
283 |
for meta in image.imagemetadata_set.order_by('meta_key'): |
|
284 |
metadata[meta.meta_key] = meta.meta_value |
|
285 |
print_dict(metadata) |
|
286 |
return |
|
287 |
|
|
288 |
try: |
|
289 |
meta = image.imagemetadata_set.get(meta_key=key) |
|
290 |
except models.ImageMetadata.DoesNotExist: |
|
291 |
meta = None |
|
292 |
|
|
293 |
if val is None: |
|
294 |
if meta: |
|
295 |
print_dict({key: meta.meta_value}) |
|
296 |
return |
|
297 |
|
|
298 |
if val: |
|
299 |
if not meta: |
|
300 |
meta = image.imagemetadata_set.create(meta_key=key) |
|
301 |
meta.meta_value = val |
|
302 |
meta.save() |
|
303 |
else: |
|
304 |
# Delete if val is empty |
|
305 |
if meta: |
|
306 |
meta.delete() |
|
307 |
|
|
308 |
|
|
262 | 309 |
def print_categories(exe, categories): |
263 | 310 |
print 'Usage: %s <category> <command>' % exe |
264 | 311 |
|
Also available in: Unified diff