• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python osi.run_command函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中system.osi.run_command函数的典型用法代码示例。如果您正苦于以下问题:Python run_command函数的具体用法?Python run_command怎么用?Python run_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了run_command函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: post

 def post(self, request):
     with self._handle_exception(request):
         name = request.data.get('name')
         cert = request.data.get('cert')
         key = request.data.get('key')
         TLSCertificate.objects.filter().exclude(name=name).delete()
         co, created = TLSCertificate.objects.get_or_create(name=name, defaults={'certificate': cert, 'key': key})
         if (not created):
             co.certificate = cert
             co.key = key
             co.save()
         fo, kpath = mkstemp()
         fo, cpath = mkstemp()
         with open(kpath, 'w') as kfo, open(cpath, 'w') as cfo:
             kfo.write(key)
             cfo.write(cert)
         try:
             o, e, rc = run_command([OPENSSL, 'rsa', '-noout', '-modulus',
                                     '-in', kpath])
         except Exception, e:
             logger.exception(e)
             e_msg = ('RSA key modulus could not be verified for the given '
                      'Private Key. Correct your input and try again')
             handle_exception(Exception(e_msg), request)
         try:
             o2, e, rc = run_command([OPENSSL, 'x509', '-noout',
                                      '-modulus', '-in', cpath])
         except Exception, e:
             logger.exception(e)
             e_msg = ('RSA key modulus could not be verified for the given '
                      'Certificate. Correct your input and try again')
             handle_exception(Exception(e_msg), request)
开发者ID:Ajunboys,项目名称:rockstor-core,代码行数:32,代码来源:tls_certificate.py


示例2: snaps_info

def snaps_info(mnt_pt, share_name):
    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-u', '-p', '-q', mnt_pt])
    share_id = share_uuid = None
    for l in o:
        if (re.match('ID ', l) is not None):
            fields = l.split()
            if (fields[-1] == share_name):
                share_id = fields[1]
                share_uuid = fields[12]
    if (share_id is None): return {}

    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', '-p', '-q',
                            '-u', mnt_pt])
    snaps_d = {}
    snap_uuids = []
    for l in o:
        if (re.match('ID ', l) is not None):
            fields = l.split()
            # parent uuid must be share_uuid or another snapshot's uuid
            if (fields[7] != share_id and fields[15] != share_uuid and
                fields[15] not in snap_uuids):
                continue
            snap_name, writable = parse_snap_details(mnt_pt, fields)
            snaps_d[snap_name] = ('0/%s' % fields[1], writable, )
            # we rely on the observation that child snaps are listed after their
            # parents, so no need to iterate through results separately.
            # Instead, we add the uuid of a snap to the list and look up if
            # it's a parent of subsequent entries.
            snap_uuids.append(fields[17])

    return snaps_d
开发者ID:BillTheBest,项目名称:rockstor-core,代码行数:31,代码来源:btrfs.py


示例3: snaps_info

def snaps_info(mnt_pt, share_name):
    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-u', '-p', '-q', mnt_pt])
    share_id = share_uuid = None
    for l in o:
        if (re.match('ID ', l) is not None):
            fields = l.split()
            if (fields[-1] == share_name):
                share_id = fields[1]
                share_uuid = fields[12]
    if (share_id is None):
        raise Exception('Failed to get uuid of the share(%s) under mount(%s)'
                        % (share_name, mnt_pt))

    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', '-p', '-q',
                            mnt_pt])
    snaps_d = {}
    for l in o:
        if (re.match('ID ', l) is not None):
            fields = l.split()
            #parent uuid must be share_uuid
            if (fields[7] != share_id and fields[15] != share_uuid):
                continue
            writable = True
            o1, e1, rc1 = run_command([BTRFS, 'property', 'get',
                                       '%s/%s' % (mnt_pt, fields[-1])])
            for l1 in o1:
                if (re.match('ro=', l1) is not None):
                    if (l1.split('=')[1] == 'true'):
                        writable = False
            snap_name = fields[-1].split('/')[-1]
            snaps_d[snap_name] = ('0/%s' % fields[1], writable)
    return snaps_d
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:32,代码来源:btrfs.py


示例4: shares_info

