Esempio n. 1
0
    def create_tenant_rpc_server(self, tid):
        """create_ blocking rpc server

        @param tid: openstack tenant id
        """
        ret = {}

        if tid in self.rpc_servers:
            LOG.warning(_LW("already in message queue and server. queue=%s"),
                        self.rpc_servers[tid]['topic'])
            return {'result': 'FAILED'}

        topic = "%s-%s" % (self.topic, tid)

        target = Target(topic=topic, server=cfg.CONF.host, fanout=False)

        assert n_rpc.TRANSPORT is not None
        serializer = n_rpc.RequestContextSerializer(None)

        server = get_rpc_server(n_rpc.TRANSPORT, target,
                                self.agent_top.endpoints, 'blocking',
                                serializer)
        self.rpc_servers[tid] = {'server': server, 'topic': topic}

        LOG.debug("RPCServer create: topic=%s", topic)

        self.rpc_servers[tid]['server'].start()

        ret['result'] = 'SUCCESS'
        ret['tenant_id'] = tid
        ret['topic'] = topic

        return ret
Esempio n. 2
0
    def _create_vlan(self, context, **kwargs):
        nwa_tenant_id = kwargs.get('nwa_tenant_id')
        nwa_info = kwargs.get('nwa_info')
        nwa_data = kwargs.get('nwa_data')

        network_id = nwa_info['network']['id']
        nw_vlan_key = data_utils.get_vlan_key(network_id)
        if nw_vlan_key in nwa_data:
            LOG.warning(_LW("aleady in vlan_key %s"), nw_vlan_key)
            return nwa_data

        rcode, body = self.client.l2.create_vlan(
            nwa_tenant_id,
            nwa_info['subnet']['netaddr'],
            nwa_info['subnet']['mask'],
            nwa_info['network']['vlan_type'],
            openstack_network_id=network_id)

        if rcode == 200 and body['status'] == 'SUCCEED':
            # create vlan succeed.
            LOG.debug("CreateVlan succeed.")
            data_utils.set_network_data(nwa_data, network_id, nwa_info,
                                        body['resultdata']['LogicalNWName'])
            data_utils.set_vlan_data(nwa_data, network_id,
                                     body['resultdata']['VlanID'])
        else:
            # create vlan failed.
            LOG.error(_LE("CreateVlan Failed."))
            raise nwa_exc.AgentProxyException(value=nwa_data)

        return nwa_data
Esempio n. 3
0
    def create_tenant_fw(self, context, **kwargs):
        nwa_data = self.proxy_l2.ensure_l2_network(context, **kwargs)
        device_id = kwargs['nwa_info']['device']['id']
        network_id = kwargs['nwa_info']['network']['id']
        dev_key = data_utils.get_device_key(device_id)
        net_key = data_utils.get_device_net_key(device_id, network_id)
        if dev_key not in nwa_data:
            nwa_data = self._create_tenant_fw(nwa_data, context, **kwargs)
        elif net_key not in nwa_data:
            nwa_data = self._update_tenant_fw(context,
                                              connect='connect',
                                              nwa_data=nwa_data,
                                              **kwargs)
        else:
            LOG.warning(_LW("unknown device."))

        if not nwa_data:
            raise nwa_exc.AgentProxyException(value=kwargs['nwa_data'])
        ret = self.proxy_tenant.update_tenant_binding(context,
                                                      kwargs['tenant_id'],
                                                      kwargs['nwa_tenant_id'],
                                                      nwa_data)
        resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw']
        vlan_id = data_utils.get_vp_net_vlan_id(nwa_data, network_id,
                                                resource_group_name_nw,
                                                nwa_const.NWA_DEVICE_TFW)

        self.nwa_l2_rpc.update_port_state_with_notifier(
            context, device_id, self.agent_top.agent_id,
            kwargs['nwa_info']['port']['id'], {
                api.PHYSICAL_NETWORK: kwargs['nwa_info']['physical_network'],
                api.NETWORK_TYPE: n_constants.TYPE_VLAN,
                api.SEGMENTATION_ID: vlan_id
            }, network_id)
        return ret
