Merge lp:~smoser/uvtool/sm-features00 into lp:~uvtool-dev/uvtool/trunk

Proposed by Scott Moser
Status: Needs review
Proposed branch: lp:~smoser/uvtool/sm-features00
Merge into: lp:~uvtool-dev/uvtool/trunk
Diff against target: 201 lines (+90/-14)
3 files modified
bin/uvt-kvm (+20/-9)
uvtool/libvirt/simplestreams.py (+9/-5)
uvtool/ubuntu.py (+61/-0)
To merge this branch: bzr merge lp:~smoser/uvtool/sm-features00
Reviewer Review Type Date Requested Status
uvtool development Pending
Review via email: mp+198838@code.launchpad.net

Description of the change

smoser improvements

This does:
 * adds execute to bin/uvt-simplestreams-libvirt
 * adds a 'uvtool.ubuntu' that knows some thigns about ubuntu specifically
   this means the user can now say "trusty" rather than "release=trusty".
   Also , if user says trusty and doesn't specify mirror then it picks daily stream.
 * prefers keys via ssh-add -L to ~/.ssh/id_rsa.pub

To post a comment you must log in.
lp:~smoser/uvtool/sm-features00 updated
70. By Scott Moser

fix incorrect variable usage

Unmerged revisions

70. By Scott Moser

fix incorrect variable usage

69. By Scott Moser

bin/uvt-simplestreams-libvirt: make executable

68. By Scott Moser

add awareness of ubuntu releases

knowing about ubuntu releases by name allows shorter syntax and more complex
behavior.

Now the user can refer to a supported ubuntu release just by its short name:
 uvt-simplestreams-libvirt sync trusty arch=amd64

Additionally, if the release specified is ubuntu development release and
no mirror is provided, then the daily builds are chosen.

67. By Scott Moser

support reading keys from 'ssh-add -L'

