From dd912e8958eabbfb40a9b0a8ddeb8a51b6fd844e Mon Sep 17 00:00:00 2001 From: halcyon <864072399@qq.com> Date: Tue, 1 Dec 2015 23:39:49 +0800 Subject: [PATCH] asset list and add system_arch --- jasset/asset_api.py | 89 ++---------------- jasset/forms.py | 3 +- jasset/models.py | 1 + jumpserver/templatetags/mytags.py | 5 + .../excels/cmdb_excel_2015_12_01_22_17.xlsx | Bin 0 -> 5898 bytes templates/jasset/asset_detail.html | 6 +- templates/jasset/asset_edit.html | 3 + templates/jasset/asset_list.html | 33 ++----- 8 files changed, 31 insertions(+), 109 deletions(-) create mode 100644 static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx diff --git a/jasset/asset_api.py b/jasset/asset_api.py index 0034f6495..2c8446f70 100644 --- a/jasset/asset_api.py +++ b/jasset/asset_api.py @@ -1,4 +1,5 @@ # coding: utf-8 +from __future__ import division import xlrd import xlsxwriter from django.db.models import AutoField @@ -75,83 +76,6 @@ def db_asset_update(**kwargs): Asset.objects.filter(id=asset_id).update(**kwargs) -# -# -# def batch_host_edit(host_alter_dic, j_user='', j_password=''): -# """ 批量修改主机函数 """ -# j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment = host_alter_dic -# groups, depts = [], [] -# is_active = {u'是': '1', u'否': '2'} -# login_types = {'LDAP': 'L', 'MAP': 'M'} -# a = Asset.objects.get(id=j_id) -# if '...' in j_group[0].split(): -# groups = a.bis_group.all() -# else: -# for group in j_group[0].split(): -# c = BisGroup.objects.get(name=group.strip()) -# groups.append(c) -# -# if '...' in j_dept[0].split(): -# depts = a.dept.all() -# else: -# for d in j_dept[0].split(): -# p = DEPT.objects.get(name=d.strip()) -# depts.append(p) -# -# j_type = login_types[j_type] -# j_idc = IDC.objects.get(name=j_idc) -# if j_type == 'M': -# if a.password != j_password: -# j_password = cryptor.decrypt(j_password) -# a.ip = j_ip -# a.port = j_port -# a.login_type = j_type -# a.idc = j_idc -# a.is_active = j_active -# a.comment = j_comment -# a.username = j_user -# a.password = j_password -# else: -# a.ip = j_ip -# a.port = j_port -# a.idc = j_idc -# a.login_type = j_type -# a.is_active = is_active[j_active] -# a.comment = j_comment -# a.save() -# a.bis_group = groups -# a.dept = depts -# a.save() -# -# -# def db_host_delete(request, host_id): -# """ 删除主机操作 """ -# if is_group_admin(request) and not validate(request, asset=[host_id]): -# return httperror(request, '删除失败, 您无权删除!') -# -# asset = Asset.objects.filter(id=host_id) -# if asset: -# asset.delete() -# else: -# return httperror(request, '删除失败, 没有此主机!') -# -# -# def db_idc_delete(request, idc_id): -# """ 删除IDC操作 """ -# if idc_id == 1: -# return httperror(request, '删除失败, 默认IDC不能删除!') -# -# default_idc = IDC.objects.get(id=1) -# -# idc = IDC.objects.filter(id=idc_id) -# if idc: -# idc_class = idc[0] -# idc_class.asset_set.update(idc=default_idc) -# idc.delete() -# else: -# return httperror(request, '删除失败, 没有这个IDC!') - - def sort_ip_list(ip_list): """ ip地址排序 """ ip_list.sort(key=lambda s: map(int, s.split('.'))) @@ -389,7 +313,6 @@ def get_ansible_asset_info(asset_ip, setup_info): for disk_name, disk_info in disk_all.iteritems(): if disk_name.startswith('sd') or disk_name.startswith('hd') or disk_name.startswith('vd'): disk_need[disk_name] = disk_info.get("size") - all_ip = setup_info.get("ansible_all_ipv4_addresses") other_ip_list = all_ip.remove(asset_ip) if asset_ip in all_ip else [] other_ip = ','.join(other_ip_list) if other_ip_list else '' @@ -401,12 +324,17 @@ def get_ansible_asset_info(asset_ip, setup_info): cpu_cores = setup_info.get("ansible_processor_count") cpu = cpu_type + ' * ' + unicode(cpu_cores) memory = setup_info.get("ansible_memtotal_mb") + try: + memory_format = round((int(memory) / 1000), 1) + except Exception: + memory_format = memory disk = disk_need system_type = setup_info.get("ansible_distribution") system_version = setup_info.get("ansible_distribution_version") + system_arch = setup_info.get("ansible_architecture") # asset_type = setup_info.get("ansible_system") sn = setup_info.get("ansible_product_serial") - asset_info = [other_ip, mac, cpu, memory, disk, sn, system_type, system_version, brand] + asset_info = [other_ip, mac, cpu, memory_format, disk, sn, system_type, system_version, brand, system_arch] return asset_info @@ -422,7 +350,7 @@ def asset_ansible_update(obj_list, name=''): continue else: asset_info = get_ansible_asset_info(asset.ip, setup_info) - other_ip, mac, cpu, memory, disk, sn, system_type, system_version, brand = asset_info + other_ip, mac, cpu, memory, disk, sn, system_type, system_version, brand, system_arch = asset_info asset_dic = {"other_ip": other_ip, "mac": mac, "cpu": cpu, @@ -431,6 +359,7 @@ def asset_ansible_update(obj_list, name=''): "sn": sn, "system_type": system_type, "system_version": system_version, + "system_arch": system_arch, "brand": brand } diff --git a/jasset/forms.py b/jasset/forms.py index 03eca04ed..7f96b30c6 100644 --- a/jasset/forms.py +++ b/jasset/forms.py @@ -12,7 +12,8 @@ class AssetForm(forms.ModelForm): fields = [ "ip", "other_ip", "hostname", "port", "group", "username", "password", "use_default_auth", "idc", "mac", "remote_ip", "brand", "cpu", "memory", "disk", "system_type", "system_version", - "cabinet", "position", "number", "status", "asset_type", "env", "sn", "is_active", "comment" + "cabinet", "position", "number", "status", "asset_type", "env", "sn", "is_active", "comment", + "system_arch" ] diff --git a/jasset/models.py b/jasset/models.py index b3765fbe4..558479111 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -78,6 +78,7 @@ class Asset(models.Model): disk = models.CharField(max_length=128, blank=True, null=True, verbose_name=u'硬盘') system_type = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"系统类型") system_version = models.CharField(max_length=8, blank=True, null=True, verbose_name=u"系统版本号") + system_arch = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"系统平台") cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号') position = models.IntegerField(blank=True, null=True, verbose_name=u'机器位置') number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号') diff --git a/jumpserver/templatetags/mytags.py b/jumpserver/templatetags/mytags.py index 2adb62deb..b23a14b96 100644 --- a/jumpserver/templatetags/mytags.py +++ b/jumpserver/templatetags/mytags.py @@ -272,3 +272,8 @@ def get_push_info(push_id, arg): return [role.name for role in push.role.all()] else: return [] + + +@register.filter(name='get_cpu_core') +def get_cpu_core(cpu_info): + return cpu_info.split('* ')[1] if cpu_info else '' diff --git a/static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx b/static/files/excels/cmdb_excel_2015_12_01_22_17.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..37718bab375fd8f0f1228321a03d78923e381f02 GIT binary patch literal 5898 zcmZ`-1yI!Q+Fd|msbz5&X%M6v2?^=WrKLn->0DB}JER1pOF#sa?v`2w6hykDK|&Ca z{8s<>eqNb-cV~X@%+8!=X3u$^_jk?%Q^vRj0RR9vfCtq<@?Qw-7fI0p0ADNsfE4ws zmpzxK6T;5b8V+}J<@$Z_aC$k|$EE5!eWitjEv)O&&NF%0Bnea-^PjWES^6;wJl39h zB#|`SK|`y`)LzebNSx8*ITD6J*L7&9Q*i%w^`d*^Tu=zO+&l;3PO?n1kd{lslN3Dx zLOF|g3=F{)2MYQizlpBl0!O+?XwC_qRTKVD|V}CU5;W?Y3V2FMDP@j+-*bc z)Lz#taGABn*YX~jiv(=-F*-|E>ReXc^75!B3_9LFdAZ1=3Tau6vZg@9>;wlfB0{I> zGC|)iYM$JAdJ+eD=x@#t164k{;^CzbL0s7~3K}3(ST@HwzZJCOq`XPVQTmZ;GVyu< zQLGyN^4?l;ZAU4q?Y7a!1|lE&xdH|4%HoKwN%x$K1ERvyd(bNXHucHpdKfeIYS1|J zE-r;fOjEGiO(HISZ3~m7Typiv-k6MGt}C}z?0x5>Y|@-(dS5GhIhf5eTnN0~AO<;@ zO)-Q!n0;oDb1<7@=yNa|W1ybttydPUi!xR>qaF7Hp=&-oq75)-IMWu7pV$^R7$NsM z!J_?P141{;og+esC^NI?y$S8c#kFI$&wCTrO^EBmOt~AXE9xI0>hHO?D5ZKG_uiLO zU7esY4DV6RP8r$>;&Vt~Ow+Dp=ZD$OVMFGfyf+cuT@gIVE&VU^$wXj@&^j3g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&67-=816baPr+M!64^`9I;vqxoNE<1Zk@3w)kIwj`SCxBiXM=%jp=I^M z64T8LrI$RP`0X7Hoi-D{nHJDm8C(o8Tc}V)1w9?#%L><9%V&j+t{dxqX}Nehv4iLNYRMl(kkp|$lY_KMaGHkT)0 zpehwkK6Y+z>|_RZ%l3zn(HIQItzbPElmX|6adNl;SIpBXVT3lauAv!34UJWJQ${nf zH)%I~f2CQ0F2YN5G5u>yiUlR%i)f;c>$!|YlCICoQZ+K$95pzHzAL`8!5Y`gFtdXe zRa8jq^hI6|5~_}o`4X(zNsI`xu6Qc=AR@D*-E9-0M(jx?C9DY6ff?=?A=3vV%QORu zIUic^kwRpV{bF24=q?i{TY5DUBH5$<&O=`Wiqoe%xW8{LZ_&e)(a<3n|9k6*BI)-h zFzDCuzjlx}tK8f+{Zj(~2nGmTXc6rHK>s^S-h|%_N`K%9IR7;^-7Ij^>HjGJ!u{v}|G)3Q3B76Q{yaf!qY%oUA`UZB$xBiS|F{45o~U3N!!!F6tYI>J7JFtqAx( D8uumu literal 0 HcmV?d00001 diff --git a/templates/jasset/asset_detail.html b/templates/jasset/asset_detail.html index bc38235ed..7109888eb 100644 --- a/templates/jasset/asset_detail.html +++ b/templates/jasset/asset_detail.html @@ -97,7 +97,7 @@ 内存 - {{ asset.memory|default_if_none:"" }}{% if asset.memory %}M{% endif %} + {{ asset.memory|default_if_none:"" }}{% if asset.memory %}G{% endif %} 硬盘 @@ -129,6 +129,10 @@ 系统版本 {{ asset.system_type|default_if_none:"" }} {{ asset.system_version|default_if_none:"" }} + + 系统平台 + {{ asset.system_arch|default_if_none:"" }} + 运行环境 {{ asset.get_env_display|default_if_none:"" }} diff --git a/templates/jasset/asset_edit.html b/templates/jasset/asset_edit.html index 0faa89a37..339fde387 100644 --- a/templates/jasset/asset_edit.html +++ b/templates/jasset/asset_edit.html @@ -105,6 +105,9 @@
{{ af.system_version|bootstrap_horizontal }} +
+ {{ af.system_arch|bootstrap_horizontal }} +
{{ af.number|bootstrap_horizontal }} diff --git a/templates/jasset/asset_list.html b/templates/jasset/asset_list.html index 887ce81a3..8373f8a0f 100644 --- a/templates/jasset/asset_list.html +++ b/templates/jasset/asset_list.html @@ -96,31 +96,6 @@ -{#
#} - -{#
#} -{##} -{#
#} - -{#
#} -{#
#} - -{#
#} -{#
#} -{#
#} -{# #} -{# #} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{#
#} -
@@ -134,7 +109,9 @@ {# #} - + + + @@ -150,7 +127,9 @@ {# #} - + + +
所属主机组 配置信息 操作系统 使用默认管理 cpu核数 内存 硬盘 操作
{{ asset.group.all|group_str2 }}{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}{{ asset.system_type|default_if_none:"" }}{{ asset.system_version|default_if_none:"" }} {{ asset.use_default_auth|bool2str }} {{ asset.cpu|get_cpu_core }} {{ asset.memory }}{% if asset.memory %}G{% endif %} {{ asset.disk }} 详情 {% ifnotequal session_role_id 0 %}