Beispiel #1
0
 def _execute(cls, options, command, args, run_as_root=False,
              namespace=None, log_fail_as_error=True):
     opt_list = ['-%s' % o for o in options]
     ip_cmd = add_namespace_to_cmd(['ip'], namespace)
     cmd = ip_cmd + opt_list + [command] + list(args)
     return utils.execute(cmd, run_as_root=run_as_root,
                          log_fail_as_error=log_fail_as_error)
Beispiel #2
0
 def run_vsctl(self, args):
     full_args = ["ovs-vsctl"] + self.opts + args
     try:
         # We log our own errors, so never have utils.execute do it
         return utils.execute(full_args, run_as_root=True,
                              log_fail_as_error=False).rstrip()
     except Exception:
         with excutils.save_and_reraise_exception() as ctxt:
             if self.log_errors:
                 LOG.exception(("Unable to execute %(cmd)s."),
                               {'cmd': full_args})
             if not self.check_error:
                 ctxt.reraise = False
Beispiel #3
0
 def get_xapi_iface_id(self, xs_vif_uuid):
     args = [
         "xe", "vif-param-get", "param-name=other-config",
         "param-key=nicira-iface-id",
         "uuid=%s" % xs_vif_uuid
     ]
     try:
         return utils.execute(args, run_as_root=True).strip()
     except Exception as e:
         with excutils.save_and_reraise_exception():
             LOG.error(("Unable to execute %(cmd)s. "
                        "Exception: %(exception)s"), {
                            'cmd': args,
                            'exception': e
                        })
Beispiel #4
0
    def execute(self, cmds, addl_env=None, check_exit_code=True,
                log_fail_as_error=True, extra_ok_codes=None,
                run_as_root=False):
        ns_params = []
        kwargs = {'run_as_root': run_as_root}
        if self._parent.namespace:
            kwargs['run_as_root'] = True
            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()])
        cmd = ns_params + env_params + list(cmds)
        return utils.execute(cmd, check_exit_code=check_exit_code,
                             extra_ok_codes=extra_ok_codes,
                             log_fail_as_error=log_fail_as_error, **kwargs)
Beispiel #5
0
    def get_devices(self, exclude_loopback=False):
        retval = []
        if self.namespace:
            # we call out manually because in order to avoid screen scraping
            # iproute2 we use find to see what is in the sysfs directory, as
            # suggested by Stephen Hemminger (iproute2 dev).
            output = utils.execute(['ip', 'netns', 'exec', self.namespace,
                                    'find', SYS_NET_PATH, '-maxdepth', '1',
                                    '-type', 'l', '-printf', '%f '],
                                   run_as_root=True,
                                   log_fail_as_error=self.log_fail_as_error
                                   ).split()
        else:
            output = (
                i for i in os.listdir(SYS_NET_PATH)
                if os.path.islink(os.path.join(SYS_NET_PATH, i))
            )

        for name in output:
            if exclude_loopback and name == LOOPBACK_DEVNAME:
                continue
            retval.append(IPDevice(name, namespace=self.namespace))

        return retval
Beispiel #6
0
 def run_ofctl(self, cmd, args, process_input=None):
     full_args = ["ovs-ofctl", cmd, self.br_name] + args
     # TODO(kevinbenton): This error handling is really brittle and only
     # detects one specific type of failure. The callers of this need to
     # be refactored to expect errors so we can re-raise and they can
     # take appropriate action based on the type of error.
     for i in range(1, 11):
         try:
             return utils.execute(full_args,
                                  run_as_root=True,
                                  process_input=process_input)
         except Exception as e:
             if "failed to connect to socket" in str(e):
                 LOG.debug(
                     "Failed to connect to OVS. Retrying "
                     "in 1 second. Attempt: %s/10", i)
                 time.sleep(1)
                 continue
             LOG.error(("Unable to execute %(cmd)s. Exception: "
                        "%(exception)s"), {
                            'cmd': full_args,
                            'exception': e
                        })
             break
Beispiel #7
0
def iproute_arg_supported(command, arg):
    command += ['help']
    stdout, stderr = utils.execute(command, check_exit_code=False,
                                   return_stderr=True)
    return any(arg in line for line in stderr.split('\n'))