Get or create the keyring from the mon using the mon keyring by keytype and
    copy to dest_dir
516893
def gatherkeys_missing(args, distro, rlogger, keypath, keytype, dest_dir):
    
    args_prefix = [
        '/usr/bin/ceph',
        '--connect-timeout=25',
        '--cluster={cluster}'.format(
            cluster=args.cluster),
        '--name', 'mon.',
        '--keyring={keypath}'.format(
            keypath=keypath),
        ]

    identity = keytype_identity(keytype)
    if identity is None:
        raise RuntimeError('Could not find identity for keytype:%s' % keytype)
    capabilites = keytype_capabilities(keytype)
    if capabilites is None:
        raise RuntimeError('Could not find capabilites for keytype:%s' % keytype)

    # First try getting the key if it already exists, to handle the case where
    # it exists but doesn't match the caps we would pass into get-or-create.
    # This is the same behvaior as in newer ceph-create-keys
    out, err, code = remoto.process.check(
        distro.conn,
        args_prefix + ['auth', 'get', identity]
        )
    if code == errno.ENOENT:
        out, err, code = remoto.process.check(
            distro.conn,
            args_prefix + ['auth', 'get-or-create', identity] + capabilites
            )
    if code != 0:
        rlogger.error(
            '"ceph auth get-or-create for keytype %s returned %s',
            keytype, code
        )
        for line in err:
            rlogger.debug(line)
        return False
    keyring_name_local = keytype_path_to(args, keytype)
    keyring_path_local = os.path.join(dest_dir, keyring_name_local)
    with open(keyring_path_local, 'wb') as f:
        for line in out:
            f.write(line + b'\n')
    return True
1365277
def create_keytab(name, keytab, enctypes=None):
    '''
    
    '''
    ret = {}

    krb_cmd = 'ktadd -k {0}'.format(keytab)

    if enctypes:
        krb_cmd += ' -e {0}'.format(enctypes)

    krb_cmd += ' {0}'.format(name)

    cmd = __execute_kadmin(krb_cmd)

    if cmd['retcode'] != 0 or cmd['stderr']:
        ret['comment'] = cmd['stderr'].splitlines()[-1]
        ret['result'] = False

        return ret

    return True
4187
def get_key(self, fileobj):
        
        mapping = self.get_map()
        if mapping is None:
            raise RuntimeError("Selector is closed")
        try:
            return mapping[fileobj]
        except KeyError:
            raise KeyError("{0!r} is not registered".format(fileobj))
843040
def gatherkeys(args):
    
    oldmask = os.umask(0o77)
    try:
        try:
            tmpd = tempfile.mkdtemp()
            LOG.info("Storing keys in temp directory %s", tmpd)
            sucess = False
            for host in args.mon:
                sucess = gatherkeys_with_mon(args, host, tmpd)
                if sucess:
                    break
            if not sucess:
                LOG.error("Failed to connect to host:%s" ,', '.join(args.mon))
                raise RuntimeError('Failed to connect any mon')
            had_error = False
            date_string = time.strftime("%Y%m%d%H%M%S")
            for keytype in ["admin", "mds", "mgr", "mon", "osd", "rgw"]:
                filename = keytype_path_to(args, keytype)
                tmp_path = os.path.join(tmpd, filename)
                if not os.path.exists(tmp_path):
                    LOG.error("No key retrived for '%s'" , keytype)
                    had_error = True
                    continue
                if not os.path.exists(filename):
                    LOG.info("Storing %s" % (filename))
                    shutil.move(tmp_path, filename)
                    continue
                if _keyring_equivalent(tmp_path, filename):
                    LOG.info("keyring '%s' already exists" , filename)
                    continue
                backup_keyring = "%s-%s" % (filename, date_string)
                LOG.info("Replacing '%s' and backing up old key as '%s'", filename, backup_keyring)
                shutil.copy(filename, backup_keyring)
                shutil.move(tmp_path, filename)
            if had_error:
                raise RuntimeError('Failed to get all key types')
        finally:
            LOG.info("Destroy temp directory %s" %(tmpd))
            shutil.rmtree(tmpd)
    finally:
        os.umask(oldmask)