def shares_info(mnt_pt):
    #return a lit of share names unter this mount_point.
    #useful to gather names of all shares in a pool
    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-s', mnt_pt])
    snap_ids = []
    for l in o:
        if (re.match('ID ', l) is not None):
            snap_ids.append(l.split()[1])

    o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-p', mnt_pt])
    shares_d = {}
    share_ids = []
    for l in o:
        if (re.match('ID ', l) is None):
            continue
        fields = l.split()
        vol_id = fields[1]
        if (vol_id in snap_ids):
            #snapshot
            continue

        parent_id = fields[5]
        if (parent_id in share_ids):
            #subvol of subvol. add it so child subvols can also be ignored.
            share_ids.append(vol_id)
        elif (parent_id in snap_ids):
            #snapshot/subvol of snapshot. add it so child subvols can also be ignored.
            snap_ids.append(vol_id)
        else:
            shares_d[fields[-1]] = '0/%s' % vol_id
            share_ids.append(vol_id)
    return shares_d
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:32,代码来源:btrfs.py


示例5: remove_share

def remove_share(pool, share_name, pqgroup, force=False):
    """
    umount share if its mounted.
    mount root pool
    btrfs subvolume delete root_mnt/vol_name
    umount root pool
    """
    if (is_share_mounted(share_name)):
        mnt_pt = ('%s%s' % (DEFAULT_MNT_DIR, share_name))
        umount_root(mnt_pt)
    root_pool_mnt = mount_root(pool)
    subvol_mnt_pt = root_pool_mnt + '/' + share_name
    if (not is_subvol(subvol_mnt_pt)):
        return
    if (force):
        o, e, rc = run_command([BTRFS, 'subvolume', 'list', '-o', subvol_mnt_pt])
        for l in o:
            if (re.match('ID ', l) is not None):
                subvol = root_pool_mnt + '/' + l.split()[-1]
                run_command([BTRFS, 'subvolume', 'delete', subvol], log=True)
    qgroup = ('0/%s' % share_id(pool, share_name))
    delete_cmd = [BTRFS, 'subvolume', 'delete', subvol_mnt_pt]
    run_command(delete_cmd, log=True)
    qgroup_destroy(qgroup, root_pool_mnt)
    return qgroup_destroy(pqgroup, root_pool_mnt)
开发者ID:sfranzen,项目名称:rockstor-core,代码行数:25,代码来源:btrfs.py


示例6: backup_config

def backup_config():
    models = {'storageadmin':
              ['user', 'group', 'sambashare', 'sambacustomconfig',
               'netatalkshare', 'nfsexport',
               'nfsexportgroup', 'advancednfsexport', ],
              'smart_manager':
              ['service', ], }
    model_list = []
    for a in models:
        for m in models[a]:
            model_list.append('%s.%s' % (a, m))
    logger.debug('model list = %s' % model_list)

    filename = ('backup-%s.json' % datetime.now().strftime('%Y-%m-%d-%H%M%S'))
    cb_dir = ConfigBackup.cb_dir()

    if (not os.path.isdir(cb_dir)):
        os.mkdir(cb_dir)
    fp = os.path.join(cb_dir, filename)
    with open(fp, 'w') as dfo:
        call_command('dumpdata', *model_list, stdout=dfo)
        dfo.write('\n')
        call_command('dumpdata', database='smart_manager', *model_list,
                     stdout=dfo)
    run_command(['/usr/bin/gzip', fp])
    gz_name = ('%s.gz' % filename)
    fp = os.path.join(cb_dir, gz_name)
    size = os.stat(fp).st_size
    cbo = ConfigBackup(filename=gz_name, md5sum=md5sum(fp), size=size)
    cbo.save()
    return cbo
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:31,代码来源:config_backup.py


示例7: owncloud_install

def owncloud_install(rockon):
    for c in DContainer.objects.filter(rockon=rockon).order_by('launch_order'):
        cmd = list(DCMD2) + ['--name', c.name, ]
        db_user = DCustomConfig.objects.get(rockon=rockon, key='db_user').val
        db_pw = DCustomConfig.objects.get(rockon=rockon, key='db_pw').val
        if (c.dimage.name == 'postgres'):
            cmd.extend(['-e', 'POSTGRES_USER=%s' % db_user, '-e',
                        'POSTGRES_PASSWORD=%s' % db_pw])
        cmd.extend(port_ops(c))
        for lo in DContainerLink.objects.filter(destination=c):
            cmd.extend(['--link', '%s:%s' % (lo.source.name, lo.name)])
        cmd.extend(vol_ops(c))
        if (c.name == 'owncloud'):
            cmd.extend(['-v', '%s/rockstor.key:/etc/ssl/private/owncloud.key' % settings.CERTDIR,
                        '-v', '%s/rockstor.cert:/etc/ssl/certs/owncloud.crt' % settings.CERTDIR,
                        '-e', 'HTTPS_ENABLED=true'])
            cmd.extend(['-e', 'DB_USER=%s' % db_user, '-e', 'DB_PASS=%s' % db_pw,])
        cmd.append(c.dimage.name)
        logger.debug('docker cmd = %s' % cmd)
        run_command(cmd)
        if (c.dimage.name == 'postgres'):
            #make sure postgres is setup
            cur_wait = 0;
            while (True):
                o, e, rc = run_command([DOCKER, 'exec', c.name, 'psql', '-U',
                                        'postgres', '-c', "\l"], throw=False)
                if (rc == 0):
                    break
                if (cur_wait > 300):
                    logger.error('Waited too long(300 seconds) for '
                                 'postgres to initialize for owncloud. giving up.')
                    break
                time.sleep(1)
                cur_wait += 1
