Пример #1
0
def getAnalysisDataRequest(request):
    accountModelList = VcenterAccount.objects.all()
    accountModel = accountModelList[0]

    vmManager = VmManage(host=accountModel.vcenter_host,
                         user=accountModel.account_name,
                         password=accountModel.account_password,
                         port=accountModel.vcenter_port,
                         ssl=None)
    clusters = vmManager.get_cluster_pools()

    storageList = []
    memroyList = []
    cpuList = []
    cpuCoresList = []
    analysis_data = {'storage': [], 'memroy': [], 'cpu': [], 'cpuCores': []}

    for cluster in clusters:
        datastores = cluster.datastore
        clusterForDatastoreTotal = 0
        if len(datastores) > 0:
            for store in datastores:
                clusterForDatastoreTotal += store.summary.capacity
                # print (store.summary.capacity/(1024*1024*1024*1024))
                # print (store.summary.freeSpace/(1024*1024*1024*1024))

        memroyList.append({
            'category': cluster.name,
            'value': cluster.summary.totalMemory
        })
        cpuList.append({
            'category': cluster.name,
            'value': cluster.summary.totalCpu
        })
        storageList.append({
            'category': cluster.name,
            'value': clusterForDatastoreTotal / 1000
        })
        cpuCoresList.append({
            'category': cluster.name,
            'value': cluster.summary.numCpuCores
        })
    analysis_data['storage'] = storageList
    analysis_data['memroy'] = memroyList
    analysis_data['cpu'] = cpuList
    analysis_data['cpuCores'] = cpuCoresList
    return render_json(analysis_data)
Пример #2
0
def getClusterList(request):
    logger.info("获取集群")
    try:
        request_data = json.loads(request.body)
        if 'vaId' in request_data.keys():
            accountModelList = []
            vaId = int(request_data.get('vaId'))
            logging.info('请求的vaId: %d' % vaId)
            accountModelList = VcenterAccount.objects.filter(id=vaId)

            if len(accountModelList) == 0:
                logging.info('请求的accountModelList的长度: %d' % len(accountModelList))
                res = {
                    'code': '30011',
                    'msg': u'获取数据失败,vcenter账号错误'
                }
            else:
                accountModel = accountModelList[0]
                logging.info('获得accountModel对象')
                vmManage = VmManage(host=accountModel.vcenter_host,user=accountModel.account_name,password=accountModel.account_password,port=accountModel.vcenter_port,ssl=None)
                clisters = vmManage.get_cluster_pools()
                clisterList = []
                if clisters is not None:
                    for cluster in clisters:
                       clisterList.append({
                           'id': cluster.name,
                           'text': cluster.name
                       })

                res = {
                    'code': '0',
                    'msg': u'获取集群列表成功',
                    'recordsTotal': len(clisterList),
                    'data': clisterList
                }
        else:
            res = {
                'code': '30012',
                'msg': u'va_id为必须参数'
            }
    except Exception as e:
        logging.info('请求抛出的异常:%s',e.message)
        res = {
            'code': '50000',
            'msg': e.message
        }
    return render_json(res)
Пример #3
0
def getFlowAnalysisList(request):
    logging.info('获取流量分析数据')
    try:
        request_data = json.load(request.body)
        #request_data = request.GET
        if 'vaId' in request_data.keys():
            vaId = int(request_data.get('vaId'))
            accountModelList = VcenterAccount.objects.filter(id=vaId)
            if len(accountModelList) == 0:
                logging.info('请求的accountModelList的长度: %d' % len(accountModelList))
                res = {
                    'code': '51011',
                    'msg': u'获取数据失败,vcenter账号错误'
                }
            else:
                accountModel = accountModelList[0]
                logging.info('请求获取accountModel')
                vmManager = VmManage(host=accountModel.vcenter_host, user=accountModel.account_name,password=accountModel.account_password, port=accountModel.vcenter_port, ssl=None)
                clusters = vmManager.get_cluster_pools()

                storageList = []
                memroyList = []
                cpuList = []
                cpuCoresList = []

                analysis_data ={
                    'storage': [],
                    'memroy': [],
                    'cpu': [],
                    'cpuCores': []
                }
                for cluster in clusters :
                    datastores = cluster.datastore
                    clusterForDatastoreTotal = 0
                    # if len(datastores) > 0 :
                    #     for datastore in datastores:
                    #         clusterForDatastoreTotal += datastore.summary.capacity

                    memroyList.append({'category': cluster.name, 'value': cluster.summary.totalMemory})
                    cpuList.append({'category': cluster.name, 'value': cluster.summary.totalCpu})
                    storageList.append({'category': cluster.name, 'value': clusterForDatastoreTotal / 1000})
                    cpuCoresList.append({'category': cluster.name, 'value': cluster.summary.numCpuCores})
                analysis_data['memroy'] = memroyList
                analysis_data['cpu'] = cpuList
                analysis_data['storage'] = storageList
                analysis_data['cpuCores'] = cpuCoresList

                res = {
                    'code': '0',
                    'msg': '获取流量分析数据成功',
                    'data': analysis_data
                }
        else:
            res = {
                'code': '51012',
                'msg': u'va_id为必须参数'
            }
    except Exception as e:
        res = {
            'code':'50000',
            'msg': e.message
        }
    return render_json(res)