Esempio n. 1
0
def device_cluster_converter(object_dict,
                             otype,
                             helper,
                             source_identity_attributes,
                             destination_identity_attributes,
                             to_aim=True):
    if to_aim:
        result = utils.default_converter(object_dict,
                                         otype,
                                         helper,
                                         source_identity_attributes,
                                         destination_identity_attributes,
                                         to_aim=to_aim)
    else:
        result = utils.default_converter(object_dict,
                                         otype,
                                         helper,
                                         source_identity_attributes,
                                         destination_identity_attributes,
                                         to_aim=to_aim)
        if object_dict['encap']:
            lif = service_graph.DeviceClusterInterface(
                tenant_name=object_dict['tenant_name'],
                device_cluster_name=object_dict['name'],
                name='interface',
                encap=object_dict['encap'])
            result.append(lif)
        else:
            lif = None
        nodes = []
        for node in object_dict['devices']:
            if 'name' in node:
                cdev = service_graph.ConcreteDevice(
                    tenant_name=object_dict['tenant_name'],
                    device_cluster_name=object_dict['name'],
                    name=node['name'])
                cdev_if = service_graph.ConcreteDeviceInterface(
                    tenant_name=object_dict['tenant_name'],
                    device_cluster_name=object_dict['name'],
                    device_name=node['name'],
                    name='interface')
                if 'path' in node:
                    cdev_if.path = node['path']
                nodes.extend([cdev, cdev_if])
                if lif:
                    lif.concrete_interfaces.append(cdev_if.dn)
        result.extend(nodes)
    return result
Esempio n. 2
0
    def test_host_data_migration(self):
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth0', path='h1/path/VPC'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth1', path='h1/path/2'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h1', interface_name='eth2', path='h1/path/VPC'))
        self.mgr.create(self.ctx, infra.HostLink(
            host_name='h2', interface_name='eth2', path='h2/path'))

        epg1 = self.mgr.create(self.ctx, resource.EndpointGroup(
            tenant_name='t1', app_profile_name='ap', name='epg1',
            static_paths=[{'path': 'h1/path/2', 'encap': '100'},
                          {'path': 'h2/path', 'encap': '100'},
                          {'path': 'not_known', 'encap': '100'}]))
        epg2 = self.mgr.create(self.ctx, resource.EndpointGroup(
            tenant_name='t1', app_profile_name='ap', name='epg2',
            static_paths=[{'path': 'h1/path/2', 'encap': '100'},
                          {'path': 'h1/path/VPC', 'encap': '100'}]))
        dc = self.mgr.create(self.ctx, service_graph.DeviceCluster(
            tenant_name='t2', name='dc',
            devices=[{'path': 'h1/path/2', 'name': '1'},
                     {'path': 'h2/path', 'name': '2'}]))
        cdi1 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface(
            tenant_name='t2', device_cluster_name='dc', device_name='1',
            name='dc', path='h1/path/VPC'))
        cdi2 = self.mgr.create(self.ctx, service_graph.ConcreteDeviceInterface(
            tenant_name='t2', device_cluster_name='dc', device_name='2',
            name='dc', path='h2/path'))
        l3out_iface1 = self.mgr.create(
            self.ctx, resource.L3OutInterface(
                tenant_name='t2', l3out_name='dc', node_profile_name='1',
                interface_profile_name='dc1', interface_path='h1/path/VPC'))
        l3out_iface2 = self.mgr.create(
            self.ctx, resource.L3OutInterface(
                tenant_name='t2', l3out_name='dc', node_profile_name='1',
                interface_profile_name='dc2', interface_path='h2/path'))
        add_host_column.migrate(self.ctx.db_session)
        epg1 = self.mgr.get(self.ctx, epg1)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'},
                 {'path': 'h2/path', 'encap': '100', 'host': 'h2'},
                 {'path': 'not_known', 'encap': '100'}]),
            utils.deep_sort(epg1.static_paths))
        epg2 = self.mgr.get(self.ctx, epg2)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'encap': '100', 'host': 'h1'},
                 {'path': 'h1/path/VPC', 'encap': '100', 'host': 'h1'}]),
            utils.deep_sort(epg2.static_paths))
        dc = self.mgr.get(self.ctx, dc)
        self.assertEqual(
            utils.deep_sort(
                [{'path': 'h1/path/2', 'name': '1', 'host': 'h1'},
                 {'path': 'h2/path', 'name': '2', 'host': 'h2'}]),
            utils.deep_sort(dc.devices))
        cdi1 = self.mgr.get(self.ctx, cdi1)
        self.assertEqual('h1', cdi1.host)
        cdi2 = self.mgr.get(self.ctx, cdi2)
        self.assertEqual('h2', cdi2.host)
        l3out_iface1 = self.mgr.get(self.ctx, l3out_iface1)
        self.assertEqual('h1', l3out_iface1.host)
        l3out_iface2 = self.mgr.get(self.ctx, l3out_iface2)
        self.assertEqual('h2', l3out_iface2.host)
