Ejemplo n.º 1
0
    def generate_network_scheme(cls, node, networks):
        attrs = super(NeutronNetworkDeploymentSerializer60, cls).generate_network_scheme(node, networks)

        for item in attrs.get("transformations", ()):
            if "tags" in item:
                item["vlan_ids"] = item["tags"]

        # Include information about all subnets that don't belong to this node.
        # This is used during deployment to configure routes to all other
        # networks in the environment.
        nm = Cluster.get_network_manager(node.cluster)
        other_nets = nm.get_networks_not_on_node(node, networks)

        netgroup_mapping = [("storage", "br-storage"), ("management", "br-mgmt"), ("fuelweb_admin", "br-fw-admin")]
        if Node.should_have_public(node):
            netgroup_mapping.append(("public", "br-ex"))

        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get("gateway"):
                attrs["endpoints"][brname]["gateway"] = netgroup["gateway"]
            attrs["endpoints"][brname]["other_nets"] = other_nets.get(ngname, [])

        if Node.should_have_public(node):
            attrs["endpoints"]["br-ex"]["default_gateway"] = True
        else:
            gw = nm.get_default_gateway(node.id)
            attrs["endpoints"]["br-fw-admin"]["gateway"] = gw
            attrs["endpoints"]["br-fw-admin"]["default_gateway"] = True

        return attrs
Ejemplo n.º 2
0
    def get_default_network_to_endpoint_mapping(cls, node):
        mapping = {
            consts.NETWORKS.fuelweb_admin: 'br-fw-admin',
            consts.NETWORKS.storage: 'br-storage',
            consts.NETWORKS.management: 'br-mgmt',
            consts.NETWORKS.private: 'br-prv'}

        if Node.should_have_public(node):
            mapping[consts.NETWORKS.public] = 'br-ex'

        return mapping
Ejemplo n.º 3
0
 def update_nodes_net_info(cls, cluster, nodes):
     """Adds information about networks to each node."""
     for node in Cluster.get_nodes_not_for_deletion(cluster):
         netw_data = node.network_data
         addresses = {}
         for net in node.cluster.network_groups:
             if net.name == "public" and not Node.should_have_public(node):
                 continue
             if net.meta.get("render_addr_mask"):
                 addresses.update(cls.get_addr_mask(netw_data, net.name, net.meta.get("render_addr_mask")))
         [n.update(addresses) for n in nodes if n["uid"] == str(node.uid)]
     return nodes
Ejemplo n.º 4
0
    def generate_network_scheme(cls, node, networks):
        attrs = super(NeutronNetworkDeploymentSerializer60, cls). \
            generate_network_scheme(node, networks)

        for item in attrs.get('transformations', ()):
            if 'tags' in item:
                item['vlan_ids'] = item['tags']

        # Include information about all subnets that don't belong to this node.
        # This is used during deployment to configure routes to all other
        # networks in the environment.
        nm = Cluster.get_network_manager(node.cluster)
        other_nets = nm.get_networks_not_on_node(node, networks)

        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if Node.should_have_public(node):
            netgroup_mapping.append(('public', 'br-ex'))

        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get('gateway'):
                attrs['endpoints'][brname]['gateway'] = netgroup['gateway']
            attrs['endpoints'][brname]['other_nets'] = \
                other_nets.get(ngname, [])

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex']['default_gateway'] = True
        else:
            gw = nm.get_default_gateway(node.id)
            attrs['endpoints']['br-fw-admin']['gateway'] = gw
            attrs['endpoints']['br-fw-admin']['default_gateway'] = True

        return attrs
Ejemplo n.º 5
0
    def generate_network_scheme(cls, node):
        attrs = super(NeutronNetworkDeploymentSerializer60, cls). \
            generate_network_scheme(node)

        for item in attrs.get('transformations', ()):
            if 'tags' in item:
                item['vlan_ids'] = item['tags']

        # Include information about all subnets that don't belong to this node.
        # This is used during deployment to configure routes to all other
        # networks in the environment.
        nm = Cluster.get_network_manager(node.cluster)
        other_nets = nm.get_networks_not_on_node(node)

        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if Node.should_have_public(node):
            netgroup_mapping.append(('public', 'br-ex'))

        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_node_network_by_netname(node, ngname)
            if netgroup.get('gateway'):
                attrs['endpoints'][brname]['gateway'] = netgroup['gateway']
            attrs['endpoints'][brname]['other_nets'] = \
                other_nets.get(ngname, [])

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex']['default_gateway'] = True
        else:
            gw = nm.get_default_gateway(node.id)
            attrs['endpoints']['br-fw-admin']['gateway'] = gw
            attrs['endpoints']['br-fw-admin']['default_gateway'] = True

        return attrs
Ejemplo n.º 6
0
 def update_nodes_net_info(cls, cluster, nodes):
     """Adds information about networks to each node."""
     for node in Cluster.get_nodes_not_for_deletion(cluster):
         netw_data = node.network_data
         addresses = {}
         for net in node.cluster.network_groups:
             if net.name == 'public' and \
                     not Node.should_have_public(node):
                 continue
             if net.meta.get('render_addr_mask'):
                 addresses.update(
                     cls.get_addr_mask(netw_data, net.name,
                                       net.meta.get('render_addr_mask')))
         [n.update(addresses) for n in nodes if n['uid'] == str(node.uid)]
     return nodes
