Retrieve a dict containing Cassandra client config params.
17882
def _get_cassandra_config(self):
        """"""
        parts = urlsplit(os.environ.get('CASSANDRA_URI', DEFAULT_URI))
        if parts.scheme != 'cassandra':
            raise RuntimeError(
                'CASSANDRA_URI scheme is not "cassandra://"!')

        _, _, ip_addresses = socket.gethostbyname_ex(parts.hostname)
        if not ip_addresses:
            raise RuntimeError('Unable to find Cassandra in DNS!')

        return {
            'contact_points': ip_addresses,
            'port': parts.port or DEFAULT_PORT,
        }
1063769
def _get_api_params(api_url=None,
                    api_version=None,
                    api_key=None):
    '''
    
    '''
    mandrill_cfg = __salt__['config.merge']('mandrill')
    if not mandrill_cfg:
        mandrill_cfg = {}
    return {
        'api_url': api_url or mandrill_cfg.get('api_url') or BASE_URL,  # optional
        'api_key': api_key or mandrill_cfg.get('key'),  # mandatory
        'api_version': api_version or mandrill_cfg.get('api_version') or DEFAULT_VERSION
    }
1159482
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self,
                   'configuration_id') and self.configuration_id is not None:
            _dict['configuration_id'] = self.configuration_id
        if hasattr(self, 'status') and self.status is not None:
            _dict['status'] = self.status
        if hasattr(self, 'notices') and self.notices is not None:
            _dict['notices'] = [x._to_dict() for x in self.notices]
        return _dict
261455
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'credential_id') and self.credential_id is not None:
            _dict['credential_id'] = self.credential_id
        if hasattr(self, 'source_type') and self.source_type is not None:
            _dict['source_type'] = self.source_type
        if hasattr(
                self,
                'credential_details') and self.credential_details is not None:
            _dict['credential_details'] = self.credential_details._to_dict()
        return _dict
1297202
def config_dict(config):
    
    return dict(
        (key, getattr(config, key))
        for key in config.values
    )
1111618
def get_api_params(self):
        
        result = self.params
        if type(result) != dict:
            raise ValueError(
                '{}.params should return dictionary'.format(
                    self.__class__.__name__
                )
            )
        return result
86987
protected List<ColumnDef> getColumnMetadata(Cassandra.Client client)
            throws InvalidRequestException,
            UnavailableException,
            TimedOutException,
            SchemaDisagreementException,
            TException,
            CharacterCodingException,
            org.apache.cassandra.exceptions.InvalidRequestException,
            ConfigurationException,
            NotFoundException
    {
        List<ColumnDef> keyColumns = null;
        // get key columns
        try
        {
            keyColumns = getKeysMeta(client);
        }
        catch(Exception e)
        {
            logger.error("Error in retrieving key columns" , e);
        }

        // get other columns
        List<ColumnDef> columns = getColumnMeta(client, false, !hasCompactValueAlias);

        // combine all columns in a list
        if (keyColumns != null && columns != null)
            keyColumns.addAll(columns);

        return keyColumns;
    }
774301
def _recurse_config_to_dict(t_data):
    '''
    
    '''
    if not isinstance(t_data, type(None)):
        if isinstance(t_data, list):
            t_list = []
            for i in t_data:
                t_list.append(_recurse_config_to_dict(i))
            return t_list
        elif isinstance(t_data, dict):
            t_dict = {}
            for k, v in six.iteritems(t_data):
                t_dict[k] = _recurse_config_to_dict(v)
            return t_dict
        else:
            if hasattr(t_data, '__dict__'):
                return _recurse_config_to_dict(t_data.__dict__)
            else:
                return _serializer(t_data)
328819
def get_config_dict(self):
        
        config_dict = {}
        for dotted_key, value in self.get_config_values().items():
            subkeys = dotted_key.split('.')
            d = config_dict
            for key in subkeys:
                d = d.setdefault(key, value if key == subkeys[-1] else {})
        return config_dict
1241844
def get_params(self):
        
        return odict([(key,param.value) for key,param in self.params.items()])
317654
def to_dict(self):
        
        return dict((parameter.name, parameter.value) for parameter in self.values())
