本文整理汇总了Python中pyrax.get_setting函数的典型用法代码示例。如果您正苦于以下问题:Python get_setting函数的具体用法?Python get_setting怎么用?Python get_setting使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_setting函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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
示例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)
示例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)
示例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