218
228
server = self._find_server(args.server)
219
229
server.backup_schedule.delete()
224
help="Flavor ID (see 'novaclient flavors'). "\
225
"Defaults to 256MB RAM instance.")
229
help="Image ID (see 'novaclient images'). "\
230
"Defaults to Ubuntu 10.04 LTS.")
234
help="IP group name or ID (see 'novaclient ipgroup-list').")
236
metavar="<key=value>",
239
help="Record arbitrary key/value metadata. "\
240
"May be give multiple times.")
242
metavar="<dst-path=src-path>",
246
help="Store arbitrary files from <src-path> locally to <dst-path> "\
247
"on the new server. You may store up to 5 files.")
252
help="Key the server with an SSH keypair. "\
253
"Looks in ~/.ssh for a key, "\
254
"or takes an explicit <path> to one.")
255
@arg('name', metavar='<name>', help='Name for the new server')
256
def do_boot(self, args):
231
def _boot(self, args, reservation_id=None, min_count=None, max_count=None):
257
232
"""Boot a new server."""
233
if min_count is None:
235
if max_count is None:
236
max_count = min_count
237
if min_count > max_count:
238
raise CommandError("min_instances should be <= max_instances")
239
if not min_count or not max_count:
240
raise CommandError("min_instances nor max_instances should be 0")
258
242
flavor = args.flavor or self.cs.flavors.find(ram=256)
259
243
image = args.image or self.cs.images.find(name="Ubuntu 10.04 LTS "\
297
281
except IOError, e:
298
282
raise CommandError("Can't open '%s': %s" % (keyfile, e))
300
server = self.cs.servers.create(args.name, image, flavor, ipgroup,
302
print_dict(server._info)
284
return (args.name, image, flavor, ipgroup, metadata, files,
285
reservation_id, min_count, max_count)
290
help="Flavor ID (see 'novaclient flavors'). "\
291
"Defaults to 256MB RAM instance.")
295
help="Image ID (see 'novaclient images'). "\
296
"Defaults to Ubuntu 10.04 LTS.")
300
help="IP group name or ID (see 'novaclient ipgroup-list').")
302
metavar="<key=value>",
305
help="Record arbitrary key/value metadata. "\
306
"May be give multiple times.")
308
metavar="<dst-path=src-path>",
312
help="Store arbitrary files from <src-path> locally to <dst-path> "\
313
"on the new server. You may store up to 5 files.")
318
help="Key the server with an SSH keypair. "\
319
"Looks in ~/.ssh for a key, "\
320
"or takes an explicit <path> to one.")
321
@arg('name', metavar='<name>', help='Name for the new server')
322
def do_boot(self, args):
323
"""Boot a new server."""
324
name, image, flavor, ipgroup, metadata, files, reservation_id, \
325
min_count, max_count = self._boot(args)
327
server = self.cs.servers.create(args.name, image, flavor,
333
print_dict(server._info)
338
help="Flavor ID (see 'novaclient flavors'). "\
339
"Defaults to 256MB RAM instance.")
343
help="Image ID (see 'novaclient images'). "\
344
"Defaults to Ubuntu 10.04 LTS.")
348
help="IP group name or ID (see 'novaclient ipgroup-list').")
350
metavar="<key=value>",
353
help="Record arbitrary key/value metadata. "\
354
"May be give multiple times.")
356
metavar="<dst-path=src-path>",
360
help="Store arbitrary files from <src-path> locally to <dst-path> "\
361
"on the new server. You may store up to 5 files.")
366
help="Key the server with an SSH keypair. "\
367
"Looks in ~/.ssh for a key, "\
368
"or takes an explicit <path> to one.")
369
@arg('account', metavar='<account>', help='Account to build this'\
371
@arg('name', metavar='<name>', help='Name for the new server')
372
def do_boot_for_account(self, args):
373
"""Boot a new server in an account."""
374
name, image, flavor, ipgroup, metadata, files, reservation_id, \
375
min_count, max_count = self._boot(args)
377
server = self.cs.accounts.create_instance_for(args.account, args.name,
382
print_dict(server._info)
387
help="Flavor ID (see 'novaclient flavors'). "\
388
"Defaults to 256MB RAM instance.")
392
help="Image ID (see 'novaclient images'). "\
393
"Defaults to Ubuntu 10.04 LTS.")
397
help="IP group name or ID (see 'novaclient ipgroup-list').")
399
metavar="<key=value>",
402
help="Record arbitrary key/value metadata. "\
403
"May be give multiple times.")
405
metavar="<dst-path=src-path>",
409
help="Store arbitrary files from <src-path> locally to <dst-path> "\
410
"on the new server. You may store up to 5 files.")
415
help="Key the server with an SSH keypair. "\
416
"Looks in ~/.ssh for a key, "\
417
"or takes an explicit <path> to one.")
418
@arg('--reservation_id',
420
metavar='<reservation_id>',
421
help="Reservation ID (a UUID). "\
422
"If unspecified will be generated by the server.")
423
@arg('--min_instances',
427
help="The minimum number of instances to build. "\
429
@arg('--max_instances',
433
help="The maximum number of instances to build. "\
434
"Defaults to 'min_instances' setting.")
435
@arg('name', metavar='<name>', help='Name for the new server')
436
def do_zone_boot(self, args):
437
"""Boot a new server, potentially across Zones."""
438
reservation_id = args.reservation_id
439
min_count = args.min_instances
440
max_count = args.max_instances
441
name, image, flavor, ipgroup, metadata, \
442
files, reservation_id, min_count, max_count = \
444
reservation_id=reservation_id,
448
reservation_id = self.cs.zones.boot(args.name, image, flavor,
452
reservation_id=reservation_id,
455
print "Reservation ID=", reservation_id
457
def _translate_flavor_keys(self, collection):
458
convert = [('ram', 'memory_mb'), ('disk', 'local_gb')]
459
for item in collection:
460
keys = item.__dict__.keys()
461
for from_key, to_key in convert:
462
if from_key in keys and to_key not in keys:
463
setattr(item, to_key, item._info[from_key])
304
465
def do_flavor_list(self, args):
305
466
"""Print a list of available 'flavors' (sizes of servers)."""
306
print_list(self.cs.flavors.list(), [
467
flavors = self.cs.flavors.list()
468
self._translate_flavor_keys(flavors)
469
print_list(flavors, [
386
549
"""Delete an IP group."""
387
550
self._find_ipgroup(args.group).delete()
554
metavar='<fixed_ip>',
556
help='Only match against fixed IP.')
557
@arg('--reservation_id',
558
dest='reservation_id',
559
metavar='<reservation_id>',
561
help='Only return instances that match reservation_id.')
562
@arg('--recurse_zones',
563
dest='recurse_zones',
569
help='Recurse through all zones if set.')
572
metavar='<ip_regexp>',
574
help='Search with regular expression match by IP address')
577
metavar='<ip6_regexp>',
579
help='Search with regular expression match by IPv6 address')
580
@arg('--server_name',
582
metavar='<name_regexp>',
584
help='Search with regular expression match by server name')
587
metavar='<name_regexp>',
589
help='Search with regular expression match by display name')
590
@arg('--instance_name',
592
metavar='<name_regexp>',
594
help='Search with regular expression match by instance name')
389
595
def do_list(self, args):
390
596
"""List active servers."""
391
print_list(self.cs.servers.list(), ['ID', 'Name', 'Status',
392
'Public IP', 'Private IP'])
597
recurse_zones = args.recurse_zones
599
'reservation_id': args.reservation_id,
600
'fixed_ip': args.fixed_ip,
601
'recurse_zones': recurse_zones,
605
'server_name': args.server_name,
606
'display_name': args.display_name}
608
to_print = ['UUID', 'Name', 'Status', 'Public IP', 'Private IP']
610
to_print = ['ID', 'Name', 'Status', 'Public IP', 'Private IP']
611
print_list(self.cs.servers.list(search_opts=search_opts),
395
615
dest='reboot_type',
425
645
server.resize(flavor)
427
647
@arg('server', metavar='<server>', help='Name or ID of server.')
648
@arg('name', metavar='<name>', help='Name of snapshot.')
649
@arg('backup_type', metavar='<daily|weekly>', help='type of backup')
650
@arg('rotation', type=int, metavar='<rotation>',
651
help="Number of backups to retain. Used for backup image_type.")
652
def do_backup(self, args):
653
"""Resize a server."""
654
server = self._find_server(args.server)
655
server.backup(args.name, args.backup_type, args.rotation)
657
@arg('server', metavar='<server>', help='Name or ID of server.')
658
def do_migrate(self, args):
659
"""Migrate a server."""
660
self._find_server(args.server).migrate()
662
@arg('server', metavar='<server>', help='Name or ID of server.')
428
663
def do_pause(self, args):
429
664
"""Pause a server."""
430
665
self._find_server(args.server).pause()
537
785
print_dict(zone._info)
539
787
@arg('api_url', metavar='<api_url>', help="URL for the Zone's API")
540
@arg('zone_username', metavar='<zone_username>',
788
@arg('zone_username', metavar='<zone_username>',
541
789
help='Authentication username.')
542
790
@arg('password', metavar='<password>', help='Authentication password.')
791
@arg('weight_offset', metavar='<weight_offset>',
792
help='Child Zone weight offset (typically 0.0).')
793
@arg('weight_scale', metavar='<weight_scale>',
794
help='Child Zone weight scale (typically 1.0).')
543
795
def do_zone_add(self, args):
544
796
"""Add a new child zone."""
545
zone = self.cs.zones.create(args.api_url, args.zone_username,
797
zone = self.cs.zones.create(args.api_url, args.zone_username,
798
args.password, args.weight_offset,
547
800
print_dict(zone._info)
549
@arg('zone', metavar='<zone name>', help='Name or ID of the zone')
802
@arg('zone', metavar='<zone>', help='Name or ID of the zone')
550
803
def do_zone_delete(self, args):
551
804
"""Delete a zone."""
552
805
self.cs.zones.delete(args.zone)
554
807
def do_zone_list(self, args):
555
808
"""List the children of a zone."""
556
print_list(self.cs.zones.list(), ['ID', 'Name', 'Is Active',
557
'Capabilities', 'API URL'])
809
print_list(self.cs.zones.list(), ['ID', 'Name', 'Is Active', \
810
'API URL', 'Weight Offset', 'Weight Scale'])
812
@arg('server', metavar='<server>', help='Name or ID of server.')
813
@arg('network_id', metavar='<network_id>', help='Network ID.')
814
def do_add_fixed_ip(self, args):
815
"""Add new IP address to network."""
816
server = self._find_server(args.server)
817
server.add_fixed_ip(args.network_id)
819
@arg('server', metavar='<server>', help='Name or ID of server.')
820
@arg('address', metavar='<address>', help='IP Address.')
821
def do_remove_fixed_ip(self, args):
822
"""Remove an IP address from a server."""
823
server = self._find_server(args.server)
824
server.remove_fixed_ip(args.address)
559
826
def _find_server(self, server):
560
827
"""Get a server by name or ID."""