本文整理汇总了Python中euca2ools.commands.ec2.EC2Request类的典型用法代码示例。如果您正苦于以下问题:Python EC2Request类的具体用法?Python EC2Request怎么用?Python EC2Request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EC2Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_cli_args
def process_cli_args(self):
# We need to parse out -t and -p *before* argparse can see it because
# of Python bug 9334, which prevents argparse from recognizing '-1:-1'
# as an option value and not a (nonexistent) option name.
saved_sys_argv = list(sys.argv)
def parse_neg_one_value(opt_name):
if opt_name in sys.argv:
index = sys.argv.index(opt_name)
if (index < len(sys.argv) - 1 and
sys.argv[index + 1].startswith('-1')):
opt_val = sys.argv[index + 1]
del sys.argv[index:index + 2]
return opt_val
icmp_type_code = (parse_neg_one_value('-t') or
parse_neg_one_value('--icmp-type-code'))
port_range = (parse_neg_one_value('-p') or
parse_neg_one_value('--port-range'))
EC2Request.process_cli_args(self)
if icmp_type_code:
self.args['icmp_type_code'] = icmp_type_code
if port_range:
self.args['port_range'] = port_range
sys.argv = saved_sys_argv
示例2: configure
def configure(self):
EC2Request.configure(self)
if not self.params.get('Storage.S3.AWSAccessKeyId'):
config_key_id = self.config.get_user_option('key-id')
if config_key_id:
self.log.info('Using access key ID %s from configuration',
config_key_id)
self.params['Storage.S3.AWSAccessKeyId'] = config_key_id
else:
raise ArgumentError('argument -o/--owner-akid is required')
if not self.params.get('Storage.S3.UploadPolicy'):
if not self.args.get('owner_sak'):
config_secret_key = self.config.get_user_option('secret-key')
if config_secret_key:
self.log.info('Using secret key from configuration')
self.args['owner_sak'] = config_secret_key
else:
raise ArgumentError('argument -w/--owner-sak is required '
'when -c/--policy is not used')
elif not self.args.get('Storage.S3.UploadPolicySignature'):
if not self.args.get('owner_sak'):
config_secret_key = self.config.get_user_option('secret-key')
if config_secret_key:
self.log.info('Using secret key from configuration')
self.args['owner_sak'] = config_secret_key
else:
raise ArgumentError('argument -w/--owner-sak is required '
'when -s/--policy-signature is not '
'used')
示例3: configure
def configure(self):
EC2Request.configure(self)
self.configure_s3_access()
if (self.params['DiskImage.1.Image.Format'].upper() in
('VMDK', 'VHD', 'RAW')):
self.params['DiskImage.1.Image.Format'] = \
self.params['DiskImage.1.Image.Format'].upper()
if not self.params.get('DiskImage.1.Image.Bytes'):
if self.params['DiskImage.1.Image.Format'] == 'RAW':
image_size = euca2ools.util.get_filesize(self.args['source'])
self.params['DiskImage.1.Image.Bytes'] = image_size
else:
raise ArgumentError(
'argument --image-size is required for {0} files'
.format(self.params['DiskImage.1.Image.Format']))
if not self.params.get('DiskImage.1.Volume.Size'):
vol_size = math.ceil(self.params['DiskImage.1.Image.Bytes'] /
2 ** 30)
self.params['DiskImage.1.Volume.Size'] = int(vol_size)
if not self.args.get('expires'):
self.args['expires'] = 30
if self.args['expires'] < 1:
raise ArgumentError(
'argument -x/--expires: value must be positive')
示例4: configure
def configure(self):
EC2Request.configure(self)
if self.args.get('user_data'):
if os.path.isfile(self.args['user_data']):
raise ArgumentError(
'argument -d/--user-data: to pass the contents of a file '
'as user data, use -f/--user-data-file. To pass the '
"literal value '{0}' as user data even though it matches "
'the name of a file, use --user-data-force.')
else:
self.params['UserData'] = base64.b64encode(
self.args['user_data'])
elif self.args.get('user_data_force'):
self.params['UserData'] = base64.b64encode(
self.args['user_data_force'])
elif self.args.get('user_data_file'):
with open(self.args['user_data_file']) as user_data_file:
self.params['UserData'] = base64.b64encode(
user_data_file.read())
if self.args.get('KeyName') is None:
default_key_name = self.config.get_region_option(
'ec2-default-keypair')
if default_key_name:
self.log.info("using default key pair '%s'", default_key_name)
self.params['KeyName'] = default_key_name
示例5: configure
def configure(self):
EC2Request.configure(self)
gateway_id = self.args['gateway_id']
if gateway_id:
if gateway_id.startswith('nat-'):
self.params['NatGatewayId'] = gateway_id
else:
self.params['GatewayId'] = gateway_id
示例6: configure
def configure(self):
EC2Request.configure(self)
self.configure_s3_access()
if not self.args.get('expires'):
self.args['expires'] = 30
if self.args['expires'] < 1:
raise ArgumentError(
'argument -x/--expires: value must be positive')
示例7: configure
def configure(self):
EC2Request.configure(self)
if (self.args.get('Reset') and
any(self.args.get(attr) is not None for attr in
('Cpu', 'Disk', 'Memory'))):
# Basically, reset is mutually exclusive with everything else.
raise ArgumentError('argument --reset may not be used with '
'instance type attributes')
示例8: configure
def configure(self):
EC2Request.configure(self)
if self.args.get("PublicIp") is not None and self.args.get("AllocationId") is not None:
# Can't be both EC2 and VPC
raise ArgumentError("argument -a/--allocation-id: not allowed with an IP address")
if self.args.get("PublicIp") is None and self.args.get("AllocationId") is None:
# ...but we still have to be one of them
raise ArgumentError("argument -a/--allocation-id or an IP address is required")
示例9: configure
def configure(self):
EC2Request.configure(self)
if self.args.get('all'):
if self.args.get('Owner'):
raise ArgumentError('argument -a/--all: not allowed with '
'argument -o/--owner')
if self.args.get('RestorableBy'):
raise ArgumentError('argument -a/--all: not allowed with '
'argument -r/--restorable-by')
示例10: configure
def configure(self):
EC2Request.configure(self)
if self.args.get("positional_interface"):
if self.params.get("NetworkInterfaceId"):
# Shouldn't be supplied both positionally and optionally
raise ArgumentError("unrecognized arguments: {0}".format(self.args["positional_interface"]))
self.params["NetworkInterfaceId"] = self.args["positional_interface"]
if not self.params.get("NetworkInterfaceId"):
raise ArgumentError("argument -n/--network-interface is required")
示例11: configure
def configure(self):
EC2Request.configure(self)
if not self.args.get('Storage.S3.UploadPolicy'):
if not self.args.get('owner_sak'):
raise ArgumentError('argument -w/--owner-sak is required when '
'-c/--policy is not used')
elif not self.args.get('Storage.S3.UploadPolicySignature'):
if not self.args.get('owner_sak'):
raise ArgumentError('argument -w/--owner-sak is required when '
'-s/--policy-signature is not used')
示例12: configure
def configure(self):
EC2Request.configure(self)
if (self.args.get('Attachment.DeleteOnTermination') is not None and
not self.args.get('Attachment.AttachmentId')):
raise ArgumentError('argument --delete-on-termination may only be '
'used with -a/--attachment')
if (self.args.get('Attachment.AttachmentId') and
self.args.get('Attachment.DeleteOnTermination') is None):
raise ArgumentError('argument -a/--attachment also requires '
'--delete-on-termination')
示例13: configure
def configure(self):
EC2Request.configure(self)
if self.args.get('positional_vpc'):
if self.params.get('VpcId'):
# Shouldn't be supplied both positionally and optionally
raise ArgumentError('unrecognized arguments: {0}'.format(
self.args['positional_vpc']))
self.params['VpcId'] = self.args['positional_vpc']
if not self.params.get('VpcId'):
raise ArgumentError('argument -c/--vpc is required')
示例14: configure
def configure(self):
EC2Request.configure(self)
if self.args.get('positional_interface'):
if self.params.get('NetworkInterfaceId'):
# Shouldn't be supplied both positionally and optionally
raise ArgumentError('unrecognized arguments: {0}'.format(
self.args['positional_interface']))
self.params['NetworkInterfaceId'] = \
self.args['positional_interface']
if not self.params.get('NetworkInterfaceId'):
raise ArgumentError('argument -n/--network-interface is required')
示例15: configure
def configure(self):
EC2Request.configure(self)
if self.args.get('all', False):
if self.args.get('ImageId'):
raise ArgumentError('argument -a/--all: not allowed with '
'a list of images')
if self.args.get('ExecutableBy'):
raise ArgumentError('argument -a/--all: not allowed with '
'argument -x/--executable-by')
if self.args.get('Owner'):
raise ArgumentError('argument -a/--all: not allowed with '
'argument -o/--owner')