开发者ID:pecigonzalo,项目名称:rockstor-core,代码行数:34,代码来源:rockon_helpers.py


示例8: qgroup_assign

def qgroup_assign(qid, pqid, mnt_pt):
    if (qgroup_is_assigned(qid, pqid, mnt_pt)):
        return True

    # since btrfs-progs 4.2, qgroup assign succeeds but throws a warning:
    # "WARNING: # quotas may be inconsistent, rescan needed" and returns with
    # exit code 1.
    try:
        run_command([BTRFS, 'qgroup', 'assign', qid, pqid, mnt_pt])
    except CommandException as e:
        wmsg = 'WARNING: quotas may be inconsistent, rescan needed'
        if (e.rc == 1 and e.err[0] == wmsg):
            # schedule a rescan if one is not currently running.
            dmsg = ('Quota inconsistency while assigning %s. Rescan scheduled.'
                    % qid)
            try:
                run_command([BTRFS, 'quota', 'rescan', mnt_pt])
                return logger.debug(dmsg)
            except CommandException as e2:
                emsg = 'ERROR: quota rescan failed: Operation now in progress'
                if (e2.rc == 1 and e2.err[0] == emsg):
                    return logger.debug('%s.. Another rescan already in '
                                        'progress.' % dmsg)
                logger.exception(e2)
                raise e2
        logger.exception(e)
        raise e
开发者ID:priyaganti,项目名称:rockstor-core,代码行数:27,代码来源:btrfs.py


示例9: fill_up_share

def fill_up_share(pname, sname, chunk=(1024 * 1024 * 2)):
    so = Share.objects.get(name=sname)
    rusage, eusage = share_usage(so.pool, so.qgroup)
    print('Writing to Share(%s) until quota is exceeded.' % sname)
    print('Share(%s) Size: %d Usage: %d' % (sname, so.size, rusage))
    spath = '/mnt2/%s/%s' % (pname, sname)
    file_indices = sorted([int(f.split('-')[1]) for f in os.listdir(spath)],
                          reverse=True)
    counter = 0
    if (len(file_indices) > 0):
        counter = file_indices[0] + 1
    quota_exceeded = False
    while (not quota_exceeded):
        fname = '%s/file-%d' % (spath, counter)
        one_mb = 's' * chunk
        try:
            with open(fname, 'w') as ofo:
                for i in range(100):
                    ofo.write(one_mb)
        except IOError as e:
            if (re.search('Disk quota exceeded', e.__str__()) is not None):
                print(e.__str__())
                quota_exceeded = True
            else:
                raise e

        run_command(['/usr/bin/sync'])
        rusage, eusage = share_usage(so.pool, so.qgroup)
        print('Share(%s) Size: %d Usage: %d' % (sname, so.size, rusage))
        counter += 1
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:30,代码来源:qgroup_test.py


示例10: qgroup_destroy

def qgroup_destroy(qid, mnt_pt):
    o, e, rc = run_command([BTRFS, 'qgroup', 'show', mnt_pt])
    for l in o:
        if (re.match(qid, l) is not None and
            l.split()[0] == qid):
            return run_command([BTRFS, 'qgroup', 'destroy', qid, mnt_pt], log=True)
    return False
开发者ID:BillTheBest,项目名称:rockstor-core,代码行数:7,代码来源:btrfs.py


示例11: main

