Пример #1
0
def init_app_enum():
    global icswServiceEnum
    from initat.icsw.service import instance
    icswServiceEnum = Enum(value="icswClientEnum",
                           names=[(entry.name, entry.value)
                                  for entry in client_enums],
                           type=icswAppBaseServiceEnumClass)
    _xml = instance.InstanceXML(quiet=True)
    for _inst in _xml.get_all_instances():
        if _xml.get_attrib(_inst)["runs_on"] in [
                "client"
        ] or _inst.find("ignore-missing-database") is not None:
            _attr = _xml.get_attrib(_inst)
            _enums = _xml.get_config_enums(_inst)
            for _enum_str in _enums:
                if _enum_str.count("-"):
                    _err_str = "config-enum names in *.xml are not allowed to have dashes in there name: {}".format(
                        _enum_str, )
                    raise SyntaxError(_err_str)
                try:
                    _enum = getattr(icswServiceEnum, _enum_str)
                except AttributeError:
                    print("Unknown ClientEnum '{}'".format(_enum_str))
                else:
                    _enum.value.add_instance_name(_attr["name"])
Пример #2
0
 def _call(self, cur_inst):
     # from initat.cluster.backbone.models import device
     # print("devcount=", device.objects.all().count())
     inst_xml = instance.InstanceXML(cur_inst.log)
     cur_c = container.ServiceContainer(cur_inst.log)
     _def_ns = service_parser.Parser.get_default_ns()
     cur_c.check_system(_def_ns, inst_xml)
     cur_inst.srv_com["status"] = inst_xml.tree
     _local_state = query_local_meta_server(inst_xml, "overview")
     if _local_state is not None:
         _bldr = cur_inst.srv_com.builder()
         cur_inst.srv_com["metastatus"] = _local_state["overview:instances"]
         cur_inst.srv_com["version_info"] = _bldr(
             "sys",
             **settings.ICSW_VERSION_DICT
         )
         cur_inst.srv_com["fingerprint"] = hfp_tools.get_local_hfp(serialize=True)
         cur_inst.srv_com.set_result(
             "checked system {}".format(global_config["SERVER_FULL_NAME"]),
         )
     else:
         cur_inst.srv_com.set_result(
             "error querying local meta-server (timeout?)",
             server_command.SRV_REPLY_STATE_ERROR,
         )
Пример #3
0
def init_app_enum():
    global icswServiceEnum
    from initat.cluster.backbone.models.functions import register_service_enum
    from initat.host_monitoring.client_enums import icswServiceEnum as icswServiceEnumClient
    from initat.icsw.service import instance
    register_service_enum(icswServiceEnumClient, "client")
    if icswServiceEnum is None:
        from django.conf import settings
        _all = []
        for _enum in settings.ICSW_SERVICE_ENUM_LIST:
            for entry in _enum:
                entry.value.clear_instance_names()
                _all.append((entry.name, entry.value))
        icswServiceEnum = BaseEnum(
            value="icswServerEnum",
            names=_all,
            type=icswAppBaseServiceEnumClass,
        )
    _xml = instance.InstanceXML(quiet=True)
    for _inst in _xml.get_all_instances():
        _attr = _xml.get_attrib(_inst)
        _enums = _xml.get_config_enums(_inst)
        for _enum_str in _enums:
            if _enum_str.count("-"):
                _err_str = "config-enum names in *.xml are not allowed to have dashes in there name: {}".format(
                    _enum_str, )
                raise SyntaxError(_err_str)
            try:
                _enum = getattr(icswServiceEnum, _enum_str)
            except AttributeError:
                print("Unknown ServerEnum '{}'".format(_enum_str))
                if settings.DEBUG:
                    raise
            else:
                _enum.value.add_instance_name(_attr["name"])
Пример #4
0
 def _init_statemachine(self):
     self.__transitions = []
     self.def_ns = service_parser.Parser.get_default_ns(call_meta=False)
     self.server_instance = instance.InstanceXML(self.log)
     self.service_state = ServiceState(self.log, self.server_instance)
     self.container = container.ServiceContainer(self.log)
     self.service_state.sync_with_instance(self.server_instance)
     self.__watcher.add_watcher(
         "xml",
         self.server_instance.source_dir,
         inotify_tools.IN_CLOSE_WRITE | inotify_tools.IN_DELETE,
         self._instance_event,
     )
