本文整理汇总了Python中boto.pyami.config.Config.set方法的典型用法代码示例。如果您正苦于以下问题:Python Config.set方法的具体用法?Python Config.set怎么用?Python Config.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto.pyami.config.Config
的用法示例。
在下文中一共展示了Config.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from boto.pyami.config import Config [as 别名]
# 或者: from boto.pyami.config.Config import set [as 别名]
def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
if config_file:
cfg = Config(path=config_file)
if cfg.has_section('EC2'):
# include any EC2 configuration values that aren't specified in params:
for option in cfg.options('EC2'):
if option not in params:
params[option] = cfg.get('EC2', option)
getter = CommandLineGetter()
getter.get(cls, params)
region = params.get('region')
ec2 = region.connect()
cls.add_credentials(cfg, ec2.aws_access_key_id, ec2.aws_secret_access_key)
ami = params.get('ami')
kp = params.get('keypair')
group = params.get('group')
zone = params.get('zone')
# deal with possibly passed in logical volume:
if logical_volume != None:
cfg.set('EBS', 'logical_volume_name', logical_volume.name)
cfg_fp = StringIO.StringIO()
cfg.write(cfg_fp)
# deal with the possibility that zone and/or keypair are strings read from the config file:
if isinstance(zone, Zone):
zone = zone.name
if isinstance(kp, KeyPair):
kp = kp.name
reservation = ami.run(min_count=1,
max_count=params.get('quantity', 1),
key_name=kp,
security_groups=[group],
instance_type=params.get('instance_type'),
placement = zone,
user_data = cfg_fp.getvalue())
l = []
i = 0
elastic_ip = params.get('elastic_ip')
instances = reservation.instances
if elastic_ip != None and instances.__len__() > 0:
instance = instances[0]
print 'Waiting for instance to start so we can set its elastic IP address...'
while instance.update() != 'running':
time.sleep(1)
instance.use_ip(elastic_ip)
print 'set the elastic IP of the first instance to %s' % elastic_ip
for instance in instances:
s = cls()
s.ec2 = ec2
s.name = params.get('name') + '' if i==0 else str(i)
s.description = params.get('description')
s.region_name = region.name
s.instance_id = instance.id
if elastic_ip and i == 0:
s.elastic_ip = elastic_ip
s.put()
l.append(s)
i += 1
return l
示例2: create
# 需要导入模块: from boto.pyami.config import Config [as 别名]
# 或者: from boto.pyami.config.Config import set [as 别名]
def create(cls, config_file=None, logical_volume = None, cfg = None, **params):
"""
Create a new instance based on the specified configuration file or the specified
configuration and the passed in parameters.
If the config_file argument is not None, the configuration is read from there.
Otherwise, the cfg argument is used.
The config file may include other config files with a #import reference. The included
config files must reside in the same directory as the specified file.
The logical_volume argument, if supplied, will be used to get the current physical
volume ID and use that as an override of the value specified in the config file. This
may be useful for debugging purposes when you want to debug with a production config
file but a test Volume.
The dictionary argument may be used to override any EC2 configuration values in the
config file.
"""
if config_file:
cfg = Config(path=config_file)
if cfg.has_section('EC2'):
# include any EC2 configuration values that aren't specified in params:
for option in cfg.options('EC2'):
if option not in params:
params[option] = cfg.get('EC2', option)
getter = CommandLineGetter()
getter.get(cls, params)
region = params.get('region')
ec2 = region.connect()
cls.add_credentials(cfg, ec2.aws_access_key_id, ec2.aws_secret_access_key)
ami = params.get('ami')
kp = params.get('keypair')
group = params.get('group')
zone = params.get('zone')
# deal with possibly passed in logical volume:
if logical_volume != None:
cfg.set('EBS', 'logical_volume_name', logical_volume.name)
cfg_fp = StringIO.StringIO()
cfg.write(cfg_fp)
# deal with the possibility that zone and/or keypair are strings read from the config file:
if isinstance(zone, Zone):
zone = zone.name
if isinstance(kp, KeyPair):
kp = kp.name
reservation = ami.run(min_count=1,
max_count=params.get('quantity', 1),
key_name=kp,
security_groups=[group],
instance_type=params.get('instance_type'),
placement = zone,
user_data = cfg_fp.getvalue())
l = []
i = 0
elastic_ip = params.get('elastic_ip')
instances = reservation.instances
if elastic_ip is not None and instances.__len__() > 0:
instance = instances[0]
print 'Waiting for instance to start so we can set its elastic IP address...'
# Sometimes we get a message from ec2 that says that the instance does not exist.
# Hopefully the following delay will giv eec2 enough time to get to a stable state:
time.sleep(5)
while instance.update() != 'running':
time.sleep(1)
instance.use_ip(elastic_ip)
print 'set the elastic IP of the first instance to %s' % elastic_ip
for instance in instances:
s = cls()
s.ec2 = ec2
s.name = params.get('name') + '' if i==0 else str(i)
s.description = params.get('description')
s.region_name = region.name
s.instance_id = instance.id
if elastic_ip and i == 0:
s.elastic_ip = elastic_ip
s.put()
l.append(s)
i += 1
return l
示例3: Server
# 需要导入模块: from boto.pyami.config import Config [as 别名]
# 或者: from boto.pyami.config.Config import set [as 别名]
class Server(Model):
ec2 = boto.connect_ec2()
@classmethod
def Inventory(cls):
"""
Returns a list of Server instances, one for each Server object
persisted in the db
"""
l = ServerSet()
rs = cls.find()
for server in rs:
l.append(server)
return l
@classmethod
def Register(cls, name, instance_id, description=''):
s = cls()
s.name = name
s.instance_id = instance_id
s.description = description
s.save()
return s
def __init__(self, id=None, **kw):
Model.__init__(self, id, **kw)
self._reservation = None
self._instance = None
self._ssh_client = None
self._pkey = None
self._config = None
name = StringProperty(unique=True, verbose_name="Name")
instance_id = StringProperty(verbose_name="Instance ID")
config_uri = StringProperty()
ami_id = StringProperty(verbose_name="AMI ID")
zone = StringProperty(verbose_name="Availability Zone")
security_group = StringProperty(verbose_name="Security Group", default="default")
key_name = StringProperty(verbose_name="Key Name")
elastic_ip = StringProperty(verbose_name="Elastic IP")
instance_type = StringProperty(verbose_name="Instance Type")
description = StringProperty(verbose_name="Description")
log = StringProperty()
def setReadOnly(self, value):
raise AttributeError
def getInstance(self):
if not self._instance:
if self.instance_id:
try:
rs = self.ec2.get_all_instances([self.instance_id])
except:
return None
if len(rs) > 0:
self._reservation = rs[0]
self._instance = self._reservation.instances[0]
return self._instance
instance = property(getInstance, setReadOnly, None, 'The Instance for the server')
def getAMI(self):
if self.instance:
return self.instance.image_id
ami = property(getAMI, setReadOnly, None, 'The AMI for the server')
def getStatus(self):
if self.instance:
self.instance.update()
return self.instance.state
status = property(getStatus, setReadOnly, None,
'The status of the server')
def getHostname(self):
if self.instance:
return self.instance.public_dns_name
hostname = property(getHostname, setReadOnly, None,
'The public DNS name of the server')
def getPrivateHostname(self):
if self.instance:
return self.instance.private_dns_name
private_hostname = property(getPrivateHostname, setReadOnly, None,
'The private DNS name of the server')
def getLaunchTime(self):
if self.instance:
return self.instance.launch_time
launch_time = property(getLaunchTime, setReadOnly, None,
'The time the Server was started')
def getConsoleOutput(self):
if self.instance:
return self.instance.get_console_output()
#.........这里部分代码省略.........
示例4: CertValidationTest
# 需要导入模块: from boto.pyami.config import Config [as 别名]
# 或者: from boto.pyami.config.Config import set [as 别名]
class CertValidationTest(unittest.TestCase):
def setUp(self):
self.config = Config()
# Enable https_validate_certificates.
self.config.add_section('Boto')
self.config.setbool('Boto', 'https_validate_certificates', True)
# Set up bogus credentials so that the auth module is willing to go
# ahead and make a request; the request should fail with a service-level
# error if it does get to the service (S3 or GS).
self.config.add_section('Credentials')
self.config.set('Credentials', 'gs_access_key_id', 'xyz')
self.config.set('Credentials', 'gs_secret_access_key', 'xyz')
self.config.set('Credentials', 'aws_access_key_id', 'xyz')
self.config.set('Credentials', 'aws_secret_access_key', 'xyz')
self._config_patch = mock.patch('boto.config', self.config)
self._config_patch.start()
def tearDown(self):
self._config_patch.stop()
def enableProxy(self):
self.config.set('Boto', 'proxy', PROXY_HOST)
self.config.set('Boto', 'proxy_port', PROXY_PORT)
def assertConnectionThrows(self, connection_class, error):
conn = connection_class('fake_id', 'fake_secret')
self.assertRaises(error, conn.get_all_buckets)
def do_test_valid_cert(self):
# When connecting to actual servers with bundled root certificates, no
# cert errors should be thrown; instead we will get "invalid
# credentials" errors since the config used does not contain any
# credentials.
self.assertConnectionThrows(S3Connection, exception.S3ResponseError)
self.assertConnectionThrows(GSConnection, exception.GSResponseError)
def test_valid_cert(self):
self.do_test_valid_cert()
def test_valid_cert_with_proxy(self):
self.enableProxy()
self.do_test_valid_cert()
def do_test_invalid_signature(self):
self.config.set('Boto', 'ca_certificates_file', DEFAULT_CA_CERTS_FILE)
self.assertConnectionThrows(S3Connection, ssl.SSLError)
self.assertConnectionThrows(GSConnection, ssl.SSLError)
def test_invalid_signature(self):
self.do_test_invalid_signature()
def test_invalid_signature_with_proxy(self):
self.enableProxy()
self.do_test_invalid_signature()
def do_test_invalid_host(self):
self.config.set('Credentials', 'gs_host', INVALID_HOSTNAME_HOST)
self.config.set('Credentials', 's3_host', INVALID_HOSTNAME_HOST)
self.assertConnectionThrows(S3Connection, ssl.SSLError)
self.assertConnectionThrows(GSConnection, ssl.SSLError)
def do_test_invalid_host(self):
self.config.set('Credentials', 'gs_host', INVALID_HOSTNAME_HOST)
self.config.set('Credentials', 's3_host', INVALID_HOSTNAME_HOST)
self.assertConnectionThrows(
S3Connection, https_connection.InvalidCertificateException)
self.assertConnectionThrows(
GSConnection, https_connection.InvalidCertificateException)
def test_invalid_host(self):
self.do_test_invalid_host()
def test_invalid_host_with_proxy(self):
self.enableProxy()
self.do_test_invalid_host()