Esempio n. 4
0
    def _create_vlan(self, context, **kwargs):
        nwa_tenant_id = kwargs.get('nwa_tenant_id')
        nwa_info = kwargs.get('nwa_info')
        nwa_data = kwargs.get('nwa_data')

        network_id = nwa_info['network']['id']
        nw_vlan_key = data_utils.get_vlan_key(network_id)
        if nw_vlan_key in nwa_data:
            LOG.warning(_LW("aleady in vlan_key %s"), nw_vlan_key)
            return nwa_data

        rcode, body = self.client.l2.create_vlan(
            nwa_tenant_id,
            nwa_info['subnet']['netaddr'],
            nwa_info['subnet']['mask'],
            nwa_info['network']['vlan_type'],
            openstack_network_id=network_id
        )

        if rcode == 200 and body['status'] == 'SUCCEED':
            # create vlan succeed.
            LOG.debug("CreateVlan succeed.")
            data_utils.set_network_data(nwa_data, network_id, nwa_info,
                                        body['resultdata']['LogicalNWName'])
            data_utils.set_vlan_data(nwa_data, network_id,
                                     body['resultdata']['VlanID'])
        else:
            # create vlan failed.
            LOG.error(_LE("CreateVlan Failed."))
            raise nwa_exc.AgentProxyException(value=nwa_data)

        return nwa_data
    def workflow_kick_and_wait(self, call, url, body):
        http_status = -1
        rj = None
        (http_status, rj) = call(url, body)

        if not isinstance(rj, dict):
            return (http_status, None)

        exeid = rj.get('executionid')
        if not isinstance(exeid, six.string_types):
            LOG.error(_LE('Invalid executin id %s'), exeid)
        try:
            wait_time = self.workflow_first_wait
            eventlet.sleep(wait_time)
            for __ in range(self.workflow_retry_count):
                (http_status, rw) = self.workflowinstance(exeid)
                if not isinstance(rw, dict):
                    LOG.error(
                        _LE('NWA workflow: failed %(http_status)s %(body)s'),
                        {'http_status': http_status, 'body': rw}
                    )
                    return (http_status, None)
                if rw.get('status') != 'RUNNING':
                    LOG.debug('%s', rw)
                    return (http_status, rw)
                eventlet.sleep(wait_time)
                wait_time = self.workflow_wait_sleep
            LOG.warning(_LW('NWA workflow: retry over. retry count is %s.'),
                        self.workflow_retry_count)
        except Exception as e:
            LOG.error(_LE('NWA workflow: %s'), e)
        return (http_status, None)
Esempio n. 6
0
def load_json_from_file(name, json_file, json_str, default_value):
    if json_file:
        json_file_abspath = cfg.CONF.find_file(json_file)
        if not json_file_abspath:
            LOG.error(_LE('Failed to load %(name)s_file'
                          '"%(json_file)s": file not found'),
                      {'name': name, 'json_file': json_file})
            raise cfg.Error(_('NECNWA option parse error'))
        try:
            with open(json_file_abspath) as f:
                return jsonutils.loads(f.read())
        except Exception as e:
            LOG.error(_LE('Failed to load %(name)s_file '
                          '"%(json_file)s": %(reason)s'),
                      {'reason': e, 'name': name, 'json_file': json_file})
            raise cfg.Error(_('NECNWA option parse error'))
    elif json_str:
        try:
            return jsonutils.loads(json_str)
        except Exception as e:
            LOG.error(_LE('NECNWA option error during loading %(name)s '
                          '(%(data)s): %(reason)s'),
                      {'reason': e, 'name': name, 'data': json_str})
            raise cfg.Error(_('NECNWA option parse error'))
    else:
        LOG.warning(_LW('%(name)s is not configured. '
                        'Make sure to set [NWA] %(name)s_file '
                        'in NWA plugin configuration file. '
                        'Using %(default)s as default value.'),
                    {'name': name, 'default': default_value})
        return default_value
Esempio n. 7
0
    def delete_tenant_rpc_server(self, tid):
        if tid not in self.rpc_servers:
            LOG.warning(_LW("rpc server not found. tid=%s"), tid)
            return {'result': 'FAILED'}

        LOG.debug('RPCServer delete: stop %s', tid)
        self.rpc_servers[tid]['server'].stop()

        LOG.debug('RPCServer delete: wait %s', tid)
        self.rpc_servers[tid]['server'].wait()

        LOG.debug('RPCServer delete: pop %s', tid)
        self.rpc_servers.pop(tid)

        LOG.debug('RPCServer delete: sleep %s', tid)
        eventlet.sleep(0)

        ret = {
            'result': 'SUCCESS',
            'tenant_id': tid
        }

        LOG.debug("RPCServer deleted: %s", ret)

        return ret