187047
def from_key(cls, *args):
        
        key = args if len(args) > 1 else args[0]
        return cls._instances.get(key, None)
1327021
def _get_auth_from_keyring(self):
        """"""
        if not keyring:
            return None

        # Take user from URL if available, else the OS login name
        password = self._get_password_from_keyring(self.user or getpass.getuser())
        if password is not None:
            self.user = self.user or getpass.getuser()
            self.password = password

        return 'keyring'
1199598
def from_dict(val, onts, mdb_safe=False):
    
    if isinstance(val, dict):
        if "__class__" in val:
            ns, typ = val["__class__"].split("&")
            cls = getattr(onts[ns], typ)
            if cls is md.Extensions:
                lv = []
                for key, ditems in val.items():
                    if key in EXP_SKIP:
                        continue
                    for item in ditems:
                        ns, typ = item["__class__"].split("&")
                        cls = getattr(onts[ns], typ)
                        kwargs = _kwa(item, onts, mdb_safe)
                        inst = cls(**kwargs)
                        lv.append(element_to_extension_element(inst))
                return lv
            else:
                kwargs = _kwa(val, onts, mdb_safe)
                inst = cls(**kwargs)
            return inst
        else:
            res = {}
            for key, v in val.items():
                if mdb_safe:
                    key = key.replace("__", ".")
                res[key] = from_dict(v, onts)
            return res
    elif isinstance(val, six.string_types):
        return val
    elif isinstance(val, list):
        return [from_dict(v, onts) for v in val]
    else:
        return val
1305499
def get_deep_attr(obj, keys):
    
    cur = obj
    for k in keys:
        if isinstance(cur, Mapping) and k in cur:
            cur = cur[k]
            continue
        else:
            try:
                cur = getattr(cur, k)
                continue
            except AttributeError:
                pass
        raise DataError(error='Unexistent key')
    return cur
651892
def fromkeys(cls, iterable, value, **kwargs):
        
        return cls(((k, value) for k in iterable), **kwargs)
917429
def fromkeys(cls, seq, value=None, **kwargs):
        
        other = cls(**kwargs)
        other.update(((key, value) for key in seq))

        return other
924799
def jsonify(o, max_depth=-1, parse_enums=PARSE_KEEP):
    
    if max_depth == 0:
        return o
    max_depth -= 1
    if isinstance(o, dict):
        keyattrs = getattr(o.__class__, '_altnames', {})

        def _getter(key, value):
            key = keyattrs.get(key, key)
            other = getattr(o, key, value)
            if callable(other):
                other = value
            if isinstance(key, Enum):  # Make sure we use a name as the key... if we don't it might mess some things up.
                key = key.name
            return key, jsonify(other, max_depth=max_depth, parse_enums=parse_enums)

        return dict(_getter(key, value) for key, value in six.iteritems(o))
    elif isinstance(o, list):
        return [jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o]
    elif isinstance(o, tuple):
        return (jsonify(x, max_depth=max_depth, parse_enums=parse_enums) for x in o)
    elif isinstance(o, Enum):
        o = _parse_enum(o, parse_enums=parse_enums)
    return o
