def handle(self, *args, **options): if len(args) != 1: raise CommandError("Please provide a volume ID") volume = common.get_resource("volume", args[0]) pprint.pprint_volume(volume, stdout=self.stdout, display_mails=options["displaymail"]) self.stdout.write('\n\n')
def handle(self, *args, **options): if len(args) != 1: raise CommandError("Please provide a volume ID") volume = common.get_resource("volume", args[0]) pprint.pprint_volume(volume, stdout=self.stdout, display_mails=options['displaymail']) self.stdout.write('\n\n') pprint.pprint_volume_in_ganeti(volume, stdout=self.stdout)
def handle(self, *args, **options): if len(args) != 1: raise CommandError("Please provide a volume ID") volume = common.get_resource("volume", args[0], for_update=True) name = options.get("name") description = options.get("description") delete_on_termination = options.get("delete_on_termination") if delete_on_termination is not None: delete_on_termination = parse_bool(delete_on_termination) volume = volumes.update(volume, name, description, delete_on_termination) pprint.pprint_volume(volume, stdout=self.stdout) self.stdout.write('\n\n')
def handle(self, *args, **options): if len(args) != 1: raise CommandError("Please provide a volume ID") credentials = Credentials("snf_manage", is_admin=True) volume = common.get_resource("volume", args[0]) name = options.get("name") description = options.get("description") delete_on_termination = options.get("delete_on_termination") if delete_on_termination is not None: delete_on_termination = parse_bool(delete_on_termination) volume = volumes.update(volume.id, name=name, description=description, delete_on_termination=delete_on_termination, credentials=credentials) pprint.pprint_volume(volume, stdout=self.stdout) self.stdout.write('\n\n')
def handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") size = options.get("size") user_id = options.get("user_id") project_id = options.get("project") server_id = options.get("server_id") volume_type_id = options.get("volume_type_id") wait = parse_bool(options["wait"]) credentials = Credentials(user_id) display_name = options.get("name", "") display_description = options.get("description", "") if size is None: raise CommandError("Please specify the size of the volume") if server_id: vm = common.get_resource("server", server_id) if project_id is None: project_id = vm.project if user_id is None and server_id is None: raise CommandError("Please specify the id of a user or a server") elif user_id is None and server_id is not None: user_id = vm.userid if volume_type_id is not None: vtype = common.get_resource("volume-type", volume_type_id) elif server_id: vtype = vm.flavor.volume_type else: raise CommandError("Please specify the id of the volume type") # At this point, user_id, vtype must have been provided or extracted by # the server. The project_id is optional and will default to the user's # project. source_image_id = source_volume_id = source_snapshot_id = None source = options.get("source") if source is not None: try: source_type, source_uuid = source.split(":", 1) except (ValueError, TypeError): raise CommandError("Invalid '--source' option. Value must be" " of the form <source_type>:<source_uuid>") if source_type == "image": source_image_id = source_uuid elif source_type == "snapshot": source_snapshot_id = source_uuid else: raise CommandError("Unknown volume source type '%s'" % source_type) volume = volumes.create(credentials, size, server_id, name=display_name, description=display_description, source_image_id=source_image_id, source_snapshot_id=source_snapshot_id, source_volume_id=source_volume_id, volume_type_id=vtype.id, metadata={}, project_id=project_id) self.stdout.write("Created volume '%s' in DB:\n" % volume.id) pprint.pprint_volume(volume, stdout=self.stdout) self.stdout.write("\n") if volume.machine is not None: volume.machine.task_job_id = volume.backendjobid common.wait_server_task(volume.machine, wait, stdout=self.stdout)
def handle(self, *args, **options): if args: raise CommandError("Command doesn't accept any arguments") size = options.get("size") user_id = options.get("user_id") project_id = options.get("project") server_id = options.get("server_id") volume_type_id = options.get("volume_type_id") wait = parse_bool(options["wait"]) display_name = options.get("name", "") display_description = options.get("description", "") if size is None: raise CommandError("Please specify the size of the volume") if server_id is None: raise CommandError("Please specify the server to attach the" " volume.") vm = common.get_resource("server", server_id, for_update=True) if user_id is None: user_id = vm.userid if volume_type_id is not None: vtype = common.get_resource("volume-type", volume_type_id) else: vtype = vm.flavor.volume_type if project_id is None: project_id = vm.project source_image_id = source_volume_id = source_snapshot_id = None source = options.get("source") if source is not None: try: source_type, source_uuid = source.split(":", 1) except (ValueError, TypeError): raise CommandError("Invalid '--source' option. Value must be" " of the form <source_type>:<source_uuid>") if source_type == "image": source_image_id = source_uuid elif source_type == "snapshot": source_snapshot_id = source_uuid else: raise CommandError("Unknown volume source type '%s'" % source_type) volume = volumes.create(user_id, size, server_id, name=display_name, description=display_description, source_image_id=source_image_id, source_snapshot_id=source_snapshot_id, source_volume_id=source_volume_id, volume_type_id=vtype.id, metadata={}, project=project_id) self.stdout.write("Created volume '%s' in DB:\n" % volume.id) pprint.pprint_volume(volume, stdout=self.stdout) self.stdout.write("\n") if volume.machine is not None: volume.machine.task_job_id = volume.backendjobid common.wait_server_task(volume.machine, wait, stdout=self.stdout)