Esempio n. 8
0
    def create_tenant_rpc_server(self, tid):
        """create_ blocking rpc server

        @param tid: openstack tenant id
        """
        ret = {}

        if tid in self.rpc_servers:
            LOG.warning(
                _LW("already in message queue and server. queue=%s"),
                self.rpc_servers[tid]['topic']
            )
            return {'result': 'FAILED'}

        topic = "%s-%s" % (self.topic, tid)

        target = Target(
            topic=topic, server=cfg.CONF.host, fanout=False)

        assert n_rpc.TRANSPORT is not None
        serializer = n_rpc.RequestContextSerializer(None)

        server = get_rpc_server(
            n_rpc.TRANSPORT, target,
            self.agent_top.endpoints,
            'blocking', serializer
        )

        LOG.debug("RPCServer create: topic=%s", topic)
        if self.greenpool.free() < 1:
            self.greenpool_size += nwa_const.NWA_GREENPOOL_ADD_SIZE
            self.greenpool.resize(self.greenpool_size)
            LOG.info(_LI('RPCServer greenpool resize %s'), self.greenpool_size)

        def server_start():
            while True:
                try:
                    LOG.debug('RPCServer thread %d start %s',
                              (self.greenpool.running(), server))
                    server.start()
                    LOG.debug('RPCServer thread end %s', server)
                    break
                except Exception as e:
                    LOG.exception(_LE('RPCServer thread start failed: %s'), e)

        self.rpc_servers[tid] = {
            'thread': self.greenpool.spawn(server_start),
            'server': server,
            'topic': topic
        }
        eventlet.sleep(0)
        LOG.info(_LI('RPCServer started: %(topic)s server=%(server)s'),
                 {'topic': topic, 'server': server})

        ret['result'] = 'SUCCESS'
        ret['tenant_id'] = tid
        ret['topic'] = topic

        return ret
 def get_workflow_list(self):
     try:
         url = '/umf/workflow/list'
         return self.get(url)
     except Exception as e:
         LOG.warning(_LW('The initial worklist is not updated,'
                         ' using default worklist. (%s)'), e)
         return None, None
Esempio n. 10
0
 def create_port_precommit(self, context):
     device_owner = context._port['device_owner']
     if device_owner not in (constants.DEVICE_OWNER_ROUTER_INTF,
                             constants.DEVICE_OWNER_ROUTER_GW):
         LOG.warning(_LW("device owner missmatch device_owner=%s"),
                     device_owner)
         return
     self._l3_create_tenant_fw(context)
     self._bind_segment_to_vif_type(context)
Esempio n. 11
0
 def create_port_precommit(self, context):
     device_owner = context._port['device_owner']
     if device_owner not in (constants.DEVICE_OWNER_ROUTER_INTF,
                             constants.DEVICE_OWNER_ROUTER_GW):
         LOG.warning(_LW("device owner missmatch device_owner=%s"),
                     device_owner)
         return
     self._l3_create_tenant_fw(context)
     self._bind_segment_to_vif_type(context)
Esempio n. 12
0
 def _l2_delete_general_dev(self, context, use_original_port=False):
     try:
         kwargs = self._make_l2api_kwargs(
             context, use_original_port=use_original_port)
         proxy = self._get_l2api_proxy(context, kwargs['tenant_id'])
         kwargs['nwa_info'] = self._revert_dhcp_agent_device_id(
             context, kwargs['nwa_info'])
         proxy.delete_general_dev(context.network._plugin_context, **kwargs)
     except nwa_exc.TenantNotFound as e:
         LOG.warning(_LW("skip delete_general_dev: %s"), e)
Esempio n. 13
0
 def _l2_delete_general_dev(self, context, use_original_port=False):
     try:
         kwargs = self._make_l2api_kwargs(
             context, use_original_port=use_original_port)
         proxy = self._get_l2api_proxy(context, kwargs['tenant_id'])
         kwargs['nwa_info'] = self._revert_dhcp_agent_device_id(
             context, kwargs['nwa_info'])
         proxy.delete_general_dev(context.network._plugin_context, **kwargs)
     except nwa_exc.TenantNotFound as e:
         LOG.warning(_LW("skip delete_general_dev: %s"), e)
Esempio n. 14
0
 def try_to_bind_segment_for_agent(self, context, segment, agent):
     if self._bind_segment_to_vif_type(context, agent):
         device_owner = context._port['device_owner']
         if device_owner not in (constants.DEVICE_OWNER_ROUTER_GW,
                                 constants.DEVICE_OWNER_ROUTER_INTF):
             self._bind_port_nwa_debug_message(context)
             self._l2_create_general_dev(context)
             return True
     LOG.warning(_LW("binding segment not found for agent=%s"), agent)
     return super(NECNWAMechanismDriver,
                  self).try_to_bind_segment_for_agent(
                      context, segment, agent)
Esempio n. 15
0
 def disassociate_floatingips(self, context, port_id, do_notify=True):
     floating_ips = context.session.query(l3_db.FloatingIP).filter(
         or_(l3_db.FloatingIP.fixed_port_id == port_id,
             l3_db.FloatingIP.floating_port_id == port_id)
     )
     if not floating_ips:
         LOG.warning(_LW('floatingip not found %s'), port_id)
     for fip in floating_ips:
         self._delete_nat(context, fip)
     router_ids = super(NECNWAL3Plugin, self).disassociate_floatingips(
         context, port_id, do_notify)
     return router_ids
Esempio n. 16
0
 def try_to_bind_segment_for_agent(self, context, segment, agent):
     if self._bind_segment_to_vif_type(context, agent):
         device_owner = context._port['device_owner']
         if device_owner not in (constants.DEVICE_OWNER_ROUTER_GW,
                                 constants.DEVICE_OWNER_ROUTER_INTF):
             self._bind_port_nwa_debug_message(context)
             self._l2_create_general_dev(context)
             return True
     LOG.warning(_LW("binding segment not found for agent=%s"), agent)
     return super(
         NECNWAMechanismDriver, self
     ).try_to_bind_segment_for_agent(context, segment, agent)
Esempio n. 17
0
    def delete_tenant(self, context, **kwargs):
        """delete tenant.

        @param context: contains user information.
        @param kwargs: nwa_tenant_id
        @return: result(succeed = (True, dict(empty)  other = False, None)
        """
        nwa_tenant_id = kwargs.get('nwa_tenant_id')
        rcode, body = self.client.tenant.delete_tenant(nwa_tenant_id)
        if rcode != 200:
            LOG.warning(_LW('unexpected status code %s in delete_tenant'),
                        rcode)
        return body
Esempio n. 18
0
 def _create_nwa_agent_tenant_queue(self, context, tenant_id):
     if (
             self._is_alive_nwa_agent(context) and
             necnwa_api.get_nwa_tenant_queue(
                 context.session,
                 tenant_id
             ) is None
     ):
         self.nwa_rpc.create_server(context, tenant_id)
         necnwa_api.add_nwa_tenant_queue(context.session, tenant_id)
     else:
         LOG.warning(_LW('%s is not alive.'),
                     nwa_const.NWA_AGENT_TYPE)
Esempio n. 19
0
    def delete_tenant_rpc_server(self, tid):
        if tid not in self.rpc_servers:
            LOG.warning(_LW("rpc server not found. tid=%s"), tid)
            return {'result': 'FAILED'}

        self.rpc_servers[tid]['server'].stop()
        self.rpc_servers.pop(tid)

        ret = {'result': 'SUCCESS', 'tenant_id': tid}

        LOG.debug("RPCServer delete: %s", ret)

        return ret
Esempio n. 20
0
 def get_nwa_proxy(self, tid, context=None):
     if tid not in self.nwa_proxies:
         self.nwa_proxies[tid] = nwa_proxy_api.NECNWAProxyApi(
             nwa_const.NWA_AGENT_TOPIC, tid
         )
         if context:
             self._create_nwa_agent_tenant_queue(context, tid)
             nwa_topics = self.get_nwa_topics(context, tid)
             if len(nwa_topics) == 1:
                 LOG.info(_LI('NWA tenant queue: new topic is %s'),
                          str(nwa_topics[0]))
             else:
                 LOG.warning(_LW('NWA tenant queue is not created. tid=%s'),
                             tid)
     LOG.debug('proxy tid=%s', tid)
     return self.nwa_proxies[tid]
    def delete_tenant_rpc_server(self, tid):
        if tid not in self.rpc_servers:
            LOG.warning(_LW("rpc server not found. tid=%s"), tid)
            return {'result': 'FAILED'}

        self.rpc_servers[tid]['server'].stop()
        self.rpc_servers.pop(tid)

        ret = {
            'result': 'SUCCESS',
            'tenant_id': tid
        }

        LOG.debug("RPCServer delete: %s", ret)

        return ret
Esempio n. 22
0
def load_json_from_file(name, json_file, json_str, default_value):
    if json_file:
        json_file_abspath = cfg.CONF.find_file(json_file)
        if not json_file_abspath:
            LOG.error(
                _LE('Failed to load %(name)s_file'
                    '"%(json_file)s": file not found'), {
                        'name': name,
                        'json_file': json_file
                    })
            raise cfg.Error(_('NECNWA option parse error'))
        try:
            with open(json_file_abspath) as f:
                return jsonutils.loads(f.read())
        except Exception as e:
            LOG.error(
                _LE('Failed to load %(name)s_file '
                    '"%(json_file)s": %(reason)s'), {
                        'reason': e,
                        'name': name,
                        'json_file': json_file
                    })
            raise cfg.Error(_('NECNWA option parse error'))
    elif json_str:
        try:
            return jsonutils.loads(json_str)
        except Exception as e:
            LOG.error(
                _LE('NECNWA option error during loading %(name)s '
                    '(%(data)s): %(reason)s'), {
                        'reason': e,
                        'name': name,
                        'data': json_str
                    })
            raise cfg.Error(_('NECNWA option parse error'))
    else:
        LOG.warning(
            _LW('%(name)s is not configured. '
                'Make sure to set [NWA] %(name)s_file '
                'in NWA plugin configuration file. '
                'Using %(default)s as default value.'), {
                    'name': name,
                    'default': default_value
                })
        return default_value
Esempio n. 23
0
 def delete_general_dev(self, tenant_id, dc_resource_group_name,
                        logical_name, vlan_type='BusinessVLAN',
                        port_type=None, openstack_network_id=None):
     body = {
         'DeleteNW_DeviceType1': 'GeneralDev',
         'TenantID': tenant_id,
         'DeleteNW_VlanLogicalName1': logical_name,
         'DeleteNW_VlanType1': vlan_type,
         'DeleteNW_DCResourceGroupName': dc_resource_group_name
     }
     if logical_name and openstack_network_id:
         LOG.warning(_LW('VLAN logical name and id to be specified '
                         'in the exclusive.'))
     if openstack_network_id:
         body['DeleteNW_VlanLogicalID1'] = openstack_network_id
     if port_type:
         body['DeleteNW_PortType1'] = port_type
     return self.client.call_workflow(
         tenant_id, self.client.post, 'DeleteGeneralDev', body
     )
    def create_tenant_rpc_server(self, tid):
        """create_ blocking rpc server

        @param tid: openstack tenant id
        """
        ret = {}

        if tid in self.rpc_servers:
            LOG.warning(
                _LW("already in message queue and server. queue=%s"),
                self.rpc_servers[tid]['topic']
            )
            return {'result': 'FAILED'}

        topic = "%s-%s" % (self.topic, tid)

        target = Target(
            topic=topic, server=cfg.CONF.host, fanout=False)

        assert n_rpc.TRANSPORT is not None
        serializer = n_rpc.RequestContextSerializer(None)

        server = get_rpc_server(
            n_rpc.TRANSPORT, target,
            self.agent_top.endpoints,
            'blocking', serializer
        )
        self.rpc_servers[tid] = {
            'server': server,
            'topic': topic
        }

        LOG.debug("RPCServer create: topic=%s", topic)

        self.rpc_servers[tid]['server'].start()

        ret['result'] = 'SUCCESS'
        ret['tenant_id'] = tid
        ret['topic'] = topic

        return ret
