Merge lp:~alexandru-sirbu/cloud-init/bigstep-datasource into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Alex Sirbu
Status: Merged
Merged at revision: 1175
Proposed branch: lp:~alexandru-sirbu/cloud-init/bigstep-datasource
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 50 lines (+46/-0)
1 file modified
cloudinit/sources/DataSourceBigstep.py (+46/-0)
To merge this branch: bzr merge lp:~alexandru-sirbu/cloud-init/bigstep-datasource
Reviewer Review Type Date Requested Status
Dan Watkins Approve
Review via email: mp+287752@code.launchpad.net

Description of the change

The Bigstep datasource, which looks inside the /var/lib/cloud/data/seed/bigstep/url file to get an URL which to call to obtain the cloud-init scripts, has been added.

This datasource will be used by Bigstep in provisioning its templates, by using cloudinit.

To post a comment you must log in.
Revision history for this message
Dan Watkins (oddbloke) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'cloudinit/sources/DataSourceBigstep.py'
2--- cloudinit/sources/DataSourceBigstep.py 1970-01-01 00:00:00 +0000
3+++ cloudinit/sources/DataSourceBigstep.py 2016-03-02 09:06:44 +0000
4@@ -0,0 +1,46 @@
5+#
6+# Copyright (C) 2015-2016 Bigstep Cloud Ltd.
7+#
8+# Author: Alexandru Sirbu <alexandru.sirbu@bigstep.com>
9+#
10+
11+import json
12+
13+from cloudinit import log as logging
14+from cloudinit import sources
15+from cloudinit import util
16+from cloudinit import url_helper
17+
18+LOG = logging.getLogger(__name__)
19+
20+
21+class DataSourceBigstep(sources.DataSource):
22+ def __init__(self, sys_cfg, distro, paths):
23+ sources.DataSource.__init__(self, sys_cfg, distro, paths)
24+ self.metadata = {}
25+ self.vendordata_raw = ""
26+ self.userdata_raw = ""
27+
28+ def get_data(self, apply_filter=False):
29+ url = get_url_from_file()
30+ response = url_helper.readurl(url)
31+ decoded = json.loads(response.contents)
32+ self.metadata = decoded["metadata"]
33+ self.vendordata_raw = decoded["vendordata_raw"]
34+ self.userdata_raw = decoded["userdata_raw"]
35+ return True
36+
37+
38+def get_url_from_file():
39+ content = util.load_file("/var/lib/cloud/data/seed/bigstep/url")
40+ return content
41+
42+# Used to match classes to dependencies
43+datasources = [
44+ (DataSourceBigstep, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
45+]
46+
47+
48+# Return a list of data sources that match this set of dependencies
49+def get_datasource_list(depends):
50+ return sources.list_from_depends(depends, datasources)