[pkg-eucalyptus-commits] [SCM] managing cloud instances for Eucalyptus branch, master, updated. 3.0.0-alpha3-257-g1da8e3a
Garrett Holmstrom
gholms at fedoraproject.org
Sun Jun 16 02:29:43 UTC 2013
The following commit has been merged in the master branch:
commit d24c81519842b0c0a4678a12ae29a64af764b8d4
Author: Garrett Holmstrom <gholms at fedoraproject.org>
Date: Sat Apr 21 16:57:31 2012 -0700
Rewrite BundleInstance
diff --git a/bin/euca-bundle-instance b/bin/euca-bundle-instance
index d1cbfd0..b4a32f0 100755
--- a/bin/euca-bundle-instance
+++ b/bin/euca-bundle-instance
@@ -1,42 +1,6 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# Software License Agreement (BSD License)
-#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
-# All rights reserved.
-#
-# Redistribution and use of this software in source and binary forms, with or
-# without modification, are permitted provided that the following conditions
-# are met:
-#
-# Redistributions of source code must retain the above
-# copyright notice, this list of conditions and the
-# following disclaimer.
-#
-# Redistributions in binary form must reproduce the above
-# copyright notice, this list of conditions and the
-# following disclaimer in the documentation and/or other
-# materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-# Mitch Garnaat mgarnaat at eucalyptus.com
+#!/usr/bin/python -tt
import euca2ools.commands.euca.bundleinstance
if __name__ == '__main__':
- cmd = euca2ools.commands.euca.bundleinstance.BundleInstance()
- cmd.main_cli()
-
+ euca2ools.commands.euca.bundleinstance.BundleInstance().do_cli()
diff --git a/euca2ools/commands/euca/__init__.py b/euca2ools/commands/euca/__init__.py
index 343792c..04063b9 100644
--- a/euca2ools/commands/euca/__init__.py
+++ b/euca2ools/commands/euca/__init__.py
@@ -225,6 +225,14 @@ class EucalyptusRequest(Euca2oolsRequest, TabifyingCommand):
[attachment.get(attr) for attr in
('instanceId', 'device', 'status', 'attachTime')])
+ def print_bundle_task(self, task):
+ print self.tabify(['BUNDLE', task.get('bundleId'),
+ task.get('instanceId'),
+ task.get('storage', {}).get('S3', {}).get('bucket'),
+ task.get('storage', {}).get('S3', {}).get('prefix'),
+ task.get('startTime'), task.get('updateTime'),
+ task.get('state')])
+
## TODO: test this
class BlockDeviceMapping(dict):
'''
diff --git a/euca2ools/commands/euca/bundleinstance.py b/euca2ools/commands/euca/bundleinstance.py
index 7db9694..c0a1613 100644
--- a/euca2ools/commands/euca/bundleinstance.py
+++ b/euca2ools/commands/euca/bundleinstance.py
@@ -1,6 +1,6 @@
# Software License Agreement (BSD License)
#
-# Copyright (c) 2009-2011, Eucalyptus Systems, Inc.
+# Copyright (c) 2009-2012, Eucalyptus Systems, Inc.
# All rights reserved.
#
# Redistribution and use of this software in source and binary forms, with or
@@ -27,86 +27,77 @@
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
-#
-# Author: Neil Soman neil at eucalyptus.com
-# Mitch Garnaat mgarnaat at eucalyptus.com
-import os
-import euca2ools.commands.eucacommand
-from boto.roboto.param import Param
-import sys
import base64
from datetime import datetime, timedelta
+import hashlib
+import hmac
+import json
+from requestbuilder import Arg
+import textwrap
+from . import EucalyptusRequest
-class BundleInstance(euca2ools.commands.eucacommand.EucaCommand):
+class BundleInstance(EucalyptusRequest):
+ Description = 'Bundle an S3-backed Windows instance'
+ Args = [Arg('InstanceId', metavar='INSTANCE', help='instance to bundle'),
+ Arg('-b', '--bucket', dest='Storage.S3.Bucket', metavar='BUCKET',
+ required=True,
+ help='bucket in which to store the new machine image'),
+ Arg('-p', '--prefix', dest='Storage.S3.Prefix', metavar='PREFIX',
+ required=True,
+ help='beginning of the machine image bundle name'),
+ Arg('-o', '--owner-akid', '--user-access-key', metavar='KEY-ID',
+ dest='Storage.S3.AWSAccessKeyId', required=True,
+ help="bucket owner's access key ID"),
+ Arg('-c', '--policy', metavar='POLICY',
+ dest='Storage.S3.UploadPolicy',
+ help='''Base64-encoded upload policy that allows the server
+ to upload a bundle on your behalf. If unused, -w is
+ required'''),
+ Arg('-s', '--policy-signature', metavar='SIGNATURE',
+ dest='Storage.S3.UploadPolicySignature',
+ help='''signature of the Base64-encoded upload policy. If
+ unused, -w is required'''),
+ Arg('-w', '--owner-sak', '--user-secret-key', metavar='KEY',
+ route_to=None,
+ help="""bucket owner's secret access key, used to sign upload
+ policies. This is required unless both -c and -s are
+ used."""),
+ Arg('-x', '--expires', metavar='HOURS', type=int, default=24,
+ route_to=None,
+ help='generated upload policy expiration time (default: 24)')]
- Description = 'Bundles an S3-backed Windows instance.'
- Options = [Param(name='bucket', short_name='b', long_name='bucket',
- optional=False, ptype='string',
- doc='Name of the bucket to upload.'),
- Param(name='prefix', short_name='p', long_name='prefix',
- optional=False, ptype='string', default='image',
- doc='The prefix for the image file name'),
- Param(name='access_key_id',
- short_name='o', long_name='user-access-key',
- optional=False, ptype='string',
- doc='Access Key ID of the owner of the bucket'),
- Param(name='policy', short_name='c', long_name='policy',
- optional=True, ptype='string',
- doc="""Base64 encoded upload policy that defines
- upload permissions and conditions. If no
- policy is specified, a default policy
- is generated.
- NOTE: Not supported on Eucalyptus."""),
- Param(name='secret_key',
- short_name='w', long_name='user-secret-key',
- optional=False, ptype='string',
- doc='Secret key used to sign the upload policy'),
- Param(name='expires', short_name='x', long_name='expires',
- optional=False, ptype='integer', default=24,
- doc='Expiration for the generated policy (hours).')]
- Args = [Param(name='instance_id', ptype='string',
- doc='ID of the instance to be bundled.')]
-
- def display_bundle(self, bundle):
- bundle_string = '%s\t%s\t%s\t%s\t%s\t%s\t%s' % (bundle.id,
- bundle.instance_id,
- bundle.bucket,
- bundle.prefix,
- bundle.state,
- bundle.start_time,
- bundle.update_time)
- print 'BUNDLE\t%s' % (bundle_string)
+ def generate_default_policy(self):
+ delta = timedelta(hours=self.args['expires'])
+ expire_time = (datetime.utcnow() + delta).replace(microsecond=0)
- def generate_default_policy(self, bucket, prefix, expiration, acl):
- delta = timedelta(hours=expiration)
- expiration_time = (datetime.utcnow() + delta).replace(microsecond=0)
- expiration_str = expiration_time.isoformat()
+ policy = {'conditions': [{'acl': 'ec2-bundle-read'},
+ {'bucket': self.args.get('Storage.S3.Bucket')},
+ ['starts-with', '$key',
+ self.args.get('Storage.S3.Prefix')]],
+ 'expiration': expire_time.isoformat()}
+ self.args['Storage.S3.UploadPolicy'] = \
+ base64.b64encode(json.dumps(policy))
- policy = '{"expiration": "%s",' % expiration_str + \
- '"conditions": [' + \
- '{"bucket": "%s" },' % bucket + \
- '{"acl": "%s" },' % acl + \
- '["starts-with", "$key", "%s"]' % prefix + \
- ']' + \
- '}'
- encoded_policy = base64.b64encode(policy)
- return encoded_policy
+ def sign_policy(self):
+ my_hmac = hmac.new(self.args['owner_sak'], digestmod=hashlib.sha1)
+ my_hmac.update(self.args['Storage.S3.UploadPolicy'])
+ self.args['Storage.S3.UploadPolicySignature'] = \
+ base64.b64encode(my_hmac.digest())
def main(self):
- conn = self.make_connection_cli()
- if not self.policy:
- self.policy = self.generate_default_policy(self.bucket,
- self.prefix,
- self.expires,
- 'ec2-bundle-read')
- return self.make_request_cli(conn, 'bundle_instance',
- instance_id=self.instance_id,
- s3_bucket=self.bucket,
- s3_prefix=self.prefix,
- s3_upload_policy=self.policy)
+ if not self.args.get('Storage.S3.UploadPolicy'):
+ if not self.args.get('owner_sak'):
+ self._cli_parser.error('argument -w/--owner-sak is required '
+ 'when -c/--policy is not used')
+ self.generate_default_policy()
+ self.sign_policy()
+ elif not self.args.get('Storage.S3.UploadPolicySignature'):
+ if not self.args.get('owner_sak'):
+ self._cli_parser.error('argument -w/--owner-sak is required '
+ 'when -c/--policy is not used')
+ self.sign_policy()
+ return self.send()
- def main_cli(self):
- bundle_task = self.main()
- self.display_bundle(bundle_task)
-
+ def print_result(self, result):
+ self.print_bundle_task(result['bundleInstanceTask'])
--
managing cloud instances for Eucalyptus
More information about the pkg-eucalyptus-commits
mailing list