Example #1
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        with self._handle_exception(request):
            service = Service.objects.get(name='nis')
            if (command == 'config'):
                try:
                    config = request.data['config']
                    configure_nis(config['domain'], config['server'])
                    self._save_config(service, config)
                except Exception as e:
                    logger.exception(e)
                    e_msg = ('NIS could not be configured. Try again')
                    handle_exception(Exception(e_msg), request)

            else:
                try:
                    if (command == 'stop'):
                        chkconfig('ypbind', 'off')
                    else:
                        chkconfig('ypbind', 'on')
                        chkconfig('rpcbind', 'on')
                        init_service_op('rpcbind', command)
                    init_service_op('ypbind', command)
                except Exception as e:
                    logger.exception(e)
                    e_msg = ('Failed to %s NIS service due to system error.' %
                             command)
                    handle_exception(Exception(e_msg), request)

            return Response()
Example #2
0
    def put(self, request, sname):
        """
        execute a command on the service
        """
        if (sname not in self.service_list):
            msg = ('Unknown service: %s requested' % sname)
            logger.error(msg)
            raise Exception(msg)

        command = request.DATA['command']
        if (command not in self.command_list):
            msg = ('Unknown command: %s for service: %s' % (command, sname))
            logger.error(msg)
            raise Exception(msg)
        init_service_op()
Example #3
0
    def put(self, request, sname):
        """
        execute a command on the service
        """
        if (sname not in self.service_list):
            msg = ('Unknown service: %s requested' % sname)
            logger.error(msg)
            raise Exception(msg)

        command = request.DATA['command']
        if (command not in self.command_list):
            msg = ('Unknown command: %s for service: %s' % (command, sname))
            logger.error(msg)
            raise Exception(msg)
        init_service_op()
Example #4
0
 def post(self, request, command):
     """
     execute a command on the service
     """
     service = Service.objects.get(name='ntpd')
     if (command == 'config'):
         try:
             config = request.DATA['config']
             init_service_op('ntpd', 'stop')
             set_ntpserver(config['server'])
             init_service_op('ntpd', 'start')
             self._save_config(service, config)
         except Exception, e:
             logger.exception(e)
             e_msg = ('NTP could not be configured. Try again')
             handle_exception(Exception(e_msg), request)
Example #5
0
    def put(self, request, sname):
        """
        execute a command on the service
        """
        try:
            if (sname not in self.service_list):
                msg = ('Unknown service: %s requested' % sname)
                handle_exception(Exception(msg, request))

            command = request.DATA['command']
            if (command not in self.command_list):
                msg = ('Unknown command: %s for service: %s' % (command,
                                                                sname))
                handle_exception(Exception(msg, request))

            if (sname == 'ldap' or sname == 'ad' or sname == 'iscsi'):
                return Response()
            else:
                logger.info('sname: %s command: %s' % (sname, command))
                out, err, rc = init_service_op(sname, command)
                logger.info('out: %s err: %s rc: %s' % (out, err, rc))
                return self.get_helper(sname)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Example #6
0
 def get(self, request, sname):
     """
     return current status of the service
     """
     if (sname not in self.service_list):
         msg = ('Unknown service: %s requested' % sname)
         logger.error(msg)
         raise Exception(msg)
     out, err, rc = init_service_op(sname, 'status')
Example #7
0
 def get(self, request, sname):
     """
     return current status of the service
     """
     if (sname not in self.service_list):
         msg = ('Unknown service: %s requested' % sname)
         logger.error(msg)
         raise Exception(msg)
     out, err, rc = init_service_op(sname, 'status')
Example #8
0
    def run(self):
        while (True):
            if (os.getppid() != self.ppid):
                return

            if (self.q.qsize() < 1000):
                for s in Service.objects.filter(registered=True):
                    # get status
                    service_status = ServiceStatus(service=s, status=False)
                    try:
                        out, err, rc = init_service_op(s.name, 'status')
                        if (rc == 0):
                            service_status.status = True
                    except Exception, e:
                        pass
                    finally:
                        self.q.put(service_status)
Example #9
0

class SambaServiceView(BaseServiceView):

    @transaction.commit_on_success
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='samba')
        if (command == 'config'):
            #nothing to really configure atm. just save the model
            try:
                config = request.DATA['config']
                service.config = config
                service.save()
            except Exception, e:
                logger.exception(e)
                e_msg = ('Samba could not be configured. Try again')
                handle_exception(Exception(e_msg), request)

        else:
            try:
                init_service_op('smb', command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s samba due to a system error.')
                handle_exception(Exception(e_msg), request)

        return Response()
Example #10
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='ntpd')
        if (command == 'config'):
            try:
                config = request.DATA['config']
                init_service_op('ntpd', 'stop')
                set_ntpserver(config['server'])
                init_service_op('ntpd', 'start')
                self._save_config(service, config)
            except Exception, e:
                logger.exception(e)
                e_msg = ('NTP could not be configured. Try again')
                handle_exception(Exception(e_msg), request)
        else:
            try:
                switch = 'on'
                if (command == 'stop'):
                    switch = 'off'
                chkconfig('ntpd', switch)
                init_service_op('ntpd', command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s NTP service due to system error.' %
                         command)
                handle_exception(Exception(e_msg), request)

        return Response()