Esempio n. 25
0
    def create_tenant_fw(self, context, **kwargs):
        nwa_data = self.proxy_l2.ensure_l2_network(context, **kwargs)
        device_id = kwargs['nwa_info']['device']['id']
        network_id = kwargs['nwa_info']['network']['id']
        dev_key = data_utils.get_device_key(device_id)
        net_key = data_utils.get_device_net_key(device_id, network_id)
        if dev_key not in nwa_data:
            nwa_data = self._create_tenant_fw(nwa_data, context, **kwargs)
        elif net_key not in nwa_data:
            nwa_data = self._update_tenant_fw(
                context, connect='connect', nwa_data=nwa_data, **kwargs)
        else:
            LOG.warning(_LW("unknown device."))

        if not nwa_data:
            raise nwa_exc.AgentProxyException(value=kwargs['nwa_data'])
        ret = self.proxy_tenant.update_tenant_binding(
            context,
            kwargs['tenant_id'], kwargs['nwa_tenant_id'],
            nwa_data
        )
        resource_group_name_nw = kwargs['nwa_info']['resource_group_name_nw']
        vlan_id = data_utils.get_vp_net_vlan_id(nwa_data, network_id,
                                                resource_group_name_nw,
                                                nwa_const.NWA_DEVICE_TFW)

        self.nwa_l2_rpc.update_port_state_with_notifier(
            context,
            device_id,
            self.agent_top.agent_id,
            kwargs['nwa_info']['port']['id'],
            {
                api.PHYSICAL_NETWORK: kwargs['nwa_info']['physical_network'],
                api.NETWORK_TYPE: n_constants.TYPE_VLAN,
                api.SEGMENTATION_ID: vlan_id
            },
            network_id
        )
        return ret
Esempio n. 26
0
 def delete_general_dev(self,
                        tenant_id,
                        dc_resource_group_name,
                        logical_name,
                        vlan_type='BusinessVLAN',
                        port_type=None,
                        openstack_network_id=None):
     body = {
         'DeleteNW_DeviceType1': 'GeneralDev',
         'TenantID': tenant_id,
         'DeleteNW_VlanLogicalName1': logical_name,
         'DeleteNW_VlanType1': vlan_type,
         'DeleteNW_DCResourceGroupName': dc_resource_group_name
     }
     if logical_name and openstack_network_id:
         LOG.warning(
             _LW('VLAN logical name and id to be specified '
                 'in the exclusive.'))
     if openstack_network_id:
         body['DeleteNW_VlanLogicalID1'] = openstack_network_id
     if port_type:
         body['DeleteNW_PortType1'] = port_type
     return self.client.call_workflow(tenant_id, self.client.post,
                                      'DeleteGeneralDev', body)
    def _get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        LOG.debug("Device %(device)s details requested by agent "
                  "%(agent_id)s with host %(host)s",
                  {'device': device, 'agent_id': agent_id, 'host': host})

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(device)
        port_context = plugin.get_bound_port_context(rpc_context,
                                                     port_id,
                                                     host)
        if not port_context:
            LOG.warning(_LW("Device %(device)s requested by agent "
                            "%(agent_id)s not found in database"),
                        {'device': device, 'agent_id': agent_id})
            return {'device': device}

        port = port_context.current

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            segments = db_ml2.get_network_segments(session, port['network_id'],
                                                   filter_dynamic=True)
            if not segments:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s has network %(network_id)s not "
                                "no segment"),
                            {'device': device, 'agent_id': agent_id,
                             'network_id': port['network_id']})
                return {'device': device}
            elif len(segments) != 1:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s has network %(network_id)s not "
                                "no segment size miss mach"),
                            {'device': device, 'agent_id': agent_id,
                             'network_id': port['network_id']})
                return {'device': device}
            elif segments[0]['segmentation_id'] == 0:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s, segment %(segment_id)s has "
                                "network %(network_id)s not "
                                "no segment from NWA"),
                            {'device': device, 'agent_id': agent_id,
                             'segment_id': segments[0]['id'],
                             'network_id': port['network_id']})
                return {'device': device}

            binding = necnwa_api.ensure_port_binding(session, port_id)

            if not binding.segment_id:
                LOG.warning(_LW("Device %(device)s requested by agent "
                                "%(agent_id)s on network %(network_id)s not "
                                "bound, vif_type: %(vif_type)s"),
                            {'device': device,
                             'agent_id': agent_id,
                             'network_id': port['network_id'],
                             'vif_type': binding.vif_type})
                return {'device': device}

        port = port_context.current

        new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                      else constants.PORT_STATUS_DOWN)

        if (
                port['status'] != new_status and
                port['status'] != constants.PORT_STATUS_ACTIVE
        ):
            plugin.update_port_status(rpc_context,
                                      port_id,
                                      new_status,
                                      host)

        entry = {'device': device,
                 'network_id': port['network_id'],
                 'port_id': port_id,
                 'mac_address': port['mac_address'],
                 'admin_state_up': port['admin_state_up'],
                 'network_type': segments[0]['network_type'],
                 'segmentation_id': segments[0]['segmentation_id'],
                 'physical_network': segments[0]['physical_network'],
                 'fixed_ips': port['fixed_ips'],
                 'device_owner': port['device_owner'],
                 'profile': port[portbindings.PROFILE]}
        LOG.debug("Returning: %s", entry)
        return entry
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        # cached networks used for reducing number of network db calls
        # for server internal usage only
        cached_networks = kwargs.get('cached_networks')
        LOG.debug("Device %(device)s details requested by agent "
                  "%(agent_id)s with host %(host)s",
                  {'device': device, 'agent_id': agent_id, 'host': host})

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(rpc_context, device)
        port_context = plugin.get_bound_port_context(rpc_context,
                                                     port_id,
                                                     host,
                                                     cached_networks)
        if not port_context:
            LOG.warning(_LW("Device %(device)s requested by agent "
                            "%(agent_id)s not found in database"),
                        {'device': device, 'agent_id': agent_id})
            return {'device': device}

        segment = port_context.bottom_bound_segment

        port = port_context.current
        # caching information about networks for future use
        if cached_networks is not None:
            if port['network_id'] not in cached_networks:
                cached_networks[port['network_id']] = (
                    port_context.network.current)
        if not segment:
            LOG.warning(_LW("Device %(device)s requested by agent "
                            "%(agent_id)s on network %(network_id)s not "
                            "bound, vif_type: %(vif_type)s"),
                        {'device': device,
                         'agent_id': agent_id,
                         'network_id': port['network_id'],
                         'vif_type': port[portbindings.VIF_TYPE]})
            return {'device': device}

        elif segment['segmentation_id'] == 0:
            LOG.warning(_LW("Device %(device)s requested by agent "
                            "%(agent_id)s, segment %(segment_id)s has "
                            "network %(network_id)s not no segment from NWA"),
                        {'device': device, 'agent_id': agent_id,
                         'segment_id': segment['id'],
                         'network_id': port['network_id']})
            return {'device': device}

        if not host or host == port_context.host:
            new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                          else constants.PORT_STATUS_DOWN)
            if (
                    port['status'] != new_status and
                    port['status'] != constants.PORT_STATUS_ACTIVE
            ):
                plugin.update_port_status(rpc_context,
                                          port_id,
                                          new_status,
                                          host)

        entry = {'device': device,
                 'network_id': port['network_id'],
                 'port_id': port_id,
                 'mac_address': port['mac_address'],
                 'admin_state_up': port['admin_state_up'],
                 'network_type': segment[api.NETWORK_TYPE],
                 'segmentation_id': segment[api.SEGMENTATION_ID],
                 'physical_network': segment[api.PHYSICAL_NETWORK],
                 'fixed_ips': port['fixed_ips'],
                 'device_owner': port['device_owner'],
                 'allowed_address_pairs': port['allowed_address_pairs'],
                 'port_security_enabled': port.get(psec.PORTSECURITY, True),
                 'profile': port[portbindings.PROFILE]}
        LOG.debug("Returning: %s", entry)
        return entry
