# Path: config/views.py
# def get_dir(args):
#     config = ConfigParser.RawConfigParser()
#     dirs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#     with open(dirs+'/adminset.conf', 'r') as cfgfile:
#         config.readfp(cfgfile)
#         a_path = config.get('config', 'ansible_path')
#         r_path = config.get('config', 'roles_path')
#         p_path = config.get('config', 'playbook_path')
#         s_path = config.get('config', 'scripts_path')
#         token = config.get('token', 'token')
#         ssh_pwd = config.get('token', 'ssh_pwd')
#         log_path = config.get('log', 'log_path')
#         log_level = config.get('log', 'log_level')
#         mongodb_ip = config.get('mongodb', 'mongodb_ip')
#         mongodb_port = config.get('mongodb', 'mongodb_port')
#         mongodb_user = config.get('mongodb', 'mongodb_user')
#         mongodb_pwd = config.get('mongodb', 'mongodb_pwd')
#         mongodb_collection = config.get('mongodb', 'collection')
#         webssh_domain = config.get('webssh', 'domain')
#     # 根据传入参数返回变量以获取配置，返回变量名与参数名相同
#     if args:
#         return vars()[args]
#     else:
#         return HttpResponse(status=403)


from django.http import HttpResponse
from models import Host, HostGroup, ASSET_TYPE, ASSET_STATUS
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.views.decorators.csrf import csrf_exempt
from lib.common import token_verify
from lib.deploy_key import deploy_key
from lib.log import log
from config.views import get_dir
import logging
    import json
    import simplejson as json
        show_end = 0

    # 所有对象， 分页器， 本页对象， 所有页码， 本页页码，是否显示第一页，是否显示最后一页
    return post_objects, paginator, page_objects, page_range, current_page, show_first, show_end


@csrf_exempt
@token_verify()
def collect(request):
    asset_info = json.loads(request.body)
    if request.method == 'POST':
        vendor = asset_info['vendor']
        # group = asset_info['group']
        disk = asset_info['disk']
        cpu_model = asset_info['cpu_model']
        cpu_num = asset_info['cpu_num']
        memory = asset_info['memory']
        sn = asset_info['sn']
        osver = asset_info['osver']
        hostname = asset_info['hostname']
        ip = asset_info['ip']
        # asset_type = ""
        # status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except Exception as msg:
            print(msg)
            host = Host()
            level = get_dir("log_level")
            ssh_pwd = get_dir("ssh_pwd")

# Path: config/views.py
# def get_dir(args):
#     config = ConfigParser.RawConfigParser()
#     dirs = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
#     with open(dirs+'/adminset.conf', 'r') as cfgfile:
#         config.readfp(cfgfile)
#         a_path = config.get('config', 'ansible_path')
#         r_path = config.get('config', 'roles_path')
#         p_path = config.get('config', 'playbook_path')
#         s_path = config.get('config', 'scripts_path')
#         token = config.get('token', 'token')
#         ssh_pwd = config.get('token', 'ssh_pwd')
#         log_path = config.get('log', 'log_path')
#         log_level = config.get('log', 'log_level')
#         mongodb_ip = config.get('mongodb', 'mongodb_ip')
#         mongodb_port = config.get('mongodb', 'mongodb_port')
#         mongodb_user = config.get('mongodb', 'mongodb_user')
#         mongodb_pwd = config.get('mongodb', 'mongodb_pwd')
#         mongodb_collection = config.get('mongodb', 'collection')
#         webssh_domain = config.get('webssh', 'domain')
#     # 根据传入参数返回变量以获取配置，返回变量名与参数名相同
#     if args:
#         return vars()[args]
#     else:
#         return HttpResponse(status=403)


# Path: cmdb/api.py
from django.http import HttpResponse
from models import Host, HostGroup, ASSET_TYPE, ASSET_STATUS
from django.core.paginator import Paginator, EmptyPage, InvalidPage
from django.views.decorators.csrf import csrf_exempt
from lib.common import token_verify
from lib.deploy_key import deploy_key
from lib.log import log
from config.views import get_dir
import logging
    import json
    import simplejson as json

        show_end = 0

    # 所有对象， 分页器， 本页对象， 所有页码， 本页页码，是否显示第一页，是否显示最后一页
    return post_objects, paginator, page_objects, page_range, current_page, show_first, show_end


@csrf_exempt
@token_verify()
def collect(request):
    asset_info = json.loads(request.body)
    if request.method == 'POST':
        vendor = asset_info['vendor']
        # group = asset_info['group']
        disk = asset_info['disk']
        cpu_model = asset_info['cpu_model']
        cpu_num = asset_info['cpu_num']
        memory = asset_info['memory']
        sn = asset_info['sn']
        osver = asset_info['osver']
        hostname = asset_info['hostname']
        ip = asset_info['ip']
        # asset_type = ""
        # status = ""
        try:
            host = Host.objects.get(hostname=hostname)
        except Exception as msg:
            print(msg)
            host = Host()
            level = get_dir("log_level")
            ssh_pwd = get_dir("ssh_pwd")

            log_path = get_dir("log_path")