228189
function copydir(from, to, options, callback) {
  if (typeof options === 'function') {
    if(!callback) {
      callback = options;
      options = {};
    }
    options = {
      filter: options
    };
  }
  if(typeof callback !== 'function') {
    callback = function() {};
  }
  if(typeof options.cover === 'undefined') {
    options.cover = true;
  }
  options.filter = typeof options.filter === 'function' ? options.filter : function(state, filepath, filename) {
    return options.filter;
  };
  fs.lstat(from, function(err, stats) {
    if (err) {
      callback(err);
    } else {
      var statsname = stats.isDirectory() ? 'directory' :
        stats.isFile() ? 'file' :
        stats.isSymbolicLink() ? 'symbolicLink' :
        '';
      var valid = options.filter(statsname, from, path.dirname(from), path.basename(from));
      if (statsname === 'directory' || statsname === 'symbolicLink') {
        // Directory or SymbolicLink
        if(valid) {
          fs.stat(to, function(err) {
            if(err) {
              if(err.code === 'ENOENT') {
                fs.mkdir(to, function(err) {
                  if(err) {
                    callback(err);
                  } else {
                    options.debug && console.log('>> ' + to);
                    rewrite(to, options, stats, function(err) {
                      if(err) {
                        callback(err);
                      } else {
                        listDirectory(from, to, options, callback);
                      }
                    });
                  }
                });
              } else {
                callback(err);
              }
            } else {
              rewrite(to, options, stats, function(err) {
                if(err) {
                  callback(err);
                } else {
                  listDirectory(from, to, options, callback);
                }
              });
            }
          });
        } else {
          callback();
        }
      } else if(stats.isFile()) {
        // File
        if(valid) {
          if(options.cover) {
            writeFile(from, to, options, stats, callback);
          } else {
            fs.stat(to, function(err) {
              if(err) {
                if(err.code === 'ENOENT') {
                  writeFile(from, to, options, stats, callback);
                } else {
                  callback(err);
                }
              } else {
                callback();
              }
            });
          }
        } else {
          callback();
        }
      } else {
        callback(new Error('stats invalid: '+ from));
      }
    }
  });
}
1123169
function keyname(str) {
  return path.basename(path.normalize(str), path.extname(str));
}
365021
def get(key, default=-1):
        """"""
        if isinstance(key, int):
            return TOS_DEL(key)
        if key not in TOS_DEL._member_map_:
            extend_enum(TOS_DEL, key, default)
        return TOS_DEL[key]
471177
def from_text(textring):
    """"""

    keyring = {}
    for keytext in textring:
        keyname = dns.name.from_text(keytext)
        secret = base64.decodestring(textring[keytext])
        keyring[keyname] = secret
    return keyring
