Пример #1
0
    def configure(self, template=None):

        if template is None:
            template = [_('nginx/%(domain)s.conf'), 'nginx/default.conf']

        super(Nginx, self).configure()

        self.update_static_files()  #added static_files var for fab.env

        upload_first(template,
                     fab.env.os.path.join(self.sites_dir,
                                          _('%(domain)s.conf')),
                     fab.env,
                     use_sudo=True,
                     use_jinja=True)

        os = fab.env.os
        log_dir = os.path.join(self.log_dir, _('%(user)s'))
        os.mkdir(log_dir, sudo=True)
        os.change_owner(log_dir, self.log_user, 'adm')

        self.disable_site('%(domain)s.conf' % self.env)
        self.enable_site('%(domain)s.conf' % self.env)

        if hasattr(fab.env, 'logrotate'):
            fab.env.logrotate.add_script('nginx/logrotate', 'nginx')
Пример #2
0
 def supervisor_configure(self):
     upload_first([_('uwsgi/%(domain)s.supervisor.conf'),
                   'uwsgi/supervisor.conf',
                  ],
                  _('%(remote_dir)s/etc/supervisor/uwsgi.conf'),
                  fab.env,
                  use_jinja=True)
Пример #3
0
 def configure(self):
     upload_template(_('apache/%(domain)s.conf'),
                     fab.env.os.path.join(self.sites_dir,
                                          _('%(domain)s.conf') ),
                     fab.env,
                     use_sudo=True,
                     use_jinja=True)
Пример #4
0
 def supervisor_configure(self):
     upload_first([_('gunicorn/%(domain)s.supervisor.conf'),
                   'gunicorn/supervisor.conf',
                  ],
                  _('%(remote_dir)s/etc/supervisor/gunicorn.conf'),
                  fab.env,
                  use_jinja=True)
Пример #5
0
def func_service_afr_info(servicename, path=''):
    retcode = 'operation failed'
    clusterservicemirrorinfo = []
    cmd = 'sudo python %s service afr_info_topage %s ' % (settings.digimanager,
                                                          servicename)
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    Ologger.info(cmd)
    result = proc.stdout.readlines()
    proc.wait()
    retcode = result[0]
    mirrorname = ''
    #ss = simplejson.loads('\n'.join(result[1:]))
    if retcode == '0\n':
        ss = result[1]  #.strip()
        #print >> sys.stderr, type(eval(ss))#.replace('\'', "\"")
        #print >> sys.stderr, simplejson.loads(ss)
        if not ss:
            return retcode == '0' and retcode or _(retcode)
        if not path:
            return eval(ss)
        else:
            t_dict = eval(ss)
            #print >> sys.stderr, getChild(t_dict, path)
            return getChild(t_dict, path)
    else:
        return retcode == '0' and retcode or _(retcode)
Пример #6
0
def func_service_nfs_list_user(clusterservicename):
    retcode = 'operation failed'
    try:
        cmd = 'sudo python %s service nfs_list_user %s' % (
            settings.digimanager, clusterservicename)
        print >> sys.stderr, cmd
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        #print >> sys.stderr,result
        retcode = result[0]
        user_list = []
        #print >> sys.stderr, result[1:]
        if retcode == '0\n':
            user_str = result[1].replace('\n', '')
            if user_str != 'None':
                user_list = user_str.replace('None', '').split(',')
                print >> sys.stderr, user_list
            return user_list
        else:
            return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #7