def main():
    for p in Pool.objects.all():
        print('Processing pool(%s)' % p.name)
        mnt_pt = mount_root(p)
        o, e, rc = run_command([BTRFS, 'qgroup', 'show', '-p', mnt_pt],
                               throw=False)
        if (rc != 0):
            print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
            continue

        qgroup_ids = []
        for l in o:
            if (re.match('qgroupid', l) is not None or
                re.match('-------', l) is not None):
                continue
            cols = l.strip().split()
            if (len(cols) != 4):
                print('Ignoring unexcepted line(%s).' % l)
                continue
            if (cols[3] == '---'):
                print('No parent qgroup for %s' % l)
                continue
            qgroup_ids.append(cols[3])

        for q in qgroup_ids:
            print('relaxing the limit on qgroup %s' % q)
            run_command([BTRFS, 'qgroup', 'limit', 'none', q, mnt_pt])

        print('Finished processing pool(%s)' % p.name)
开发者ID:Stoney49th,项目名称:rockstor-core,代码行数:29,代码来源:qgroup_maxout_limit.py


示例12: main

def main():
    for p in Pool.objects.all():
        print('Processing pool(%s)' % p.name)
        mnt_pt = mount_root(p)
        o, e, rc = run_command([BTRFS, 'subvol', 'list', mnt_pt])
        subvol_ids = []
        for l in o:
            if (re.match('ID ', l) is not None):
                subvol_ids.append(l.split()[1])

        o, e, rc = run_command([BTRFS, 'qgroup', 'show', mnt_pt], throw=False)
        if (rc != 0):
            print('Quotas not enabled on pool(%s). Skipping it.' % p.name)
            continue

        qgroup_ids = []
        for l in o:
            if (re.match('0/', l) is not None):
                q = l.split()[0].split('/')[1]
                if (q == '5'):
                    continue
                qgroup_ids.append(l.split()[0].split('/')[1])

        for q in qgroup_ids:
            if (q not in subvol_ids):
                print('qgroup %s not in use. deleting' % q)
                run_command([BTRFS, 'qgroup', 'destroy', '0/%s' % q, mnt_pt])
            else:
                print('qgroup %s is in use. Moving on.' % q)
        print('Finished processing pool(%s)' % p.name)
开发者ID:Stoney49th,项目名称:rockstor-core,代码行数:30,代码来源:qgroup_clean.py


示例13: init_update_issue

def init_update_issue():
    default_if = None
    ipaddr = None
    o, e, c = run_command(['/usr/sbin/route'])
    for i in o:
        if (re.match('default', i) is not None):
            default_if = i.split()[-1]
    if (default_if is not None):
        o2, e, c = run_command(['/usr/sbin/ifconfig', default_if])
        for i2 in o2:
            if (re.match('inet ', i2.strip()) is not None):
                ipaddr = i2.split()[1]
    with open('/etc/issue', 'w') as ifo:
        if (ipaddr is None):
            ifo.write('The system does not yet have an ip address.\n')
            ifo.write('Rockstor cannot be configured using the web interface '
                        'without this.\n\n')
            ifo.write('Press Enter to receive updated network status\n')
            ifo.write('If this message persists login as root and configure '
                      'your network manually to proceed further.\n')
        else:
            ifo.write('\nRockstor is successfully installed.\n\n')
            ifo.write('You can access the web-ui by pointing your browser to '
                      'https://%s\n\n' % ipaddr)
    return ipaddr
开发者ID:Lorgne,项目名称:rockstor-core,代码行数:25,代码来源:initrock.py


示例14: main

def main():
    for p in Pool.objects.all():
        try:
            print("Processing pool(%s)" % p.name)
            mnt_pt = mount_root(p)
            o, e, rc = run_command([BTRFS, "qgroup", "show", "-p", mnt_pt], throw=False)
            if rc != 0:
                print("Quotas not enabled on pool(%s). Skipping it." % p.name)
                continue

            qgroup_ids = []
            for l in o:
                if re.match("qgroupid", l) is not None or re.match("-------", l) is not None:
                    continue
                cols = l.strip().split()
                if len(cols) != 4:
                    print("Ignoring unexcepted line(%s)." % l)
                    continue
                if cols[3] == "---":
                    print("No parent qgroup for %s" % l)
                    continue
                qgroup_ids.append(cols[3])

            for q in qgroup_ids:
                print("relaxing the limit on qgroup %s" % q)
                run_command([BTRFS, "qgroup", "limit", "none", q, mnt_pt])

            print("Finished processing pool(%s)" % p.name)
        except Exception, e:
            print("Exception while qgroup-maxout of Pool(%s): %s" % (p.name, e.__str__()))