Пример #5
0
 def __init__(self, name, *args, **kwargs):
     inst_xml = instance.InstanceXML(quiet=True)
     self.__mc_enabled = kwargs.get("mc_enabled", True)
     _mc_addr = "127.0.0.1"
     _mc_port = inst_xml.get_port_dict("memcached", command=True)
     self.__mc_addr = "{}:{:d}".format(_mc_addr, _mc_port)
     self.__name = name
     self.__backend_init = False
     self.mc_prefix = ""
     self.__verbose = kwargs.get("verbose", False)
     self.__spm = kwargs.pop("single_process_mode", False)
     self._reopen_mc(True)
     self.clear_log()
     if args:
         self.add_config_entries(*args)
Пример #6
0
def role_command(options):
    from initat.icsw.config.create_role_fixtures import create_noctua_fixtures
    basic_services = ['logging-server', 'meta-server']
    log_com = icsw_logging.get_logger("config", options)
    inst_xml = instance.InstanceXML(log_com)
    if options.role == "noctua":
        create_noctua_fixtures()
        services = basic_services + [
            "md-sync-server",
            "md-config-server",
            "icinga-init",
            "nginx",
            "uwsgi-init",
        ]
    print("starting necessary services...")
    _result = query_local_meta_server(inst_xml, "enable", services=services)
Пример #7
0
def scan_for_images(opt_ns):
    _inst = instance.InstanceXML()
    result = query_local_server(_inst, "get_image_list")
    images = result.xpath(".//ns:image_list/ns:image")
    print("Found {}:".format(logging_tools.get_plural("image", len(images))))
    for _image in images:
        print("    {:<40s}, arch={}, version={}".format(
            _image.text,
            _image.get("arch", "???"),
            _image.get("version", "???"),
        ))
    if opt_ns.mode == "take":
        if not opt_ns.image_name:
            print("Need an image name")
            sys.exit(1)
        _xml_wrapper = XMLWrapper()
        image.take_image(_xml_wrapper, result, opt_ns.image_name)
        _xml_wrapper.show()
Пример #8
0
def reload_relay():
    print("reloading relayer")
    from initat.icsw.service import transition, container, instance
    cur_c = container.ServiceContainer(log_com)
    cur_t = transition.ServiceTransition(
        "reload",
        ["host-relay"],
        cur_c,
        instance.InstanceXML(log_com),
        log_com,
    )
    while True:
        _left = cur_t.step(cur_c)
        if _left:
            time.sleep(1)
        else:
            break
    print("done")
Пример #9
0
def restart_services():
    from initat.icsw.service import transition, container, instance
    srv_list = ["host-monitoring", "cluster-server"]
    print("restarting {}: {}".format(
        logging_tools.get_plural("service", len(srv_list)),
        ", ".join(srv_list),
    ))
    cur_c = container.ServiceContainer(log_com)
    cur_t = transition.ServiceTransition(
        "restart",
        srv_list,
        cur_c,
        instance.InstanceXML(log_com),
        log_com,
    )
    while True:
        _left = cur_t.step(cur_c)
        if _left:
            time.sleep(1)
        else:
            break
    print("done")
Пример #10
0
def _parse_environ(opts):
    for _src_file, _target in [
        ("/etc/sge_server", "server_address"),
    ]:
        if not getattr(opts, _target) and os.path.exists(_src_file):
            setattr(opts, _target, file(_src_file, "r").read().strip())
    if not opts.job_id:
        if "JOB_ID" in os.environ:
            opts.job_id = os.environ["JOB_ID"]
    if not opts.task_id:
        if "SGE_TASK_ID" in os.environ:
            try:
                opts.task_id = int(os.environ["SGE_TASK_ID"])
            except:
                opts.task_id = 0
    if not opts.server_port:
        from initat.icsw.service import instance
        _inst = instance.InstanceXML()
        opts.server_port = _inst.get_port_dict("rms-server", ptype="command")
    if opts.task_id:
        opts.full_job_id = "{}.{:d}".format(opts.job_id, opts.task_id)
    else:
        opts.full_job_id = opts.job_id