summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYue Luo <yueluo@google.com>2014-04-09 14:40:53 -0700
committerYue Luo <yueluo@google.com>2014-04-09 14:40:53 -0700
commit5a860dfce4bf7ffd7c270ae270a7176110272ebb (patch)
treec2d9402dbcd0d61e0b355a2807d48bf0230fc696
parentb5647527e1107536f236d17a4468a9464fb6bb54 (diff)
downloadgoogle-compute-image-packages-5a860dfce4bf7ffd7c270ae270a7176110272ebb.tar.gz
Incorporate code review feedback.
-rwxr-xr-xgcimagebundle/gcimagebundlelib/tests/image_bundle_test_base.py6
-rw-r--r--gcimagebundle/gcimagebundlelib/utils.py6
-rwxr-xr-xgoogle-daemon/usr/share/google/google_daemon/desired_accounts.py8
3 files changed, 11 insertions, 9 deletions
diff --git a/gcimagebundle/gcimagebundlelib/tests/image_bundle_test_base.py b/gcimagebundle/gcimagebundlelib/tests/image_bundle_test_base.py
index bab8a4f..4c3c1ad 100755
--- a/gcimagebundle/gcimagebundlelib/tests/image_bundle_test_base.py
+++ b/gcimagebundle/gcimagebundlelib/tests/image_bundle_test_base.py
@@ -64,10 +64,10 @@ class MockHttp(utils.Http):
def Get(self, request):
"""Accepts an Http request and returns a precanned response."""
url = request.get_full_url()
- if url == 'http://169.254.169.254/computeMetadata/':
+ if url == utils.METADATA_URL_PREFIX:
return 'v1/'
- elif url.startswith('http://169.254.169.254/computeMetadata/v1/'):
- url = url.replace('http://169.254.169.254/computeMetadata/v1/', '')
+ elif url.startswith(utils.METADATA_V1_URL_PREFIX):
+ url = url.replace(utils.METADATA_V1_URL_PREFIX, '')
if url == 'instance/?recursive=true':
return self._instance_response
raise urllib2.HTTPError
diff --git a/gcimagebundle/gcimagebundlelib/utils.py b/gcimagebundle/gcimagebundlelib/utils.py
index d890905..295b52d 100644
--- a/gcimagebundle/gcimagebundlelib/utils.py
+++ b/gcimagebundle/gcimagebundlelib/utils.py
@@ -21,6 +21,9 @@ import subprocess
import time
import urllib2
+METADATA_URL_PREFIX = 'http://169.254.169.254/computeMetadata/'
+METADATA_V1_URL_PREFIX = METADATA_URL_PREFIX + 'v1/'
+
class MakeFileSystemException(Exception):
"""Error occurred in file system creation."""
@@ -405,11 +408,10 @@ class Http(object):
"""
# Use the latest version of the metadata.
- base_url = 'http://169.254.169.254/computeMetadata/v1/'
suffix = ''
if recursive:
suffix = '?recursive=true'
- url = '{0}{1}{2}'.format(base_url, url_path, suffix)
+ url = '{0}{1}{2}'.format(METADATA_V1_URL_PREFIX, url_path, suffix)
request = urllib2.Request(url)
request.add_unredirected_header('X-Google-Metadata-Request', 'True')
return self.Get(request)
diff --git a/google-daemon/usr/share/google/google_daemon/desired_accounts.py b/google-daemon/usr/share/google/google_daemon/desired_accounts.py
index 409450f..702741d 100755
--- a/google-daemon/usr/share/google/google_daemon/desired_accounts.py
+++ b/google-daemon/usr/share/google/google_daemon/desired_accounts.py
@@ -20,12 +20,12 @@ import time
import urllib2
-ATTRIBUTES_URL = (
- 'http://169.254.169.254/computeMetadata/v1/?recursive=true&%s')
+METADATA_V1_URL_PREFIX = 'http://169.254.169.254/computeMetadata/v1/'
+ATTRIBUTES_URL = METADATA_V1_URL_PREFIX + '?recursive=true&%s'
INSTANCE_SSHKEYS_URL = (
- 'http://169.254.169.254/computeMetadata/v1/instance/attributes/sshKeys?%s')
+ METADATA_V1_URL_PREFIX + 'instance/attributes/sshKeys?%s')
PROJECT_SSHKEYS_URL = (
- 'http://169.254.169.254/computeMetadata/v1/project/attributes/sshKeys?%s')
+ METADATA_V1_URL_PREFIX + 'project/attributes/sshKeys?%s')
WAIT_FOR_CHANGE = 'wait_for_change=true&last_etag=%s&timeout_sec=%s'