Ejemplo n.º 7
0
    def _update_public_network(cls, cluster, public_map, roles_metadata):
        """Applies changes to node's public_network checked using public_map.

        :param instance: Cluster object
        :param public_map: dict of Node.id to should_have_public result.
        :param roles_metadata: dict from objects.Cluster.get_roles
        """

        if cluster.network_config.configuration_template is not None:
            return
        from nailgun.objects import Node
        for node in cluster.nodes:
            should_have_public = Node.should_have_public(node, roles_metadata)
            if public_map.get(node.id) == should_have_public:
                continue
            if should_have_public:
                cls.assign_public_network(node)
            else:
                cls.unassign_public_network(node)
Ejemplo n.º 8
0
    def generate_network_scheme(cls, node):
        attrs = super(NeutronNetworkDeploymentSerializer70,
                      cls).generate_network_scheme(node)

        attrs['roles']['neutron/api'] = 'br-mgmt'
        attrs['roles']['neutron/mesh'] = 'br-mgmt'
        attrs['roles']['neutron/private'] = 'br-prv'

        attrs['roles']['mgmt/corosync'] = 'br-mgmt'
        attrs['roles']['mgmt/database'] = 'br-mgmt'
        attrs['roles']['mgmt/messaging'] = 'br-mgmt'
        attrs['roles']['mgmt/api'] = 'br-mgmt'
        attrs['roles']['mgmt/vip'] = 'br-mgmt'

        attrs['roles']['nova/api'] = 'br-mgmt'
        attrs['roles']['murano/api'] = 'br-mgmt'
        attrs['roles']['sahara/api'] = 'br-mgmt'
        attrs['roles']['ceilometer/api'] = 'br-mgmt'
        attrs['roles']['heat/api'] = 'br-mgmt'
        attrs['roles']['keystone/api'] = 'br-mgmt'
        attrs['roles']['horizon'] = 'br-mgmt'
        attrs['roles']['glance/api'] = 'br-mgmt'

        if Node.should_have_public(node):
            attrs['roles']['neutron/floating'] = 'br-floating'
            attrs['roles']['public/vip'] = 'br-ex'
            attrs['roles']['ceph/radosgw'] = 'br-ex'
            attrs['roles']['swift/public'] = 'br-ex'

        attrs['roles']['admin/pxe'] = 'br-fw-admin'

        attrs['roles']['ceph/replication'] = 'br-storage'
        attrs['roles']['ceph/public'] = 'br-mgmt'

        attrs['roles']['swift/replication'] = 'br-storage'
        attrs['roles']['swift/api'] = 'br-mgmt'

        attrs['roles']['cinder/iscsi'] = 'br-storage'
        attrs['roles']['cinder/api'] = 'br-mgmt'

        attrs['roles']['mongo/db'] = 'br-mgmt'

        return attrs
Ejemplo n.º 9
0
    def _update_public_network(cls, cluster, public_map, roles_metadata):
        """Applies changes to node's public_network checked using public_map.

        :param instance: Cluster object
        :param public_map: dict of Node.id to should_have_public result.
        :param roles_metadata: dict from objects.Cluster.get_roles
        """

        if cluster.network_config.configuration_template is not None:
            return
        from nailgun.objects import Node
        for node in cluster.nodes:
            should_have_public = Node.should_have_public(
                node, roles_metadata)
            if public_map.get(node.id) == should_have_public:
                continue
            if should_have_public:
                cls.assign_public_network(node)
            else:
                cls.unassign_public_network(node)
Ejemplo n.º 10
0
    def generate_network_scheme(cls, node):

        # Create a data structure and fill it with static values.

        attrs = {
            'version': '1.0',
            'provider': 'ovs',
            'interfaces': {},  # It's a list of physical interfaces.
            'endpoints': {
                'br-storage': {},
                'br-mgmt': {},
                'br-fw-admin': {},
            },
            'roles': {
                'management': 'br-mgmt',
                'storage': 'br-storage',
                'fw-admin': 'br-fw-admin',
            },
            'transformations': []
        }

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex'] = {}
            attrs['roles']['ex'] = 'br-ex'

        nm = Cluster.get_network_manager(node.cluster)
        iface_types = consts.NETWORK_INTERFACE_TYPES

        # Add a dynamic data to a structure.

        vlan_splinters_data = \
            node.cluster.attributes.editable\
            .get('vlan_splinters', {})\

        # if vlan_splinters is enabled - use its value
        use_vlan_splinters = 'disabled'
        if vlan_splinters_data\
                .get('metadata', {})\
                .get('enabled'):

            use_vlan_splinters = \
                vlan_splinters_data\
                .get('vswitch', {})\
                .get('value', 'disabled')

        # Fill up interfaces and add bridges for them.
        bonded_ifaces = [x for x in node.nic_interfaces if x.bond]
        for iface in node.interfaces:
            # Handle vlan splinters.
            if iface.type == iface_types.ether:
                attrs['interfaces'][iface.name] = {
                    'L2': cls._get_vlan_splinters_desc(
                        use_vlan_splinters, iface, node.cluster
                    )
                }

            if iface in bonded_ifaces:
                continue
            attrs['transformations'].append({
                'action': 'add-br',
                'name': 'br-%s' % iface.name
            })
            if iface.type == iface_types.ether:
                attrs['transformations'].append({
                    'action': 'add-port',
                    'bridge': 'br-%s' % iface.name,
                    'name': iface.name
                })
            elif iface.type == iface_types.bond:
                attrs['transformations'].append({
                    'action': 'add-bond',
                    'bridge': 'br-%s' % iface.name,
                    'name': iface.name,
                    'interfaces': [x['name'] for x in iface.slaves],
                    'properties': nm.get_ovs_bond_properties(iface)
                })

        # Add bridges for networks.
        # We have to add them after br-ethXX bridges because it is the way
        # to provide a right ordering of ifdown/ifup operations with
        # IP interfaces.
        brnames = ['br-ex', 'br-mgmt', 'br-storage', 'br-fw-admin']
        if not Node.should_have_public(node):
            brnames.pop(0)

        for brname in brnames:
            attrs['transformations'].append({
                'action': 'add-br',
                'name': brname
            })

        # Populate IP address information to endpoints.
        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if Node.should_have_public(node):
            netgroup_mapping.append(('public', 'br-ex'))

        netgroups = {}
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_node_network_by_netname(node, ngname)
            if netgroup.get('ip'):
                attrs['endpoints'][brname]['IP'] = [netgroup['ip']]
            netgroups[ngname] = netgroup

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex']['gateway'] = \
                netgroups['public']['gateway']
        else:
            attrs['endpoints']['br-fw-admin']['gateway'] = settings.MASTER_IP

        # Connect interface bridges to network bridges.
        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_node_network_by_netname(node, ngname)
            if not netgroup['vlan']:
                # Untagged network.
                attrs['transformations'].append({
                    'action': 'add-patch',
                    'bridges': ['br-%s' % netgroup['dev'], brname],
                    'trunks': [0]
                })
            elif netgroup['vlan'] > 1:
                # Tagged network.
                attrs['transformations'].append({
                    'action': 'add-patch',
                    'bridges': ['br-%s' % netgroup['dev'], brname],
                    'tags': [netgroup['vlan'], 0]
                })
            else:
                # FIXME! Should raise some exception I think.
                logger.error('Invalid vlan for network: %s' % str(netgroup))

        # Dance around Neutron segmentation type.
        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['endpoints']['br-prv'] = {'IP': 'none'}
            attrs['roles']['private'] = 'br-prv'

            attrs['transformations'].append({
                'action': 'add-br',
                'name': 'br-prv',
            })

            attrs['transformations'].append({
                'action': 'add-patch',
                'bridges': [
                    'br-%s' % nm.get_node_interface_by_netname(
                        node.id,
                        'private'
                    ).name,
                    'br-prv'
                ]
            })
        elif node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            attrs['roles']['mesh'] = 'br-mgmt'

        return attrs
Ejemplo n.º 11
0
    def generate_network_scheme(cls, node, networks):

        # Create a data structure and fill it with static values.
        attrs = {
            'version': '1.1',
            'provider': 'lnx',
            'interfaces': {},  # It's a list of physical interfaces.
            'endpoints': {},
            'roles': {
                'management': 'br-mgmt',
                'storage': 'br-storage',
                'fw-admin': 'br-fw-admin',
            },
        }

        is_public = Node.should_have_public(node)
        if is_public:
            attrs['endpoints']['br-ex'] = {'IP': 'none'}
            attrs['endpoints']['br-floating'] = {'IP': 'none'}
            attrs['roles']['ex'] = 'br-ex'
            attrs['roles']['neutron/floating'] = 'br-floating'

        nm = Cluster.get_network_manager(node.cluster)

        # Populate IP and GW information to endpoints.
        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if is_public:
            netgroup_mapping.append(('public', 'br-ex'))

        if node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            netgroup_mapping.append(('private', 'br-mesh'))
            attrs['endpoints']['br-mesh'] = {}
            attrs['roles']['neutron/mesh'] = 'br-mesh'

        netgroups = {}
        nets_by_ifaces = defaultdict(list)
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get('ip'):
                attrs['endpoints'][brname] = {'IP': [netgroup['ip']]}
            netgroups[ngname] = netgroup
            nets_by_ifaces[netgroup['dev']].append({
                'br_name': brname,
                'vlan_id': netgroup['vlan']
            })

        # Add gateway.
        if is_public and netgroups['public'].get('gateway'):
            attrs['endpoints']['br-ex']['gateway'] = \
                netgroups['public']['gateway']
        else:
            gw = nm.get_default_gateway(node.id)
            attrs['endpoints']['br-fw-admin']['gateway'] = gw

        # Fill up interfaces.
        for iface in node.nic_interfaces:
            if iface.bond:
                attrs['interfaces'][iface.name] = {}
            else:
                attrs['interfaces'][iface.name] = \
                    nm.get_iface_properties(iface)

        # Dance around Neutron segmentation type.
        prv_base_ep = None
        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['endpoints']['br-prv'] = {'IP': 'none'}
            attrs['roles']['neutron/private'] = 'br-prv'

            netgroup = nm.get_network_by_netname('private', networks)
            # create br-aux if there is no untagged network (endpoint) on the
            # same interface.
            if netgroup['dev'] in nets_by_ifaces:
                for ep in nets_by_ifaces[netgroup['dev']]:
                    if not ep['vlan_id']:
                        prv_base_ep = ep['br_name']
            if not prv_base_ep:
                nets_by_ifaces[netgroup['dev']].append({
                    'br_name': 'br-aux',
                    'vlan_id': None
                })

        attrs['transformations'] = cls.generate_transformations(
            node, nm, nets_by_ifaces, is_public, prv_base_ep)

        if NodeGroupCollection.get_by_cluster_id(node.cluster.id).count() > 1:
            cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups,
                                networks)

        attrs = cls.generate_driver_information(node, attrs, nm, networks)

        return attrs