865174
def from_dict(self, d):
        

        if 'uid' in d:
            if d['uid']:
                self._uid = d['uid']

        if 'name' in d:
            if d['name']:
                self._name = d['name']

        if 'state' in d:
            if isinstance(d['state'], str) or isinstance(d['state'], unicode):
                self._state = d['state']
            else:
                raise TypeError(entity='state', expected_type=str,
                                actual_type=type(d['state']))
        else:
            self._state = states.INITIAL

        if 'state_history' in d:
            if isinstance(d['state_history'], list):
                self._state_history = d['state_history']
            else:
                raise TypeError(entity='state_history', expected_type=list, actual_type=type(
                    d['state_history']))

        if 'pre_exec' in d:
            if isinstance(d['pre_exec'], list):
                self._pre_exec = d['pre_exec']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['pre_exec']))

        if 'executable' in d:
            if isinstance(d['executable'], str) or isinstance(d['executable'], unicode):
                self._executable = d['executable']
            else:
                raise TypeError(expected_type=str,
                                actual_type=type(d['executable']))

        if 'arguments' in d:
            if isinstance(d['arguments'], list):
                self._arguments = d['arguments']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['arguments']))

        if 'post_exec' in d:
            if isinstance(d['post_exec'], list):
                self._post_exec = d['post_exec']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['post_exec']))

        if 'cpu_reqs' in d:
            if isinstance(d['cpu_reqs'], dict):
                self._cpu_reqs = d['cpu_reqs']
            else:
                raise TypeError(expected_type=dict,
                                actual_type=type(d['cpu_reqs']))

        if 'gpu_reqs' in d:
            if isinstance(d['gpu_reqs'], dict):
                self._gpu_reqs = d['gpu_reqs']
            else:
                raise TypeError(expected_type=dict,
                                actual_type=type(d['gpu_reqs']))

        if 'lfs_per_process' in d:
            if d['lfs_per_process']:
                if isinstance(d['lfs_per_process'], int):
                    self._lfs_per_process = d['lfs_per_process']
                else:
                    raise TypeError(expected_type=int,
                                    actual_type=type(d['lfs_per_process']))

        if 'upload_input_data' in d:
            if isinstance(d['upload_input_data'], list):
                self._upload_input_data = d['upload_input_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['upload_input_data']))

        if 'copy_input_data' in d:
            if isinstance(d['copy_input_data'], list):
                self._copy_input_data = d['copy_input_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['copy_input_data']))

        if 'link_input_data' in d:
            if isinstance(d['link_input_data'], list):
                self._link_input_data = d['link_input_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['link_input_data']))

        if 'move_input_data' in d:
            if isinstance(d['move_input_data'], list):
                self._move_input_data = d['move_input_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['move_input_data']))


        if 'copy_output_data' in d:
            if isinstance(d['copy_output_data'], list):
                self._copy_output_data = d['copy_output_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['copy_output_data']))

        if 'move_output_data' in d:
            if isinstance(d['move_output_data'], list):
                self._move_output_data = d['move_output_data']
            else:
                raise TypeError(expected_type=list,
                                actual_type=type(d['move_output_data']))

        if 'download_output_data' in d:
            if isinstance(d['download_output_data'], list):
                self._download_output_data = d['download_output_data']
            else:
                raise TypeError(expected_type=list, actual_type=type(
                    d['download_output_data']))

        if 'stdout' in d:
            if d['stdout']:
                if isinstance(d['stdout'], str) or isinstance(d['stdout'], unicode):
                    self._stdout = d['stdout']
                else:
                    raise TypeError(expected_type=str, actual_type=type(d['stdout']))

        if 'stderr' in d:
            if d['stderr']:
                if isinstance(d['stderr'], str) or isinstance(d['stderr'], unicode):
                    self._stderr = d['stderr']
                else:
                    raise TypeError(expected_type=str, actual_type=type(d['stderr']))

        if 'exit_code' in d:
            if d['exit_code']:
                if isinstance(d['exit_code'], int):
                    self._exit_code = d['exit_code']
                else:
                    raise TypeError(
                        entity='exit_code', expected_type=int, actual_type=type(d['exit_code']))

        if 'path' in d:
            if d['path']:
                if isinstance(d['path'], str) or isinstance(d['path'], unicode):
                    self._path = d['path']
                else:
                    raise TypeError(entity='path', expected_type=str,
                                    actual_type=type(d['path']))

        if 'tag' in d:
            if d['tag']:
                if isinstance(d['tag'], str) or isinstance(d['tag'], unicode):
                    self._tag = str(d['tag'])
                else:
                    raise TypeError(expected_type=str,
                                    actual_type=type(d['tag']))

        if 'parent_stage' in d:
            if isinstance(d['parent_stage'], dict):
                self._p_stage = d['parent_stage']
            else:
                raise TypeError(
                    entity='parent_stage', expected_type=dict, actual_type=type(d['parent_stage']))

        if 'parent_pipeline' in d:
            if isinstance(d['parent_pipeline'], dict):
                self._p_pipeline = d['parent_pipeline']
            else:
                raise TypeError(entity='parent_pipeline', expected_type=dict, actual_type=type(
                    d['parent_pipeline']))
24706
def value_for_keypath(obj, path):
    
    val = obj
    for part in path.split('.'):
        match = re.match(list_index_re, part)
        if match is not None:
            val = _extract(val, match.group(1))
            if not isinstance(val, list) and not isinstance(val, tuple):
                raise TypeError('expected list/tuple')
            index = int(match.group(2))
            val = val[index]
        else:
            val = _extract(val, part)
        if val is None:
            return None
    return val