def _check_ug(self): (user, group) = self._get_apache_user_group() if not sh.user_exists(user): msg = "No user named %r exists on this system!" % (user) raise excp.ConfigException(msg) if not sh.group_exists(group): msg = "No group named %r exists on this system!" % (group) raise excp.ConfigException(msg) if user in BAD_APACHE_USERS: msg = ("You may want to adjust your configuration, " "(user=%s, group=%s) will not work with apache!" % (user, group)) raise excp.ConfigException(msg)
def load(path, distros_patch=None): """Load configuration for all distros found in path. :param path: path containing distro configuration in yaml format :param distros_patch: distros file patch, jsonpath format (rfc6902) """ distro_possibles = [] patch = jsonpatch.JsonPatch(distros_patch) if distros_patch else None input_files = glob.glob(sh.joinpths(path, '*.yaml')) if not input_files: raise excp.ConfigException( 'Did not find any distro definition files in %r' % path) for fn in input_files: LOG.debug("Attempting to load distro definition from %r", fn) try: cls_kvs = utils.load_yaml(fn) # Apply any user specified patches to distros file if patch: patch.apply(cls_kvs, in_place=True) except Exception as err: LOG.warning('Could not load distro definition from %r: %s', fn, err) else: if 'name' not in cls_kvs: name, _ext = os.path.splitext(sh.basename(fn)) cls_kvs['name'] = name distro_possibles.append(Distro(**cls_kvs)) matches = _match_distros(distro_possibles) LOG.debug("Matched distros %s", [m.name for m in matches]) return matches
def verify(self): # Do a little check to make sure actually have that interface/s public_interface = self.installer.get_option('public_interface') vlan_interface = self.installer.get_option('vlan_interface', default_value=public_interface) known_interfaces = utils.get_interfaces() if public_interface not in known_interfaces: msg = "Public interface %r is not a known interface (is it one of %s??)" % (public_interface, ", ".join(known_interfaces)) raise exceptions.ConfigException(msg) if vlan_interface not in known_interfaces: msg = "VLAN interface %r is not a known interface (is it one of %s??)" % (vlan_interface, ", ".join(known_interfaces)) raise exceptions.ConfigException(msg) # Driver specific interface checks drive_canon = utils.canon_virt_driver(self.installer.get_option('virt_driver')) if drive_canon == 'libvirt': flat_interface = self.installer.get_option('flat_interface') if flat_interface and flat_interface not in known_interfaces: msg = "Libvirt flat interface %s is not a known interface (is it one of %s??)" % (flat_interface, ", ".join(known_interfaces)) raise exceptions.ConfigException(msg)
def _match_distros(distros): plts = _get_platform_names() matches = [] for d in distros: if any(d.supports_platform(plt) for plt in plts): matches.append(d) if not matches: raise excp.ConfigException('No distro matched for platform %s' % plts) else: return matches
def __init__(self, uri, dst, **kwargs): Downloader.__init__(self, uri, dst) self._branch = self._get_string_from_dict(kwargs, 'branch') self._tag = self._get_string_from_dict(kwargs, 'tag') self._sha1 = self._get_string_from_dict(kwargs, 'sha1') self._refspec = self._get_string_from_dict(kwargs, 'refspec') git_sources = len([a for a in (self._tag, self._sha1, self._branch) if a]) if git_sources > 1: raise exceptions.ConfigException('Too many sources. Please, ' 'specify only one of tag/SHA1/branch.') if not git_sources: self._branch = 'master'
def setup_rpc(self, conf, rpc_backends=None, mq_type=None): # How is your message queue setup? if not mq_type: raw_mq_type = self.installer.get_option('mq-type') if raw_mq_type: mq_type = utils.canon_mq_type(raw_mq_type) if not mq_type: msg = ("%s requires a message queue to operate. " "Please specify a 'mq-type' in configuration." % self.installer.name.title()) raise exceptions.ConfigException(msg) if rpc_backends is not None: try: conf.add('rpc_backend', rpc_backends[mq_type]) except KeyError: msg = ("%s does not support mq type %s." % (self.installer.name.title(), mq_type)) raise exceptions.ConfigException(msg) if mq_type == 'rabbit': conf.add( 'rabbit_host', self.installer.get_option( 'rabbit', 'host', default_value=self.installer.get_option('ip'))) conf.add('rabbit_password', self.installer.get_password('rabbit')) conf.add('rabbit_userid', self.installer.get_option('rabbit', 'user_id')) elif mq_type == 'qpid': conf.add( 'qpid_hostname', self.installer.get_option( 'qpid', 'host', default_value=self.installer.get_option('ip'))) conf.add('qpid_password', self.installer.get_password('qpid')) conf.add('qpid_username', self.installer.get_option('qpid', 'user_id'))
def _match_distro(distros): plt = platform.platform() distro_matched = None for d in distros: if d.supports_platform(plt): distro_matched = d break if not distro_matched: raise excp.ConfigException('No distro matched for platform %r' % plt) else: LOG.info('Matched distro %s for platform %s', colorizer.quote(distro_matched.name), colorizer.quote(plt)) return distro_matched
def load(path): distro_possibles = [] input_files = glob.glob(sh.joinpths(path, '*.yaml')) if not input_files: raise excp.ConfigException( 'Did not find any distro definition files in %r' % path) for fn in input_files: LOG.debug("Attempting to load distro definition from %r", fn) try: cls_kvs = utils.load_yaml(fn) except Exception as err: LOG.warning('Could not load distro definition from %r: %s', fn, err) distro_possibles.append(Distro(**cls_kvs)) return _match_distro(distro_possibles)
def load(path): distro_possibles = [] input_files = glob.glob(sh.joinpths(path, '*.yaml')) if not input_files: raise excp.ConfigException('Did not find any distro definition files in %r' % path) for fn in input_files: LOG.debug("Attempting to load distro definition from %r", fn) try: # Don't use sh here so that we always # read this (even if dry-run) with open(fn, 'r') as fh: contents = fh.read() cls_kvs = yaml.safe_load(contents) distro_possibles.append(Distro(**cls_kvs)) except (IOError, yaml.YAMLError) as err: LOG.warning('Could not load distro definition from %r: %s', fn, err) return _match_distro(distro_possibles)
def get_interpolated_option(self, option, default_value=None): tried = [option] while True: option_value = utils.get_deep(self.options, [option]) if option_value is None: return default_value else: if not isinstance(option_value, six.string_types): return option_value if option_value.startswith("$"): maybe_option = option_value[1:] if maybe_option in tried: tried.append(maybe_option) raise excp.ConfigException("Option loop %s detected" % tried) else: tried.append(maybe_option) option = maybe_option else: return option_value