def _get_allowed_hostclass(self, project_name):
"""Get the allowed list of hostclass from configuration."""
try:
group = CONF[project_name]
except cfg.NoSuchOptError:
# dynamically add the group into the configuration
group = cfg.OptGroup(project_name, 'project options')
CONF.register_group(group)
CONF.register_opt(cfg.ListOpt('allowed_classes'),
group=project_name)
try:
allowed_classes = CONF[project_name].allowed_classes
except cfg.NoSuchOptError:
LOG.error('No allowed_classes config option in [%s]', project_name)
return []
else:
if allowed_classes:
return allowed_classes
else:
return []
python类ListOpt()的实例源码
def filter_images(self):
"""Filter which images to build"""
filter_ = list()
if self.regex:
filter_ += self.regex
if self.conf.profile:
for profile in self.conf.profile:
if profile not in self.conf.profiles:
self.conf.register_opt(cfg.ListOpt(profile,
default=[]),
'profiles')
if len(self.conf.profiles[profile]) == 0:
msg = 'Profile: {} does not exist'.format(profile)
raise ValueError(msg)
else:
filter_ += self.conf.profiles[profile]
if filter_:
patterns = re.compile(r"|".join(filter_).join('()'))
for image in self.images:
if image['status'] == 'matched':
continue
if re.search(patterns, image['name']):
image['status'] = 'matched'
while (image['parent'] is not None and
image['parent']['status'] != 'matched'):
image = image['parent']
image['status'] = 'matched'
LOG.debug('%s:Matched regex', image['name'])
else:
image['status'] = 'unmatched'
else:
for image in self.images:
image['status'] = 'matched'
def filter_images(self):
"""Filter which images to build"""
filter_ = list()
if self.regex:
filter_ += self.regex
if self.conf.profile:
for profile in self.conf.profile:
if profile not in self.conf.profiles:
self.conf.register_opt(cfg.ListOpt(profile,
default=[]),
'profiles')
if len(self.conf.profiles[profile]) == 0:
msg = 'Profile: {} does not exist'.format(profile)
raise ValueError(msg)
else:
filter_ += self.conf.profiles[profile]
if filter_:
patterns = re.compile(r"|".join(filter_).join('()'))
for image in self.images:
if image['status'] == 'matched':
continue
if re.search(patterns, image['name']):
image['status'] = 'matched'
while (image['parent'] is not None and
image['parent']['status'] != 'matched'):
image = image['parent']
image['status'] = 'matched'
LOG.debug('%s:Matched regex', image['name'])
else:
image['status'] = 'unmatched'
else:
for image in self.images:
image['status'] = 'matched'
def filter_images(self):
"""Filter which images to build."""
filter_ = list()
if self.regex:
filter_ += self.regex
elif self.conf.profile:
for profile in self.conf.profile:
if profile not in self.conf.profiles:
self.conf.register_opt(cfg.ListOpt(profile,
default=[]),
'profiles')
if len(self.conf.profiles[profile]) == 0:
msg = 'Profile: {} does not exist'.format(profile)
raise ValueError(msg)
else:
filter_ += self.conf.profiles[profile]
if filter_:
patterns = re.compile(r"|".join(filter_).join('()'))
for image in self.images:
if image.status in (STATUS_MATCHED, STATUS_SKIPPED):
continue
if re.search(patterns, image.name):
image.status = STATUS_MATCHED
while (image.parent is not None and
image.parent.status not in (STATUS_MATCHED,
STATUS_SKIPPED)):
image = image.parent
if self.conf.skip_parents:
image.status = STATUS_SKIPPED
elif (self.conf.skip_existing and
image.in_docker_cache()):
image.status = STATUS_SKIPPED
else:
image.status = STATUS_MATCHED
LOG.debug('Image %s matched regex', image.name)
else:
image.status = STATUS_UNMATCHED
else:
for image in self.images:
image.status = STATUS_MATCHED