Пример #1
0
    def setup_rpc(self):
        # print("cfarquhar: in setup_rpc")
        self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN)
        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self.sg_agent = agent_sg_rpc.SecurityGroupAgentRpc(
            self.context, self.sg_plugin_rpc, defer_refresh_firewall=True)
        # LOG.info("cfarquhar: vars(plugin_rpc): {}".format(vars(self.plugin_rpc)))
        # LOG.info("cfarquhar: vars(sg_plugin_rpc): {}".format(vars(self.sg_plugin_rpc)))
        # LOG.info("cfarquhar: vars(sg_agent.plugin_rpc): {}".format(vars(self.sg_agent.plugin_rpc)))

        self.agent_id = self.mgr.get_agent_id()
        LOG.info("RPC agent_id: %s", self.agent_id)

        self.topic = topics.AGENT
        self.state_rpc = agent_rpc.PluginReportStateAPI(topics.REPORTS)
        # RPC network init
        # Handle updates from service
        self.rpc_callbacks = self.mgr.get_rpc_callbacks(
            self.context, self, self.sg_agent)
        self.endpoints = [self.rpc_callbacks]
        self._validate_rpc_endpoints()
        # Define the listening consumers for the agent
        consumers = self.mgr.get_rpc_consumers()
        self.connection = agent_rpc.create_consumers(self.endpoints,
                                                     self.topic,
                                                     consumers,
                                                     start_listening=False)
Пример #2
0
    def _setup(self):
        """Setup the layer two agent."""
        super(HyperVNeutronAgent, self)._setup()

        self._sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self._sec_groups_agent = HyperVSecurityAgent(self._context,
                                                     self._sg_plugin_rpc)
        self._vlan_driver = trunk_driver.HyperVTrunkDriver(self._context)
        if CONF.NVGRE.enable_support:
            self._consumers.append([h_constant.TUNNEL, topics.UPDATE])
            self._consumers.append([h_constant.LOOKUP, h_constant.UPDATE])
Пример #3
0
    def __init__(self, vsphere_hostname, vsphere_login, vsphere_password,
                 bridge_mappings, polling_interval):
        super(DVSAgent, self).__init__()

        self.agent_state = {
            'binary': 'neutron-dvs-agent',
            'host': cfg.CONF.host,
            'topic': n_const.L2_AGENT_TOPIC,
            'configurations': {
                'bridge_mappings': bridge_mappings,
                'vsphere_hostname': vsphere_hostname
            },
            'agent_type': 'DVS agent',
            'start_flag': True
        }

        report_interval = cfg.CONF.AGENT.report_interval

        self.polling_interval = polling_interval
        # Security group agent support
        self.context = context.get_admin_context_without_session()
        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self.sg_agent = dvs_rpc.DVSSecurityGroupRpc(
            self.context, self.sg_plugin_rpc, defer_refresh_firewall=True)

        self.setup_rpc()
        self.run_daemon_loop = True
        self.iter_num = 0

        self.network_map = dvs_util.create_network_map_from_config(
            cfg.CONF.ML2_VMWARE, pg_cache=True)
        uplink_map = dvs_util.create_uplink_map_from_config(
            cfg.CONF.ML2_VMWARE, self.network_map)
        for phys, dvs in six.iteritems(self.network_map):
            if phys in uplink_map:
                dvs.load_uplinks(phys, uplink_map[phys])
        self.updated_ports = set()
        self.deleted_ports = set()
        self.known_ports = set()
        self.added_ports = set()
        self.booked_ports = set()
        LOG.info(_LI("Agent out of sync with plugin!"))
        connected_ports = self._get_dvs_ports()
        self.added_ports = connected_ports
        if cfg.CONF.DVS.clean_on_restart:
            self._clean_up_vsphere_extra_resources(connected_ports)
        self.fullsync = False

        # The initialization is complete; we can start receiving messages
        self.connection.consume_in_threads()
        if report_interval:
            heartbeat = loopingcall.FixedIntervalLoopingCall(
                self._report_state)
            heartbeat.start(interval=report_interval)
Пример #4
0
    def test_security_group_rules_for_devices(self):
        rpcapi = securitygroups_rpc.SecurityGroupServerRpcApi('fake_topic')

        with mock.patch.object(rpcapi.client, 'call') as rpc_mock,\
                mock.patch.object(rpcapi.client, 'prepare') as prepare_mock:
            prepare_mock.return_value = rpcapi.client
            rpcapi.security_group_rules_for_devices('context', ['fake_device'])

            rpc_mock.assert_called_once_with(
                'context',
                'security_group_rules_for_devices',
                devices=['fake_device'])
