[Python-apps-commits] r10052 - in packages/cloud-init/trunk/debian (4 files)

zigo at users.alioth.debian.org zigo at users.alioth.debian.org
Wed Oct 9 07:57:01 UTC 2013


    Date: Wednesday, October 9, 2013 @ 07:57:00
  Author: zigo
Revision: 10052

Adds debian/patches/adds-google-cloud-engine-source.patch and uploads to experimental

Added:
  packages/cloud-init/trunk/debian/patches/adds-google-cloud-engine-source.patch
Modified:
  packages/cloud-init/trunk/debian/changelog
  packages/cloud-init/trunk/debian/cloud-init.templates
  packages/cloud-init/trunk/debian/patches/series

Modified: packages/cloud-init/trunk/debian/changelog
===================================================================
--- packages/cloud-init/trunk/debian/changelog	2013-10-07 07:01:15 UTC (rev 10051)
+++ packages/cloud-init/trunk/debian/changelog	2013-10-09 07:57:00 UTC (rev 10052)
@@ -1,3 +1,12 @@
+cloud-init (0.7.2-4) experimental; urgency=low
+
+  * Added GCE as new source, thanks to the patch from Brendan Burns
+    <bburns at google.com> (Closes: 725384).
+  * Uploading the package with the GCE patch to Experimental, to stage it for
+    some tests.
+
+ -- Thomas Goirand <zigo at debian.org>  Wed, 09 Oct 2013 06:52:22 +0000
+
 cloud-init (0.7.2-3) unstable; urgency=low
 
   [ Charles Plessy ]

Modified: packages/cloud-init/trunk/debian/cloud-init.templates
===================================================================
--- packages/cloud-init/trunk/debian/cloud-init.templates	2013-10-07 07:01:15 UTC (rev 10051)
+++ packages/cloud-init/trunk/debian/cloud-init.templates	2013-10-09 07:57:00 UTC (rev 10052)
@@ -1,8 +1,8 @@
 Template: cloud-init/datasources
 Type: multiselect
-Default: NoCloud, AltCloud, CloudStack, ConfigDrive, Ec2, MAAS, OVF, None
-Choices-C: NoCloud, AltCloud, CloudStack, ConfigDrive, Ec2, MAAS, OVF, None
-__Choices: /var/lib/cloud/seed only, AltCloud Config Drive, CloudStack metadata service, OpenStack Config Drive, EC2 Metadata service, Ubuntu MAAS, OVF Transports, Failsafe datasource
+Default: NoCloud, AltCloud, CloudStack, ConfigDrive, Ec2, MAAS, OVF, GCE, None
+Choices-C: NoCloud, AltCloud, CloudStack, ConfigDrive, Ec2, MAAS, OVF, GCE, None
+__Choices: /var/lib/cloud/seed only, AltCloud Config Drive, CloudStack metadata service, OpenStack Config Drive, EC2 Metadata service, Ubuntu MAAS, OVF Transports, Google Cloud Engine, Failsafe datasource
 _Description: Data sources to read from:
  Cloud-init supports searching different "Data Sources" for information
  that it uses to configure a cloud instance.

Added: packages/cloud-init/trunk/debian/patches/adds-google-cloud-engine-source.patch
===================================================================
--- packages/cloud-init/trunk/debian/patches/adds-google-cloud-engine-source.patch	                        (rev 0)
+++ packages/cloud-init/trunk/debian/patches/adds-google-cloud-engine-source.patch	2013-10-09 07:57:00 UTC (rev 10052)
@@ -0,0 +1,121 @@
+Description: Adds Google Cloud Engine (GCE) as new source
+Author: Brendan Burns <bburns at google.com>
+Bug-Debian: http://bugs.debian.org/725384
+Origin: upstream, http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=725384
+Last-Update: 2013-10-08
+
+--- /dev/null
++++ cloud-init-0.7.2/cloudinit/sources/DataSourceGCE.py
+@@ -0,0 +1,112 @@
++# Copyright 2013 Google Inc. All Rights Reserved.
++#
++# 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/>.
++"""An implementation of the DataSource API for cloud-init that knows
++how to talk to Google Compute Engine virtual machines.
++"""
++import urllib2
++
++from cloudinit import log as logging
++from cloudinit import sources
++
++MD_URL = 'http://metadata/computeMetadata/v1beta1'
++
++LOG = logging.getLogger(__name__)
++
++class MetaDataResponse(object):
++  """ An object that represents a response from the metadata server."""
++  def __init__(self, code, contents):
++    self._code = code
++    self._contents = contents
++
++  @property
++  def code(self):
++    return self._code
++
++  @property
++  def contents(self):
++    return self._contents
++
++
++class DataSourceGCE(sources.DataSource):
++  """Implements the cloud-init DataSource API for GCE."""
++
++  def __str__(self):
++    clazz = self.__class__
++    return str(clazz.__name__)
++
++  def _ReadUrl(self, url):
++    headers = {}
++    try:
++      req = urllib2.Request(url, data=None, headers=headers)
++      resp = urllib2.urlopen(req, timeout=50)
++      return MetaDataResponse(200, resp.read())
++    except urllib2.HTTPError as e:
++      return MetaDataResponse(e.code, '')
++
++  def _GetMetadata(self, server_name, local_name):
++    result = self._ReadUrl(MD_URL + '/' + server_name)
++    if result.code != 200:
++      LOG.error('Failed to fetch %s from server (%d)',
++                server_name, result.code)
++      return False
++    self.metadata[local_name] = result.contents
++    return True
++
++  def get_data(self):
++    """Overrides the implementation in the parent class."""
++    self.metadata = {}
++    try:
++      if not self._GetMetadata('instance/id', 'instance-id'):
++        return False
++      if not self._GetMetadata('instance/zone', 'availability-zone'):
++        return False
++      if not self._GetMetadata('project/attributes/sshKeys', 'public-keys'):
++        return False
++      if not self._GetMetadata('instance/hostname', 'local-hostname'):
++        return False
++    except:
++      LOG.error('GCE Metadata lookup failed.', exc_info=True)
++      return False
++
++    clipped_keys = self._TrimKeys(self.metadata['public-keys'])
++    self.metadata['public-keys'] = clipped_keys
++
++    try:
++      userdata_result = self._ReadUrl(MD_URL + 'instance/attributes/user-data')
++      if userdata_result != 200:
++        LOG.error('Got %d from metadata server',
++                  userdata_result.code)
++      self.userdata_raw = userdata_result.contents
++    except:
++      LOG.error('Failed to load userdata', exc_info=True)
++      if not self.userdata_raw:
++        self.userdata_raw = ''
++    return True
++
++  def _TrimKeys(self, key_string):
++    index = key_string.index(':')
++    if index > 0:
++      return key_string[(index + 1):]
++    else:
++      return key_string
++
++
++DATASOURCES = [
++    (DataSourceGCE, (sources.DEP_FILESYSTEM, sources.DEP_NETWORK)),
++    ]
++
++
++# DataSource instantiation hook.
++def get_datasource_list(depends):
++  return sources.list_from_depends(depends, DATASOURCES)

Modified: packages/cloud-init/trunk/debian/patches/series
===================================================================
--- packages/cloud-init/trunk/debian/patches/series	2013-10-07 07:01:15 UTC (rev 10051)
+++ packages/cloud-init/trunk/debian/patches/series	2013-10-09 07:57:00 UTC (rev 10052)
@@ -1,2 +1,3 @@
 fix-path-to-blkid-binary.patch
 disable-rhel-set-hostname-test.patch
+adds-google-cloud-engine-source.patch




More information about the Python-apps-commits mailing list