diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-01-26 13:19:49 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-01-26 13:19:49 -0500 |
commit | 262479dfe04e8342843df8851eaef61caaa95f5a (patch) | |
tree | a201b63118ad1f45afe78a9ca8822a176b9e665f /ec2init/util.py | |
parent | 1252e1a690c5c4f53f01ed4d06b5558cce204fd2 (diff) | |
download | vyos-cloud-init-262479dfe04e8342843df8851eaef61caaa95f5a.tar.gz vyos-cloud-init-262479dfe04e8342843df8851eaef61caaa95f5a.zip |
add cloud config support for apt_sources
This includes support for
- signing key import via 'keyid' and 'keyserver' or 'key'
- ppa:* support (provided by 'add-apt-repository')
now there is a dependency on python-software-properties
Diffstat (limited to 'ec2init/util.py')
-rw-r--r-- | ec2init/util.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/ec2init/util.py b/ec2init/util.py index 0737f117..ece5755a 100644 --- a/ec2init/util.py +++ b/ec2init/util.py @@ -1,6 +1,7 @@ import yaml import os import errno +import subprocess def read_conf(fname): stream = file(fname) @@ -42,3 +43,29 @@ def write_file(file,content,mode=0644): f.close() os.chmod(file,mode) +# get keyid from keyserver +def getkeybyid(keyid,keyserver): + shcmd=""" + k=${1} ks=${2}; + exec 2>/dev/null + [ -n "$k" ] || exit 1; + armour=$(gpg --list-keys --armour "${k}") + if [ -z "${armour}" ]; then + gpg --keyserver ${ks} --recv $k >/dev/null && + armour=$(gpg --export --armour "${k}") && + gpg --batch --yes --delete-keys "${k}" + fi + [ -n "${armour}" ] && echo "${armour}" + """ + args=['sh', '-c', shcmd, "export-gpg-keyid", keyid, keyserver] + return(subp(args)[0]) + +def subp(args, input=None): + s_in = None + if input is not None: + s_in = subprocess.PIPE + sp = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=s_in) + out,err = sp.communicate(input) + if sp.returncode is not 0: + raise subprocess.CalledProcessError(sp.returncode,args) + return(out,err) |