Return a dict of ceph pools from a single ceph unit, with
        pool name as keys, pool id as vals.
166809
def get_ceph_pools(self, sentry_unit):
        """"""
        pools = {}
        cmd = 'sudo ceph osd lspools'
        output, code = sentry_unit.run(cmd)
        if code != 0:
            msg = ('{} `{}` returned {} '
                   '{}'.format(sentry_unit.info['unit_name'],
                               cmd, code, output))
            amulet.raise_status(amulet.FAIL, msg=msg)

        # For mimic ceph osd lspools output
        output = output.replace("\n", ",")

        # Example output: 0 data,1 metadata,2 rbd,3 cinder,4 glance,
        for pool in str(output).split(','):
            pool_id_name = pool.split(' ')
            if len(pool_id_name) == 2:
                pool_id = pool_id_name[0]
                pool_name = pool_id_name[1]
                pools[pool_name] = int(pool_id)

        self.log.debug('Pools on {}: {}'.format(sentry_unit.info['unit_name'],
                                                pools))
        return pools
1191601
def from_dict(cls, eas_from_nios):
        """"""
        if not eas_from_nios:
            return
        return cls({name: cls._process_value(ib_utils.try_value_to_bool,
                                             eas_from_nios[name]['value'])
                    for name in eas_from_nios})
440007
def _keyring_equivalent(keyring_one, keyring_two):
    
    def keyring_extract_key(file_path):
        """
        Cephx keyring files may or may not have white space before some lines.
        They may have some values in quotes, so a safe way to compare is to
        extract the key.
        """
        with open(file_path) as f:
            for line in f:
                content = line.strip()
                if len(content) == 0:
                    continue
                split_line = content.split('=')
                if split_line[0].strip() == 'key':
                    return "=".join(split_line[1:]).strip()
        raise RuntimeError("File '%s' is not a keyring" % file_path)
    key_one = keyring_extract_key(keyring_one)
    key_two = keyring_extract_key(keyring_two)
    return key_one == key_two
501703
def from_dict(cls, d):
        
        return Dos(d["efermi"], d["energies"],
                   {Spin(int(k)): v
                    for k, v in d["densities"].items()})
293735
def as_dict(self):
        """"""
        d = {"comment": self.comment, "nkpoints": self.num_kpts,
             "generation_style": self.style.name, "kpoints": self.kpts,
             "usershift": self.kpts_shift,
             "kpts_weights": self.kpts_weights, "coord_type": self.coord_type,
             "labels": self.labels, "tet_number": self.tet_number,
             "tet_weight": self.tet_weight,
             "tet_connections": self.tet_connections}

        optional_paras = ["genvec1", "genvec2", "genvec3", "shift"]
        for para in optional_paras:
            if para in self.__dict__:
                d[para] = self.__dict__[para]
        d["@module"] = self.__class__.__module__
        d["@class"] = self.__class__.__name__
        return d
372375
def fields_from_dict(d):
        """"""
        class_container = FieldsContainer.class_container
        fields = [field_cls.from_dict(field_dict) 
                  for field_cls, container in class_container.iteritems()
                  for field_dict in d.get(container, [])]
        return fields
152539
def get_keys(self, key=None):
        
        if key:
            value = _lxc.Container.get_keys(self, key)
        else:
            value = _lxc.Container.get_keys(self)

        if value is False:
            return False
        elif value.endswith("\n"):
            return value.rstrip("\n").split("\n")
        else:
            return value
