[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, experimental, updated. debian/2.1.1-1_experimental1-51-g95835b7
Lubomir Rintel
lubo.rintel at gooddata.com
Thu Jan 3 11:06:11 UTC 2013
The following commit has been merged in the experimental branch:
commit 568183c4cec9d465fab93d7985c5936318dc31aa
Author: Lubomir Rintel <lubo.rintel at gooddata.com>
Date: Mon Nov 5 13:15:42 2012 +0100
Direct errors and warnings to stderr
Otherwise they get lost if an actual response is expected in a pipeline.
The same thing is done by ec2-api-tools.
diff --git a/euca2ools/bundler.py b/euca2ools/bundler.py
index de36209..d74653a 100644
--- a/euca2ools/bundler.py
+++ b/euca2ools/bundler.py
@@ -233,14 +233,14 @@ class Bundler(object):
k = EVP.Cipher(alg='aes_128_cbc', key=unhexlify(key),
iv=unhexlify(iv), op=1)
except TypeError:
- print
- print 'WARNING: retrying encryption to work around a rare RNG bug'
- print 'Please report the following values to Eucalyptus Systems at'
- print 'https://eucalyptus.atlassian.net/browse/TOOLS-103 to help'
- print 'diagnose this issue.'
- print 'k: ', key
- print 'iv:', iv
- print
+ print >> sys.stderr
+ print >> sys.stderr, 'WARNING: retrying encryption to work around a rare RNG bug'
+ print >> sys.stderr, 'Please report the following values to Eucalyptus Systems at'
+ print >> sys.stderr, 'https://eucalyptus.atlassian.net/browse/TOOLS-103 to help'
+ print >> sys.stderr, 'diagnose this issue.'
+ print >> sys.stderr, 'k: ', key
+ print >> sys.stderr, 'iv:', iv
+ print >> sys.stderr
return self.encrypt_image(file)
in_file = open(file, 'rb')
@@ -623,7 +623,7 @@ class Bundler(object):
if not os.path.exists(destination_path):
os.makedirs(destination_path)
if self.img == 'Unsupported':
- print 'Platform not fully supported.'
+ print >> sys.stderr, 'Platform not fully supported.'
raise UnsupportedException
self.img.create_image(size_in_MB, image_path)
self.img.make_fs(image_path, fs_type=fs_type, uuid=uuid, label=label)
@@ -642,7 +642,7 @@ class Bundler(object):
if not output[1]:
return loop_dev
else:
- print 'Could not create loopback device. Aborting'
+ print >> sys.stderr, 'Could not create loopback device. Aborting'
raise CommandFailed
tries += 1
@@ -709,10 +709,10 @@ class Bundler(object):
# rsync return code 24: Partial transfer due to vanished source files
if pipe.returncode in (23, 24):
- print 'Warning: rsync reports files partially copied:'
- print output
+ print >> sys.stderr, 'Warning: rsync reports files partially copied:'
+ print >> sys.stderr, output
else:
- print 'Error: rsync failed with return code %d' \
+ print >> sys.stderr, 'Error: rsync failed with return code %d' \
% pipe.returncode
raise CopyError
@@ -731,7 +731,7 @@ class Bundler(object):
output = self.copy_to_image(mount_point, volume_path,
excludes)
if self.img == 'Unsupported':
- print 'Platform not fully supported.'
+ print >> sys.stderr, 'Platform not fully supported.'
raise UnsupportedException
self.img.add_fstab(mount_point, generate_fstab, fstab_path)
except CopyError:
@@ -744,7 +744,7 @@ class Bundler(object):
message = None
index = msg.find('<')
if index < 0:
- print msg
+ print >> sys.stderr, msg
sys.exit(1)
msg = msg[index - 1:]
msg = msg.replace('\n', '')
@@ -763,8 +763,8 @@ class Bundler(object):
if node.nodeType == node.TEXT_NODE:
message = node.data
- print '%s:' % code, message
+ print >> sys.stderr, '%s:' % code, message
except Exception:
- print msg
+ print >> sys.stderr, msg
sys.exit(1)
diff --git a/euca2ools/commands/euca/bundlevol.py b/euca2ools/commands/euca/bundlevol.py
index f6452d0..9da891c 100644
--- a/euca2ools/commands/euca/bundlevol.py
+++ b/euca2ools/commands/euca/bundlevol.py
@@ -118,7 +118,7 @@ class BundleVol(euca2ools.commands.eucacommand.EucaCommand):
if os.geteuid() == 0:
return
else:
- print 'Must be superuser to execute this command.'
+ print >> sys.stderr, 'Must be superuser to execute this command.'
sys.exit()
def parse_excludes(self, excludes_string):
@@ -137,34 +137,34 @@ class BundleVol(euca2ools.commands.eucacommand.EucaCommand):
try:
ramdisk_id = md.get_instance_ramdisk()
except MetadataReadError:
- print 'Unable to read ramdisk id'
+ print >> sys.stderr, 'Unable to read ramdisk id'
if not kernel_id:
try:
kernel_id = md.get_instance_kernel()
except MetadataReadError:
- print 'Unable to read kernel id'
+ print >> sys.stderr, 'Unable to read kernel id'
if not block_dev_mapping:
try:
block_dev_mapping = \
md.get_instance_block_device_mappings()
except MetadataReadError:
- print 'Unable to read block device mapping'
+ print >> sys.stderr, 'Unable to read block device mapping'
try:
product_codes = md.get_instance_product_codes().split('\n'
)
except MetadataReadError:
- print 'Unable to read product codes'
+ print >> sys.stderr, 'Unable to read product codes'
try:
ancestor_ami_ids = md.get_ancestor_ami_ids().split('\n')
except MetadataReadError:
- print 'Unable to read ancestor ids'
+ print >> sys.stderr, 'Unable to read ancestor ids'
except IOError:
- print 'Unable to read instance metadata. Pass the --no-inherit option if you wish to exclude instance metadata.'
+ print >> sys.stderr, 'Unable to read instance metadata. Pass the --no-inherit option if you wish to exclude instance metadata.'
sys.exit()
return (ramdisk_id, kernel_id, block_dev_mapping, product_codes,
@@ -244,7 +244,7 @@ class BundleVol(euca2ools.commands.eucacommand.EucaCommand):
try:
fsinfo = bundler.get_fs_info(self.volume_path)
except UnsupportedException, e:
- print e
+ print >> sys.stderr, e
sys.exit(1)
try:
image_path = bundler.make_image(self.size, excludes, self.prefix,
@@ -270,7 +270,7 @@ class BundleVol(euca2ools.commands.eucacommand.EucaCommand):
bundler.copy_volume(image_path, self.volume_path, excludes,
self.generate_fstab, self.fstab_path)
except CopyError:
- print 'Unable to copy files'
+ print >> sys.stderr, 'Unable to copy files'
self.cleanup(image_path)
sys.exit(1)
except (NotFoundError, CommandFailed, UnsupportedException):
diff --git a/euca2ools/commands/euca/deletebundle.py b/euca2ools/commands/euca/deletebundle.py
index 5f6201b..f54dbe8 100644
--- a/euca2ools/commands/euca/deletebundle.py
+++ b/euca2ools/commands/euca/deletebundle.py
@@ -77,7 +77,7 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
try:
bucket_instance = s3conn.get_bucket(bucket)
except S3ResponseError, s3error:
- print 'Unable to get bucket %s' % bucket
+ print >> sys.stderr, 'Unable to get bucket %s' % bucket
sys.exit()
return bucket_instance
@@ -93,7 +93,7 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
if node.nodeType == node.TEXT_NODE:
parts.append(node.data)
except:
- print 'problem parsing: %s' % manifest_filename
+ print >> sys.stderr, 'problem parsing: %s' % manifest_filename
return parts
def get_manifests(self, bucket):
@@ -119,8 +119,8 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
except S3ResponseError, s3error:
s3error_string = '%s' % s3error
if s3error_string.find('200') < 0:
- print s3error_string
- print 'unable to download manifest %s' % manifest
+ print >> sys.stderr, s3error_string
+ print >> sys.stderr, 'unable to download manifest %s' % manifest
if os.path.exists(manifest_filename):
os.remove(manifest_filename)
return False
@@ -139,8 +139,8 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
except S3ResponseError, s3error:
s3error_string = '%s' % s3error
if s3error_string.find('200') < 0:
- print s3error_string
- print 'unable to delete part %s' % part
+ print >> sys.stderr, s3error_string
+ print >> sys.stderr, 'unable to delete part %s' % part
sys.exit()
@@ -153,12 +153,12 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
except Exception, s3error:
s3error_string = '%s' % s3error
if s3error_string.find('200') < 0:
- print s3error_string
- print 'unable to delete manifest %s' % manifest
+ print >> sys.stderr, s3error_string
+ print >> sys.stderr, 'unable to delete manifest %s' % manifest
try:
bucket = self.ensure_bucket(bucket_name)
except ConnectionFailed, e:
- print e.message
+ print >> sys.stderr, e.message
sys.exit(1)
if clear:
try:
@@ -166,8 +166,8 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
except Exception, s3error:
s3error_string = '%s' % s3error
if s3error_string.find('200') < 0:
- print s3error_string
- print 'unable to delete bucket %s' % bucket.name
+ print >> sys.stderr, s3error_string
+ print >> sys.stderr, 'unable to delete bucket %s' % bucket.name
def remove_manifests(self, manifests, directory):
for manifest in manifests:
@@ -179,9 +179,9 @@ class DeleteBundle(euca2ools.commands.eucacommand.EucaCommand):
directory = os.path.abspath('/tmp')
if not self.manifest_path and not self.prefix:
- print 'Neither a manifestpath nor a prefix was specified.'
- print 'All bundles in bucket', self.bucket, 'will be deleted.'
- print ('If this is not what you want, press Ctrl+C in the next '
+ print >> sys.stderr, 'Neither a manifestpath nor a prefix was specified.'
+ print >> sys.stderr, 'All bundles in bucket', self.bucket, 'will be deleted.'
+ print >> sys.stderr, ('If this is not what you want, press Ctrl+C in the next '
'10 seconds'),
for __ in range(10):
sys.stdout.write('.')
diff --git a/euca2ools/commands/euca/downloadbundle.py b/euca2ools/commands/euca/downloadbundle.py
index 92d87ba..8eea990 100644
--- a/euca2ools/commands/euca/downloadbundle.py
+++ b/euca2ools/commands/euca/downloadbundle.py
@@ -63,7 +63,7 @@ class DownloadBundle(euca2ools.commands.eucacommand.EucaCommand):
try:
bucket_instance = s3conn.get_bucket(bucket)
except S3ResponseError, s3error:
- print 'Unable to get bucket %s' % bucket
+ print >> sys.stderr, 'Unable to get bucket %s' % bucket
sys.exit()
return bucket_instance
diff --git a/euca2ools/commands/eucacommand.py b/euca2ools/commands/eucacommand.py
index 3a5a488..b17d8e4 100644
--- a/euca2ools/commands/eucacommand.py
+++ b/euca2ools/commands/eucacommand.py
@@ -69,10 +69,10 @@ def euca_except_hook(debugger_flag, debug_flag):
else:
debugger.post_mortem(tb)
elif debug_flag:
- print traceback.print_tb(tb)
+ print >> sys.stderr, traceback.print_tb(tb)
sys.exit(1)
else:
- print value
+ print >> sys.stderr, value
sys.exit(1)
return excepthook
@@ -158,7 +158,7 @@ class EucaCommand(object):
self.short_options(),
self.long_options())
except getopt.GetoptError, e:
- print e
+ print >> sys.stderr, e
sys.exit(1)
for (name, value) in opts:
if name in ('-h', '--help'):
@@ -396,9 +396,9 @@ class EucaCommand(object):
def display_error_and_exit(self, exc):
try:
- print '%s: %s' % (exc.error_code, exc.error_message)
+ print >> sys.stderr, '%s: %s' % (exc.error_code, exc.error_message)
except:
- print '%s' % exc
+ print >> sys.stderr, '%s' % exc
finally:
sys.exit(1)
@@ -446,23 +446,23 @@ class EucaCommand(object):
if not self.euca_cert_path:
self.euca_cert_path = self.environ['EUCA_CERT']
if not self.euca_cert_path:
- print 'EUCA_CERT variable must be set.'
+ print >> sys.stderr, 'EUCA_CERT variable must be set.'
raise euca2ools.exceptions.ConnectionFailed
if not self.euca_private_key_path:
self.euca_private_key_path = self.environ['EUCA_PRIVATE_KEY']
if not self.euca_private_key_path:
- print 'EUCA_PRIVATE_KEY variable must be set.'
+ print >> sys.stderr, 'EUCA_PRIVATE_KEY variable must be set.'
raise euca2ools.exceptions.ConnectionFailed
if not self.ec2_user_access_key:
self.ec2_user_access_key = self.environ['EC2_ACCESS_KEY']
if not self.ec2_user_access_key:
- print 'EC2_ACCESS_KEY environment variable must be set.'
+ print >> sys.stderr, 'EC2_ACCESS_KEY environment variable must be set.'
raise euca2ools.exceptions.ConnectionFailed
if not self.ec2_user_secret_key:
self.ec2_user_secret_key = self.environ['EC2_SECRET_KEY']
if not self.ec2_user_secret_key:
- print 'EC2_SECRET_KEY environment variable must be set.'
+ print >> sys.stderr, 'EC2_SECRET_KEY environment variable must be set.'
raise euca2ools.exceptions.ConnectionFailed
def get_connection_details(self):
@@ -490,7 +490,7 @@ class EucaCommand(object):
if not self.url:
self.url = \
'http://localhost:8773/services/Walrus'
- print 'S3_URL not specified. Trying %s' \
+ print >> sys.stderr, 'S3_URL not specified. Trying %s' \
% self.url
self.get_connection_details()
@@ -527,7 +527,7 @@ class EucaCommand(object):
if not self.url:
self.url = \
'http://localhost:8773/services/Eucalyptus'
- print 'EC2_URL not specified. Trying %s' \
+ print >> sys.stderr, 'EC2_URL not specified. Trying %s' \
% self.url
if not self.region.endpoint:
@@ -584,7 +584,7 @@ class EucaCommand(object):
params['filters'] = self.filters
method = getattr(connection, request_name)
except AttributeError:
- print 'Unknown request: %s' % request_name
+ print >> sys.stderr, 'Unknown request: %s' % request_name
sys.exit(1)
try:
return method(**params)
diff --git a/euca2ools/commands/eustore/installimage.py b/euca2ools/commands/eustore/installimage.py
index e15415d..50b0224 100644
--- a/euca2ools/commands/eustore/installimage.py
+++ b/euca2ools/commands/eustore/installimage.py
@@ -247,10 +247,10 @@ class InstallImage(AWSQueryRequest):
try:
names = bundler.untarzip_image(self.destination, file)
except OSError:
- print "Error: cannot unbundle image, possibly corrupted file"
+ print >> sys.stderr, "Error: cannot unbundle image, possibly corrupted file"
sys.exit(-1)
except IOError:
- print "Error: cannot unbundle image, possibly corrupted file"
+ print >> sys.stderr, "Error: cannot unbundle image, possibly corrupted file"
sys.exit(-1)
kernel_dir=None
if not(self.cli_options.kernel_type==None):
@@ -285,10 +285,10 @@ class InstallImage(AWSQueryRequest):
print ramdisk_id
if not(kernel_found):
if not(kernel_dir):
- print "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk"
+ print >> sys.stderr, "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk"
sys.exit(-1);
elif i==0:
- print "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk"
+ print >> sys.stderr, "Error: couldn't find kernel. Check your parameters or specify an existing kernel/ramdisk"
sys.exit(-1);
else:
break
@@ -314,30 +314,30 @@ class InstallImage(AWSQueryRequest):
# tarball and image option are mutually exclusive
if (not(self.cli_options.image_name) and not(self.cli_options.tarball)):
- print "Error: one of -i or -t must be specified"
+ print >> sys.stderr, "Error: one of -i or -t must be specified"
sys.exit(-1)
if (self.cli_options.image_name and self.cli_options.tarball):
- print "Error: -i and -t cannot be specified together"
+ print >> sys.stderr, "Error: -i and -t cannot be specified together"
sys.exit(-1)
if (self.cli_options.tarball and \
(not(self.cli_options.description) or not(self.cli_options.architecture))):
- print "Error: when -t is specified, -s and -a are required"
+ print >> sys.stderr, "Error: when -t is specified, -s and -a are required"
sys.exit(-1)
if (self.cli_options.architecture and \
not(self.cli_options.architecture == 'i386' or self.cli_options.architecture == 'x86_64')):
- print "Error: architecture must be either 'i386' or 'x86_64'"
+ print >> sys.stderr, "Error: architecture must be either 'i386' or 'x86_64'"
sys.exit(-1)
if (self.cli_options.kernel and not(self.cli_options.ramdisk)) or \
(not(self.cli_options.kernel) and self.cli_options.ramdisk):
- print "Error: kernel and ramdisk must both be overridden"
+ print >> sys.stderr, "Error: kernel and ramdisk must both be overridden"
sys.exit(-1)
if (self.cli_options.architecture and self.cli_options.image_name):
- print "Warning: you may be overriding the default architecture of this image!"
+ print >> sys.stderr, "Warning: you may be overriding the default architecture of this image!"
euare_svc = EuareService()
@@ -348,7 +348,7 @@ class InstallImage(AWSQueryRequest):
is_secure=euare_svc.args['is_secure'])
userinfo = conn.get_user().arn.split(':')
if not(userinfo[4]=='eucalyptus') and not(self.cli_options.kernel):
- print "Error: must be cloud admin to upload kernel/ramdisk. try specifying existing ones with --kernel and --ramdisk"
+ print >> sys.stderr, "Error: must be cloud admin to upload kernel/ramdisk. try specifying existing ones with --kernel and --ramdisk"
sys.exit(-1)
self.eustore_url = self.ServiceClass.StoreBaseURL
@@ -388,10 +388,10 @@ class InstallImage(AWSQueryRequest):
# more param checking now
if image['single-kernel']=='True':
if self.cli_options.kernel_type:
- print "The -k option will be ignored because the image is single-kernel"
+ print >> sys.stderr, "The -k option will be ignored because the image is single-kernel"
else:
if not(self.cli_options.kernel_type):
- print "Error: The -k option must be specified because this image has separate kernels"
+ print >> sys.stderr, "Error: The -k option must be specified because this image has separate kernels"
sys.exit(-1)
print "Downloading Image : ",image['description']
imageURL = self.eustore_url+image['url']
@@ -419,10 +419,10 @@ class InstallImage(AWSQueryRequest):
if image['name'] == crc.rjust(10,"0"):
print "Installed image: "+self.bundleAll(fp.name, None, image['description'], image['architecture'])
else:
- print "Error: Downloaded image was incomplete or corrupt, please try again"
+ print >> sys.stderr, "Error: Downloaded image was incomplete or corrupt, please try again"
os.remove(fp.name)
else:
- print "Image name not found, please run eustore-describe-images"
+ print >> sys.stderr, "Image name not found, please run eustore-describe-images"
def main_cli(self):
euca2ools.utils.print_version_if_necessary()
diff --git a/euca2ools/image.py b/euca2ools/image.py
index a531e5a..76120f0 100644
--- a/euca2ools/image.py
+++ b/euca2ools/image.py
@@ -30,6 +30,7 @@
#
# Author: Neil Soman neil at eucalyptus.com
+import sys
import os
import shutil
import subprocess
@@ -173,15 +174,15 @@ class SolarisImage:
self.debug = debug
def create_image(self, size_in_MB, image_path):
- print 'Sorry. Solaris not supported yet'
+ print >> sys.stderr, 'Sorry. Solaris not supported yet'
raise UnsupportedException
def make_fs(self, image_path, fstype = None, uuid = None, label = None):
- print 'Sorry. Solaris not supported yet'
+ print >> sys.stderr, 'Sorry. Solaris not supported yet'
raise UnsupportedException
def make_essential_devs(self, image_path):
- print 'Sorry. Solaris not supported yet'
+ print >> sys.stderr, 'Sorry. Solaris not supported yet'
raise UnsupportedException
diff --git a/euca2ools/utils.py b/euca2ools/utils.py
index 859e14a..45476b6 100644
--- a/euca2ools/utils.py
+++ b/euca2ools/utils.py
@@ -44,7 +44,7 @@ def check_prerequisite_command(command):
except OSError, e:
error_string = '%s' % e
if 'No such' in error_string:
- print 'Command %s not found. Is it installed?' % command
+ print >> sys.stderr, 'Command %s not found. Is it installed?' % command
raise exceptions.NotFoundError
else:
raise OSError(e)
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list