1. 程式人生 > >cmdb項目1

cmdb項目1

models mode www. 管理人 stat gen 說明 generic sql

CMDB項目

需求:

1.ip地址

2.mac地址

3.

1.查看Linux硬件基礎信息

1.查看cpu cat/proc/cpuinfo

(1)processor:包括這一邏輯處理器的唯一標識符。

(2)physical id :包括每個物理封裝的唯一標識符。

(3)core id :保存每個內核的唯一標識符。

(4)siblings :列出了位於相同物理封裝中的邏輯處理器的數量。

(5)cpu cores :包含位於相同物理封裝中的內核數量。

(6)如果處理器為英特爾處理器,則vendor id 條目中的字符串是GenuineIntel。

(9)model name :cpu型號

2.邏輯cpu個數

cat /proc/cpuinfo | grep ‘processor‘ | wc -l

3.物理cpu個數 (cpu插槽)

cat /proc/cpuinfo | grep ‘physical id‘ | sort | uniq | wc -l

3.查看cpu是否支持64bit

cat /proc/cpuinfo | grep flags | grep ‘lm‘ | wc -l

結果大於0,說明支持64bit計算

4.查看cpu型號

cat /proc/cpuinfo | grep ‘model name‘ | awk -F ‘:‘ ‘{print $2}‘

5.ip地址:

6.mac地址:

2.python

1.使用的模塊

commands

commands.getstatusoutput(cmd) 返回兩個元素(status, results);

commands.getoutput(cmd) 返回results

urllib

urllib.urlopen(url,date,proxies,context)

urllib2

該urllib2模塊定義了有助於在復雜世界中打開URL(主要是HTTP)的功能和類 - 基本和摘要身份驗證,重定向,Cookie等

urllib2.urlopen(url,data,timeout)

paramiko

各代表什麽意思

def __xxx(self):

def _xxx(self):

hasattr(object, name) 內置函數

The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. (This is implemented by calling getattr(object, name) and seeing whether it raises an AttributeError or not.)

getattr(object, name[, default])

Return the value of the named attribute of object. name must be a string. If the string is the name of one of the object’s attributes, the result is the value of that attribute. For example, getattr(x, ‘foobar‘) is equivalent to x.foobar. If the named attribute does not exist, default is returned if provided, otherwise AttributeError is raised.

2.data={}

{‘cpu‘: {‘CpuModeName‘: ‘Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz‘, ‘processor‘: ‘1‘}, ‘hostname‘: ‘kevin‘, ‘asset‘: {‘Wake-up Type‘: ‘Power Switch‘, ‘UUID‘: ‘E4144D56-8399-AE0E-F1D1-5C01911B965C‘, ‘Serial Number‘: ‘VMware-56 4d 14 e4 99 83 0e ae-f1 d1 5c 01 91 1b 96 5c‘, ‘Manufacturer‘: ‘VMware, Inc.‘, ‘Product Name‘: ‘VMware Virtual Platform‘}, ‘network‘: {‘macadd‘: ‘00:0C:29:1B:96:5C‘, ‘netmask‘: ‘255.255.255.0‘, ‘ip‘: ‘10.1.6.153‘, ‘gateway‘: ‘10.1.6.255‘}}

3. name = models.CharField(max_length=64, unique=True)

sn = models.CharField(max_length=64, unique=True)

network = models.GenericIPAddressField(null=True, blank=True)

#asset = models.OneToOneField(‘Asset‘)

ip = models.GenericIPAddressField(null=True, blank=True)

mac = models.CharField(max_length=50)

hostname = models.CharField(max_length=50)

processor=models.BooleanField(default = 5)

physicalId=models.BooleanField(default = 5)

#是否支持64位

support=models.BooleanField(default = 5)

models_Name=models.CharField(max_length=50)

3.myql

ip地址,mac地址,

cpu -- cpu個數,cpu插槽,查看cpu是否支持64bit,查看cpu型號。。。

4.Client發送數據判斷是否和前一次數據相同?

5.遇到問題:

1.django erro

2.一條數據從Client 傳過來,怎麽判定是Updata還是 Create??

答:新插入:通過一遍又一遍分析別人的代碼,別人轉換思想,在MySQL創建一個新資產審批庫,然後把新數據插入庫中....待處理

當一條數據傳送過來,先判定數據中是否有同樣的sn,若有則是更新中,無則是新建,然後在新資產審批庫中Create ,然後在管理人員在web 頁面確認。

3.流程圖:https://www.processon.com/view/link/59b54c84e4b00e6de914c04a

cmdb項目1