def dispatch(self, argv): if self.selector is None: yield namespace = get_option("--namespace", argv) if namespace is None: namespace = os.environ.get("OSVC_NAMESPACE") action = self.get_action(argv) if action in ("create", "deploy"): expanded_svcs = self.selector.split(",") elif action == "ls": from commands.svc.parser import SvcOptParser parser = SvcOptParser() expanded_svcs = None yield parser else: local = action == "boot" expanded_svcs = self.node.svcs_selector(self.selector, namespace, local=local) self.expanded_svcs = expanded_svcs if expanded_svcs is not None: svc_by_kind = self.dispatch_svcs(expanded_svcs) for kind, paths in svc_by_kind.items(): modname = "commands.{kind}.parser".format(kind=kind) mod = importlib.import_module(modname) parser = getattr(mod, kind.capitalize() + "OptParser")() yield parser
def dns_opts(args): if not self.svc.node.dns or "--dns" in args: return [] net = get_option("--net", args, boolean=False) if net and net.startswith("container:"): return [] if net == "host": return [] l = [] for dns in self.svc.node.dns: l += ["--dns", dns] for search in self.dns_search(): l += ["--dns-search", search] dns_options = [ o for o in get_options(self.dns_option_option, args) ] args = drop_option(self.dns_option_option, args, drop_value=True) for o in self.dns_options(dns_options): l += [self.dns_option_option, o] return l
def _add_run_args(self, errors="raise"): if self.run_args is None: args = [] else: args = [] + self.run_args args = drop_option("-d", args, drop_value=False) args = drop_option("--detach", args, drop_value=False) if self.detach: args += ["--detach"] # drop user specified --name. we set ours already args = drop_option("--name", args, drop_value=True) args = drop_option("-n", args, drop_value=True) args += ['--name=' + self.container_name] args += ['--label=' + self.container_label_id] args = drop_option("--hostname", args, drop_value=True) args = drop_option("-h", args, drop_value=True) if not self.netns or (self.netns != "host" and not self.netns.startswith("container#")): # only allow hostname setting if the container has a private netns if self.vm_hostname: args += ["--hostname", self.vm_hostname] elif not self.run_args: pass else: hostname = get_option("--hostname", self.run_args, boolean=False) if not hostname: hostname = get_option("-h", self.run_args, boolean=False) if hostname: args += ["--hostname", hostname] if self.entrypoint: args = drop_option("--entrypoint", args, drop_value=True) args += ["--entrypoint", self.entrypoint] if self.netns: args = drop_option("--net", args, drop_value=True) args = drop_option("--network", args, drop_value=True) if self.netns.startswith("container#"): res = self.svc.get_resource(self.netns) if res is not None: args += ["--net=container:" + res.container_name] elif errors == "raise": raise ex.Error( "resource %s, referenced in %s.netns, does not exist" % (self.netns, self.rid)) else: args += ["--net=" + self.netns] elif not has_option("--net", args): args += ["--net=" + self.default_net] if self.pidns: args = drop_option("--pid", args, drop_value=True) if self.pidns.startswith("container#"): res = self.svc.get_resource(self.netns) if res is not None: args += ["--pid=container:" + res.container_name] elif errors == "raise": raise ex.Error( "resource %s, referenced in %s.pidns, does not exist" % (self.pidns, self.rid)) else: args += ["--pid=" + self.pidns] if self.ipcns: args = drop_option("--ipc", args, drop_value=True) if self.ipcns.startswith("container#"): res = self.svc.get_resource(self.netns) if res is not None: args += ["--ipc=container:" + res.container_name] elif errors == "raise": raise ex.Error( "resource %s, referenced in %s.ipcns, does not exist" % (self.ipcns, self.rid)) else: args += ["--ipc=" + self.ipcns] if self.utsns == "host": args = drop_option("--uts", args, drop_value=True) args += ["--uts=host"] if self.userns is not None: args = drop_option("--userns", args, drop_value=True) if self.userns == "host": args += ["--userns=host"] if self.privileged is not None: args = drop_option("--privileged", args, drop_value=False) if self.privileged: args += ["--privileged"] if self.interactive is not None: args = drop_option("--interactive", args, drop_value=False) args = drop_option("-i", args, drop_value=False) if self.interactive: args += ["--interactive"] if self.tty is not None: args = drop_option("--tty", args, drop_value=False) args = drop_option("-t", args, drop_value=False) if self.tty: args += ["--tty"] drop_option("--rm", args, drop_value=False) drop_option("-v", args, drop_value=True) drop_option("--volume", args, drop_value=True) for vol in self.volume_options(errors=errors): args.append("--volume=%s" % vol) drop_option("--device", args, drop_value=True) for dev in self.device_options(errors=errors): args.append("--device=%s" % dev) args += self.cgroup_options() def dns_opts(args): if not self.svc.node.dns or "--dns" in args: return [] net = get_option("--net", args, boolean=False) if net and net.startswith("container:"): return [] if net == "host": return [] l = [] for dns in self.svc.node.dns: l += ["--dns", dns] for search in self.dns_search(): l += ["--dns-search", search] dns_options = [ o for o in get_options(self.dns_option_option, args) ] args = drop_option(self.dns_option_option, args, drop_value=True) for o in self.dns_options(dns_options): l += [self.dns_option_option, o] return l args += dns_opts(args) args += self.environment_options() return args