Example #11
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='nfs')
        if (command == 'config'):
            #nothing to really configure atm. just save the model
            try:
                config = request.DATA['config']
                self._save_config(service, config)
            except Exception, e:
                logger.exception(e)
                e_msg = ('NFS could not be configured. Try again')
                handle_exception(Exception(e_msg), request)

        else:
            try:
                if (command == 'stop'):
                    chkconfig('nfs', 'on')
                else:
                    chkconfig('nfs', 'on')
                    chkconfig('rpcbind', 'on')
                    init_service_op('rpcbind', command)
                init_service_op('nfs', command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s NFS due to a system error.')
                handle_exception(Exception(e_msg), request)

        return Response()
Example #12
0
        """
        execute a command on the service
        """
        with self._handle_exception(request):
            service = Service.objects.get(name="nis")
            if command == "config":
                try:
                    config = request.data["config"]
                    configure_nis(config["domain"], config["server"])
                    self._save_config(service, config)
                except Exception, e:
                    logger.exception(e)
                    e_msg = "NIS could not be configured. Try again"
                    handle_exception(Exception(e_msg), request)

            else:
                try:
                    if command == "stop":
                        chkconfig("ypbind", "off")
                    else:
                        chkconfig("ypbind", "on")
                        chkconfig("rpcbind", "on")
                        init_service_op("rpcbind", command)
                    init_service_op("ypbind", command)
                except Exception, e:
                    logger.exception(e)
                    e_msg = "Failed to %s NIS service due to system error." % command
                    handle_exception(Exception(e_msg), request)

            return Response()
Example #13
0

class NFSServiceView(BaseServiceView):

    @transaction.commit_on_success
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='nfs')
        if (command == 'config'):
            #nothing to really configure atm. just save the model
            try:
                config = request.DATA['config']
                service.config = config
                service.save()
            except Exception, e:
                logger.exception(e)
                e_msg = ('NFS could not be configured. Try again')
                handle_exception(Exception(e_msg), request)

        else:
            try:
                init_service_op('nfs', command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s NFS due to a system error.')
                handle_exception(Exception(e_msg), request)

        return Response()
Example #14
0
        execute a command on the service
        """
        with self._handle_exception(request):
            service = Service.objects.get(name='nis')
            if (command == 'config'):
                try:
                    config = request.data['config']
                    configure_nis(config['domain'], config['server'])
                    self._save_config(service, config)
                except Exception, e:
                    logger.exception(e)
                    e_msg = ('NIS could not be configured. Try again')
                    handle_exception(Exception(e_msg), request)

            else:
                try:
                    if (command == 'stop'):
                        chkconfig('ypbind', 'off')
                    else:
                        chkconfig('ypbind', 'on')
                        chkconfig('rpcbind', 'on')
                        init_service_op('rpcbind', command)
                    init_service_op('ypbind', command)
                except Exception, e:
                    logger.exception(e)
                    e_msg = ('Failed to %s NIS service due to system error.' %
                             command)
                    handle_exception(Exception(e_msg), request)

            return Response()
Example #15
0
class NISServiceView(BaseServiceView):

    @transaction.commit_on_success
    def post(self, request, command):
        """
        execute a command on the service
        """
        service = Service.objects.get(name='nis')
        if (command == 'config'):
            try:
                config = request.DATA['config']
                configure_nis(config['domain'], config['server'])
                service.config = config
                service.save()
            except Exception, e:
                logger.exception(e)
                e_msg = ('NIS could not be configured. Try again')
                handle_exception(Exception(e_msg), request)

        else:
            try:
                init_service_op('rpcbind', command)
                init_service_op('ypbind', command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s NIS service due to system error.' %
                         command)
                handle_exception(Exception(e_msg), request)

        return Response()
Example #16
0
    @transaction.commit_on_success
    def post(self, request, command):
        """
        execute a command on the service
        """
        service_name = 'smb'
        service = Service.objects.get(name=service_name)
        if (command == 'config'):
            #nothing to really configure atm. just save the model
            try:
                config = request.DATA['config']
                self._save_config(service, config)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Samba could not be configured. Try again')
                handle_exception(Exception(e_msg), request)

        else:
            try:
                switch = 'on'
                if (command == 'stop'):
                    switch = 'off'
                chkconfig(service_name, switch)
                init_service_op(service_name, command)
            except Exception, e:
                logger.exception(e)
                e_msg = ('Failed to %s samba due to a system error.')
                handle_exception(Exception(e_msg), request)

        return Response()