def generate_networks_for_template(self, template, ip_nets,
                                       ip_prefixlen):
        """Slice network to subnets for template.

        Generate networks from network template and ip_nets descriptions
        for node groups and value to slice that descriptions. ip_nets is a
        dict with key named as nodegroup and strings values for with
        description of network for that nodegroup in format '127.0.0.1/24'
        to be sliced in pieces for networks. ip_prefixlen - the amount the
        network prefix length should be sliced by. 24 will create networks
        '127.0.0.1/24' from network '127.0.0.1/16'.

        :param template: Yaml template with network assignments on interfaces.
        :param ip_nets: Dict with network descriptions.
        :param ip_prefixlen: Integer for slicing network prefix.
        :return: Data to be used to assign networks to nodes.
        """
        networks_data = []
        nodegroups = self.fuel_web.client.get_nodegroups()
        for nodegroup, section in template['adv_net_template'].items():
            networks = [(n, section['network_assignments'][n]['ep'])
                        for n in section['network_assignments']]
            assert_true(any(n['name'] == nodegroup for n in nodegroups),
                        'Network templates contains settings for Node Group '
                        '"{0}", which does not exist!'.format(nodegroup))
            group_id = [n['id'] for n in nodegroups if
                        n['name'] == nodegroup][0]
            ip_network = IPNetwork(ip_nets[nodegroup])
            ip_subnets = ip_network.subnet(
                int(ip_prefixlen) - int(ip_network.prefixlen))
            for network, interface in networks:
                ip_subnet = ip_subnets.pop()
                networks_data.append(
                    {
                        'name': network,
                        'cidr': str(ip_subnet),
                        'group_id': group_id,
                        'interface': interface,
                        'gateway': None,
                        'meta': {
                            "notation": "ip_ranges",
                            "render_type": None,
                            "map_priority": 0,
                            "configurable": True,
                            "unmovable": False,
                            "use_gateway": False,
                            "render_addr_mask": None,
                            'ip_range': [str(ip_subnet[1]), str(ip_subnet[-2])]
                        }
                    }
                )
        return networks_data
Пример #2
0
    def generate_networks_for_template(self, template, ip_nets, ip_prefixlen):
        """Slice network to subnets for template.

        Generate networks from network template and ip_nets descriptions
        for node groups and value to slice that descriptions. ip_nets is a
        dict with key named as nodegroup and strings values for with
        description of network for that nodegroup in format '127.0.0.1/24'
        to be sliced in pieces for networks. ip_prefixlen - the amount the
        network prefix length should be sliced by. 24 will create networks
        '127.0.0.1/24' from network '127.0.0.1/16'.

        :param template: Yaml template with network assignments on interfaces.
        :param ip_nets: Dict with network descriptions.
        :param ip_prefixlen: Integer for slicing network prefix.
        :return: Data to be used to assign networks to nodes.
        """
        networks_data = []
        nodegroups = self.fuel_web.client.get_nodegroups()
        for nodegroup, section in template['adv_net_template'].items():
            networks = [(n, section['network_assignments'][n]['ep'])
                        for n in section['network_assignments']]
            assert_true(
                any(n['name'] == nodegroup for n in nodegroups),
                'Network templates contains settings for Node Group '
                '"{0}", which does not exist!'.format(nodegroup))
            group_id = [n['id'] for n in nodegroups
                        if n['name'] == nodegroup][0]
            ip_network = IPNetwork(ip_nets[nodegroup])
            ip_subnets = ip_network.subnet(
                int(ip_prefixlen) - int(ip_network.prefixlen))
            for network, interface in networks:
                ip_subnet = ip_subnets.pop()
                networks_data.append({
                    'name': network,
                    'cidr': str(ip_subnet),
                    'group_id': group_id,
                    'interface': interface,
                    'gateway': None,
                    'meta': {
                        "notation": "ip_ranges",
                        "render_type": None,
                        "map_priority": 0,
                        "configurable": True,
                        "unmovable": False,
                        "use_gateway": False,
                        "render_addr_mask": None,
                        'ip_range': [str(ip_subnet[1]),
                                     str(ip_subnet[-2])]
                    }
                })
        return networks_data
Пример #3
0
def calcSubnet(cidr, positional=1):
  net = IPNetwork(args.CIDR)
  try:
    subnet = list(net.subnet(positional))
  except ValueError:
    finalcidr = int(cidr.split('/')[1]) + positional
    print "[%s] is out of range with [%s] positions away (A /%s, seriously?). Cannot calculate." % (cidr, positional, finalcidr)
    raise SystemExit

  newcidr = subnet[0].prefixlen
  count = len(subnet)

  print "[%s] hosts with [/%s] (diff of %s)" % (count, newcidr, positional)
  for i in subnet:
    print "--%s" % i
Пример #4
0
 def generate_networks_for_template(self, template, ip_network,
                                    ip_prefixlen):
     networks_data = []
     nodegroups = self.fuel_web.client.get_nodegroups()
     for nodegroup, section in template['adv_net_template'].items():
         networks = [(n, section['network_assignments'][n]['ep'])
                     for n in section['network_assignments']]
         assert_true(
             any(n['name'] == nodegroup for n in nodegroups),
             'Network templates contains settings for Node Group '
             '"{0}", which does not exist!'.format(nodegroup))
         group_id = [n['id'] for n in nodegroups
                     if n['name'] == nodegroup][0]
         ip_network = IPNetwork(ip_network)
         ip_subnets = ip_network.subnet(
             int(ip_prefixlen) - int(ip_network.prefixlen))
         for network, interface in networks:
             ip_subnet = ip_subnets.pop()
             networks_data.append({
                 'name': network,
                 'cidr': str(ip_subnet),
                 'group_id': group_id,
                 'interface': interface,
                 'gateway': None,
                 'meta': {
                     "notation": "ip_ranges",
                     "render_type": None,
                     "map_priority": 0,
                     "configurable": True,
                     "unmovable": False,
                     "use_gateway": False,
                     "render_addr_mask": None,
                     'ip_range': [str(ip_subnet[1]),
                                  str(ip_subnet[-2])]
                 }
             })
     return networks_data
Пример #5
0
 def generate_networks_for_template(self, template, ip_network,
                                    ip_prefixlen):
     networks_data = []
     nodegroups = self.fuel_web.client.get_nodegroups()
     for nodegroup, section in template['adv_net_template'].items():
         networks = [(n, section['network_assignments'][n]['ep'])
                     for n in section['network_assignments']]
         assert_true(any(n['name'] == nodegroup for n in nodegroups),
                     'Network templates contains settings for Node Group '
                     '"{0}", which does not exist!'.format(nodegroup))
         group_id = [n['id'] for n in nodegroups if
                     n['name'] == nodegroup][0]
         ip_network = IPNetwork(ip_network)
         ip_subnets = ip_network.subnet(
             int(ip_prefixlen) - int(ip_network.prefixlen))
         for network, interface in networks:
             ip_subnet = ip_subnets.pop()
             networks_data.append(
                 {
                     'name': network,
                     'cidr': str(ip_subnet),
                     'group_id': group_id,
                     'interface': interface,
                     'gateway': None,
                     'meta': {
                         "notation": "ip_ranges",
                         "render_type": None,
                         "map_priority": 0,
                         "configurable": True,
                         "unmovable": False,
                         "use_gateway": False,
                         "render_addr_mask": None,
                         'ip_range': [str(ip_subnet[1]), str(ip_subnet[-2])]
                     }
                 }
             )
     return networks_data