diff options
author | yuhuan.yang <yuhuan.yang@123.com> | 2017-07-14 22:34:05 +0800 |
---|---|---|
committer | yuhuan.yang <yuhuan.yang@123.com> | 2017-07-14 22:35:40 +0800 |
commit | 37990a24ee9d73b35db5cefa60af9ec6f9fb2338 (patch) | |
tree | e13eb774ffc4a1c80e73f598aa074132ccd1ac13 | |
parent | e319a7011290ec4a5458f0e8ffcb1482de06805d (diff) | |
download | mic-37990a24ee9d73b35db5cefa60af9ec6f9fb2338.tar.gz mic-37990a24ee9d73b35db5cefa60af9ec6f9fb2338.tar.bz2 mic-37990a24ee9d73b35db5cefa60af9ec6f9fb2338.zip |
Add new option of --run_script
Change-Id: I7c2d194ba3bcc4e8fc78073bc922f6e7eb853821
-rwxr-xr-x | mic/cmd_create.py | 2 | ||||
-rwxr-xr-x | mic/conf.py | 1 | ||||
-rwxr-xr-x | plugins/imager/fs_plugin.py | 12 | ||||
-rwxr-xr-x | plugins/imager/loop_plugin.py | 11 | ||||
-rwxr-xr-x | plugins/imager/qcow_plugin.py | 12 | ||||
-rwxr-xr-x | plugins/imager/raw_plugin.py | 12 | ||||
-rwxr-xr-x | tools/mic | 2 |
7 files changed, 52 insertions, 0 deletions
diff --git a/mic/cmd_create.py b/mic/cmd_create.py index 54fdbde..8dfaf8f 100755 --- a/mic/cmd_create.py +++ b/mic/cmd_create.py @@ -189,6 +189,8 @@ def main(parser, args, argv): if args.ignore_ksrepo:
configmgr.create['ignore_ksrepo'] = args.ignore_ksrepo
+ if args.run_script:
+ configmgr.create['run_script'] = args.run_script
creater = createrClass()
creater.do_create(args)
diff --git a/mic/conf.py b/mic/conf.py index d844c65..a45b05e 100755 --- a/mic/conf.py +++ b/mic/conf.py @@ -75,6 +75,7 @@ class ConfigMgr(object): "extrarepos": {}, "ignore_ksrepo": False, "strict_mode": False, + "run_script": None, }, 'chroot': { "saveto": None, diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index 86b1849..a6b5cf8 100755 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -15,6 +15,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. +import subprocess from mic import chroot, msger, rt_util from mic.utils import misc, errors, fs_related from mic.imager import fs @@ -114,6 +115,17 @@ class FsPlugin(ImagerPlugin): finally: creator.cleanup() + #Run script of --run_script after image created + if creatoropts['run_script']: + cmd = creatoropts['run_script'] + msger.info("Running command in parameter run_script: "+"".join(cmd)) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + p.communicate() + except OSError,err: + msger.warning(str(err)) + + msger.info("Finished.") return 0 diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index 755d8d5..c3fa67b 100755 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -16,6 +16,7 @@ # Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os +import subprocess import shutil import tempfile @@ -119,6 +120,16 @@ class LoopPlugin(ImagerPlugin): finally: creator.cleanup() + #Run script of --run_script after image created + if creatoropts['run_script']: + cmd = creatoropts['run_script'] + msger.info("Running command in parameter run_script: "+"".join(cmd)) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + p.communicate() + except OSError,err: + msger.warning(str(err)) + msger.info("Finished.") return 0 diff --git a/plugins/imager/qcow_plugin.py b/plugins/imager/qcow_plugin.py index 09bc790..27a712b 100755 --- a/plugins/imager/qcow_plugin.py +++ b/plugins/imager/qcow_plugin.py @@ -15,6 +15,7 @@ # Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os +import subprocess import shutil from mic import msger, rt_util @@ -150,6 +151,17 @@ class QcowPlugin(ImagerPlugin): finally: creator.cleanup() + #Run script of --run_script after image created + if creatoropts['run_script']: + cmd = creatoropts['run_script'] + msger.info("Running command in parameter run_script: "+"".join(cmd)) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + p.communicate() + except OSError,err: + msger.warning(str(err)) + + msger.info("Finished.") return 0 diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 09a9714..554eac7 100755 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -16,6 +16,7 @@ # Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os +import subprocess import shutil import re import tempfile @@ -113,6 +114,17 @@ class RawPlugin(ImagerPlugin): finally: creator.cleanup() + #Run script of --run_script after image created + if creatoropts['run_script']: + cmd = creatoropts['run_script'] + msger.info("Running command in parameter run_script: "+"".join(cmd)) + try: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) + p.communicate() + except OSError,err: + msger.warning(str(err)) + + msger.info("Finished.") return 0 @@ -132,6 +132,8 @@ def create_parser(parser): parent_parser.add_argument('-i', '--interactive', action='store_true', dest='interactive', default=True, help='interactive output') + parent_parser.add_argument('--run_script', action='store', dest='run_script', + default=None, help='Run script on local PC after image created') parser.set_defaults(alias="cr") |