本文整理汇总了Python中pyrax.get_setting函数的典型用法代码示例。如果您正苦于以下问题:Python get_setting函数的具体用法?Python get_setting怎么用?Python get_setting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_setting函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_set_identity_type_setting
def test_set_identity_type_setting(self):
savtyp = pyrax.get_setting("identity_type")
savcls = pyrax.get_setting("identity_class")
pyrax.set_setting("identity_class", None)
pyrax.set_setting("identity_type", "keystone")
cls = pyrax.get_setting("identity_class")
self.assertEqual(cls, pyrax.keystone_identity.KeystoneIdentity)
pyrax.set_setting("identity_type", savtyp)
pyrax.set_setting("identity_class", savcls)
开发者ID:Gu1,项目名称:pyrax,代码行数:9,代码来源:test_module.py
示例2: setup
def setup():
default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')
env = get_config(p, 'rax', 'environment', 'RAX_ENV', None)
if env:
pyrax.set_environment(env)
keyring_username = pyrax.get_setting('keyring_username')
# Attempt to grab credentials from environment first
creds_file = get_config(p, 'rax', 'creds_file',
'RAX_CREDS_FILE', None)
if creds_file is not None:
creds_file = os.path.expanduser(creds_file)
else:
# But if that fails, use the default location of
# ~/.rackspace_cloud_credentials
if os.path.isfile(default_creds_file):
creds_file = default_creds_file
elif not keyring_username:
sys.stderr.write('No value in environment variable %s and/or no '
'credentials file at %s\n'
% ('RAX_CREDS_FILE', default_creds_file))
sys.exit(1)
identity_type = pyrax.get_setting('identity_type')
pyrax.set_setting('identity_type', identity_type or 'rackspace')
region = pyrax.get_setting('region')
try:
if keyring_username:
pyrax.keyring_auth(keyring_username, region=region)
else:
pyrax.set_credential_file(creds_file, region=region)
except Exception as e:
sys.stderr.write("%s: %s\n" % (e, e.message))
sys.exit(1)
regions = []
if region:
regions.append(region)
else:
region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all',
islist=True)
for region in region_list:
region = region.strip().upper()
if region == 'ALL':
regions = pyrax.regions
break
elif region not in pyrax.regions:
sys.stderr.write('Unsupported region %s' % region)
sys.exit(1)
elif region not in regions:
regions.append(region)
return regions
开发者ID:Cocorena-Dev,项目名称:ansible-minecraft,代码行数:57,代码来源:rax.py
示例3: test_read_config
def test_read_config(self):
dummy_cfg = fakes.fake_config_file
sav_region = pyrax.default_region
sav_USER_AGENT = pyrax.USER_AGENT
with utils.SelfDeletingTempfile() as cfgfile:
open(cfgfile, "w").write(dummy_cfg)
pyrax.settings.read_config(cfgfile)
self.assertEqual(pyrax.get_setting("default_region"), "FAKE")
self.assertTrue(pyrax.get_setting("user_agent").startswith("FAKE "))
pyrax.default_region = sav_region
pyrax.USER_AGENT = sav_USER_AGENT
开发者ID:tvaught,项目名称:pyrax,代码行数:11,代码来源:test_module.py
示例4: authenticate
def authenticate(self, username=None, password=None, api_key=None,
tenant_id=None, connect=False):
"""
Using the supplied credentials, connects to the specified
authentication endpoint and attempts to log in.
Credentials can either be passed directly to this method, or
previously-stored credentials can be used. If authentication is
successful, the token and service catalog information is stored, and
clients for each service and region are created.
The 'connect' parameter is retained for backwards compatibility. It no
longer has any effect.
"""
self.username = username or self.username or pyrax.get_setting(
"username")
# Different identity systems may pass these under inconsistent names.
self.password = password or self.password or api_key or self.api_key
self.api_key = api_key or self.api_key or self.password
self.tenant_id = tenant_id or self.tenant_id or pyrax.get_setting(
"tenant_id")
creds = self._format_credentials()
headers = {"Content-Type": "application/json",
"Accept": "application/json",
}
resp, resp_body = self.method_post("tokens", data=creds,
headers=headers, std_headers=False)
if resp.status_code == 401:
# Invalid authorization
raise exc.AuthenticationFailed("Incorrect/unauthorized "
"credentials received")
elif 500 <= resp.status_code < 600:
# Internal Server Error
try:
error_msg = resp_body[list(resp_body.keys())[0]]["message"]
except KeyError:
error_msg = "Service Currently Unavailable"
raise exc.InternalServerError(error_msg)
elif resp.status_code > 299:
try:
msg = resp_body[list(resp_body.keys())[0]]["message"]
except KeyError:
msg = None
if msg:
err = "%s - %s." % (resp.reason, msg)
else:
err = "%s." % resp.reason
raise exc.AuthenticationFailed(err)
self._parse_response(resp_body)
self.authenticated = True
开发者ID:CarlFK,项目名称:pyrax,代码行数:51,代码来源:base_identity.py
示例5: keyring_auth
def keyring_auth(self, username=None):
"""
Uses the keyring module to retrieve the user's password or api_key.
"""
if not keyring:
# Module not installed
raise exc.KeyringModuleNotInstalled("The 'keyring' Python module "
"is not installed on this system.")
if username is None:
username = pyrax.get_setting("keyring_username")
if not username:
raise exc.KeyringUsernameMissing("No username specified for "
"keyring authentication.")
password = keyring.get_password("pyrax", username)
if password is None:
raise exc.KeyringPasswordNotFound("No password was found for the "
"username '%s'." % username)
style = self._creds_style or self._default_creds_style
# Keyring username may be different than the credentials. Use the
# existing username, if present; otherwise, use the supplied username.
username = self.username or username
if style == "apikey":
return self.authenticate(username=username, api_key=password)
else:
return self.authenticate(username=username, password=password)
开发者ID:CarlFK,项目名称:pyrax,代码行数:25,代码来源:base_identity.py
示例6: setup
def setup():
rax_username = get_config(p, 'rax', 'username', 'RAX_USERNAME', None)
rax_api_key = get_config(p, 'rax', 'api_key', 'RAX_API_KEY', None)
pyrax.set_setting('identity_type', 'rackspace')
pyrax.set_credentials(rax_username, rax_api_key)
region = pyrax.get_setting('region')
regions = []
if region:
regions.append(region)
else:
region_list = get_config(p, 'rax', 'regions', 'RAX_REGION', 'all',
islist=True)
for region in region_list:
region = region.strip().upper()
if region == 'ALL':
regions = pyrax.regions
break
elif region not in pyrax.regions:
sys.stderr.write('Unsupported region %s' % region)
sys.exit(1)
elif region not in regions:
regions.append(region)
return regions
开发者ID:shaweiguo,项目名称:deploy,代码行数:27,代码来源:rax.py
示例7: test_settings_get_from_env
def test_settings_get_from_env(self):
pyrax.settings._settings = {"default": {}}
pyrax.settings.env_dct = {"identity_type": "fake"}
typ = utils.random_unicode()
ident = utils.random_unicode()
sav_env = os.environ
sav_imp = pyrax._import_identity
pyrax._import_identity = Mock(return_value=ident)
os.environ = {"fake": typ}
ret = pyrax.get_setting("identity_class")
pyrax._import_identity = sav_imp
os.environ = sav_env
开发者ID:Gu1,项目名称:pyrax,代码行数:12,代码来源:test_module.py
示例8: test_connect_to_cloudfiles_ServiceNet
def test_connect_to_cloudfiles_ServiceNet(self):
orig = pyrax.get_setting("use_servicenet")
pyrax.set_setting("use_servicenet", True)
pyrax.cloudfiles = None
pyrax.connect_to_cloudfiles = self.orig_connect_to_cloudfiles
sav = pyrax._create_client
pyrax._create_client = Mock()
cf = pyrax.connect_to_cloudfiles(public=False)
pyrax._create_client.assert_called_once_with(ep_name="object_store",
region=None, public=False)
pyrax.set_setting("use_servicenet", orig)
pyrax._create_client = sav
开发者ID:rackspace,项目名称:pyrax,代码行数:12,代码来源:test_module.py
示例9: test_connect_to_cloudfiles_ServiceNet
def test_connect_to_cloudfiles_ServiceNet(self, client):
orig = pyrax.get_setting("use_servicenet")
pyrax.set_setting("use_servicenet", True)
pyrax.cloudfiles = None
pyrax.connect_to_cloudfiles = self.orig_connect_to_cloudfiles
cf = pyrax.connect_to_cloudfiles(public=False)
# Check the call arguments to see that our setting stuck and we're
# sending internalURL on to CFClient.
_, kwargs = client.call_args
opts = kwargs["os_options"]
self.assertEqual(opts["endpoint_type"], "internalURL")
self.assertIsNotNone(cf)
pyrax.set_setting("use_servicenet", orig)
开发者ID:Gu1,项目名称:pyrax,代码行数:13,代码来源:test_module.py
示例10: setup
def setup():
default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')
env = get_config(p, 'rax', 'environment', 'RAX_ENV', None)
if env:
pyrax.set_environment(env)
keyring_username = pyrax.get_setting('keyring_username')
# Attempt to grab credentials from environment first
creds_file = get_config(p, 'rax', 'creds_file',
'RAX_CREDS_FILE', None)
if creds_file is not None:
creds_file = os.path.expanduser(creds_file)
else:
# But if that fails, use the default location of
# ~/.rackspace_cloud_credentials
if os.path.isfile(default_creds_file):
creds_file = default_creds_file
elif not keyring_username:
sys.stderr.write('No value in environment variable %s and/or no '
'credentials file at %s\n'
% ('RAX_CREDS_FILE', default_creds_file))
sys.exit(1)
identity_type = pyrax.get_setting('identity_type')
pyrax.set_setting('identity_type', identity_type or 'rackspace')
region = pyrax.get_setting('region')
try:
if keyring_username:
pyrax.keyring_auth(keyring_username, region=region)
else:
pyrax.set_credential_file(creds_file, region=region)
except Exception, e:
sys.stderr.write("%s: %s\n" % (e, e.message))
sys.exit(1)
开发者ID:jethar,项目名称:richard-ansible,代码行数:38,代码来源:rax.py
示例11: _create_client
def _create_client(self, clt_class, url, public=True, special=False):
"""
Creates a client instance for the service.
"""
verify_ssl = pyrax.get_setting("verify_ssl")
if self.service == "compute" and not special:
# Novaclient requires different parameters.
client = pyrax.connect_to_cloudservers(region=self.region,
context=self.identity)
client.identity = self.identity
else:
client = clt_class(self.identity, region_name=self.region,
management_url=url, verify_ssl=verify_ssl)
return client
开发者ID:CarlFK,项目名称:pyrax,代码行数:14,代码来源:base_identity.py
示例12: _create_client
def _create_client(self, clt_class, url, public=True):
"""
Creates a client instance for the service.
"""
verify_ssl = pyrax.get_setting("verify_ssl")
if self.service == "object_store":
# Swiftclient requires different parameters.
client = pyrax.connect_to_cloudfiles(region=self.region, public=public, context=self.identity)
elif self.service == "compute":
# Novaclient also requires special handling.
client = pyrax.connect_to_cloudservers(region=self.region, context=self.identity)
else:
client = clt_class(self.identity, region_name=self.region, management_url=url, verify_ssl=verify_ssl)
return client
开发者ID:rgbkrk,项目名称:pyrax,代码行数:14,代码来源:base_identity.py
示例13: test_safe_region
def test_safe_region(self):
# Pass direct
reg = utils.random_unicode()
ret = pyrax._safe_region(reg)
self.assertEqual(reg, ret)
# From config setting
orig_reg = pyrax.get_setting("region")
reg = utils.random_unicode()
pyrax.set_setting("region", reg)
ret = pyrax._safe_region()
self.assertEqual(reg, ret)
# Identity default
pyrax.set_setting("region", None)
orig_defreg = pyrax.identity.get_default_region
reg = utils.random_unicode()
pyrax.identity.get_default_region = Mock(return_value=reg)
ret = pyrax._safe_region()
self.assertEqual(reg, ret)
pyrax.identity.get_default_region = orig_defreg
pyrax.set_setting("region", orig_reg)
开发者ID:Gu1,项目名称:pyrax,代码行数:20,代码来源:test_module.py
示例14: setup
def setup():
default_creds_file = os.path.expanduser('~/.rackspace_cloud_credentials')
env = os.getenv('RAX_ENV', None)
if env:
pyrax.set_environment(env)
keyring_username = pyrax.get_setting('keyring_username')
# Attempt to grab credentials from environment first
try:
creds_file = os.path.expanduser(os.environ['RAX_CREDS_FILE'])
except KeyError, e:
# But if that fails, use the default location of
# ~/.rackspace_cloud_credentials
if os.path.isfile(default_creds_file):
creds_file = default_creds_file
elif not keyring_username:
sys.stderr.write('No value in environment variable %s and/or no '
'credentials file at %s\n'
% (e.message, default_creds_file))
sys.exit(1)
开发者ID:shterrel,项目名称:Ansible,代码行数:22,代码来源:rax.py
示例15: _get_auth_endpoint
def _get_auth_endpoint(self):
ep = pyrax.get_setting("auth_endpoint")
if ep is None:
raise exc.EndpointNotDefined("No auth endpoint has been specified.")
return ep
开发者ID:CarlFK,项目名称:pyrax,代码行数:5,代码来源:keystone_identity.py
示例16: test_settings_set_verify_ssl
def test_settings_set_verify_ssl(self):
key = "verify_ssl"
val = utils.random_unicode()
pyrax.settings.set(key, val)
self.assertEqual(pyrax.get_setting(key), val)
开发者ID:rackspace,项目名称:pyrax,代码行数:5,代码来源:test_module.py
示例17: _get_auth_endpoint
def _get_auth_endpoint(self):
return (self._auth_endpoint or pyrax.get_setting("auth_endpoint")
or AUTH_ENDPOINT)
开发者ID:CarlFK,项目名称:pyrax,代码行数:3,代码来源:rax_identity.py
示例18: _get_auth_endpoint
def _get_auth_endpoint(self):
"""
Broken out in case subclasses need to determine endpoints dynamically.
"""
return self._auth_endpoint or pyrax.get_setting("auth_endpoint")
开发者ID:CarlFK,项目名称:pyrax,代码行数:5,代码来源:base_identity.py
示例19: test_settings_get
def test_settings_get(self):
def_ep = pyrax.get_setting("auth_endpoint", "default")
alt_ep = pyrax.get_setting("auth_endpoint", "alternate")
self.assertEqual(def_ep, "DEFAULT_AUTH")
self.assertEqual(alt_ep, "ALT_AUTH")
开发者ID:Gu1,项目名称:pyrax,代码行数:5,代码来源:test_module.py
示例20: Mock
<<<<<<< HEAD
typ = utils.random_name()
ident = utils.random_name()
=======
typ = utils.random_unicode()
ident = utils.random_unicode()
>>>>>>> upstream/master
=======
typ = utils.random_unicode()
ident = utils.random_unicode()
>>>>>>> upstream/working
sav_env = os.environ
sav_imp = pyrax._import_identity
pyrax._import_identity = Mock(return_value=ident)
os.environ = {"fake": typ}
ret = pyrax.get_setting("identity_class")
pyrax._import_identity = sav_imp
os.environ = sav_env
def test_read_config(self):
dummy_cfg = fakes.fake_config_file
sav_region = pyrax.default_region
sav_USER_AGENT = pyrax.USER_AGENT
with utils.SelfDeletingTempfile() as cfgfile:
with open(cfgfile, "w") as cfg:
cfg.write(dummy_cfg)
pyrax.settings.read_config(cfgfile)
self.assertEqual(pyrax.get_setting("region"), "FAKE")
self.assertTrue(pyrax.get_setting("user_agent").startswith("FAKE "))
pyrax.default_region = sav_region
pyrax.USER_AGENT = sav_USER_AGENT
开发者ID:asmajlovic,项目名称:pyrax,代码行数:31,代码来源:test_module.py
注:本文中的pyrax.get_setting函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论