本文整理汇总了Python中oslo_config.cfg.CONF属性的典型用法代码示例。如果您正苦于以下问题:Python cfg.CONF属性的具体用法?Python cfg.CONF怎么用?Python cfg.CONF使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类oslo_config.cfg
的用法示例。
在下文中一共展示了cfg.CONF属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def __init__(self, context, node_id=None):
"""Create a pci device tracker.
If a node_id is passed in, it will fetch pci devices information
from database, otherwise, it will create an empty devices list
and the resource tracker will update the node_id information later.
"""
super(PciDevTracker, self).__init__()
self.stale = {}
self.node_id = node_id
self.dev_filter = whitelist.Whitelist(CONF.pci.passthrough_whitelist)
self.stats = stats.PciDeviceStats(dev_filter=self.dev_filter)
self._context = context
if node_id:
self.pci_devs = objects.PciDevice.list_by_compute_node(
context, node_id)
else:
self.pci_devs = []
self._build_device_tree(self.pci_devs)
self._initial_instance_usage()
示例2: _need_configure_l3
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _need_configure_l3(vif):
if not hasattr(vif, 'physnet'):
return True
physnet = vif.physnet
mapping_res = CONF.sriov_physnet_resource_mappings
try:
resource = mapping_res[physnet]
except KeyError:
LOG.exception("No resource name for physnet %s", physnet)
raise
mapping_driver = CONF.sriov_resource_driver_mappings
try:
driver_name = mapping_driver[resource]
except KeyError:
LOG.exception("No driver for resource_name %s", resource)
raise
if driver_name in consts.USERSPACE_DRIVERS:
LOG.info("_configure_l3 will not be called for vif %s "
"because of it's driver", vif)
return False
return True
示例3: _make_request
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _make_request(self, path, cni_envs, expected_status=None):
method = 'POST'
host = CONF.cni_daemon.cni_daemon_host
port = CONF.cni_daemon.cni_daemon_port
url = 'http://%s:%s/%s' % (host, port, path)
try:
LOG.debug('Making request to CNI Daemon. %(method)s %(path)s\n'
'%(body)s',
{'method': method, 'path': url, 'body': cni_envs})
resp = requests.post(url, json=cni_envs,
headers={'Connection': 'close'})
except requests.ConnectionError:
LOG.exception('Looks like %s:%s cannot be reached. '
'Is zun-cni-daemon running?', (host, port))
raise
LOG.debug('CNI Daemon returned "%(status)d %(reason)s".',
{'status': resp.status_code, 'reason': resp.reason})
if expected_status and resp.status_code != expected_status:
LOG.error('CNI daemon returned error "%(status)d %(reason)s".',
{'status': resp.status_code, 'reason': resp.reason})
raise exception.CNIError('Got invalid status code from CNI daemon')
return resp
示例4: __init__
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def __init__(self, url='unix://var/run/docker.sock'):
if (CONF.docker.cert_file or
CONF.docker.key_file):
client_cert = (CONF.docker.cert_file, CONF.docker.key_file)
else:
client_cert = None
if (CONF.docker.ca_file or
CONF.docker.api_insecure or
client_cert):
ssl_config = docker.tls.TLSConfig(
client_cert=client_cert,
ca_cert=CONF.docker.ca_file,
verify=CONF.docker.api_insecure)
else:
ssl_config = False
super(DockerHTTPClient, self).__init__(
base_url=url,
version=DEFAULT_DOCKER_API_VERSION,
timeout=DEFAULT_TIMEOUT_SECONDS,
tls=ssl_config
)
self._setup_decorators()
示例5: __init__
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def __init__(self, config_path=None):
"""Initialize the loader, and attempt to find the config.
:param config_path: Full or relative path to the paste config.
:returns: None
"""
self.config_path = None
config_path = config_path or CONF.api_paste_config
if not os.path.isabs(config_path):
self.config_path = CONF.find_file(config_path)
elif os.path.exists(config_path):
self.config_path = config_path
if not self.config_path:
raise exception.EC2APIConfigNotFound(path=config_path)
示例6: allocate_address
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def allocate_address(self, context, domain=None):
os_public_network = ec2utils.get_os_public_network(context)
neutron = clients.neutron(context)
with common.OnCrashCleaner() as cleaner:
os_floating_ip = {'floating_network_id': os_public_network['id']}
try:
os_floating_ip = neutron.create_floatingip(
{'floatingip': os_floating_ip})
except neutron_exception.OverQuotaClient:
raise exception.AddressLimitExceeded()
os_floating_ip = os_floating_ip['floatingip']
if ((not domain or domain == 'standard') and
not CONF.disable_ec2_classic):
return None, os_floating_ip
cleaner.addCleanup(neutron.delete_floatingip, os_floating_ip['id'])
address = {'os_id': os_floating_ip['id'],
'public_ip': os_floating_ip['floating_ip_address']}
address = db_api.add_item(context, 'eipalloc', address)
return address, os_floating_ip
示例7: _s3_conn
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _s3_conn(context):
region = CONF.s3_region
ec2_creds = clients.keystone(context).ec2.list(context.user_id)
# Here we a) disable user's default config to let ec2api works independetly
# of user's local settings;
# b) specify region to be used by botocore;
# c) do not change standard botocore keys to get these settings
# from environment
connection_data = {
'config_file': (None, 'AWS_CONFIG_FILE', None, None),
'region': ('region', 'AWS_DEFAULT_REGION', region, None),
}
session = botocore.session.get_session(connection_data)
return session.create_client(
's3', region_name=region, endpoint_url=CONF.s3_url,
aws_access_key_id=ec2_creds[0].access,
aws_secret_access_key=ec2_creds[0].secret,
config=botocore.config.Config(signature_version='s3v4'))
示例8: __call__
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def __call__(self, req):
"""Generate a WSGI response based on the exception passed to ctor."""
code = ec2api.api.exception_to_ec2code(self.wrapped_exc)
status = self.wrapped_exc.status_int
message = self.wrapped_exc.explanation
if status == 501:
message = "The requested function is not supported"
if 'AWSAccessKeyId' not in req.params:
raise webob.exc.HTTPBadRequest()
user_id, _sep, project_id = req.params['AWSAccessKeyId'].partition(':')
project_id = project_id or user_id
remote_address = getattr(req, 'remote_address', '127.0.0.1')
if CONF.use_forwarded_for:
remote_address = req.headers.get('X-Forwarded-For', remote_address)
resp = ec2_error_response(common_context.generate_request_id(), code,
message=message, status=status)
return resp
示例9: _check_and_create_default_vpc
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _check_and_create_default_vpc(context):
if not CONF.disable_ec2_classic or context.is_os_admin:
return
lock_name = 'default-vpc-lock-{}-'.format(context.project_id)
@synchronized(lock_name, external=True)
def _check():
for vpc in db_api.get_items(context, 'vpc'):
if vpc.get('is_default'):
return vpc
try:
default_vpc = _create_vpc(context, DEFAULT_VPC_CIDR_BLOCK,
is_default=True)
return default_vpc
except Exception:
LOG.exception('Failed to create default vpc')
return None
return _check()
示例10: describe_regions
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def describe_regions(context, region_name=None, filter=None):
# TODO(andrey-mp): collect regions from keystone catalog
if CONF.region_list:
regions = []
for region in CONF.region_list:
name, _sep, host = region.partition('=')
if not host:
host = CONF.ec2_host
endpoint = '%s://%s:%s%s' % (CONF.ec2_scheme,
host,
CONF.ec2_port,
CONF.ec2_path)
regions.append({'regionName': name,
'regionEndpoint': endpoint})
else:
# NOTE(andrey-mp): RegionOne is a default region name that is used
# in keystone, nova and some other projects
regions = [{'regionName': 'RegionOne',
'regionEndpoint': '%s://%s:%s%s' % (CONF.ec2_scheme,
CONF.ec2_host,
CONF.ec2_port,
CONF.ec2_path)}]
return {'regionInfo': regions}
示例11: _unpack_nsx_request
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _unpack_nsx_request(self, req):
remote_address = req.headers.get('X-Forwarded-For')
if remote_address is None:
msg = _('X-Forwarded-For is missing from request.')
raise webob.exc.HTTPBadRequest(explanation=msg)
provider_id = req.headers.get('X-Metadata-Provider')
if provider_id is None:
msg = _('X-Metadata-Provider is missing from request.')
raise webob.exc.HTTPBadRequest(explanation=msg)
remote_ip = remote_address.split(',')[0]
if CONF.metadata.metadata_proxy_shared_secret:
signature = req.headers.get('X-Metadata-Provider-Signature')
self._validate_signature(signature, provider_id, remote_ip)
return provider_id, remote_ip
示例12: _validate_signature
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _validate_signature(self, signature, requester_id, requester_ip):
expected_signature = hmac.new(
CONF.metadata.metadata_proxy_shared_secret.encode("utf-8"),
requester_id.encode(),
hashlib.sha256).hexdigest()
if not (signature and
utils.constant_time_compare(expected_signature, signature)):
LOG.warning('X-Instance-ID-Signature: %(signature)s does '
'not match the expected value: '
'%(expected_signature)s for id: '
'%(requester_id)s. Request From: '
'%(requester_ip)s',
{'signature': signature,
'expected_signature': expected_signature,
'requester_id': requester_id,
'requester_ip': requester_ip})
msg = _('Invalid proxy request signature.')
raise webob.exc.HTTPForbidden(explanation=msg)
示例13: __get_backend
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def __get_backend(self):
if not self.__backend:
if self.__config_group is None:
backend_name = CONF[self.__pivot]
else:
backend_name = CONF[self.__config_group][self.__pivot]
if backend_name not in self.__backends:
msg = _('Invalid backend: %s') % backend_name
raise exception.EC2Exception(msg)
backend = self.__backends[backend_name]
if isinstance(backend, tuple):
name = backend[0]
fromlist = backend[1]
else:
name = backend
fromlist = backend
self.__backend = __import__(name, None, None, fromlist)
return self.__backend
示例14: test_no_result_data
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def test_no_result_data(self, mock_request):
req = wsgi.Request.blank('/test')
req.GET['Signature'] = 'test-signature'
req.GET['AWSAccessKeyId'] = 'test-key-id'
resp = self.kauth(req)
self._validate_ec2_error(resp, 400, 'AuthFailure')
mock_request.assert_called_with('POST',
CONF.keystone_ec2_tokens_url,
data=mock.ANY, headers=mock.ANY)
fake_request = mock.NonCallableMock(status_code=200, headers={})
fake_request.json.return_value = {'token': {}}
mock_request.return_value = fake_request
resp = self.kauth(req)
self._validate_ec2_error(resp, 400, 'AuthFailure')
fake_request.json.return_value = {'access': {}}
resp = self.kauth(req)
self._validate_ec2_error(resp, 400, 'AuthFailure')
示例15: _get_manager
# 需要导入模块: from oslo_config import cfg [as 别名]
# 或者: from oslo_config.cfg import CONF [as 别名]
def _get_manager(self):
"""Initialize a Manager object appropriate for this service.
Use the service name to look up a Manager subclass from the
configuration and initialize an instance. If no class name
is configured, just return None.
:returns: a Manager instance, or None.
"""
fl = '%s_manager' % self.name
if fl not in CONF:
return None
manager_class_name = CONF.get(fl, None)
if not manager_class_name:
return None
manager_class = importutils.import_class(manager_class_name)
return manager_class()