Пример #5
0
    def __init__(self, physical_devices_mappings, exclude_devices,
                 polling_interval, rp_bandwidths, rp_inventory_defaults,
                 rp_hypervisors):

        self.polling_interval = polling_interval
        self.network_ports = collections.defaultdict(list)
        self.conf = cfg.CONF
        self.device_mappings = physical_devices_mappings
        self.exclude_devices = exclude_devices
        self.setup_eswitch_mgr(physical_devices_mappings, exclude_devices)

        # Stores port update notifications for processing in the main loop
        self.updated_devices = set()
        # Stores <mac, pci_slot> pairs for ports whose binding has been
        # activated.
        self.activated_bindings = set()

        self.context = context.get_admin_context_without_session()
        self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN)
        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self.sg_agent = agent_sg_rpc.SecurityGroupAgentRpc(
            self.context, self.sg_plugin_rpc)
        self._setup_rpc()
        self.ext_manager = self._create_agent_extension_manager(
            self.connection)

        configurations = {
            'device_mappings': physical_devices_mappings,
            n_constants.RP_BANDWIDTHS: rp_bandwidths,
            n_constants.RP_INVENTORY_DEFAULTS: rp_inventory_defaults,
            'resource_provider_hypervisors': rp_hypervisors,
            'extensions': self.ext_manager.names()
        }

        # TODO(mangelajo): optimize resource_versions (see ovs agent)
        self.agent_state = {
            'binary': n_constants.AGENT_PROCESS_NIC_SWITCH,
            'host': self.conf.host,
            'topic': n_constants.L2_AGENT_TOPIC,
            'configurations': configurations,
            'agent_type': n_constants.AGENT_TYPE_NIC_SWITCH,
            'resource_versions': resources.LOCAL_RESOURCE_VERSIONS,
            'start_flag': True
        }

        # The initialization is complete; we can start receiving messages
        self.connection.consume_in_threads()
        # Initialize iteration counter
        self.iter_num = 0
 def _setup_rpc(self):
     self.topic = topics.AGENT
     self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN)
     self.sg_plugin_rpc = api_sg_rpc.SecurityGroupServerRpcApi(
         topics.PLUGIN)
     self.context = q_context.get_admin_context_without_session()
     self.endpoints = [self]
     consumers = [[topics.PORT, topics.UPDATE],
                  [topics.SECURITY_GROUP, topics.UPDATE]]
     self.connection = agent_rpc.create_consumers(self.endpoints,
                                                  self.topic, consumers)
     self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)
     report_interval = cfg.CONF.AGENT.report_interval
     if report_interval:
         heartbeat = loopingcall.FixedIntervalLoopingCall(
             self._report_state)
         heartbeat.start(interval=report_interval)
Пример #7
0
    def __init__(self, physical_devices_mappings, exclude_devices,
                 polling_interval):

        self.polling_interval = polling_interval
        self.network_ports = collections.defaultdict(list)
        self.conf = cfg.CONF
        self.device_mappings = physical_devices_mappings
        self.exclude_devices = exclude_devices
        self.setup_eswitch_mgr(physical_devices_mappings, exclude_devices)

        # Stores port update notifications for processing in the main loop
        self.updated_devices = set()

        self.context = context.get_admin_context_without_session()
        self.plugin_rpc = agent_rpc.PluginApi(topics.PLUGIN)
        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self.sg_agent = agent_sg_rpc.SecurityGroupAgentRpc(
            self.context, self.sg_plugin_rpc)
        self._setup_rpc()
        self.ext_manager = self._create_agent_extension_manager(
            self.connection)

        configurations = {
            'device_mappings': physical_devices_mappings,
            'extensions': self.ext_manager.names()
        }

        #TODO(mangelajo): optimize resource_versions (see ovs agent)
        self.agent_state = {
            'binary': 'neutron-sriov-nic-agent',
            'host': self.conf.host,
            'topic': n_constants.L2_AGENT_TOPIC,
            'configurations': configurations,
            'agent_type': n_constants.AGENT_TYPE_NIC_SWITCH,
            'resource_versions': resources.LOCAL_RESOURCE_VERSIONS,
            'start_flag': True
        }

        # The initialization is complete; we can start receiving messages
        self.connection.consume_in_threads()
        # Initialize iteration counter
        self.iter_num = 0