Esempio n. 29
0
    def get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        # cached networks used for reducing number of network db calls
        # for server internal usage only
        cached_networks = kwargs.get('cached_networks')
        LOG.debug(
            "Device %(device)s details requested by agent "
            "%(agent_id)s with host %(host)s", {
                'device': device,
                'agent_id': agent_id,
                'host': host
            })

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(rpc_context, device)
        port_context = plugin.get_bound_port_context(rpc_context, port_id,
                                                     host, cached_networks)
        if not port_context:
            LOG.warning(
                _LW("Device %(device)s requested by agent "
                    "%(agent_id)s not found in database"), {
                        'device': device,
                        'agent_id': agent_id
                    })
            return {'device': device}

        segment = port_context.bottom_bound_segment

        port = port_context.current
        # caching information about networks for future use
        if cached_networks is not None:
            if port['network_id'] not in cached_networks:
                cached_networks[port['network_id']] = (
                    port_context.network.current)
        if not segment:
            LOG.warning(
                _LW("Device %(device)s requested by agent "
                    "%(agent_id)s on network %(network_id)s not "
                    "bound, vif_type: %(vif_type)s"), {
                        'device': device,
                        'agent_id': agent_id,
                        'network_id': port['network_id'],
                        'vif_type': port[portbindings.VIF_TYPE]
                    })
            return {'device': device}

        elif segment['segmentation_id'] == 0:
            LOG.warning(
                _LW("Device %(device)s requested by agent "
                    "%(agent_id)s, segment %(segment_id)s has "
                    "network %(network_id)s not no segment from NWA"), {
                        'device': device,
                        'agent_id': agent_id,
                        'segment_id': segment['id'],
                        'network_id': port['network_id']
                    })
            return {'device': device}

        if not host or host == port_context.host:
            new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                          else constants.PORT_STATUS_DOWN)
            if (port['status'] != new_status
                    and port['status'] != constants.PORT_STATUS_ACTIVE):
                plugin.update_port_status(rpc_context, port_id, new_status,
                                          host)

        entry = {
            'device': device,
            'network_id': port['network_id'],
            'port_id': port_id,
            'mac_address': port['mac_address'],
            'admin_state_up': port['admin_state_up'],
            'network_type': segment[api.NETWORK_TYPE],
            'segmentation_id': segment[api.SEGMENTATION_ID],
            'physical_network': segment[api.PHYSICAL_NETWORK],
            'fixed_ips': port['fixed_ips'],
            'device_owner': port['device_owner'],
            'allowed_address_pairs': port['allowed_address_pairs'],
            'port_security_enabled': port.get(psec.PORTSECURITY, True),
            'profile': port[portbindings.PROFILE]
        }
        LOG.debug("Returning: %s", entry)
        return entry
