Ejemplo n.º 1
0
 def __init__(self):
     _inst = InstanceXML(quiet=True)
     all_instances = sum([
         _inst.xpath(".//config-enums/config-enum/text()")
         for _inst in _inst.get_all_instances()
     ], [])
     all_perms = [
         _perm.perm_name for _perm in csw_permission.objects.all()
     ] + ["$$CHECK_FOR_SUPERUSER"]
     _content = file(
         "{}/menu_relax.xml".format(os.path.join(settings.FILE_ROOT,
                                                 "menu")),
         "r",
     ).read()
     _content = _content.replace(
         "<value>RIGHTSLIST</value>",
         "".join(["<value>{}</value>".format(_pn)
                  for _pn in all_perms])).replace(
                      "<value>SERVICETYPESLIST</value>", "".join([
                          "<value>{}</value>".format(_stn)
                          for _stn in all_instances
                      ]))
     # sys.exit(0)
     self.ng = etree.RelaxNG(etree.fromstring(_content, ))
Ejemplo n.º 2
0
class LocalParser(argparse.ArgumentParser):
    def __init__(self):
        argparse.ArgumentParser.__init__(
            self, "send command to servers of the init.at Clustersoftware")
        self.inst_xml = InstanceXML(quiet=True)
        inst_list = []
        for inst in self.inst_xml.get_all_instances():
            if len(inst.xpath(".//network/ports/port[@type='command']")):
                inst_list.append(inst.get("name"))
        self.add_argument("arguments",
                          nargs="+",
                          help="additional arguments, first one is command")
        self.add_argument("-t",
                          help="set timeout [%(default)d]",
                          default=10,
                          type=int,
                          dest="timeout")
        self.add_argument("-p",
                          help="port or instance/service [%(default)s]",
                          default="{:d}".format(
                              self.inst_xml.get_port_dict(
                                  icswServiceEnum.host_monitoring,
                                  command=True)),
                          dest="port",
                          type=str)
        self.add_argument("-P",
                          help="protocoll [%(default)s]",
                          type=str,
                          default="tcp",
                          choices=["tcp", "ipc"],
                          dest="protocoll")
        self.add_argument("-S",
                          help="servername [%(default)s]",
                          type=str,
                          default="collrelay",
                          dest="server_name")
        self.add_argument("-H",
                          "--host",
                          help="host [%(default)s] or server",
                          default="localhost",
                          dest="host")
        self.add_argument("-v",
                          help="verbose mode [%(default)s]",
                          default=False,
                          dest="verbose",
                          action="store_true")
        self.add_argument("-i",
                          help="set identity substring [%(default)s]",
                          type=str,
                          default="sc",
                          dest="identity_substring")
        self.add_argument(
            "-I",
            help="set identity string [%(default)s], has precedence over -i",
            type=str,
            default="",
            dest="identity_string")
        self.add_argument("-n",
                          help="set number of iterations [%(default)d]",
                          type=int,
                          default=1,
                          dest="iterations")
        self.add_argument("-q",
                          help="be quiet [%(default)s], overrides verbose",
                          default=False,
                          action="store_true",
                          dest="quiet")
        self.add_argument("--raw",
                          help="do not convert to server_command",
                          default=False,
                          action="store_true")
        self.add_argument("--root",
                          help="connect to root-socket [%(default)s]",
                          default=False,
                          action="store_true")
        self.add_argument("--kv",
                          help="key-value pair, colon-separated [key:value]",
                          action="append")
        self.add_argument(
            "--kva",
            help="key-attribute pair, colon-separated [key:attribute:value]",
            action="append")
        self.add_argument("--kv-path",
                          help="path to store key-value pairs under",
                          type=str,
                          default="")
        self.add_argument(
            "--split",
            help="set read socket (for split-socket command), [%(default)s]",
            type=str,
            default="")
        self.add_argument("--only-send",
                          help="only send command, [%(default)s]",
                          default=False,
                          action="store_true")

    def parse(self):
        opts = self.parse_args()
        if isinstance(opts.port, str) and opts.port.isdigit():
            opts.port = int(opts.port)
        else:
            if opts.port in self.inst_xml:
                opts.port = self.inst_xml.get_port_dict(opts.port,
                                                        command=True)
            else:
                print("Invalid service / instance name '{}'".format(opts.port))
                sys.exit(-1)
        return opts