Пример #8
0
    def setup_rpc(self):
        self.agent_id = 'opflex-agent-%s' % cfg.CONF.host
        self.context = context.get_admin_context_without_session()
        # Set GBP rpc API
        self.of_rpc = rpc.GBPServerRpcApi(rpc.TOPIC_OPFLEX)
        self.plugin_rpc = ovs.OVSPluginApi(topics.PLUGIN)
        self.sg_plugin_rpc = sg_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
        self.sg_agent = agent_sg_rpc.SecurityGroupAgentRpc(
            self.context, self.sg_plugin_rpc, defer_refresh_firewall=True)

        self.state_rpc = agent_rpc.PluginReportStateAPI(topics.PLUGIN)
        self.topic = topics.AGENT
        self.endpoints = [self]
        consumers = [[topics.PORT, topics.UPDATE],
                     [topics.PORT, topics.DELETE],
                     [topics.SECURITY_GROUP, topics.UPDATE],
                     [topics.SUBNET, topics.UPDATE],
                     [rpc.TOPIC_OPFLEX, rpc.NOTIFY_VRF, topics.UPDATE],
                     [rpc.TOPIC_OPFLEX, rpc.VRF, topics.UPDATE]]
        self.connection = agent_rpc.create_consumers(self.endpoints,
                                                     self.topic,
                                                     consumers,
                                                     start_listening=False)
Пример #9
0
def neutron_dvs_cli():
    """
        CLI command for retrieving a port from Neutron by id;
        Comparing the retrieved port to a port in the linked portgroup from vSphere;
        The port from vSphere is fetched by the Neutron port MAC address and the portgroup key;
        If --correct opt is set a reconfigure task on the port will be started which will apply the rules from the Neutron port to the DVS port
    :return: 
    """
    common_config.init(sys.argv[1:])
    port_id = CONF.port_id
    correct = CONF.correct

    profiler.setup('neutron-dvs-agent-cli', cfg.CONF.host)
    agent = DvsNeutronAgent()
    neutron_ports = agent.plugin_rpc.get_devices_details_list(
        agent.context,
        devices=[port_id],
        agent_id=agent.agent_id,
        host=agent.conf.host)

    if neutron_ports[0].has_key('mac_address'):
        mac_addr = neutron_ports[0]['mac_address']
    else:
        raise Exception('Neutron port not found!')

    sg_api = securitygroups_rpc.SecurityGroupServerRpcApi(topics.PLUGIN)
    sg_info = sg_api.security_group_info_for_devices(
        agent.context, [neutron_ports[0]['port_id']])

    rules = sg_api.security_group_rules_for_devices(agent.context, [port_id])
    patched_sg_rules = sg_util._patch_sg_rules(
        rules[port_id]['security_group_rules'])

    sg_set = sg_util.security_group_set(sg_info)

    dvs = agent.api.network_dvs_map.get(neutron_ports[0]['physical_network'],
                                        None)
    sg_aggr_obj = defaultdict(lambda: defaultdict(sg_util.SgAggr))
    sg_aggr = sg_aggr_obj[dvs.uuid][sg_set]
    sg_util.apply_rules(patched_sg_rules, sg_aggr)

    sg_set_rules = sg_util.get_rules(sg_aggr)
    port_config = sg_util.port_configuration(None, sg_set_rules, {}, None,
                                             None).setting

    neutron_vlan_id = neutron_ports[0]['segmentation_id']
    dvpg_name = dvs_util.dvportgroup_name(dvs.uuid, sg_set)
    """
        Retrieving the DVS portgroup and properties
    """
    port_group = dvs.get_port_group_for_security_group_set(sg_set)
    portgroup_key = port_group['ref']['value']

    dvs_vlan_id = port_group['defaultPortConfig'].vlan.vlanId

    dvs_port = agent.api.fetch_ports_by_mac(portgroup_key, mac_addr)
    neutron_port_rules = port_config.filterPolicy.filterConfig[
        0].trafficRuleset.rules
    dvs_port_rules = dvs_port.config.setting.filterPolicy.filterConfig[
        0].trafficRuleset.rules

    match = False

    for i in range(len(dvs_port_rules)):
        config_match = dvs_util._config_differs(dvs_port_rules[i],
                                                neutron_port_rules[i])
        if config_match:
            match = True
            print("Neutron Port configuration rule not matched for : ",
                  neutron_port_rules[i])
            print("DVS Port configuraiton rule: ", dvs_port_rules[i])

    if match == False:
        print("Neutron port config matches DVS port config")
    else:
        if correct == 'True':
            print("Updating port configuration")
            if neutron_vlan_id != dvs_vlan_id:
                port_config.vlan = builder.vlan(neutron_vlan_id)

            dv_port_config_spec = builder.port_config_spec(
                key=dvs_port.key,
                version=dvs_port.config.configVersion,
                setting=port_config)
            dvs.update_ports([dv_port_config_spec])