Ejemplo n.º 12
0
    def generate_network_scheme(cls, node, networks):

        # Create a data structure and fill it with static values.

        attrs = {
            'version': '1.0',
            'provider': 'ovs',
            'interfaces': {},  # It's a list of physical interfaces.
            'endpoints': {
                'br-storage': {},
                'br-mgmt': {},
                'br-fw-admin': {},
            },
            'roles': {
                'management': 'br-mgmt',
                'storage': 'br-storage',
                'fw-admin': 'br-fw-admin',
            },
            'transformations': []
        }

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex'] = {}
            attrs['roles']['ex'] = 'br-ex'

        nm = Cluster.get_network_manager(node.cluster)
        iface_types = consts.NETWORK_INTERFACE_TYPES

        # Add a dynamic data to a structure.

        vlan_splinters_data = \
            node.cluster.attributes.editable\
            .get('vlan_splinters', {})\

        # if vlan_splinters is enabled - use its value
        use_vlan_splinters = 'disabled'
        if vlan_splinters_data\
                .get('metadata', {})\
                .get('enabled'):

            use_vlan_splinters = \
                vlan_splinters_data\
                .get('vswitch', {})\
                .get('value', 'disabled')

        # Fill up interfaces and add bridges for them.
        bonded_ifaces = [x for x in node.nic_interfaces if x.bond]
        for iface in node.interfaces:
            # Handle vlan splinters.
            if iface.type == iface_types.ether:
                attrs['interfaces'][iface.name] = {
                    'L2':
                    cls._get_vlan_splinters_desc(use_vlan_splinters, iface,
                                                 node.cluster)
                }

            if iface in bonded_ifaces:
                continue
            attrs['transformations'].append({
                'action': 'add-br',
                'name': 'br-%s' % iface.name
            })
            if iface.type == iface_types.ether:
                attrs['transformations'].append({
                    'action': 'add-port',
                    'bridge': 'br-%s' % iface.name,
                    'name': iface.name
                })
            elif iface.type == iface_types.bond:
                attrs['transformations'].append({
                    'action':
                    'add-bond',
                    'bridge':
                    'br-%s' % iface.name,
                    'name':
                    iface.name,
                    'interfaces': [x['name'] for x in iface.slaves],
                    'properties':
                    nm.get_ovs_bond_properties(iface)
                })

        # Add bridges for networks.
        # We have to add them after br-ethXX bridges because it is the way
        # to provide a right ordering of ifdown/ifup operations with
        # IP interfaces.
        brnames = ['br-ex', 'br-mgmt', 'br-storage', 'br-fw-admin']
        if not Node.should_have_public(node):
            brnames.pop(0)

        for brname in brnames:
            attrs['transformations'].append({
                'action': 'add-br',
                'name': brname
            })

        # Populate IP address information to endpoints.
        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if Node.should_have_public(node):
            netgroup_mapping.append(('public', 'br-ex'))

        netgroups = {}
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get('ip'):
                attrs['endpoints'][brname]['IP'] = [netgroup['ip']]
            netgroups[ngname] = netgroup

        if Node.should_have_public(node):
            attrs['endpoints']['br-ex']['gateway'] = \
                netgroups['public']['gateway']
        else:
            attrs['endpoints']['br-fw-admin']['gateway'] = settings.MASTER_IP

        # Connect interface bridges to network bridges.
        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_network_by_netname(ngname, networks)
            if not netgroup['vlan']:
                # Untagged network.
                attrs['transformations'].append({
                    'action':
                    'add-patch',
                    'bridges': ['br-%s' % netgroup['dev'], brname],
                    'trunks': [0]
                })
            elif netgroup['vlan'] > 1:
                # Tagged network.
                attrs['transformations'].append({
                    'action':
                    'add-patch',
                    'bridges': ['br-%s' % netgroup['dev'], brname],
                    'tags': [netgroup['vlan'], 0]
                })
            else:
                # FIXME! Should raise some exception I think.
                logger.error('Invalid vlan for network: %s' % str(netgroup))

        # Dance around Neutron segmentation type.
        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['endpoints']['br-prv'] = {'IP': 'none'}
            attrs['roles']['private'] = 'br-prv'

            attrs['transformations'].append({
                'action': 'add-br',
                'name': 'br-prv',
            })

            attrs['transformations'].append({
                'action':
                'add-patch',
                'bridges': [
                    'br-%s' %
                    nm.get_node_interface_by_netname(node.id, 'private').name,
                    'br-prv'
                ]
            })
        elif node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            attrs['roles']['mesh'] = 'br-mgmt'

        return attrs
