我们统计接口把Salt获取的信息使用django的ORM插入数据库,持续更新....
class cmdb_operater:
def __init__(self,minion_list): self.minion_list = minion_listdef create(self,minion_list):
for item in minion_list: grains = Salt_grains.objects.filter(minion_id=item) host_hostname = eval(grains[0].grains).get('id').decode('string-escape') host_ip = eval(grains[0].grains).get('fqdn_ip4')[0].decode('string-escape') #host_env = env_dispatch(host_ip) kernal = eval(grains[0].grains).get('oscodename').decode('string-escape') kernal_version = eval(grains[0].grains).get('osrelease').decode('string-escape') host_manufacturer = eval(grains[0].grains).get('manufacturer').decode('string-escape') host_kernal_release = eval(grains[0].grains).get('kernelrelease').decode('string-escape') host_cpu_model = eval(grains[0].grains).get('cpu_model').decode('string-escape') host_num_cpus = eval(grains[0].grains).get('num_cpus').decode('string-escape') host_disk = eval(grains[0].grains).get('disk').decode('string-escape')host = Host()
host.hostname = host_hostname host_cpu_model = host_cpu_model host.ip = host_ip host.kernel = kernal + kernal_version host.kernal_release = host_kernal_release host.env_id = env_dispatch(host_ip) host.asset_type = Manufactory_dispatch(host_manufacturer) host.kernal_release = host_kernal_release host.cpu_model = host_cpu_model host.cpu_num = host_num_cpus host.group_id = 1 host.project_id = 1 host.save()