~cloud-init-dev/cloud-init/trunk

« back to all changes in this revision

Viewing changes to cloudinit/sources/DataSourceBigstep.py

  • Committer: Scott Moser
  • Date: 2016-08-10 15:06:15 UTC
  • Revision ID: smoser@ubuntu.com-20160810150615-ma2fv107w3suy1ma
README: Mention move of revision control to git.

cloud-init development has moved its revision control to git.
It is available at 
  https://code.launchpad.net/cloud-init

Clone with 
  git clone https://git.launchpad.net/cloud-init
or
  git clone git+ssh://git.launchpad.net/cloud-init

For more information see
  https://git.launchpad.net/cloud-init/tree/HACKING.rst

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
#    Copyright (C) 2015-2016 Bigstep Cloud Ltd.
3
 
#
4
 
#    Author: Alexandru Sirbu <alexandru.sirbu@bigstep.com>
5
 
#
6
 
 
7
 
import errno
8
 
import json
9
 
 
10
 
from cloudinit import log as logging
11
 
from cloudinit import sources
12
 
from cloudinit import url_helper
13
 
from cloudinit import util
14
 
 
15
 
LOG = logging.getLogger(__name__)
16
 
 
17
 
 
18
 
class DataSourceBigstep(sources.DataSource):
19
 
    def __init__(self, sys_cfg, distro, paths):
20
 
        sources.DataSource.__init__(self, sys_cfg, distro, paths)
21
 
        self.metadata = {}
22
 
        self.vendordata_raw = ""
23
 
        self.userdata_raw = ""
24
 
 
25
 
    def get_data(self, apply_filter=False):
26
 
        url = get_url_from_file()
27
 
        if url is None:
28
 
            return False
29
 
        response = url_helper.readurl(url)
30
 
        decoded = json.loads(response.contents)
31
 
        self.metadata = decoded["metadata"]
32
 
        self.vendordata_raw = decoded["vendordata_raw"]
33
 
        self.userdata_raw = decoded["userdata_raw"]
34
 
        return True
35
 
 
36
 
 
37
 
def get_url_from_file():
38
 
    try:
39
 
        content = util.load_file("/var/lib/cloud/data/seed/bigstep/url")
40
 
    except IOError as e:
41
 
        # If the file doesn't exist, then the server probably isn't a Bigstep
42
 
        # instance; otherwise, another problem exists which needs investigation
43
 
        if e.errno == errno.ENOENT:
44
 
            return None
45
 
        else:
46
 
            raise
47
 
    return content
48
 
 
49
 
# Used to match classes to dependencies
50
 
datasources = [
51
 
    (DataSourceBigstep, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
52
 
]
53
 
 
54
 
 
55
 
# Return a list of data sources that match this set of dependencies
56
 
def get_datasource_list(depends):
57
 
    return sources.list_from_depends(depends, datasources)