0
def func_service_create(clusterservicename, clusterserviceraidlv,
                        clusterservicelocalpor, clusterservicedata, option):
    retcode = 'operation failed'
    try:
        if clusterservicename:
            cmd = "sudo python %s service create %s %s %s %s %s" % (
                settings.digimanager, clusterservicename, clusterserviceraidlv,
                clusterservicelocalpor, clusterservicedata, option)
            proc = subprocess.Popen(cmd,
                                    shell=True,
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
            Ologger.info(cmd)
        else:
            cmd = "sudo python %s node add %s" % (settings.digimanager,
                                                  clusternodeipaddr)
            proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            Ologger.info(cmd)
        retcode = proc.stdout.readlines()[0].strip()
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        proc.wait()
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #8
0
def func_service_list_nfs_links(clusterservicename):
    retcode = 'operation failed'
    try:
        cmd = 'sudo python %s service nfs_list_links %s' % (
            settings.digimanager, clusterservicename)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        retcode = result[0]
        links_list = []
        if retcode == '0\n':
            for link in result[1:-1]:
                linkdata = link.split('\t')
                print >> sys.stderr, linkdata
                linkdatadict = {}
                if len(linkdata) == 2:
                    linkdatadict['nodename'] = linkdata[0].strip()
                    linkdatadict['tar_ip'] = linkdata[1].strip()
                else:
                    linkdatadict['fatalerror'] = 'fatalerror'
                print >> sys.stderr, linkdatadict
                links_list.append(linkdatadict)
            return links_list
        else:
            return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #9
0
 def speedydeploy_configure(self):
     fab.sudo("groupadd -f speedydeploy")
     fab.sudo("usermod -a -G speedydeploy %s" % fab.env.user)
     fab.env.os.mkdir(_("/var/log/speedydeploy/%(user)s/"), sudo=True)
     fab.env.os.change_owner("/var/log/speedydeploy", "root", "adm")
     fab.env.os.change_owner(_("/var/log/speedydeploy/%(user)s/"), fab.env.user, "adm")
     fab.env.os.change_mode("/var/log/speedydeploy", "0775")
Пример #10
0
 def POST(self):
     try:
         params = web.input()
         content = []
         with open(USER_PASSWD_PATH, "r") as f:
             file_content = f.read()
             if file_content:
                 content = eval(file_content)
         username = params['username']
         password = params['password']
         for user in content:
             if username == user['username']:
                 if password == user["password"]:
                     # print session.keys(), session.values()
                     # session.user = {}
                     # session.user.id = 1
                     # session.user.name = username
                     # session.user.passwd = password
                     # print session.keys(), session.values()
                     return 0
                 else:
                     return _("password is error")
         return _("user does not exist")
     except Exception as e:
         print traceback.format_exc()
Пример #11
0
    def configure(self, template=None):

        if template is None:
            template = [_('nginx/%(domain)s.conf'),
                        'nginx/default.conf']

        super(Nginx, self).configure()

        self.update_static_files() #added static_files var for fab.env

        upload_first(template,
                     fab.env.os.path.join(self.sites_dir, _('%(domain)s.conf') ),
                     fab.env,
                     use_sudo=True,
                     use_jinja=True)

        os = fab.env.os
        log_dir = os.path.join(self.log_dir, _('%(user)s'))
        os.mkdir(log_dir, sudo=True)
        os.change_owner(log_dir, self.log_user, 'adm', sudo=True)

        self.disable_site('%(domain)s.conf' % self.env)
        self.enable_site('%(domain)s.conf' % self.env)

        if hasattr(fab.env, 'logrotate'):
            fab.env.logrotate.add_script('nginx/logrotate', 'nginx')
Пример #12
0
 def configure(self):
     upload_template(_('apache/%(domain)s.conf'),
                     fab.env.os.path.join(self.sites_dir,
                                          _('%(domain)s.conf')),
                     fab.env,
                     use_sudo=True,
                     use_jinja=True)
Пример #13
0
 def speedydeploy_configure(self):
     fab.sudo('groupadd -f speedydeploy')
     fab.sudo('usermod -a -G speedydeploy %s' % fab.env.user)
     fab.env.os.mkdir(_('/var/log/speedydeploy/%(user)s/'), sudo=True)
     fab.env.os.change_owner('/var/log/speedydeploy', 'root', 'adm')
     fab.env.os.change_owner(_('/var/log/speedydeploy/%(user)s/'),
                             fab.env.user, 'adm')
     fab.env.os.change_mode('/var/log/speedydeploy', '0775')
Пример #14
0
 def supervisor_configure(self):
     upload_first([
         _('gunicorn/%(domain)s.supervisor.conf'),
         'gunicorn/supervisor.conf',
     ],
                  _('%(remote_dir)s/etc/supervisor/gunicorn.conf'),
                  fab.env,
                  use_jinja=True)
Пример #15
0
 def supervisor_configure(self):
     upload_first([
         _('uwsgi/%(domain)s.supervisor.conf'),
         'uwsgi/supervisor.conf',
     ],
                  _('%(remote_dir)s/etc/supervisor/uwsgi.conf'),
                  fab.env,
                  use_jinja=True)
Пример #16
0
    def POST(self):
        params = web.input()
        name = None
        passwd = None
        enpasswd = None

        if os.path.exists("/usr/local/digioceanfs_gui/password"):
            f = open("/usr/local/digioceanfs_gui/password")
            old_password = f.read().replace("\n", "")
            f.close()
        else:
            os.system("sudo touch /usr/local/digioceanfs_gui/password")
            os.system("sudo chmod 777 /usr/local/digioceanfs_gui/password")
            old_password = ""

        if old_password == "":
            old_password = '******'

        user = {
            'name': 'admin',
            #'pass':'******', # perabytes
            'pass': old_password,  # 123456
            'skin': 'redmond',
            'lang': 'zh_CN',
            'time': time.time()
        }
        if 'name' in params:
            name = params['name'].strip()
        if 'passwd' in params:
            passwd = params['passwd'].strip()
        if not name or not passwd:
            raise web.seeother('/login')
        try:
            from hashlib import md5
            enpasswd = md5(passwd)  #.hexdigest()
        except:
            import md5
            enpasswd = md5.new(passwd)
        #retcode = clusindex.func_login(name, enpasswd)
        #if retcode == '0':
        if name != user['name']:
            retcode = _('15001')
            return simplejson.dumps(retcode)
        elif enpasswd.hexdigest() != user['pass']:
            retcode = _('15002')
            return simplejson.dumps(retcode)
        elif name == user['name'] and enpasswd.hexdigest() == user['pass']:
            session.user.id = 1
            session.user.name = name
            session.runtime.unit = 'GB'
            retcode = 0
            #if 'redirect_url' in params:
            #    raise web.seeother(params['redirect_url'])
            #else:
            #    raise web.seeother('/clusterhome')
            #else:
            #raise web.seeother('/login')
            return simplejson.dumps(retcode)
Пример #17
0
 def install_project(self):
     with fab.cd(_('%(remote_dir)s')):
         try:
             with fab.settings(warn_only=True):
                 fab.run(_("rm -rf %(vcs_repo_name)s"))
                 fab.run(_("mv build/%(vcs_repo_name)s %(vcs_repo_name)s"))
         finally:
             fab.run("rm -rf build")
     fab.env.os.set_permissions()
Пример #18
0
    def __init__(self, domain=None):
        if domain is not None:
            fab.env['domain'] = domain

        if 'project' in fab.env and fab.env.project.use_django:
            project_path = _('%(django_python_path)s')
        else:
            project_path = _('%(remote_dir)s/%(project_name)s')
        fab.env['project_path'] = project_path
Пример #19
0
    def __init__(self, domain=None):
        if domain is not None:
            fab.env['domain'] = domain

        if 'project' in fab.env and fab.env.project.use_django:
            project_path = _('%(django_python_path)s')
        else:
            project_path = _('%(remote_dir)s/%(project_name)s')
        fab.env['project_path'] = project_path
Пример #20
0
    def start(self):
        if self.supervisor:
            return

        self.start_command()

        with fab.cd(_('%(project_path)s')):
            fab.run(_('%(remote_dir)s/%(virtualenv)s/bin/%(gunicorn_starter)s'
                      ' -c %(remote_dir)s/etc/gunicorn/conf.py'))
Пример #21
0
    def configure(self):
        self.start_command()

        upload_first([_('gunicorn/%(domain)s.conf'),
                      _('nginx/%(domain)s.gunicorn.conf'),
                      'gunicorn/default.conf'],
                     _('%(remote_dir)s/etc/gunicorn/conf.py'),
                     fab.env,
                     use_jinja=True)
Пример #22
0
 def speedydeploy_configure(self):
     fab.sudo('groupadd -f speedydeploy')
     fab.sudo('usermod -a -G speedydeploy %s' % fab.env.user)
     fab.env.os.mkdir(_('/var/log/speedydeploy/%(user)s/'), sudo=True)
     fab.env.os.change_owner('/var/log/speedydeploy', 'root', 'adm')
     fab.env.os.change_owner(_('/var/log/speedydeploy/%(user)s/'),
                             fab.env.user,
                             'adm')
     fab.env.os.change_mode('/var/log/speedydeploy', '0775')
Пример #23
0
 def install_project(self):
     with fab.cd(_('%(remote_dir)s')):
         try:
             with fab.settings(warn_only=True):
                 fab.run(_("rm -rf %(vcs_repo_name)s"))
                 fab.run(_("mv build/%(vcs_repo_name)s %(vcs_repo_name)s"))
         finally:
             fab.run("rm -rf build")
     fab.env.os.set_permissions()
Пример #24
0
    def start(self):
        if self.supervisor:
            return

        self.start_command()

        with fab.cd(_('%(project_path)s')):
            fab.run(
                _('%(remote_dir)s/env/bin/%(gunicorn_starter)s'
                  ' -c %(remote_dir)s/etc/gunicorn/conf.py'))
Пример #25
0
 def start_command(self):
     if fab.env.project.use_django:
         if fab.env.project.django.HAS_WSGI:
             fab.env['gunicorn_starter'] = _('gunicorn '
                                             '%(django_project_name)s.wsgi:application')
         else:
             fab.env['gunicorn_starter'] = 'gunicorn_django'
     else:
         fab.env['gunicorn_starter'] = _('gunicorn '
                                         '%(project_name)s:application')
Пример #26
0
    def configure(self):
        self.start_command()

        upload_first([
            _('gunicorn/%(domain)s.conf'),
            _('nginx/%(domain)s.gunicorn.conf'), 'gunicorn/default.conf'
        ],
                     _('%(remote_dir)s/etc/gunicorn/conf.py'),
                     fab.env,
                     use_jinja=True)
Пример #27
0
 def deploy(self, force_remove=False):
     if exists(_('%(remote_dir)s/%(vcs_repo_name)s')) and not force_remove:
         with fab.cd(_('%(remote_dir)s/%(vcs_repo_name)s/')):
             self.update()
     else:
         with fab.cd(_('%(remote_dir)s/')):
             with fab.settings(warn_only=True):
                 fab.run(_("rm -rf %(vcs_repo_name)s"))
                 self.clone()
     with fab.cd(_('%(remote_dir)s/%(vcs_repo_name)s/')):
        self.remove_pyc()
Пример #28
0
 def deploy(self, force_remove=False):
     if exists(_('%(remote_dir)s/%(vcs_repo_name)s')) and not force_remove:
         with fab.cd(_('%(remote_dir)s/%(vcs_repo_name)s/')):
             self.update()
     else:
         with fab.cd(_('%(remote_dir)s/')):
             with fab.settings(warn_only=True):
                 fab.run(_("rm -rf %(vcs_repo_name)s"))
                 self.clone()
     with fab.cd(_('%(remote_dir)s/%(vcs_repo_name)s/')):
         self.remove_pyc()
Пример #29
0
 def start_command(self):
     if fab.env.project.use_django:
         if fab.env.project.django.HAS_WSGI:
             fab.env['gunicorn_starter'] = _(
                 'gunicorn '
                 '%(django_project_name)s.wsgi:application')
         else:
             fab.env['gunicorn_starter'] = 'gunicorn_django'
     else:
         fab.env['gunicorn_starter'] = _('gunicorn '
                                         '%(project_name)s:application')
Пример #30
0
 def start(self):
     with fab.cd(_('%(remote_dir)s/%(project_name)s')):
         # TODO use' socket=%(remote_dir)s/run/fcgi.sock'
         fab.run(_('../%(virtualenv)s/bin/python manage.py runfcgi'
                   ' host=127.0.0.1 port=8080',
                   ' daemonize=true'
                   ' minspare=1'
                   ' maxspare=%(worker_count)s'
                   ' maxchildren=%(worker_count)s'
                   ' maxrequests=10000'
                   ' method=prefork'
                   ' pidfile=%(remote_dir)s/run/fcgi.pid'
                   ' logfile=%(remote_dir)s/log/fcgi.log'))
Пример #31
0
def func_logout():
    try:
        cmd = "sudo python %s logout" % (settings.digimanager)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        print >> sys.stderr, cmd
        Ologger.info(cmd)
        retcode = proc.stdout.read().strip()
        print >> sys.stderr, retcode
        proc.wait()
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #32
0
 def start(self):
     with fab.cd(_('%(remote_dir)s/%(project_name)s')):
         # TODO use' socket=%(remote_dir)s/run/fcgi.sock'
         fab.run(
             _(
                 '../env/bin/python manage.py runfcgi'
                 ' host=127.0.0.1 port=8080', ' daemonize=true'
                 ' minspare=1'
                 ' maxspare=%(worker_count)s'
                 ' maxchildren=%(worker_count)s'
                 ' maxrequests=10000'
                 ' method=prefork'
                 ' pidfile=%(remote_dir)s/run/fcgi.pid'
                 ' logfile=%(remote_dir)s/log/fcgi.log'))
Пример #33
0
def func_manager_set(ipaddr):
    try:
        cmd = "sudo python %s manager_set %s" % (settings.digimanager, ipaddr)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        retcode = proc.stdout.read().strip()
        print >> sys.stderr, retcode
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        proc.wait()
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #34
0
def func_service_del_cifs_links(service_name, node_name, pid):
    retcode = 'operation failed'
    try:
        cmd = 'sudo python %s service cifs_del_links %s %s %s' % (
            settings.digimanager, service_name, node_name, pid)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        retcode = result[0]
        links_list = []
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #35
0
def func_group_delete(clustergroupname):
    try:
        cmd = "sudo python %s group del %s" % (settings.digimanager,
                                               clustergroupname)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        retcode = proc.stdout.read().strip()
        proc.wait()
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #36
0
    def configure(self):
        if fab.env.project.use_django:
            if fab.env.project.django.HAS_WSGI:
                default_template = 'uwsgi/django.ini'
            else:
                default_template = 'uwsgi/django_old.ini'
        else:
            default_template = 'uwsgi/default.ini'

        upload_first([_('uwsgi/%(domain)s.conf'),
                      _('nginx/%(domain)s.uwsgi.conf'),
                      default_template],
                     _('%(remote_dir)s/etc/uwsgi/conf.ini'),
                     fab.env,
                     use_jinja=True)
Пример #37
0
def func_service_cifs_add_user(clusterservicename, username, password):
    try:
        cmd = 'sudo python %s service cifs_add_user %s %s %s' % (
            settings.digimanager, clusterservicename, username, password)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        retcode = result[0]
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #38
0
    def configure(self):
        if fab.env.project.use_django:
            if fab.env.project.django.HAS_WSGI:
                default_template = 'uwsgi/django.ini'
            else:
                default_template = 'uwsgi/django_old.ini'
        else:
            default_template = 'uwsgi/default.ini'

        upload_first([
            _('uwsgi/%(domain)s.conf'),
            _('nginx/%(domain)s.uwsgi.conf'), default_template
        ],
                     _('%(remote_dir)s/etc/uwsgi/conf.ini'),
                     fab.env,
                     use_jinja=True)
Пример #39
0
def func_service_cifs_export(option, clusterservicename=''):
    retcode = 'operation failed'
    nodes_status = []
    cmd = 'sudo python %s service export_cifs %s %s' % (
        settings.digimanager, clusterservicename, option)
    proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
    Ologger.info(cmd)
    result = proc.stdout.readlines()
    proc.wait()
    retcode = result[0].strip()
    if retcode == '0' and option == 'status':
        for node_status in result[1:-1]:
            node_status = node_status.split()
            nodes_status.append(': '.join(node_status) + '<br />')
        return nodes_status
    else:
        success = result[1].split(' ')
        success = success[0].split(':')
        success = success[1].strip()
        print >> sys.stderr, success
        if retcode == '0' and success != '0':
            retcode = '0'
        else:
            retcode = '1'
        return retcode == '0' and retcode or _(retcode)
Пример #40
0
    def start(self):
        if self.supervisor:
            return

        fab.run(
            _('%(remote_dir)s/env/bin/uwsgi'
              ' --ini %(remote_dir)s/etc/uwsgi/conf.ini'))
Пример #41
0
def func_service_extend(clusterservicename, clusterservicedata):
    retcode = 'operation failed'
    try:
        cmd = 'sudo python %s service add_disk %s %s' % (
            settings.digimanager, clusterservicename, clusterservicedata)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        retcode = result[0]
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #42
0
    def configure(self):
        upload_first([_('nginx/%(domain)s-sh.fcgi'),
                      'fcgi/wrapper-sh.fcgi'],
                     _(self.fcgi_path) + 'wrapper.fcgi',
                     fab.env,
                     mode=0755,
                     use_jinja=True)

        upload_first([_('nginx/%(domain)s.fcgi'),
                      'fcgi/wrapper.fcgi'],
                     _('%(remote_dir)s/http/wrapper.fcgi'),
                     fab.env,
                     mode=0755,
                     use_jinja=True)

        upload_first([_('nginx/%(domain)s.htaccess'),
                      'fcgi/.htaccess'],
                     _('%(remote_dir)s/http/.htaccess'),
                     fab.env,
                     use_jinja=True)

        if self.use_project_media:
            with fab.cd(_('%(remote_dir)s/http')):
                with fab.settings(warn_only=True):
                    fab.run('ln -s ../media/static')
                    fab.run('ln -s ../media/media')
Пример #43
0
def func_client_node_status(op, service_name, node_name):
    retcode = 'operation failed'
    try:
        cmd = 'sudo python %s service client_%s %s %s' % (
            settings.digimanager, op, service_name, node_name)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        proc.wait()
        retcode = result[0]
        if retcode != '0':
            retcode = retcode.split(':')
            retcode = retcode[0]
        #retcode = 0;
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #44
0
def func_group_add_node(clustergroupname, clusternodename=[]):
    retcode = '0'
    try:
        for nodename in clusternodename:
            cmd = "sudo python %s node setgroup %s %s" % (
                settings.digimanager, nodename, clustergroupname)
            proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
            Ologger.info(cmd)
            ret = proc.stdout.read().strip()
            proc.wait()
            if ret != '0':
                retcode = ret.split(':')
                retcode = retcode[0]
                break
        return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #45
0
def func_manager_get():
    try:
        cmd = "sudo python %s manager_get" % (settings.digimanager)
        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        Ologger.info(cmd)
        result = proc.stdout.readlines()
        print >> sys.stderr, result
        retcode = result[0].strip()
        proc.wait()
        if retcode == "0":
            data = result[1].strip()
            print >> sys.stderr, data
            return data
        else:
            return retcode == '0' and retcode or _(retcode)
    except Exception, e:
        logger.debug(e)
        return retcode == '0' and retcode or _(retcode)
Пример #46
0
    def ssh_add_key(self, pub_key_file):
        """ Adds a ssh key from passed file to user's
            authorized_keys on server. """
        with open(os.path.normpath(pub_key_file), "rt") as f:
            ssh_key = f.read()
        if fab.env.user == "root":
            ssh_dir = "/root/.ssh"
        else:
            if "home_dir" in fab.env:
                ssh_dir = _("%(home_dir)s/.ssh")
            else:
                ssh_dir = _("/home/%(user)s/.ssh")

        remote_os = fab.env.os
        remote_os.mkdir(ssh_dir)
        fab_files.append("%s/authorized_keys" % ssh_dir, ssh_key)

        with fab.settings(warn_only=True):  # no chmod in system
            remote_os.set_permissions(ssh_dir, pattern="700")
            remote_os.set_permissions("%s/authorized_keys" % ssh_dir, pattern="600")
Пример #47
0
    def prepare(self):
        fab.local(_("cd tmp/ && tar -czf %(vcs_repo_name)s.tgz %(vcs_repo_name)s"))
        fab.put(_('tmp/%(vcs_repo_name)s.tgz'), _('%(remote_dir)s/tmp/'))

        with fab.cd(_('%(remote_dir)s/tmp')):
            fab.run(_("tar -xzf %(remote_dir)s/tmp/%(vcs_repo_name)s.tgz"))

        with fab.cd(_('%(remote_dir)s')):
            fab.env.os.mkdir("build")
            fab.run(_("mv %(remote_dir)s/tmp/%(vcs_repo_name)s build"))
Пример #48
0
    def ssh_add_key(self, pub_key_file):
        """ Adds a ssh key from passed file to user's
            authorized_keys on server. """
        with open(os.path.normpath(pub_key_file), 'rt') as f:
            ssh_key = f.read()
        if fab.env.user == 'root':
            ssh_dir = '/root/.ssh'
        else:
            if 'home_dir' in fab.env:
                ssh_dir = _('%(home_dir)s/.ssh')
            else:
                ssh_dir = _('/home/%(user)s/.ssh')

        remote_os = fab.env.os
        remote_os.mkdir(ssh_dir)
        fab_files.append('%s/authorized_keys' % ssh_dir, ssh_key)

        with fab.settings(warn_only=True): # no chmod in system
           remote_os.set_permissions(ssh_dir, pattern='700')
           remote_os.set_permissions('%s/authorized_keys' % ssh_dir,
                                     pattern='600')
Пример #49
0
    def configure(self):

        fab.put(self.local_dir + _("/%(instance_name)s"), "/tmp/")
        fab.sudo(_("cp /tmp/%(instance_name)s /etc/apache2/sites-available/%(instance_name)s"))
        self.enable_site(_("%(instance_name)s"))

        fab.put(self.local_dir + "/django.wsgi", "/tmp/")
        fab.run("chmod 755 /tmp/django.wsgi")
        fab.run(_("mkdir -p %(remote_dir)s/%(project_name)s/etc/apache"))
        fab.run(_("cp /tmp/django.wsgi %(remote_dir)s/%(project_name)s/etc/apache/django.wsgi"))
        fab.sudo(_("chown %(user)s:www-data -R %(remote_dir)s/%(project_name)s"))
        fab.sudo(_("chmod u=rwx,g=rx,o= -R %(remote_dir)s/%(project_name)s"))
Пример #50
0
    def create(self, key=None):

        if "provider" in fab.env and fab.env.provider.can_adduser:
            if key:
                self.update_rsa_key(key)  # for root

            self.os_add_user()
            self.speedydeploy_configure()

            if key:
                self.ssh_add_key(key)

            fab.run(_("echo root > %(remote_dir)s/.forward"))

        if "db" in fab.env:
            self.db_create_user(fab.env.user, fab.env.db_pass)
            self.db_create_db(fab.env.user, fab.env.user, fab.env.db_pass)

        self.create_virtual_env()
Пример #51
0
    def update_static_files(self):
        remote_dir = fab.env['remote_dir']
        files = fab.env['server_static_files'] = list()

        test_dirs = ['nginx/files',
                     _('nginx/%(domain)s')]

        for dir in test_dirs:

            if not os.path.exists(dir):
                continue

            for filename in os.listdir(dir):
                if filename.startswith('.'):
                    continue
                # TODO use jinia template engine to render txt files(robots.txt)
                fab.put("%s/%s" % (dir, filename),
                        "%s/media/%s" % (remote_dir, filename))
                files.append(filename)
Пример #52
0
 def clone(self):
     repo_name = fab.env.get('vcs_repo_name') or ''
     fab.run(_('git clone --recursive %(git_path)s') + ' ' + repo_name)
Пример #53
0
 def clone(self):
     fab.run(_('git clone --recursive %(git_path)s'))
Пример #54
0
 def find_last_rev(self):
     out = fab.local(_('svn log -ql1 %(svn_repo)s/%(vcs_repo_name)s'),
                     capture=True)
     return out.split()[1].strip('r')
Пример #55
0
 def use_submodules(self):
     return exists(_('%(remote_dir)s/%(vcs_repo_name)s/.gitmodules'))
Пример #56
0
 def clone(self):
     fab.run(_('svn checkout -r %(svn_rev)s %(svn_path)s %(vcs_repo_name)s'))
Пример #57
0
 def export(self):
     # TODO svn_rev svn_path move to self attrs
     fab.local("mkdir tmp")
     fab.local(_("svn export -r %(svn_rev)s %(svn_path)s ./tmp/%(vcs_repo_name)s"))
Пример #58
0
 def remove(self):
     self.disable()
     fab.sudo(_("rm -f %(server_dir)ssites-available/%(domain)s.conf"))
Пример #59
0
 def export(self):
     fab.local("mkdir tmp")
     fab.local(_("git clone ./tmp/%(vcs_repo_name)s"))
Пример #60
0
 def clear(self):
     with fab.cd(_('%(remote_dir)s')):
         fab.env.os.rm("build")
     fab.local("rm -rf tmp/")