672629
def GetClientConfig(filename):
  """"""
  config_lib.SetPlatformArchContext()
  config_lib.ParseConfigCommandLine()
  context = list(grr_config.CONFIG.context)
  context.append("Client Context")
  deployer = build.ClientRepacker()
  # Disable timestamping so we can get a reproducible and cachable config file.
  config_data = deployer.GetClientConfig(
      context, validate=True, deploy_timestamp=False)
  builder = build.ClientBuilder()
  with open(filename, "w") as fd:
    fd.write(config_data)
    builder.WriteBuildYaml(fd, build_timestamp=False)
1323912
def config_param(self, conf_alias, param):
        
        data = self.data_get(conf_alias)
        flat_cache = self.__data_get_flatten_cache.get(conf_alias)
        if flat_cache is None:
            flat_cache = self.__flatten_dict(data, '', '.')
            self.__data_get_flatten_cache[conf_alias] = flat_cache
        if param not in flat_cache:
            raise KeyError("Key not found: " + conf_alias)
        return flat_cache.get(param)
244080
def get_parameters(self):
        """"""
        d = {}
        for p in self.processors:
            parameter_names = list(p.PARAMETERS.keys())
            parameter_values = [getattr(p, n) for n in parameter_names]
            d.update(dict(zip(parameter_names, parameter_values)))
        return d
319866
def MultiReadClientMetadata(self, client_ids, cursor=None):
    """"""
    ids = [db_utils.ClientIDToInt(client_id) for client_id in client_ids]
    query = ("SELECT client_id, fleetspeak_enabled, certificate, "
             "UNIX_TIMESTAMP(last_ping), "
             "UNIX_TIMESTAMP(last_clock), last_ip, "
             "UNIX_TIMESTAMP(last_foreman), UNIX_TIMESTAMP(first_seen), "
             "UNIX_TIMESTAMP(last_crash_timestamp), "
             "UNIX_TIMESTAMP(last_startup_timestamp) FROM "
             "clients WHERE client_id IN ({})").format(", ".join(["%s"] *
                                                                 len(ids)))
    ret = {}
    cursor.execute(query, ids)
    while True:
      row = cursor.fetchone()
      if not row:
        break
      cid, fs, crt, ping, clk, ip, foreman, first, lct, lst = row
      ret[db_utils.IntToClientID(cid)] = rdf_objects.ClientMetadata(
          certificate=crt,
          fleetspeak_enabled=fs,
          first_seen=mysql_utils.TimestampToRDFDatetime(first),
          ping=mysql_utils.TimestampToRDFDatetime(ping),
          clock=mysql_utils.TimestampToRDFDatetime(clk),
          ip=mysql_utils.StringToRDFProto(rdf_client_network.NetworkAddress,
                                          ip),
          last_foreman_time=mysql_utils.TimestampToRDFDatetime(foreman),
          startup_info_timestamp=mysql_utils.TimestampToRDFDatetime(lst),
          last_crash_timestamp=mysql_utils.TimestampToRDFDatetime(lct))
    return ret
581591
def MultiReadClientMetadata(self, client_ids):
    """"""
    res = {}
    for client_id in client_ids:
      md = self.metadatas.get(client_id, None)
      if md is None:
        continue

      res[client_id] = rdf_objects.ClientMetadata(
          certificate=md.get("certificate"),
          fleetspeak_enabled=md.get("fleetspeak_enabled"),
          first_seen=md.get("first_seen"),
          ping=md.get("ping"),
          clock=md.get("clock"),
          ip=md.get("ip"),
          last_foreman_time=md.get("last_foreman_time"),
          last_crash_timestamp=md.get("last_crash_timestamp"),
          startup_info_timestamp=md.get("startup_info_timestamp"))

    return res
628500
def get_configuration_dict(self, secret_attrs=False):
        """"""
        rd = {'name': self.name,
              'path': self.path,
              'git_dir': self.git_dir,
              'assumed_doc_version': self.assumed_doc_version,
              'doc_dir': self.doc_dir,
              'git_ssh': self.git_ssh, }
        if secret_attrs:
            rd['pkey'] = self.pkey
        with self._index_lock:
            si = self._doc_index
        r = _invert_dict_list_val(si)
        key_list = list(r.keys())
        rd['number of documents'] = len(key_list)
        key_list.sort()
        m = []
        for k in key_list:
            v = r[k]
            fp = k[2]
            assert fp.startswith(self.doc_dir)
            rp = fp[len(self.doc_dir) + 1:]
            m.append({'keys': v, 'relpath': rp})
        rd['documents'] = m
        return rd