Beispiel #1
0
    def _as_root(self, options, command, args, use_root_namespace=False):
        if not self.root_helper:
            raise exceptions.SudoRequired()

        namespace = self.namespace if not use_root_namespace else None

        return self._execute(options, command, args, self.root_helper,
                             namespace)
Beispiel #2
0
    def execute(self, cmds, addl_env={}, check_exit_code=True):
        if not self._parent.root_helper:
            raise exceptions.SudoRequired()
        ns_params = []
        if self._parent.namespace:
            ns_params = ['ip', 'netns', 'exec', self._parent.namespace]

        env_params = []
        if addl_env:
            env_params = (['env'] +
                          ['%s=%s' % pair for pair in addl_env.items()])
        return utils.execute(ns_params + env_params + list(cmds),
                             root_helper=self._parent.root_helper,
                             check_exit_code=check_exit_code)
Beispiel #3
0
 def enforce_root_helper(self):
     if not self.root_helper and os.geteuid() != 0:
         raise exceptions.SudoRequired()