diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-03-12 14:48:15 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-03-12 14:48:15 -0400 |
commit | 6b8df9532c2d006a298dc602255e099b48793f23 (patch) | |
tree | 780f927b70a11b640c6f67592b773e5c495cbf6b | |
parent | 462b3dead2c62806e1669dd6547e74e5946d2fca (diff) | |
parent | 6a77364216dadfd7e955def9846118bfd69982e2 (diff) | |
download | vyos-cloud-init-6b8df9532c2d006a298dc602255e099b48793f23.tar.gz vyos-cloud-init-6b8df9532c2d006a298dc602255e099b48793f23.zip |
import CloudStack data source [Cosmin Luta]
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | cloudinit/DataSourceCloudStack.py | 88 | ||||
-rw-r--r-- | cloudinit/__init__.py | 2 | ||||
-rw-r--r-- | config/cloud.cfg | 2 |
4 files changed, 91 insertions, 2 deletions
@@ -28,6 +28,7 @@ - DataSourceNoCloud: support seed from external disk of ISO or vfat (LP: #857378) - DataSourceNoCloud: support inserting /etc/network/interfaces - DataSourceMaaS: add data source for Ubuntu Machines as a Service (MaaS) (LP: #942061) + - DataSourceCloudStack: add support for CloudStack datasource [Cosmin Luta] - add option 'apt_pipelining' to address issue with S3 mirrors (LP: #948461) [Ben Howard] 0.6.2: diff --git a/cloudinit/DataSourceCloudStack.py b/cloudinit/DataSourceCloudStack.py new file mode 100644 index 00000000..181b9419 --- /dev/null +++ b/cloudinit/DataSourceCloudStack.py @@ -0,0 +1,88 @@ +# vi: ts=4 expandtab +# +# Copyright (C) 2012 Canonical Ltd. +# Copyright (C) 2012 Cosmin Luta +# +# Author: Cosmin Luta <q4break@gmail.com> +# Author: Scott Moser <scott.moser@canonical.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import cloudinit.DataSource as DataSource + +from cloudinit import seeddir as base_seeddir +from cloudinit import log +import cloudinit.util as util +from socket import inet_ntoa +import time +import boto.utils as boto_utils +from struct import pack + +class DataSourceCloudStack(DataSource.DataSource): + api_ver = 'latest' + seeddir = base_seeddir + '/cs' + metadata_address = None + + def __init__(self, sys_cfg=None): + DataSource.DataSource.__init__(self, sys_cfg) + # Cloudstack has its metadata/userdata URLs located at http://<default-gateway-ip>/latest/ + self.metadata_address = "http://%s/" % self.get_default_gateway() + + def get_default_gateway(self): + """ Returns the default gateway ip address in the dotted format + """ + with open("/proc/net/route", "r") as f: + for line in f.readlines(): + items = line.split("\t") + if items[1] == "00000000": + # found the default route, get the gateway + gw = inet_ntoa(pack("<L", int(items[2], 16))) + log.debug("found default route, gateway is %s" % gw) + return gw + + def __str__(self): + return "DataSourceCloudStack" + + def get_data(self): + seedret = {} + if util.read_optional_seed(seedret, base=self.seeddir + "/"): + self.userdata_raw = seedret['user-data'] + self.metadata = seedret['meta-data'] + log.debug("using seeded cs data in %s" % self.seeddir) + return True + + try: + start = time.time() + self.userdata_raw = boto_utils.get_instance_userdata(self.api_ver, + None, self.metadata_address) + self.metadata = boto_utils.get_instance_metadata(self.api_ver, + self.metadata_address) + log.debug("crawl of metadata service took %ds" % (time.time() - start)) + return True + except Exception as e: + log.exception(e) + return False + + def get_instance_id(self): + return self.metadata['instance-id'] + + def get_availability_zone(self): + return self.metadata['availability-zone'] + +datasources = [ + (DataSourceCloudStack, (DataSource.DEP_FILESYSTEM, DataSource.DEP_NETWORK)), +] + +# return a list of data sources that match this set of dependencies +def get_datasource_list(depends): + return DataSource.list_from_depends(depends, datasources) diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 9f188766..37447a31 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -29,7 +29,7 @@ cfg_env_name = "CLOUD_CFG" cfg_builtin = """ log_cfgs: [] -datasource_list: ["NoCloud", "ConfigDrive", "OVF", "MaaS", "Ec2" ] +datasource_list: ["NoCloud", "ConfigDrive", "OVF", "MaaS", "Ec2", "CloudStack"] def_log_file: /var/log/cloud-init.log syslog_fix_perms: syslog:adm """ diff --git a/config/cloud.cfg b/config/cloud.cfg index e9e3bb6c..983b0ba6 100644 --- a/config/cloud.cfg +++ b/config/cloud.cfg @@ -1,7 +1,7 @@ user: ubuntu disable_root: 1 preserve_hostname: False -# datasource_list: ["NoCloud", "ConfigDrive", "OVF", "MaaS", "Ec2" ] +# datasource_list: ["NoCloud", "ConfigDrive", "OVF", "MaaS", "Ec2", "CloudStack"] cloud_init_modules: - bootcmd |