Any custom key=value pair can be used as a custom environment variable in virt-sandbox-image. e.g virt-sandbox-image run ubuntu /var/lib/libvirt/templates -c lxc:/// -i /bin/bash -e key1=val1 --- virt-sandbox-image/sources/DockerSource.py | 10 ++++++++++ virt-sandbox-image/sources/Source.py | 4 ++++ virt-sandbox-image/virt-sandbox-image.py | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+)
diff --git a/virt-sandbox-image/sources/DockerSource.py b/virt-sandbox-image/sources/DockerSource.py index 67bcf6b..c84b84e 100644 --- a/virt-sandbox-image/sources/DockerSource.py +++ b/virt-sandbox-image/sources/DockerSource.py @@ -47,6 +47,12 @@ class DockerConfParser(): for key,value in volumes.iteritems(): volumelist.append(key) return volumelist + def getEnvs(self): + lst = self.json_data['container_config']['Env'] + if lst is not None and isinstance(lst,list): + return lst + else: + return [] class DockerSource(Source): @@ -407,5 +413,9 @@ class DockerSource(Source): configParser = DockerConfParser(configfile) return configParser.getVolumes() + def get_env(self,configfile): + configParser = DockerConfParser(configfile) + return configParser.getEnvs() + def debug(msg): sys.stderr.write(msg) diff --git a/virt-sandbox-image/sources/Source.py b/virt-sandbox-image/sources/Source.py index 8cc508e..c467ce2 100644 --- a/virt-sandbox-image/sources/Source.py +++ b/virt-sandbox-image/sources/Source.py @@ -49,3 +49,7 @@ class Source(): @abstractmethod def get_volume(self,**args): pass + + @abstractmethod + def get_env(self,**args): + pass diff --git a/virt-sandbox-image/virt-sandbox-image.py b/virt-sandbox-image/virt-sandbox-image.py index e554d8a..dacfa0c 100755 --- a/virt-sandbox-image/virt-sandbox-image.py +++ b/virt-sandbox-image/virt-sandbox-image.py @@ -145,10 +145,12 @@ def run(args): cmd.append("-c") cmd.append(args.connect) params = ['-m','host-image:/=%s,format=%s' %(diskfile,format)] + networkArgs = args.network if networkArgs is not None: params.append('-N') params.append(networkArgs) + allVolumes = source.get_volume(configfile) volumeArgs = args.volume if volumeArgs is not None: @@ -168,6 +170,20 @@ def run(args): pass params.append("--mount") params.append("host-bind:%s=%s" %(guestPath,hostPath)) + + allEnvs = source.get_env(configfile) + envArgs = args.env + if envArgs is not None: + allEnvs = allEnvs + envArgs + for env in allEnvs: + envsplit = env.split("=") + envlen = len(envsplit) + if envlen == 2: + params.append("--env") + params.append(env) + else: + pass + params.append('--') params.append(commandToRun) cmd = cmd + params @@ -247,6 +263,9 @@ def gen_run_args(subparser): help=_("Network params for running template")) parser.add_argument("-v","--volume",action="append", help=_("Volume params for running template")) + parser.add_argument("-e","--env",action="append", + help=_("Environment params for running template")) + parser.set_defaults(func=run) if __name__ == '__main__': -- 2.1.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list