'ssh-add -L' provides ssh keys that the user is authenticated with.
If it returns success and has output, then use it as the source
rather than ~/.ssh/id_rsa.pub (which doesn't exist for me).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/uvt-kvm'
2--- bin/uvt-kvm 2013-11-12 15:02:01 +0000
3+++ bin/uvt-kvm 2013-12-13 14:30:46 +0000
4@@ -46,6 +46,7 @@
5 import uvtool.libvirt
6 import uvtool.libvirt.simplestreams
7 import uvtool.wait
8+import uvtool.ubuntu
9
10 DEFAULT_TEMPLATE = '/usr/share/uvtool/libvirt/template.xml'
11 POOL_NAME = 'uvtool'
12@@ -86,7 +87,19 @@
13
14 def get_ssh_authorized_keys(filename):
15 if filename is None:
16- filename = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa.pub')
17+ try:
18+ with open("/dev/null") as fpnull:
19+ output = subprocess.check_output(['ssh-add', '-L'],
20+ stderr=fpnull)
21+ except subprocess.CalledProcessError:
22+ pass
23+
24+ output = output.strip()
25+ if output:
26+ return output.splitlines()
27+
28+ else:
29+ filename = os.path.join(os.environ['HOME'], '.ssh', 'id_rsa.pub')
30
31 try:
32 f = open(filename, 'rb')
33@@ -101,7 +114,7 @@
34 return []
35 else:
36 with f:
37- return [f.read().strip()]
38+ return f.read().strip().splitlines()
39
40
41 def create_default_user_data(fobj, args):
42@@ -357,11 +370,6 @@
43 domain.undefine()
44
45
46-def get_lts_series():
47- output = subprocess.check_output(['distro-info', '--lts'], close_fds=True)
48- return output.strip()
49-
50-
51 def main_create_get_user_data_fobj(args):
52 """Return a user-data fobj to use, based on command line arguments
53 supplied.
54@@ -420,12 +428,15 @@
55 return
56
57 user_data_fobj = main_create_get_user_data_fobj(args)
58+
59+ (_mirror, filters) = uvtool.ubuntu.patch_filters(args.filters)
60+
61 if args.backing_image_file:
62 abs_image_backing_file = os.path.abspath(args.backing_image_file)
63 else:
64 abs_image_backing_file = None
65 create(
66- args.hostname, args.filters, user_data_fobj,
67+ args.hostname, filters, user_data_fobj,
68 backing_image_file=abs_image_backing_file,
69 bridge=args.bridge,
70 cpu=args.cpu,
71@@ -564,7 +575,7 @@
72 create_subparser.add_argument('hostname')
73 create_subparser.add_argument(
74 'filters', nargs='*', metavar='filter',
75- default=["release=%s" % get_lts_series()],
76+ default=[uvtool.ubuntu.get_lts_series()],
77 )
78 destroy_subparser = subparsers.add_parser('destroy')
79 destroy_subparser.set_defaults(func=main_destroy)
80
81=== modified file 'bin/uvt-simplestreams-libvirt' (properties changed: -x to +x)
82=== modified file 'uvtool/libvirt/simplestreams.py'
83--- uvtool/libvirt/simplestreams.py 2013-11-26 14:25:59 +0000
84+++ uvtool/libvirt/simplestreams.py 2013-12-13 14:30:46 +0000
85@@ -35,6 +35,8 @@
86 import subprocess
87 import sys
88
89+import distro_info
90+
91 import libvirt
92
93 import simplestreams.filters
94@@ -42,6 +44,7 @@
95 import simplestreams.util
96
97 import uvtool.libvirt
98+import uvtool.ubuntu
99
100 LIBVIRT_POOL_NAME = 'uvtool'
101 IMAGE_DIR = '/var/lib/uvtool/libvirt/images/' # must end in '/'; see use
102@@ -249,8 +252,10 @@
103
104
105 def main_sync(args):
106+ (mirror_url, filters) = uvtool.ubuntu.patch_filters(args.filters, args.mirror_url)
107+
108 (mirror_url, initial_path) = simplestreams.util.path_from_mirror_url(
109- args.mirror_url, args.path)
110+ mirror_url, args.path)
111
112 def policy(content, path):
113 if initial_path.endswith('sjson') and not args.no_authentication:
114@@ -263,7 +268,7 @@
115 mirror_url, policy=policy)
116
117 filter_list = simplestreams.filters.get_filters(
118- ['datatype=image-downloads', 'ftype=disk1.img'] + args.filters
119+ ['datatype=image-downloads', 'ftype=disk1.img'] + filters
120 )
121 tmirror = LibvirtMirror(filter_list, verbose=args.verbose)
122 tmirror.sync(smirror, initial_path)
123@@ -306,10 +311,9 @@
124 sync_subparser.add_argument(
125 '--keyring',
126 help='keyring to be specified to gpg via --keyring',
127- default='/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'
128+ default=uvtool.ubuntu.KEYRING,
129 )
130- sync_subparser.add_argument('--source', dest='mirror_url',
131- default='https://cloud-images.ubuntu.com/releases/')
132+ sync_subparser.add_argument('--source', dest='mirror_url', default=None)
133 sync_subparser.add_argument('--no-authentication', action='store_true')
134 sync_subparser.add_argument('filters', nargs='*', metavar='filter',
135 default=["arch=%s" % system_arch])
136
137=== added file 'uvtool/ubuntu.py'
138--- uvtool/ubuntu.py 1970-01-01 00:00:00 +0000
139+++ uvtool/ubuntu.py 2013-12-13 14:30:46 +0000
140@@ -0,0 +1,61 @@
141+# Copyright (C) 2012-3 Canonical Ltd.
142+# Author: Robie Basak <robie.basak@canonical.com>
143+#
144+# This program is free software: you can redistribute it and/or modify
145+# it under the terms of the GNU Affero General Public License as published by
146+# the Free Software Foundation, either version 3 of the License, or
147+# (at your option) any later version.
148+#
149+# This program is distributed in the hope that it will be useful,
150+# but WITHOUT ANY WARRANTY; without even the implied warranty of
151+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152+# GNU Affero General Public License for more details.
153+#
154+# You should have received a copy of the GNU Affero General Public License
155+# along with this program. If not, see <http://www.gnu.org/licenses/>.
156+
157+# Depends: distro-info, cloud-utils, python-libvirt, python-lxml
158+# also qemu-kvm (precise) or kvm (newer?)
159+# The import subcommand needs: qemu-utils (for qemu-img)
160+import distro_info
161+
162+STREAMS = {
163+ 'daily': 'https://cloud-images.ubuntu.com/releases/',
164+ 'released': 'https://cloud-images.ubuntu.com/daily/',
165+}
166+KEYRING = '/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'
167+
168+
169+def get_lts_series():
170+ return(distro_info.UbuntuDistroInfo().lts())
171+
172+
173+def get_devel_series():
174+ return(distro_info.UbuntuDistroInfo().devel())
175+
176+
177+def get_series_list():
178+ return(distro_info.UbuntuDistroInfo().supported())
179+
180+
181+def patch_filters(filters=None, mirror=None):
182+ if filters is None:
183+ filters = []
184+
185+ if mirror is None:
186+ nmirror = STREAMS['released']
187+ else:
188+ nmirror = mirror
189+
190+ devel = get_devel_series()
191+ slist = get_series_list()
192+
193+ nfilters = []
194+ for f in filters:
195+ if f in slist:
196+ f = "release=%s" % f
197+ if f == devel and mirror is None:
198+ nmirror = STREAMS['daily']
199+ nfilters.append(f)
200+
201+ return (nmirror, nfilters)

Subscribers

People subscribed via source and target branches