982440
def pool_list(call=None):
    '''
    

    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'This function must be called with -f, --function argument.'
        )
    ret = {}
    session = _get_session()
    pools = session.xenapi.pool.get_all()
    for pool in pools:
        pool_record = session.xenapi.pool.get_record(pool)
        ret[pool_record['name_label']] = pool_record
    return ret
77282
def get_single_key(d):
    """"""
    assert len(d) == 1, 'Single-item dict must have just one item, not %d.' % len(d)
    return next(six.iterkeys(d))
713866
def _map_dict_keys_to_model_attributes(model_type, model_dict):
    

    new_dict = {}
    for key, value in model_dict.items():
        new_dict[_get_k8s_model_attribute(model_type, key)] = value

    return new_dict
1214778
def from_dict(self, description):
        """"""
        assert(self.ident == description['ident'])
        self.partitions = description['partitions']
        self.indices    = description['indices']
871453
def from_dict(cls, pwinput_dict):
        
        pwinput = cls(structure=Structure.from_dict(pwinput_dict['structure']),
                          pseudo=pwinput_dict['pseudo'],
                          control=pwinput_dict['sections']['control'],
                          system=pwinput_dict['sections']['system'],
                          electrons=pwinput_dict['sections']['electrons'],
                          ions=pwinput_dict['sections']['ions'],
                          cell=pwinput_dict['sections']['cell'],
                          kpoints_mode=pwinput_dict['kpoints_mode'],
                          kpoints_grid=pwinput_dict['kpoints_grid'],
                          kpoints_shift=pwinput_dict['kpoints_shift'])
        return pwinput
563186
def _getAdditionalSpecs(poolerClass=_getDefaultPoolerClass(), poolerType="union"):
  
  typeNames = {int: "UInt32", float: "Real32", str: "Byte", bool: "bool",
               tuple: "tuple"}

  def getArgType(arg):
    t = typeNames.get(type(arg), "Byte")
    count = 0 if t == "Byte" else 1
    if t == "tuple":
      t = typeNames.get(type(arg[0]), "Byte")
      count = len(arg)
    if t == "bool":
      t = "UInt32"
    return (t, count)

  def getConstraints(arg):
    t = typeNames.get(type(arg), "Byte")
    if t == "Byte":
      return "multiple"
    elif t == "bool":
      return "bool"
    else:
      return ""

  # Get arguments from pooler constructors, figure out types of
  # variables and populate poolerSpec.
  pArgTuples = _buildArgs(poolerClass)
  poolerSpec = {}
  for argTuple in pArgTuples:
    d = dict(
      description=argTuple[1],
      accessMode="ReadWrite",
      dataType=getArgType(argTuple[2])[0],
      count=getArgType(argTuple[2])[1],
      constraints=getConstraints(argTuple[2]))
    poolerSpec[argTuple[0]] = d

  # Get arguments from spatial pooler constructors, figure out types of
  # variables and populate poolerSpec.
  # This allows setting SP parameters
  pArgTuples = _buildArgs(_getParentSpatialPoolerClass(poolerType))
  for argTuple in pArgTuples:
    d = dict(
      description=argTuple[1],
      accessMode="ReadWrite",
      dataType=getArgType(argTuple[2])[0],
      count=getArgType(argTuple[2])[1],
      constraints=getConstraints(argTuple[2]))
    poolerSpec[argTuple[0]] = d

  # Add special parameters that weren't handled automatically
  # Pooler parameters only
  poolerSpec.update(dict(
    columnCount=dict(
      description="Total number of columns (coincidences).",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints=""),

    inputWidth=dict(
      description="Size of inputs to the UP.",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints=""),

    historyLength=dict(
      description="The union window length",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints=""),

    minHistory=dict(
      description="don't perform union (output all zeros) until buffer"
                  " length >= minHistory",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints=""),

     poolerType=dict(
      description="Type of pooler to use: union",
      accessMode="ReadWrite",
      dataType="Byte",
      count=0,
      constraints="enum: union"),
     ))


  # The last group is for parameters that aren't specific to pooler
  otherSpec = dict(
    learningMode=dict(
      description="1 if the node is learning (default 1).",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints="bool"),

    inferenceMode=dict(
      description="1 if the node outputs current inference (default 1).",
      accessMode="ReadWrite",
      dataType="UInt32",
      count=1,
      constraints="bool"),



  )

  return poolerSpec, otherSpec
1294438
def to_dict(self, get_value=None):
        """"""
        self.trim()
        result = {}
        for key, value in iteritems(self.counters):
            if get_value is not None:
                value = getattr(value, get_value)
            r = result
            for _key in key[:-1]:
                r = r.setdefault(_key, {})
            r[key[-1]] = value
        return result
1164030
def from_dict(cls, parm, pool = None):
        

        if pool is None:
            pool = Pool()

        pool.id = parm['id']
        pool.name = parm['name']
        pool.description = parm['description']
        pool.default_type = parm['default_type']
        pool.ipv4_default_prefix_length = parm['ipv4_default_prefix_length']
        pool.ipv6_default_prefix_length = parm['ipv6_default_prefix_length']
        for val in ('member_prefixes_v4', 'member_prefixes_v6',
                'used_prefixes_v4', 'used_prefixes_v6', 'free_prefixes_v4',
                'free_prefixes_v6', 'total_prefixes_v4', 'total_prefixes_v6',
                'total_addresses_v4', 'total_addresses_v6', 'used_addresses_v4',
                'used_addresses_v6', 'free_addresses_v4', 'free_addresses_v6'):
            if parm[val] is not None:
                setattr(pool, val, int(parm[val]))

        pool.tags = {}
        for tag_name in parm['tags']:
            tag = Tag.from_dict({'name': tag_name })
            pool.tags[tag_name] = tag

        pool.avps = parm['avps']

        # store VRF object in pool.vrf
        if parm['vrf_id'] is not None:
            pool.vrf = VRF.get(parm['vrf_id'])

        return pool
554115
def _read_info_as_dict(fid, values):
    
    output = {}
    for key, fmt in values:
        val = unpack(fmt, fid.read(calcsize(fmt)))
        if len(val) == 1:
            output[key] = val[0]
        else:
            output[key] = val
    return output
133540
def keys(self, index=None):
        
        if index is not None and index not in self._indexes:
            raise ValueError('Index {} does not exist'.format(index))

        db = self._indexes[index][0] if index else self._main_db
        with self._lmdb.begin(db=db) as txn:
            return [
                key.decode()
                for key in txn.cursor().iternext(keys=True, values=False)
            ]