Ejemplo n.º 13
0
    def generate_network_metadata(cls, cluster):
        nodes = dict()
        nm = Cluster.get_network_manager(cluster)

        for n in Cluster.get_nodes_not_for_deletion(cluster):
            name = Node.make_slave_name(n)
            node_roles = Node.all_roles(n)

            ip_by_net = {
                'fuelweb_admin': None,
                'storage': None,
                'management': None,
                'public': None
            }
            for net in ip_by_net:
                netgroup = nm.get_node_network_by_netname(n, net)
                if netgroup.get('ip'):
                    ip_by_net[net] = netgroup['ip'].split('/')[0]

            netw_roles = {
                'admin/pxe': ip_by_net['fuelweb_admin'],
                'fw-admin': ip_by_net['fuelweb_admin'],

                'keystone/api': ip_by_net['management'],
                'neutron/api': ip_by_net['management'],
                'swift/api': ip_by_net['management'],
                'sahara/api': ip_by_net['management'],
                'ceilometer/api': ip_by_net['management'],
                'cinder/api': ip_by_net['management'],
                'glance/api': ip_by_net['management'],
                'heat/api': ip_by_net['management'],
                'nova/api': ip_by_net['management'],
                'murano/api': ip_by_net['management'],
                'horizon': ip_by_net['management'],

                'management': ip_by_net['management'],
                'mgmt/api': ip_by_net['management'],
                'mgmt/database': ip_by_net['management'],
                'mgmt/messaging': ip_by_net['management'],
                'mgmt/corosync': ip_by_net['management'],
                'mgmt/memcache': ip_by_net['management'],
                'mgmt/vip': ip_by_net['management'],

                'mongo/db': ip_by_net['management'],

                'neutron/mesh': ip_by_net['management'],

                'ceph/public': ip_by_net['management'],

                'neutron/private': None,
                'neutron/floating': None,

                'storage': ip_by_net['storage'],
                'ceph/replication': ip_by_net['storage'],
                'swift/replication': ip_by_net['storage'],
                'cinder/iscsi': ip_by_net['storage'],

            }
            if Node.should_have_public(n):
                netw_roles.update({
                    'ex': ip_by_net['public'],
                    'public/vip': ip_by_net['public'],
                    'ceph/radosgw': ip_by_net['public'],
                })

            nodes[name] = {
                "uid": n.uid,
                "fqdn": n.fqdn,
                "name": name,
                "user_node_name": n.name,
                "swift_zone": n.uid,
                "node_roles": node_roles,
                "network_roles": netw_roles
            }

        return dict(
            nodes=nodes,
            vips=nm.assign_vips_for_net_groups(cluster)
        )
Ejemplo n.º 14
0
    def generate_network_scheme(cls, node, networks):
        """Create a data structure and fill it with static values.

        :param node: instance of db.sqlalchemy.models.node.Node
        :param networks: list of networks data dicts
        :return: dict of network scheme attributes
        """
        attrs = {
            "version": "1.1",
            "provider": "lnx",
            "interfaces": {},
            "endpoints": {},
            "roles": cls.get_network_role_mapping_to_interfaces(node),
        }

        is_public = Node.should_have_public(node)
        if is_public:
            attrs["endpoints"]["br-ex"] = {"IP": "none"}
            attrs["endpoints"]["br-floating"] = {"IP": "none"}
            attrs["roles"]["ex"] = "br-ex"
            attrs["roles"]["neutron/floating"] = "br-floating"

        nm = Cluster.get_network_manager(node.cluster)

        # Populate IP and GW information to endpoints.
        netgroup_mapping = cls.get_network_to_endpoint_mapping(node).items()
        # get_network_to_endpoint_mapping() adds mapping for 'public' only in
        # case the node 'should_have_public_with_ip'. Here we need to add it
        # because proper transformations should be formed no matter if br-ex
        # has IP or not.
        public_mapping = (consts.NETWORKS.public, "br-ex")
        if is_public and public_mapping not in netgroup_mapping:
            netgroup_mapping.append(public_mapping)

        if node.cluster.network_config.segmentation_type in (
            consts.NEUTRON_SEGMENT_TYPES.gre,
            consts.NEUTRON_SEGMENT_TYPES.tun,
        ):
            attrs["endpoints"]["br-mesh"] = {}
            attrs["roles"]["neutron/mesh"] = "br-mesh"

        netgroups = {}
        nets_by_ifaces = defaultdict(list)
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get("ip"):
                attrs["endpoints"][brname] = {"IP": [netgroup["ip"]]}
            netgroups[ngname] = netgroup
            nets_by_ifaces[netgroup["dev"]].append({"br_name": brname, "vlan_id": netgroup["vlan"]})

        # Add gateway.
        if Node.should_have_public_with_ip(node):
            attrs["endpoints"]["br-ex"]["gateway"] = netgroups["public"]["gateway"]
        else:
            gw = nm.get_default_gateway(node.id)
            attrs["endpoints"]["br-fw-admin"]["gateway"] = gw

        # Fill up interfaces.
        for iface in node.nic_interfaces:
            if iface.bond:
                attrs["interfaces"][iface.name] = {}
            else:
                attrs["interfaces"][iface.name] = nm.get_iface_properties(iface)

        # Dance around Neutron segmentation type.
        prv_base_ep = None
        if node.cluster.network_config.segmentation_type == consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs["endpoints"]["br-prv"] = {"IP": "none"}
            attrs["roles"]["neutron/private"] = "br-prv"

            netgroup = nm.get_network_by_netname("private", networks)
            # create br-aux if there is no untagged network (endpoint) on the
            # same interface.
            if netgroup["dev"] in nets_by_ifaces:
                for ep in nets_by_ifaces[netgroup["dev"]]:
                    if not ep["vlan_id"]:
                        prv_base_ep = ep["br_name"]
            if not prv_base_ep:
                nets_by_ifaces[netgroup["dev"]].append({"br_name": "br-aux", "vlan_id": None})

        attrs["transformations"] = cls.generate_transformations(node, nm, nets_by_ifaces, is_public, prv_base_ep)

        if NodeGroupCollection.get_by_cluster_id(node.cluster.id).count() > 1:
            cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups, networks)

        attrs = cls.generate_driver_information(node, attrs, nm, networks)

        if node.cluster.network_config.segmentation_type in (
            consts.NEUTRON_SEGMENT_TYPES.gre,
            consts.NEUTRON_SEGMENT_TYPES.tun,
        ):
            attrs["roles"].pop("neutron/private", None)

        if node.cluster.network_config.segmentation_type == consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs["roles"].pop("neutron/mesh", None)

        return attrs