开发者ID:rockstor,项目名称:rockstor-core,代码行数:30,代码来源:qgroup_maxout_limit.py


示例15: main

def main():
    for p in Pool.objects.all():
        try:
            print("Processing pool(%s)" % p.name)
            mnt_pt = mount_root(p)
            o, e, rc = run_command([BTRFS, "subvol", "list", mnt_pt])
            subvol_ids = []
            for l in o:
                if re.match("ID ", l) is not None:
                    subvol_ids.append(l.split()[1])

            o, e, rc = run_command([BTRFS, "qgroup", "show", mnt_pt], throw=False)
            if rc != 0:
                print("Quotas not enabled on pool(%s). Skipping it." % p.name)
                continue

            qgroup_ids = []
            for l in o:
                if re.match("0/", l) is not None:
                    q = l.split()[0].split("/")[1]
                    if q == "5":
                        continue
                    qgroup_ids.append(l.split()[0].split("/")[1])

            for q in qgroup_ids:
                if q not in subvol_ids:
                    print("qgroup %s not in use. deleting" % q)
                    run_command([BTRFS, "qgroup", "destroy", "0/%s" % q, mnt_pt])
                else:
                    print("qgroup %s is in use. Moving on." % q)
            print("Finished processing pool(%s)" % p.name)
        except Exception, e:
            print("Exception while qgroup-cleanup of Pool(%s): %s" % (p.name, e.__str__()))
开发者ID:rockstor,项目名称:rockstor-core,代码行数:33,代码来源:qgroup_clean.py


示例16: switch_quota

def switch_quota(pool_name, device, flag='enable'):
    root_mnt_pt = mount_root(pool_name, device)
    cmd = [BTRFS, 'quota', flag, root_mnt_pt]
    out, err, rc = run_command(cmd)
    #@hack -- umount without sync failes.
    run_command(SYNC)
    umount_root(root_mnt_pt)
    return out, err, rc
开发者ID:tilakkalyan,项目名称:rockstor-core,代码行数:8,代码来源:btrfs.py


示例17: update_sasl

def update_sasl(smtp_server, sender, password, revert=False):
    sasl_file = '/etc/postfix/sasl_passwd'
    with open(sasl_file, 'w') as fo:
        if (not revert):
            fo.write('[%s]:587 %s:%s\n' % (smtp_server, sender, password))
    os.chmod(sasl_file, 0400)
    run_command([POSTMAP, sasl_file])
    os.chmod('%s.db' % sasl_file, 0600)
开发者ID:Mchakravartula,项目名称:rockstor-core,代码行数:8,代码来源:email_client.py


示例18: handle_exception

def handle_exception(e, request):
    logger.error('request path: %s method: %s data: %s' %
                 (request.path, request.method, request.DATA))
    logger.exception('exception: %s' % e.__str__())
    run_command(['/usr/bin/tar', '-c', '-z', '-f',
                     settings.ROOT_DIR + 'src/rockstor/logs/error.tgz',
                     settings.ROOT_DIR + 'var/log'])
    raise RockStorAPIException(detail=e.__str__())
开发者ID:sigkill,项目名称:rockstor-core,代码行数:8,代码来源:util.py


示例19: generic_install

def generic_install(rockon):
    for c in DContainer.objects.filter(rockon=rockon).order_by('launch_order'):
        cmd = list(DCMD2) + ['--name', c.name,]
        cmd.extend(vol_ops(c))
        cmd.extend(port_ops(c))
        cmd.extend(container_ops(c))
        cmd.append(c.dimage.name)
        run_command(cmd)
开发者ID:pecigonzalo,项目名称:rockstor-core,代码行数:8,代码来源:rockon_helpers.py


示例20: update_quota

def update_quota(pool_name, pool_device, qgroup, size_bytes):
    pool_device = '/dev/' + pool_device
    root_pool_mnt = mount_root(pool_name, pool_device)
    cmd = [BTRFS, 'qgroup', 'limit', size_bytes, qgroup, root_pool_mnt]
    out, err, rc = run_command(cmd)
    run_command(SYNC)
    umount_root(root_pool_mnt)
    return out, err, rc
开发者ID:tilakkalyan,项目名称:rockstor-core,代码行数:8,代码来源:btrfs.py



注:本文中的system.osi.run_command函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python process_context.ProcessContext类代码示例发布时间:2022-05-27
下一篇:
Python osi.is_share_mounted函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap