示例#1
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        e_msg = ('Failed to %s SNMP service due to system error.' %
                 command)
        with self._handle_exception(request, e_msg):
            if (not os.path.exists('/usr/lib/systemd/system/snmpd.service')):
                install_pkg('net-snmp')
            if (command == 'config'):
                service = Service.objects.get(name=self.service_name)
                config = request.data.get('config', {})
                if (type(config) != dict):
                    e_msg = ('config dictionary is required input')
                    handle_exception(Exception(e_msg), request)
                for option in ('syslocation', 'syscontact', 'rocommunity',):
                    if (option not in config):
                        e_msg = ('%s is missing in config' % option)
                        handle_exception(Exception(e_msg), request)
                    if (config[option] is None or config[option] == ''):
                        e_msg = ('%s cannot be empty' % option)
                        handle_exception(Exception(e_msg), request)
                if ('aux' not in config):
                    e_msg = ('aux is missing in config: %s' % config)
                    handle_exception(Exception(e_msg), request)
                if (type(config['aux']) != list):
                    e_msg = ('aux must be a list in config: %s' % config)
                    handle_exception(Exception(e_msg), request)

                configure_snmp(config)
                self._save_config(service, config)
            else:
                self._switch_snmp(command)
        return Response()
def discourse_install(rockon):
    #1. install git
    git = '/usr/bin/git'
    if (not os.path.isfile(git)):
        install_pkg('git')

    #2. prep Discourse.yml
    repo = discourse_repo(rockon)
    if (not os.path.isdir(repo)):
        run_command([git, 'clone',
                     'https://github.com/discourse/discourse_docker.git',
                     repo])

    co = DContainer.objects.get(rockon=rockon)
    po = DPort.objects.get(container=co)
    cc_map = {}
    for cco in DCustomConfig.objects.filter(rockon=rockon):
        cc_map[cco.key] = cco.val
    mem = int((psutil.virtual_memory().total / (1024 * 1024)) * .25)

    fo, npath = mkstemp()
    src_yml = '%s/samples/standalone.yml' % repo
    dst_yml = '%s/containers/%s.yml' % (repo, rockon.name.lower())
    with open(src_yml) as sfo, open(npath, 'w') as tfo:
        for line in sfo.readlines():
            if (re.match('  - "80:80"', line) is not None):
                tfo.write('  - "%d:80"\n' % po.hostp)
            elif (re.match('  #db_shared_buffers:', line) is not None):
                tfo.write('  db_shared_buffers: "%dMB"\n' % mem)
            elif (re.match('  #UNICORN_WORKERS:', line) is not None):
                tfo.write('  UNICORN_WORKERS: 3\n')
            elif (re.match('  DISCOURSE_DEVELOPER_EMAILS:', line) is not None):
                tfo.write("  DISCOURSE_DEVELOPER_EMAILS: '%s'\n" % cc_map['admin-email'])
            elif (re.match('  DISCOURSE_HOSTNAME:', line) is not None):
                tfo.write("  DISCOURSE_HOSTNAME: '%s'\n" % cc_map['hostname'])
            elif (re.match('  DISCOURSE_SMTP_ADDRESS:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_ADDRESS: %s\n' % cc_map['smtp-address'])
            elif (re.match('  #DISCOURSE_SMTP_PORT:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_PORT: %s\n' % cc_map['smtp-port'])
            elif (re.match('  #DISCOURSE_SMTP_USER_NAME:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_USER_NAME: %s\n' % cc_map['smtp-username'])
            elif (re.match('  #DISCOURSE_SMTP_PASSWORD:'******'  DISCOURSE_SMTP_PASSWORD: %s\n' % cc_map['smtp-password'])
            elif (re.match('      host: /var/discourse/shared/standalone', line) is not None):
                tfo.write('      host: %s/shares/standalone\n' % repo)
            elif (re.match('      host: /var/discourse/shared/standalone/log/var-log', line) is not None):
                tfo.write('      host: %s/shared/standalone/log/var-log\n' % repo)
            else:
                tfo.write(line)
    move(npath, dst_yml)

    #3. bootstrap: launcher bootstrap app
    run_command(['%s/launcher' % repo, 'bootstrap', rockon.name.lower()])

    #4. start: launcher start app
    run_command(['%s/launcher' % repo, 'start', rockon.name.lower()])
示例#3
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        e_msg = ('Failed to %s AFP service due to system error.' % command)
        with self._handle_exception(request, e_msg):
            if (command == 'start'):
                if (not os.path.exists('/usr/sbin/afpd')):
                    install_pkg(self.service_name)
            self._switch_afpd(command)

        return Response()
示例#4
0
    def post(self, request, command):
        """
        execute a command on the service
        """
        e_msg = ('Failed to %s AFP service due to system error.' %
                 command)
        with self._handle_exception(request, e_msg):
            if (command == 'start'):
                if (not os.path.exists('/usr/sbin/afpd')):
                    install_pkg(self.service_name)
            self._switch_afpd(command)

        return Response()
示例#5
0
 def post(self, request, command):
     """
     execute a command on the service
     """
     e_msg = "Failed to %s S.M.A.R.T service due to system error." % command
     with self._handle_exception(request, e_msg):
         if not os.path.exists(SMART):
             install_pkg("smartmontools")
         if command == "config":
             service = Service.objects.get(name=self.service_name)
             config = request.DATA.get("config", {})
             logger.debug("config = %s" % config)
             self._save_config(service, config)
             if "custom_config" in config:
                 config = config["custom_config"]
             else:
                 config = ""
             smart.update_config(config)
             systemctl(self.service_name, "enable")
             systemctl(self.service_name, "restart")
         else:
             self._switch(command)
     return Response()
示例#6
0
 def post(self, request, command):
     """
     execute a command on the service
     """
     e_msg = ('Failed to %s S.M.A.R.T service due to system error.' %
              command)
     with self._handle_exception(request, e_msg):
         if (not os.path.exists(SMART)):
             install_pkg('smartmontools')
         if (command == 'config'):
             service = Service.objects.get(name=self.service_name)
             config = request.DATA.get('config', {})
             logger.debug('config = %s' % config)
             self._save_config(service, config)
             if ('custom_config' in config):
                 config = config['custom_config']
             else:
                 config = ''
             smart.update_config(config)
             systemctl(self.service_name, 'enable')
             systemctl(self.service_name, 'restart')
         else:
             self._switch(command)
     return Response()
 def post(self, request, command):
     """
     execute a command on the service
     """
     e_msg = ('Failed to %s S.M.A.R.T service due to system error.' %
              command)
     with self._handle_exception(request, e_msg):
         if (not os.path.exists(SMART)):
             install_pkg('smartmontools')
         if (command == 'config'):
             service = Service.objects.get(name=self.service_name)
             config = request.DATA.get('config', {})
             logger.debug('config = %s' % config)
             self._save_config(service, config)
             if ('smartd_config' in config):
                 config = config['smartd_config']
             else:
                 config = ''
             smart.update_config(config)
             systemctl(self.service_name, 'enable')
             systemctl(self.service_name, 'restart')
         else:
             self._switch(command)
     return Response()
示例#8
0
        elif (command == 'current-user'):
            return Response(request.user.username)

        elif (command == 'auto-update-status'):
            status = True
            try:
                systemctl('yum-cron', 'status')
            except:
                status = False
            finally:
                return Response({'enabled': status, })

        elif (command == 'enable-auto-update'):
            try:
                install_pkg('yum-cron')
                systemctl('yum-cron', 'enable')
                systemctl('yum-cron', 'start')
            except Exception, e:
                msg = ('Failed to enable auto update due to a low level error')
                logger.exception(e)
                handle_exception(Exception(msg), request)
            finally:
                return Response({'enabled': True, })

        elif (command == 'disable-auto-update'):
            try:
                systemctl('yum-cron', 'stop')
                systemctl('yum-cron', 'disable')
            except Exception, e:
                msg = ('Failed to disable auto update due to a low level '
示例#9
0
def discourse_install(rockon):
    # 1. install git
    git = '/usr/bin/git'
    if (not os.path.isfile(git)):
        install_pkg('git')

    # 2. prep Discourse.yml
    repo = discourse_repo(rockon)
    if (not os.path.isdir(repo)):
        run_command([git, 'clone',
                     'https://github.com/discourse/discourse_docker.git',
                     repo])

    co = DContainer.objects.get(rockon=rockon)
    po = DPort.objects.get(container=co)
    cc_map = {}
    for cco in DCustomConfig.objects.filter(rockon=rockon):
        cc_map[cco.key] = cco.val
    mem = int((psutil.virtual_memory().total / (1024 * 1024)) * .25)

    fo, npath = mkstemp()
    src_yml = '%s/samples/standalone.yml' % repo
    dst_yml = '%s/containers/%s.yml' % (repo, rockon.name.lower())
    with open(src_yml) as sfo, open(npath, 'w') as tfo:
        for line in sfo.readlines():
            if (re.match('  - "80:80"', line) is not None):
                tfo.write('  - "%d:80"\n' % po.hostp)
            elif (re.match('  #db_shared_buffers:', line) is not None):
                tfo.write('  db_shared_buffers: "%dMB"\n' % mem)
            elif (re.match('  #UNICORN_WORKERS:', line) is not None):
                tfo.write('  UNICORN_WORKERS: 3\n')
            elif (re.match('  DISCOURSE_DEVELOPER_EMAILS:', line) is not None):
                tfo.write("  DISCOURSE_DEVELOPER_EMAILS: '%s'\n" %
                          cc_map['admin-email'])
            elif (re.match('  DISCOURSE_HOSTNAME:', line) is not None):
                tfo.write("  DISCOURSE_HOSTNAME: '%s'\n" % cc_map['hostname'])
            elif (re.match('  DISCOURSE_SMTP_ADDRESS:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_ADDRESS: %s\n' %
                          cc_map['smtp-address'])
            elif (re.match('  #DISCOURSE_SMTP_PORT:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_PORT: %s\n' % cc_map['smtp-port'])
            elif (re.match('  #DISCOURSE_SMTP_USER_NAME:', line) is not None):
                tfo.write('  DISCOURSE_SMTP_USER_NAME: %s\n' %
                          cc_map['smtp-username'])
            elif (re.match('  #DISCOURSE_SMTP_PASSWORD:'******'  DISCOURSE_SMTP_PASSWORD: %s\n' %
                          cc_map['smtp-password'])
            elif (re.match('      host: /var/discourse/shared/standalone', line) is not None):  # noqa E501
                tfo.write('      host: %s/shares/standalone\n' % repo)
            elif (re.match('      host: /var/discourse/shared/standalone/log/var-log', line) is not None):  # noqa E501
                tfo.write('      host: %s/shared/standalone/log/var-log\n'
                          % repo)
            else:
                tfo.write(line)
    move(npath, dst_yml)

    # 3. bootstrap: launcher bootstrap app
    run_command(['%s/launcher' % repo, 'bootstrap', rockon.name.lower()])

    # 4. start: launcher start app
    run_command(['%s/launcher' % repo, 'start', rockon.name.lower()])
示例#10
0
            return Response(request.user.username)

        elif (command == 'auto-update-status'):
            status = True
            try:
                systemctl('yum-cron', 'status')
            except:
                status = False
            finally:
                return Response({
                    'enabled': status,
                })

        elif (command == 'enable-auto-update'):
            try:
                install_pkg('yum-cron')
                systemctl('yum-cron', 'enable')
                systemctl('yum-cron', 'start')
            except Exception, e:
                msg = ('Failed to enable auto update due to a low level error')
                logger.exception(e)
                handle_exception(Exception(msg), request)
            finally:
                return Response({
                    'enabled': True,
                })

        elif (command == 'disable-auto-update'):
            try:
                systemctl('yum-cron', 'stop')
                systemctl('yum-cron', 'disable')