3
# Author: Neal Shrader <neal@digitalocean.com>
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License version 3, as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
from cloudinit import ec2_utils
18
from cloudinit import log as logging
19
from cloudinit import sources
20
from cloudinit import util
25
LOG = logging.getLogger(__name__)
28
'metadata_url': 'http://169.254.169.254/metadata/v1/',
29
'mirrors_url': 'http://mirrors.digitalocean.com/'
35
class DataSourceDigitalOcean(sources.DataSource):
36
def __init__(self, sys_cfg, distro, paths):
37
sources.DataSource.__init__(self, sys_cfg, distro, paths)
38
self.metadata = dict()
39
self.ds_cfg = util.mergemanydict([
40
util.get_cfg_by_path(sys_cfg, ["datasource", "DigitalOcean"], {}),
42
self.metadata_address = self.ds_cfg['metadata_url']
44
if self.ds_cfg.get('retries'):
45
self.retries = self.ds_cfg['retries']
47
self.retries = MD_RETRIES
49
if self.ds_cfg.get('timeout'):
50
self.timeout = self.ds_cfg['timeout']
52
self.timeout = MD_TIMEOUT
55
caller = functools.partial(util.read_file_or_url,
56
timeout=self.timeout, retries=self.retries)
59
return caller(url).contents
61
md = ec2_utils.MetadataMaterializer(mcaller(self.metadata_address),
62
base_url=self.metadata_address,
65
self.metadata = md.materialize()
67
if self.metadata.get('id'):
72
def get_userdata_raw(self):
73
return "\n".join(self.metadata['user-data'])
75
def get_vendordata_raw(self):
76
return "\n".join(self.metadata['vendor-data'])
78
def get_public_ssh_keys(self):
79
public_keys = self.metadata['public-keys']
80
if isinstance(public_keys, list):
86
def availability_zone(self):
87
return self.metadata['region']
89
def get_instance_id(self):
90
return self.metadata['id']
92
def get_hostname(self, fqdn=False, resolve_ip=False):
93
return self.metadata['hostname']
95
def get_package_mirror_info(self):
96
return self.ds_cfg['mirrors_url']
99
def launch_index(self):
102
# Used to match classes to dependencies
104
(DataSourceDigitalOcean, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
108
# Return a list of data sources that match this set of dependencies
109
def get_datasource_list(depends):
110
return sources.list_from_depends(depends, datasources)