def create_zabbix_data(self, iaas_instance, openstack_instance, zabbix_settings, options):
        self.stdout.write(' Migrating zabbix data for instance %s' % iaas_instance)
        from nodeconductor_zabbix.models import Template, Host, ITService, Trigger, ZabbixServiceProjectLink

        backend = zabbix_settings.get_backend()
        api = backend.api
        old_client = self.get_old_zabbix_client()

        # Zabbix host
        try:
            host_id = old_client.get_host(iaas_instance)['hostid']
        except IndexError:
            self.error(
                '  Zabbix host does not exist for instance %s (UUID: %s)' % (iaas_instance.name, iaas_instance.uuid))
            return

        host_data = api.host.get(
            filter={'hostid': host_id}, selectParentTemplates='', output='extend', selectGroups='extend')[0]
        host_interface_data = api.hostinterface.get(filter={'hostid': host_id}, output='extend')[0]
        del host_interface_data['hostid']
        del host_interface_data['interfaceid']
        template_ids = [el['templateid'] for el in host_data['parentTemplates']]
        try:
            templates = [Template.objects.get(backend_id=template_id) for template_id in template_ids]
        except Template.DoesNotExist:
            self.error('  NC Zabbix database does not have template with backend_id %s. Please pull it.' % template_ids)
            return
        try:
            host_group_name = host_data['groups'][0]['name']
        except (IndexError, KeyError):
            host_group_name = ''

        spl = ZabbixServiceProjectLink.objects.get(
            service__settings=zabbix_settings, project=openstack_instance.project)

        self.stdout.write('  [+] Host for instance %s.' % openstack_instance.name)
        host = Host.objects.create(
            service_project_link=spl,
            scope=openstack_instance,
            visible_name=host_data['name'],
            name=host_data['host'],
            backend_id=host_id,
            state=Host.States.ONLINE,
            host_group_name=host_group_name,
            interface_parameters=host_interface_data,
        )
        host.templates.add(*templates)

        service_name = old_client.get_service_name(iaas_instance)
        try:
            service_data = api.service.get(filter={'name': service_name}, output='extend')[0]
        except IndexError:
            self.error(
                '  IT service for instance %s (UUID: %s) does not exist.' % (iaas_instance.name, iaas_instance.uuid))
            return

        trigger_data = api.trigger.get(filter={'triggerid': service_data['triggerid']}, output='extend')[0]
        try:
            trigger = Trigger.objects.get(name=trigger_data['description'], backend_id=trigger_data['templateid'])
        except Trigger.DoesNotExist:
            self.error(
                '  Trigger with name "%s" that belong to template with backend_id %s does not exist in NC database.'
                ' Please pull it.' % (trigger_data['description'], trigger_data['templateid']))

        self.stdout.write('  [+] IT Service for instance %s.' % openstack_instance.name)
        ITService.objects.create(
            service_project_link=spl,
            host=host,
            is_main=True,
            algorithm=int(service_data['algorithm']),
            sort_order=int(service_data['sortorder']),
            agreed_sla=float(service_data['goodsla']),
            backend_trigger_id=service_data['triggerid'],
            state=ITService.States.ONLINE,
            backend_id=service_data['serviceid'],
            name=service_data['name'],
            trigger=trigger,
        )

        if iaas_instance.type == iaas_instance.Services.PAAS:
            self.stdout.write('  [+] Installation state as monitoring item for %s.' % openstack_instance)
            mapping = {'NO DATA': 0, 'OK': 1, 'NOT OK': 0}
            openstack_instance.monitoring_items.create(
                name=Host.MONITORING_ITEMS_CONFIGS[0]['monitoring_item_name'],
                value=mapping[iaas_instance.installation_state])
dataset/ETHPy150Open opennode/nodeconductor/nodeconductor/iaas/management/commands/iaas2openstack.py/Command.create_zabbix_data/original