Ejemplo n.º 15
0
    def generate_network_scheme(cls, node, networks):

        # Create a data structure and fill it with static values.
        attrs = {
            "version": "1.1",
            "provider": "lnx",
            "interfaces": {},  # It's a list of physical interfaces.
            "endpoints": {},
            "roles": {"management": "br-mgmt", "storage": "br-storage", "fw-admin": "br-fw-admin"},
        }

        is_public = Node.should_have_public(node)
        if is_public:
            attrs["endpoints"]["br-ex"] = {"IP": "none"}
            attrs["endpoints"]["br-floating"] = {"IP": "none"}
            attrs["roles"]["ex"] = "br-ex"
            attrs["roles"]["neutron/floating"] = "br-floating"

        nm = Cluster.get_network_manager(node.cluster)

        # Populate IP and GW information to endpoints.
        netgroup_mapping = [("storage", "br-storage"), ("management", "br-mgmt"), ("fuelweb_admin", "br-fw-admin")]
        if is_public:
            netgroup_mapping.append(("public", "br-ex"))

        if node.cluster.network_config.segmentation_type in (
            consts.NEUTRON_SEGMENT_TYPES.gre,
            consts.NEUTRON_SEGMENT_TYPES.tun,
        ):
            netgroup_mapping.append(("private", "br-mesh"))
            attrs["endpoints"]["br-mesh"] = {}
            attrs["roles"]["neutron/mesh"] = "br-mesh"

        netgroups = {}
        nets_by_ifaces = defaultdict(list)
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get("ip"):
                attrs["endpoints"][brname] = {"IP": [netgroup["ip"]]}
            netgroups[ngname] = netgroup
            nets_by_ifaces[netgroup["dev"]].append({"br_name": brname, "vlan_id": netgroup["vlan"]})

        # Add gateway.
        if is_public and netgroups["public"].get("gateway"):
            attrs["endpoints"]["br-ex"]["gateway"] = netgroups["public"]["gateway"]
        else:
            gw = nm.get_default_gateway(node.id)
            attrs["endpoints"]["br-fw-admin"]["gateway"] = gw

        # Fill up interfaces.
        for iface in node.nic_interfaces:
            if iface.bond:
                attrs["interfaces"][iface.name] = {}
            else:
                attrs["interfaces"][iface.name] = nm.get_iface_properties(iface)

        # Dance around Neutron segmentation type.
        prv_base_ep = None
        if node.cluster.network_config.segmentation_type == consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs["endpoints"]["br-prv"] = {"IP": "none"}
            attrs["roles"]["neutron/private"] = "br-prv"

            netgroup = nm.get_network_by_netname("private", networks)
            # create br-aux if there is no untagged network (endpoint) on the
            # same interface.
            if netgroup["dev"] in nets_by_ifaces:
                for ep in nets_by_ifaces[netgroup["dev"]]:
                    if not ep["vlan_id"]:
                        prv_base_ep = ep["br_name"]
            if not prv_base_ep:
                nets_by_ifaces[netgroup["dev"]].append({"br_name": "br-aux", "vlan_id": None})

        attrs["transformations"] = cls.generate_transformations(node, nm, nets_by_ifaces, is_public, prv_base_ep)

        if NodeGroupCollection.get_by_cluster_id(node.cluster.id).count() > 1:
            cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups, networks)

        attrs = cls.generate_driver_information(node, attrs, nm, networks)

        return attrs
    def generate_network_scheme(cls, node, networks):
        """Create a data structure and fill it with static values.

        :param node: instance of db.sqlalchemy.models.node.Node
        :param networks: list of networks data dicts
        :return: dict of network scheme attributes
        """
        attrs = {
            'version': '1.1',
            'provider': 'lnx',
            'interfaces': {},
            'endpoints': {},
            'roles': cls.get_network_role_mapping_to_interfaces(node),
        }

        is_public = Node.should_have_public(node)
        if is_public:
            attrs['endpoints']['br-ex'] = {'IP': 'none'}
            attrs['endpoints']['br-floating'] = {'IP': 'none'}
            attrs['roles']['ex'] = 'br-ex'
            attrs['roles']['neutron/floating'] = 'br-floating'

        nm = Cluster.get_network_manager(node.cluster)

        # Populate IP and GW information to endpoints.
        netgroup_mapping = (cls.get_network_to_endpoint_mapping(node)
                            .items())
        # get_network_to_endpoint_mapping() adds mapping for 'public' only in
        # case the node 'should_have_public_with_ip'. Here we need to add it
        # because proper transformations should be formed no matter if br-ex
        # has IP or not.
        public_mapping = (consts.NETWORKS.public, 'br-ex')
        if is_public and public_mapping not in netgroup_mapping:
            netgroup_mapping.append(public_mapping)

        if node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            attrs['endpoints']['br-mesh'] = {}
            attrs['roles']['neutron/mesh'] = 'br-mesh'

        netgroups = {}
        nets_by_ifaces = defaultdict(list)
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get('ip'):
                attrs['endpoints'][brname] = {'IP': [netgroup['ip']]}
            netgroups[ngname] = netgroup
            nets_by_ifaces[netgroup['dev']].append({
                'br_name': brname,
                'vlan_id': netgroup['vlan']
            })

        # Add gateway.
        if Node.should_have_public_with_ip(node):
            attrs['endpoints']['br-ex']['gateway'] = \
                netgroups['public']['gateway']
        else:
            gw = nm.get_default_gateway(node.id)
            attrs['endpoints']['br-fw-admin']['gateway'] = gw

        # Fill up interfaces.
        for iface in node.nic_interfaces:
            if iface.bond:
                attrs['interfaces'][iface.name] = {}
            else:
                attrs['interfaces'][iface.name] = \
                    nm.get_iface_properties(iface)

        # Dance around Neutron segmentation type.
        prv_base_ep = None
        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['endpoints']['br-prv'] = {'IP': 'none'}
            attrs['roles']['neutron/private'] = 'br-prv'

            netgroup = nm.get_network_by_netname('private', networks)
            # create br-aux if there is no untagged network (endpoint) on the
            # same interface.
            if netgroup['dev'] in nets_by_ifaces:
                for ep in nets_by_ifaces[netgroup['dev']]:
                    if not ep['vlan_id']:
                        prv_base_ep = ep['br_name']
            if not prv_base_ep:
                nets_by_ifaces[netgroup['dev']].append({
                    'br_name': 'br-aux',
                    'vlan_id': None
                })

        attrs['transformations'] = cls.generate_transformations(
            node, nm, nets_by_ifaces, is_public, prv_base_ep)

        if NodeGroupCollection.get_by_cluster_id(
                node.cluster.id).count() > 1:
            cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups,
                                networks)

        attrs = cls.generate_driver_information(node, attrs, nm, networks)

        if node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            attrs['roles'].pop('neutron/private', None)

        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['roles'].pop('neutron/mesh', None)

        return attrs