Esempio n. 30
0
    def _get_device_details(self, rpc_context, **kwargs):
        """Agent requests device details."""
        agent_id = kwargs.get('agent_id')
        device = kwargs.get('device')
        host = kwargs.get('host')
        LOG.debug(
            "Device %(device)s details requested by agent "
            "%(agent_id)s with host %(host)s", {
                'device': device,
                'agent_id': agent_id,
                'host': host
            })

        plugin = manager.NeutronManager.get_plugin()
        port_id = plugin._device_to_port_id(device)
        port_context = plugin.get_bound_port_context(rpc_context, port_id,
                                                     host)
        if not port_context:
            LOG.warning(
                _LW("Device %(device)s requested by agent "
                    "%(agent_id)s not found in database"), {
                        'device': device,
                        'agent_id': agent_id
                    })
            return {'device': device}

        port = port_context.current

        session = db_api.get_session()
        with session.begin(subtransactions=True):
            segments = db_ml2.get_network_segments(session,
                                                   port['network_id'],
                                                   filter_dynamic=True)
            if not segments:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s has network %(network_id)s not "
                        "no segment"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id']
                        })
                return {'device': device}
            elif len(segments) != 1:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s has network %(network_id)s not "
                        "no segment size miss mach"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id']
                        })
                return {'device': device}
            elif segments[0]['segmentation_id'] == 0:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s, segment %(segment_id)s has "
                        "network %(network_id)s not "
                        "no segment from NWA"), {
                            'device': device,
                            'agent_id': agent_id,
                            'segment_id': segments[0]['id'],
                            'network_id': port['network_id']
                        })
                return {'device': device}

            binding = necnwa_api.ensure_port_binding(session, port_id)

            if not binding.segment_id:
                LOG.warning(
                    _LW("Device %(device)s requested by agent "
                        "%(agent_id)s on network %(network_id)s not "
                        "bound, vif_type: %(vif_type)s"), {
                            'device': device,
                            'agent_id': agent_id,
                            'network_id': port['network_id'],
                            'vif_type': binding.vif_type
                        })
                return {'device': device}

        port = port_context.current

        new_status = (constants.PORT_STATUS_BUILD if port['admin_state_up']
                      else constants.PORT_STATUS_DOWN)

        if (port['status'] != new_status
                and port['status'] != constants.PORT_STATUS_ACTIVE):
            plugin.update_port_status(rpc_context, port_id, new_status, host)

        entry = {
            'device': device,
            'network_id': port['network_id'],
            'port_id': port_id,
            'mac_address': port['mac_address'],
            'admin_state_up': port['admin_state_up'],
            'network_type': segments[0]['network_type'],
            'segmentation_id': segments[0]['segmentation_id'],
            'physical_network': segments[0]['physical_network'],
            'fixed_ips': port['fixed_ips'],
            'device_owner': port['device_owner'],
            'profile': port[portbindings.PROFILE]
        }
        LOG.debug("Returning: %s", entry)
        return entry