def _check_only_one_service(self, item): if item['alive']: status = 'up' else: status = 'down' if item['binary'] == 'neutron-l3-agent': self.l3 += 1 mg_obj = openstack_models.NeutronStatus.objects.first() if mg_obj.neutron_l3_agent != status: mg_obj.neutron_l3_agent = status mg_obj.save() ev = event_neutron.CloudStatus('neutron-L3-agent', status) getattr(ev, status)() if mg_obj.neutron_l3_start_node: if mg_obj.neutron_l3_start_node != item['host']: # 如果名字不一样就触发迁移的日志 content = 'Neutron L3 service Migrate from %s host to ' \ '%s host' % (mg_obj.neutron_l3_start_node, item['host']) mg_obj.neutron_l3_start_node = item['host'] mg_obj.save() event_neutron.neutron_migrate(content) else: mg_obj.neutron_l3_start_node = item['host'] mg_obj.save() content = 'create L3 service and start in the %s' % item['host'] event_neutron.neutron_info(item['host'], content) elif item['binary'] == 'neutron-dhcp-agent': self.dhcp += 1 mg_obj = openstack_models.NeutronStatus.objects.first() if mg_obj.neutron_dhcp_agent != status: mg_obj.neutron_dhcp_agent = status mg_obj.save() ev = event_neutron.CloudStatus('neutron-DHCP-agent', status) getattr(ev, status)() if mg_obj.neutron_dhcp_start_node: if mg_obj.neutron_dhcp_start_node != item['host']: # 如果名字不一样就触发迁移的日志 content = 'Neutron DHCP service Migrate from %s host to ' \ '%s host' % (mg_obj.neutron_dhcp_start_node, item['host']) mg_obj.neutron_dhcp_start_node = item['host'] mg_obj.save() event_neutron.neutron_migrate(content) else: mg_obj.neutron_dhcp_start_node = item['host'] mg_obj.save() content = 'create DHCP service and start in the %s' % \ item['host'] event_neutron.neutron_info(item['host'], content)
def add_neutron_host(self): data = neutron.agent_list() db_dic = {} for item in data['agents']: if item['binary'] == 'neutron-dhcp-agent' or \ item['binary'] == 'neutron-l3-agent': print 'slllllllllllllllllll%s' % item['binary'] continue # 获取该主机的id host_id = asset_models.Host.objects.get( hostname=item['host']).id if not item['host'] in db_dic: # 判断字典里面是否有该主机 db_dic[item['host']] = {} db_dic[item['host']]['host_id'] = host_id db_dic[item['host']]['neutron_river_type'] = \ settings.NEUTRON_RIVER_TYPE binary_name = '%s' % '_'.join(item['binary'].split('-')) if item['alive']: status = 'up' else: status = 'down' db_dic[item['host']][binary_name] = status # print db_dic manager_group_obj = asset_models.Group.objects.get(name='Manager') manager_group_node_list = manager_group_obj.host_set.select_related() compute_group_obj = asset_models.Group.objects.get(name='Compute') compute_group_node_list = compute_group_obj.host_set.select_related() for host, item in db_dic.items(): compute_obj = asset_models.Host.objects.get(hostname=host) # print item if compute_obj in manager_group_node_list: # 该主机就是manager主机 nm_obj = openstack_models.NeutronManagerServiceStatus if not nm_obj.objects.filter( host_id=asset_models.Host.objects.get( hostname=host).id ): print item # import pdb # pdb.set_trace() nm_obj.objects.create(**item) # 触发事件 content = 'Add Neutron Manager: %s' % host event_neutron.neutron_info(host, content) # else: # openstack_models.NeutronManagerServiceStatus.objects.filter( # host_id=openstack_models.Host.objects.get( # hostname=item['host']).id # ).update(**item) elif compute_obj in compute_group_node_list: # 该主机就是compute主机 nc_obj = openstack_models.NeutronComputeServiceStatus if not nc_obj.objects.filter( host_id=asset_models.Host.objects.get( hostname=host).id): print item nc_obj.objects.create(**item) # 触发事件 content = 'Add Neutron Compute: %s' % host event_neutron.neutron_info(host, content)