Ejemplo n.º 17
0
    def generate_network_scheme(cls, node):

        # Create a data structure and fill it with static values.
        attrs = {
            'version': '1.1',
            'provider': 'lnx',
            'interfaces': {},  # It's a list of physical interfaces.
            'endpoints': {},
            'roles': {
                'management': 'br-mgmt',
                'storage': 'br-storage',
                'fw-admin': 'br-fw-admin',
            },
        }

        is_public = Node.should_have_public(node)
        if is_public:
            attrs['endpoints']['br-ex'] = {'IP': 'none'}
            attrs['endpoints']['br-floating'] = {'IP': 'none'}
            attrs['roles']['ex'] = 'br-ex'
            attrs['roles']['neutron/floating'] = 'br-floating'

        nm = Cluster.get_network_manager(node.cluster)

        # Populate IP and GW information to endpoints.
        netgroup_mapping = [
            ('storage', 'br-storage'),
            ('management', 'br-mgmt'),
            ('fuelweb_admin', 'br-fw-admin'),
        ]
        if is_public:
            netgroup_mapping.append(('public', 'br-ex'))

        if node.cluster.network_config.segmentation_type in \
                (consts.NEUTRON_SEGMENT_TYPES.gre,
                 consts.NEUTRON_SEGMENT_TYPES.tun):
            netgroup_mapping.append(('private', 'br-mesh'))
            attrs['endpoints']['br-mesh'] = {}
            attrs['roles']['neutron/mesh'] = 'br-mesh'

        netgroups = {}
        nets_by_ifaces = defaultdict(list)
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_node_network_by_netname(node, ngname)
            if netgroup.get('ip'):
                attrs['endpoints'][brname] = {'IP': [netgroup['ip']]}
            netgroups[ngname] = netgroup
            nets_by_ifaces[netgroup['dev']].append({
                'br_name': brname,
                'vlan_id': netgroup['vlan']
            })

        # Add gateway.
        if is_public and netgroups['public'].get('gateway'):
            attrs['endpoints']['br-ex']['gateway'] = \
                netgroups['public']['gateway']
        else:
            gw = nm.get_default_gateway(node.id)
            attrs['endpoints']['br-fw-admin']['gateway'] = gw

        # Fill up interfaces.
        for iface in node.nic_interfaces:
            if iface.bond:
                attrs['interfaces'][iface.name] = {}
            else:
                attrs['interfaces'][iface.name] = \
                    nm.get_iface_properties(iface)

        # Dance around Neutron segmentation type.
        prv_base_ep = None
        if node.cluster.network_config.segmentation_type == \
                consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs['endpoints']['br-prv'] = {'IP': 'none'}
            attrs['roles']['neutron/private'] = 'br-prv'

            netgroup = nm.get_node_network_by_netname(node, 'private')
            # create br-aux if there is no untagged network (endpoint) on the
            # same interface.
            if netgroup['dev'] in nets_by_ifaces:
                for ep in nets_by_ifaces[netgroup['dev']]:
                    if not ep['vlan_id']:
                        prv_base_ep = ep['br_name']
            if not prv_base_ep:
                nets_by_ifaces[netgroup['dev']].append({
                    'br_name': 'br-aux',
                    'vlan_id': None
                })

        attrs['transformations'] = cls.generate_transformations(
            node, nm, nets_by_ifaces, is_public, prv_base_ep)

        if NodeGroupCollection.get_by_cluster_id(
                node.cluster.id).count() > 1:
            cls.generate_routes(node, attrs, nm, netgroup_mapping, netgroups)

        attrs = cls.generate_driver_information(node, attrs, nm)

        return attrs