Esempio n. 3
0
    def _map_port_pair_group(self, plugin_context, ppg, tenant):
        session = plugin_context.session
        aim_ctx = aim_context.AimContext(session)
        # Create Logical device model, container for all the PPG port pairs.
        dc = self._get_ppg_device_cluster(session, ppg, tenant)
        type, domain = self._get_ppg_domain(plugin_context, ppg)
        if not type and not domain:
            raise exceptions.PortPairsNoUniqueDomain(id=ppg['port_pairs'])
        if type == PHYSDOM_TYPE:
            dc.device_type = 'PHYSICAL'
            dc.physical_domain_name = domain
        else:
            dc.device_type = 'VIRTUAL'
            dc.vmm_domain = [{'type': type, 'name': domain}]
        self.aim.create(aim_ctx, dc)
        # For each port pair, create the corresponding Concrete Devices
        # (represented by the static path of each interface)
        ingress_cdis = []
        egress_cdis = []
        port_pairs = self.sfc_plugin.get_port_pairs(
            plugin_context, filters={'id': ppg['port_pairs']})
        for pp in port_pairs:
            ingress_port = self.plugin.get_port(plugin_context, pp['ingress'])
            egress_port = self.plugin.get_port(plugin_context, pp['egress'])
            pp_id = self.name_mapper.port_pair(session, pp['id'])
            pp_name = aim_utils.sanitize_display_name(ppg['name'])
            cd = aim_sg.ConcreteDevice(tenant_name=dc.tenant_name,
                                       device_cluster_name=dc.name,
                                       name=pp_id,
                                       display_name=pp_name)
            # Create ConcreteDevice
            self.aim.create(aim_ctx, cd)
            for p, store in [(ingress_port, ingress_cdis),
                             (egress_port, egress_cdis)]:
                p_id = self.name_mapper.port(session, p['id'])
                p_name = aim_utils.sanitize_display_name(p['name'])
                path, encap = self.aim_mech._get_port_static_path_and_encap(
                    plugin_context, p)
                if path is None:
                    LOG.warning("Path not found for Port Pair %s member %s ",
                                "Port might be unbound.", pp['id'], p['id'])
                    continue
                # TODO(ivar): what if encap is None? is that an Opflex port?
                # Create Concrete Device Interface
                cdi = aim_sg.ConcreteDeviceInterface(
                    tenant_name=cd.tenant_name,
                    device_cluster_name=cd.device_cluster_name,
                    device_name=cd.name,
                    name=p_id,
                    display_name=p_name,
                    path=path)
                cdi = self.aim.create(aim_ctx, cdi)
                store.append((cdi, encap, p))
        # Ingress and Egress CDIs have the same length.
        # All the ingress devices must be load balances, and so the egress
        # (for reverse path). Create the proper PBR policies as well as
        # the Logical Interfaces (which see all the physical interfaces of a
        # specific direction as they were one).
        internal_dci = aim_sg.DeviceClusterInterface(
            tenant_name=dc.tenant_name,
            device_cluster_name=dc.name,
            name=INGRESS,
            display_name=INGRESS)
        external_dci = aim_sg.DeviceClusterInterface(
            tenant_name=dc.tenant_name,
            device_cluster_name=dc.name,
            name=EGRESS,
            display_name=EGRESS)
        # Create 2 PBR rules per PPG, one per direction.
        ipbr = self._get_ppg_service_redirect_policy(session, ppg, INGRESS,
                                                     tenant)
        epbr = self._get_ppg_service_redirect_policy(session, ppg, EGRESS,
                                                     tenant)

        for i in range(len(ingress_cdis)):
            icdi, iencap, iport = ingress_cdis[i]
            ecdi, eencap, eport = egress_cdis[i]
            internal_dci.encap = iencap
            external_dci.encap = eencap
            internal_dci.concrete_interfaces.append(icdi.dn)
            external_dci.concrete_interfaces.append(ecdi.dn)
            if iport['fixed_ips']:
                ipbr.destinations.append({
                    'ip':
                    iport['fixed_ips'][0]['ip_address'],
                    'mac':
                    iport['mac_address']
                })
            if eport['fixed_ips']:
                epbr.destinations.append({
                    'ip':
                    eport['fixed_ips'][0]['ip_address'],
                    'mac':
                    eport['mac_address']
                })

        self.aim.create(aim_ctx, internal_dci)
        self.aim.create(aim_ctx, external_dci)
        self.aim.create(aim_ctx, ipbr)
        self.aim.create(aim_ctx, epbr)