From 6f59b9648e1bd2d451fddb1a7712119c0e46045b Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 19 Jun 2009 15:01:12 +0200 Subject: [PATCH] rapi: implement dry-run mode This patch implements dry-run mode for the operations which modify the state of the cluster. Dry-run mode is enabled by passing a 'dry-run' query argument with positive integer value. Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- lib/rapi/baserlib.py | 6 ++++++ lib/rapi/rlib2.py | 19 +++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/rapi/baserlib.py b/lib/rapi/baserlib.py index 2bca63ba0..a5522a594 100644 --- a/lib/rapi/baserlib.py +++ b/lib/rapi/baserlib.py @@ -280,3 +280,9 @@ class R_Generic(object): """ return self._checkIntVariable('bulk') + + def dryRun(self): + """Check if the request specifies dry-run mode. + + """ + return self._checkIntVariable('dry-run') diff --git a/lib/rapi/rlib2.py b/lib/rapi/rlib2.py index 3e5208518..d79a0fc08 100644 --- a/lib/rapi/rlib2.py +++ b/lib/rapi/rlib2.py @@ -264,6 +264,7 @@ class R_2_instances(baserlib.R_Generic): beparams=beparams, file_storage_dir=fn('file_storage_dir', None), file_driver=fn('file_driver', 'loop'), + dry_run=bool(self.dryRun()), ) return baserlib.SubmitJob([op]) @@ -289,7 +290,8 @@ class R_2_instances_name(baserlib.R_Generic): """ op = opcodes.OpRemoveInstance(instance_name=self.items[0], - ignore_failures=False) + ignore_failures=False, + dry_run=bool(self.dryRun())) return baserlib.SubmitJob([op]) @@ -313,7 +315,8 @@ class R_2_instances_name_reboot(baserlib.R_Generic): [False])[0]) op = opcodes.OpRebootInstance(instance_name=instance_name, reboot_type=reboot_type, - ignore_secondaries=ignore_secondaries) + ignore_secondaries=ignore_secondaries, + dry_run=bool(self.dryRun())) return baserlib.SubmitJob([op]) @@ -334,7 +337,8 @@ class R_2_instances_name_startup(baserlib.R_Generic): instance_name = self.items[0] force_startup = bool(self.queryargs.get('force', [False])[0]) op = opcodes.OpStartupInstance(instance_name=instance_name, - force=force_startup) + force=force_startup, + dry_run=bool(self.dryRun())) return baserlib.SubmitJob([op]) @@ -350,7 +354,8 @@ class R_2_instances_name_shutdown(baserlib.R_Generic): """ instance_name = self.items[0] - op = opcodes.OpShutdownInstance(instance_name=instance_name) + op = opcodes.OpShutdownInstance(instance_name=instance_name, + dry_run=bool(self.dryRun())) return baserlib.SubmitJob([op]) @@ -396,7 +401,8 @@ class _R_Tags(baserlib.R_Generic): raise http.HttpBadRequest("Please specify tag(s) to add using the" " the 'tag' parameter") return baserlib._Tags_PUT(self.TAG_LEVEL, - self.queryargs['tag'], name=self.name) + self.queryargs['tag'], name=self.name, + dry_run=bool(self.dryRun())) def DELETE(self): """Delete a tag. @@ -412,7 +418,8 @@ class _R_Tags(baserlib.R_Generic): " tag(s) using the 'tag' parameter") return baserlib._Tags_DELETE(self.TAG_LEVEL, self.queryargs['tag'], - name=self.name) + name=self.name, + dry_run=bool(self.dryRun())) class R_2_instances_name_tags(_R_Tags): -- GitLab