Ejemplo n.º 18
0
    def generate_network_scheme(cls, node, networks):

        # Create a data structure and fill it with static values.

        attrs = {
            "version": "1.0",
            "provider": "ovs",
            "interfaces": {},  # It's a list of physical interfaces.
            "endpoints": {"br-storage": {}, "br-mgmt": {}, "br-fw-admin": {}},
            "roles": {"management": "br-mgmt", "storage": "br-storage", "fw-admin": "br-fw-admin"},
            "transformations": [],
        }

        if Node.should_have_public(node):
            attrs["endpoints"]["br-ex"] = {}
            attrs["roles"]["ex"] = "br-ex"

        nm = Cluster.get_network_manager(node.cluster)
        iface_types = consts.NETWORK_INTERFACE_TYPES

        # Add a dynamic data to a structure.

        vlan_splinters_data = node.cluster.attributes.editable.get("vlan_splinters", {})
        # if vlan_splinters is enabled - use its value
        use_vlan_splinters = "disabled"
        if vlan_splinters_data.get("metadata", {}).get("enabled"):

            use_vlan_splinters = vlan_splinters_data.get("vswitch", {}).get("value", "disabled")

        # Fill up interfaces and add bridges for them.
        bonded_ifaces = [x for x in node.nic_interfaces if x.bond]
        for iface in node.interfaces:
            # Handle vlan splinters.
            if iface.type == iface_types.ether:
                attrs["interfaces"][iface.name] = {
                    "L2": cls._get_vlan_splinters_desc(use_vlan_splinters, iface, node.cluster)
                }

            if iface in bonded_ifaces:
                continue
            attrs["transformations"].append({"action": "add-br", "name": "br-%s" % iface.name})
            if iface.type == iface_types.ether:
                attrs["transformations"].append(
                    {"action": "add-port", "bridge": "br-%s" % iface.name, "name": iface.name}
                )
            elif iface.type == iface_types.bond:
                attrs["transformations"].append(
                    {
                        "action": "add-bond",
                        "bridge": "br-%s" % iface.name,
                        "name": iface.name,
                        "interfaces": [x["name"] for x in iface.slaves],
                        "properties": nm.get_ovs_bond_properties(iface),
                    }
                )

        # Add bridges for networks.
        # We have to add them after br-ethXX bridges because it is the way
        # to provide a right ordering of ifdown/ifup operations with
        # IP interfaces.
        brnames = ["br-ex", "br-mgmt", "br-storage", "br-fw-admin"]
        if not Node.should_have_public(node):
            brnames.pop(0)

        for brname in brnames:
            attrs["transformations"].append({"action": "add-br", "name": brname})

        # Populate IP address information to endpoints.
        netgroup_mapping = [("storage", "br-storage"), ("management", "br-mgmt"), ("fuelweb_admin", "br-fw-admin")]
        if Node.should_have_public(node):
            netgroup_mapping.append(("public", "br-ex"))

        netgroups = {}
        for ngname, brname in netgroup_mapping:
            # Here we get a dict with network description for this particular
            # node with its assigned IPs and device names for each network.
            netgroup = nm.get_network_by_netname(ngname, networks)
            if netgroup.get("ip"):
                attrs["endpoints"][brname]["IP"] = [netgroup["ip"]]
            netgroups[ngname] = netgroup

        if Node.should_have_public(node):
            attrs["endpoints"]["br-ex"]["gateway"] = netgroups["public"]["gateway"]
        else:
            attrs["endpoints"]["br-fw-admin"]["gateway"] = settings.MASTER_IP

        # Connect interface bridges to network bridges.
        for ngname, brname in netgroup_mapping:
            netgroup = nm.get_network_by_netname(ngname, networks)
            if not netgroup["vlan"]:
                # Untagged network.
                attrs["transformations"].append(
                    {"action": "add-patch", "bridges": ["br-%s" % netgroup["dev"], brname], "trunks": [0]}
                )
            elif netgroup["vlan"] > 1:
                # Tagged network.
                attrs["transformations"].append(
                    {
                        "action": "add-patch",
                        "bridges": ["br-%s" % netgroup["dev"], brname],
                        "tags": [netgroup["vlan"], 0],
                    }
                )
            else:
                # FIXME! Should raise some exception I think.
                logger.error("Invalid vlan for network: %s" % str(netgroup))

        # Dance around Neutron segmentation type.
        if node.cluster.network_config.segmentation_type == consts.NEUTRON_SEGMENT_TYPES.vlan:
            attrs["endpoints"]["br-prv"] = {"IP": "none"}
            attrs["roles"]["private"] = "br-prv"

            attrs["transformations"].append({"action": "add-br", "name": "br-prv"})

            attrs["transformations"].append(
                {
                    "action": "add-patch",
                    "bridges": ["br-%s" % nm.get_node_interface_by_netname(node.id, "private").name, "br-prv"],
                }
            )
        elif node.cluster.network_config.segmentation_type in (
            consts.NEUTRON_SEGMENT_TYPES.gre,
            consts.NEUTRON_SEGMENT_TYPES.tun,
        ):
            attrs["roles"]["mesh"] = "br-mgmt"

        return attrs