Example #1
0
    def get_asset_group_member(self, str_r):
        gid_pattern = re.compile(r'^g\d+$')

        if gid_pattern.match(str_r):
            gid = int(str_r.lstrip('g'))
            # 获取资产组包含的资产
            asset_group = get_object(AssetGroup, id=gid)
            if asset_group and asset_group in self.perm_asset_groups:
                self.search_result = list(asset_group.asset_set.all())
            else:
                color_print('没有该资产组或没有权限')
                return
Example #2
0
def job_edit(request, ids):
    status = 0
    obj = get_object(PeriodicTask, id=ids)
    if request.method == 'POST':
        form = PeriodicTaskForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            status = 1
        else:
            status = 2
    else:
        form = PeriodicTaskForm(instance=obj)

    return render(request, 'jobs/job_edit.html', locals())
Example #3
0
def job_interval_edit(request, ids):
    edit_status = 0
    obj = get_object(IntervalSchedule, id=ids)

    if request.method.lower() == 'post':
        form = IntervalForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            edit_status = 1
        else:
            edit_status = 2
    else:
        form = IntervalForm(instance=obj)

    return render(request, 'jobs/job_interval_edit.html', locals())
Example #4
0
def job_result_edit(request, ids):
    edit_status = 0
    obj = get_object(TaskResult, id=ids)

    if request.method.lower() == 'post':
        # form = TaskResultForm(request.POST, instance=obj)
        form = TaskResultForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            edit_status = 1
        else:
            edit_status = 2

    else:
        form = TaskResultForm(instance=obj)

    return render(request, 'jobs/job_result_edit.html', locals())
Example #5
0
def group_edit(request, ids):
    '''编辑mock属组'''
    obj = get_object(MockGroup, id=ids)
    allgroup = MockGroup.objects.all()
    unselect = Mock.objects.filter(group__name=None)
    members = Mock.objects.filter(group__name=obj.name)
    mod_status = 0
    if request.method == 'POST':
        group_form = GroupForm(request.POST, instance=obj)
        if group_form.is_valid():
            group_form.save()
            mod_status = 1
        else:
            mod_status = 2
    else:
        group_form = GroupForm(instance=obj)
    return render(request, 'mock/group_edit.html', locals())
Example #6
0
def mock_del(request):
    '''获取所有mock接口列表'''
    temp_name = "mock/mock-header.html"
    # mock_list = Mock.objects.all()
    case_id = request.GET.get('id', '')
    # 直接删除
    if case_id:
        Mock.objects.get(id=case_id).delete()

    # 删除勾选用例
    if request.method.lower() == 'post':
        case_batch = request.GET.get('arg', '')
        mock_id_all = str(request.POST.get('mock_id_all', ''))
        if case_batch:
            for case_id in mock_id_all.split(','):
                case_item = get_object(Mock, id=case_id)
                case_item.delete()
    return redirect('/mock/index/')
Example #7
0
def mock_edit(request, ids):
    '''获取所有mock接口列表'''
    temp_name = "mock/mock-header.html"
    obj = get_object(Mock, id=ids)
    mod_status = 0
    if request.method.lower() == 'post':
        cf = MockForm(request.POST, instance=obj)

        if cf.is_valid():
            # response = str(cf.response)

            cf.save()
            mod_status = 1
        else:
            mod_status = 2

    else:
        cf = MockForm(instance=obj)
    return render(request, 'mock/mock_edit.html', locals())
Example #8
0
def mock_run(request, ids):
    '''获取所有mock接口列表'''
    temp_name = "mock/mock-header.html"
    m = get_object(Mock, id=ids)
    _path = m.path
    param = m.params
    try:
        param = json.loads(param)
    except:
        pass
    host = request.get_host()
    url = 'http://' + host + '/mock/mock_api' + _path
    method = m.request_method
    res = None
    headers = None
    if m.headers:
        headers = json.loads(m.headers)

    if method == 1:
        res = requests.get(url=url, params=param, headers=headers)
    elif method == 2:
        if isinstance(param, dict):
            res = requests.post(url=url, json=param, headers=headers)
        else:
            res = requests.post(url=url, data=param, headers=headers)

    response_code = 500
    response_msg = None
    response_headers = None
    if res:
        response_code = res.status_code
        try:
            response_msg = res.json()
        except:
            response_msg = res.text
        response_headers = res.headers

    return render(request, 'mock/mock_info.html', locals())
Example #9
0
def email_edit(request, ids):
    temp_name = 'jobs/job_header.html'
    edit_status = 0
    e_obj = get_object(EmailManager, id=ids)

    if request.method.lower() == 'post':
        # form = TaskResultForm(request.POST, instance=obj)
        form = EmailMangerForm(request.POST, instance=e_obj)
        if form.is_valid():
            form.save()
            edit_status = 1
            display_control = ''
            tips = u'更新成功!'
        else:
            edit_status = 2
            display_control = ''
            tips = u'更新失败!'

    else:
        form = EmailMangerForm(instance=e_obj)
        display_control = "none"

    return render(request, 'jobs/mail_edit.html', locals())
Example #10
0
SSH_KEY_PATH = os.path.join(BASE_DIR, 'keys','osuser')
import ConfigParser



from api import get_object, get_osuser, ServerError, get_server_info, get_user_perm

config = ConfigParser.ConfigParser()
config.read(os.path.join(BASE_DIR,'devops.conf'))

try:
    NAV_SORT_BY = config.get('connect', 'nav_sort_by')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
    NAV_SORT_BY = 'ip'

login_user = get_object(Admin, name=getpass.getuser())
try:
    remote_ip = os.environ.get('SSH_CLIENT').split()[0]
except (IndexError, AttributeError):
    remote_ip = os.popen("who -m | awk '{ print $NF }'").read().strip('()\n')

try:
    import termios
    import tty
except ImportError:
    print '\033[1;31m仅支持类Unix系统 Only unix like supported.\033[0m'
    time.sleep(3)
    sys.exit()