Beispiel #1
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        self.view.host_id = host_id

        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()
        service = config.findby1service(param[1])
        if not service:
            self.logger.debug("Get service status failed. Service not found.")
            return web.notfound("Service not found")

        sysv = SysVInit_RH(service['system_name'], service['system_command'])
        status = {
            "status": sysv.status(),
            "autostart": sysv.onboot(),
            "readonly": service["system_readonly"],
        }

        if self.__template__["media"] == 'json':
            self.view.status = json_dumps(status)
        else:
            self.view.status = status

        return True
Beispiel #2
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()

        service = config.findby1service(opts.name)
        if service is None:
            raise KssCommandException("Service not found in xml file. service=%s" % (opts.name))

        self.up_progress(10)
        sysv = SysVInit_RH(service['system_name'], service['system_command'])

        flag = None
        if opts.enable:
            flag = True
        if opts.disable:
            flag = False

        retval = sysv.onboot(flag)
        if not(retval is False) and not(retval is True):
            raise KssCommandException(str(sysv.error_msg))

        self.up_progress(50)
        if flag is True:
            message = 'Enable service. - service=%s' % (opts.name)
        else:
            message = 'Disable service. - service=%s' % (opts.name)

        self.logger.info(message)
        print >>sys.stdout, _(message)

        return True
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        self.view.host_id = host_id

        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()
        service = config.findby1service(param[1])
        if not service:
            self.logger.debug("Get service status failed. Service not found.")
            return web.notfound("Service not found")

        sysv = SysVInit_RH(service['system_name'], service['system_command'])
        status = {"status":sysv.status(),
                  "autostart":sysv.onboot(),
                  "readonly":service["system_readonly"],
                  }

        if self.__template__["media"] == 'json':
            self.view.status = json_dumps(status)
        else:
            self.view.status = status

        return True
Beispiel #4
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)
        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()

        service = config.findby1service(opts.name)
        self.up_progress(10)
        sysv = SysVInit_RH(service['system_name'], service['system_command'])

        if sysv.restart(force=False) is False:
            raise KssCommandException(str(sysv.error_msg))

        self.up_progress(50)
        self.logger.info('Restarted service. - service=%s' % (opts.name))
        print >>sys.stdout, _('Restarted service. - service=%s') % (opts.name)
        
        return True
Beispiel #5
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)
        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()

        service = config.findby1service(opts.name)
        self.up_progress(10)
        sysv = SysVInit_RH(service['system_name'], service['system_command'])

        if sysv.restart(force=False) is False:
            raise KssCommandException(str(sysv.error_msg))

        self.up_progress(50)
        self.logger.info('Restarted service. - service=%s' % (opts.name))
        print >> sys.stdout, _('Restarted service. - service=%s') % (opts.name)

        return True
Beispiel #6
0
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        self.view.host_id = host_id

        host = findbyhost1(self.orm, host_id)

        name = param[1]
        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()
        service = config.findby1service(name)
        if not service:
            self.logger.debug("Set service status failed. Service not found.")
            return web.notfound("Service not found")

        if not is_param(self.input, 'status'):
            self.logger.error(
                "Set service status failed. Missing request param.")
            return web.badrequest("Missing request param.")

        status = int(self.input.status)
        if status == SERVICE_START:
            service_job(self, host, name, "start")
        elif status == SERVICE_STOP:
            service_job(self, host, name, "stop")
        elif status == SERVICE_RESTART:
            service_job(self, host, name, "restart")
        elif status == SERVICE_ENABLE:
            service_job(self, host, name, "enable")
        elif status == SERVICE_DISABLE:
            service_job(self, host, name, "disable")
        else:
            self.logger.error(
                "Set service status failed. Invalid request param.")
            return web.badrequest("Invalid request param")

        return web.accepted()
Beispiel #7
0
    def _GET(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()

        service = config.findby1service(param[1])
        if not service:
            self.logger.debug("Get service info failed. Service not found.")
            return web.notfound("Service not found")

        sysv = SysVInit_RH(service['system_name'], service['system_command'])
        display = {
            'name' : service['system_name'],
            'display_name' : service['display_name'],
            'description' : service['display_description'],
            'status' : sysv.status(),
            'autostart' : sysv.onboot(),
            }
        self.view.service = display

        return True
Beispiel #8
0
    def process(self):
        (opts, args) = getopts()
        chkopts(opts)
        self.up_progress(10)

        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()

        service = config.findby1service(opts.name)
        if service is None:
            raise KssCommandException(
                "Service not found in xml file. service=%s" % (opts.name))

        self.up_progress(10)
        sysv = SysVInit_RH(service['system_name'], service['system_command'])

        flag = None
        if opts.enable:
            flag = True
        if opts.disable:
            flag = False

        retval = sysv.onboot(flag)
        if not (retval is False) and not (retval is True):
            raise KssCommandException(str(sysv.error_msg))

        self.up_progress(50)
        if flag is True:
            message = 'Enable service. - service=%s' % (opts.name)
        else:
            message = 'Disable service. - service=%s' % (opts.name)

        self.logger.info(message)
        print >> sys.stdout, _(message)

        return True
    def _PUT(self, *param, **params):
        host_id = self.chk_hostby1(param)
        if host_id is None: return web.notfound()

        self.view.host_id = host_id

        host = findbyhost1(self.orm, host_id)

        name = param[1]
        config = ServiceConfigParam(SERVICE_XML_FILE)
        config.load_xml_config()
        service = config.findby1service(name)
        if not service:
            self.logger.debug("Set service status failed. Service not found.")
            return web.notfound("Service not found")

        if not is_param(self.input, 'status'):
            self.logger.error("Set service status failed. Missing request param.")
            return web.badrequest("Missing request param.")

        status = int(self.input.status)
        if status == SERVICE_START:
            service_job(self, host, name, "start")
        elif status == SERVICE_STOP:
            service_job(self, host, name, "stop")
        elif status == SERVICE_RESTART:
            service_job(self, host, name, "restart")
        elif status == SERVICE_ENABLE:
            service_job(self, host, name, "enable")
        elif status == SERVICE_DISABLE:
            service_job(self, host, name, "disable")
        else:
            self.logger.error("Set service status failed. Invalid request param.")
            return web.badrequest("Invalid request param")

        return web.accepted()