Esempio n. 1
0
def convert_ipv6_format_if_needed(ip_addr):
    """Convert IPv6 address format if needed. The IPv6 address enclosed by [].

    For the invalid IPv6 cidr, its format will not be changed.

    :param ip_addr: IPv6 address.
    :return: Converted IPv6 address.
    """
    if netutils.is_valid_ipv6_cidr(ip_addr):
        ip_addr = '[%s]' % ip_addr
    return ip_addr
Esempio n. 2
0
def convert_ipv6_format_if_needed(ip_addr):
    """Convert IPv6 address format if needed. The IPv6 address enclosed by [].

    For the invalid IPv6 cidr, its format will not be changed.

    :param ip_addr: IPv6 address.
    :return: Converted IPv6 address.
    """
    if netutils.is_valid_ipv6_cidr(ip_addr):
        ip_addr = '[%s]' % ip_addr
    return ip_addr
Esempio n. 3
0
    def _create_network_interface(self, nas_server, network, port_id):
        kargs = {'ip_addr': network['ip_address'],
                 'gateway': network['gateway'],
                 'vlan_id': network['segmentation_id'],
                 'port_id': port_id}

        if netutils.is_valid_ipv6_cidr(kargs['ip_addr']):
            kargs['netmask'] = None
            kargs['prefix_length'] = str(utils.cidr_to_prefixlen(
                network['cidr']))
        else:
            kargs['netmask'] = utils.cidr_to_netmask(network['cidr'])

        # Create the interfaces on NAS server
        self.client.create_interface(nas_server, **kargs)
Esempio n. 4
0
    def _create_network_interface(self, nas_server, network, port_id):
        kargs = {'ip_addr': network['ip_address'],
                 'gateway': network['gateway'],
                 'vlan_id': network['segmentation_id'],
                 'port_id': port_id}

        if netutils.is_valid_ipv6_cidr(kargs['ip_addr']):
            kargs['netmask'] = None
            kargs['prefix_length'] = str(utils.cidr_to_prefixlen(
                network['cidr']))
        else:
            kargs['netmask'] = utils.cidr_to_netmask(network['cidr'])

        # Create the interfaces on NAS server
        self.client.create_interface(nas_server, **kargs)
Esempio n. 5
0
 def test_is_valid_ipv6_cidr(self):
     self.assertTrue(netutils.is_valid_ipv6_cidr("2600::/64"))
     self.assertTrue(netutils.is_valid_ipv6_cidr(
         "abcd:ef01:2345:6789:abcd:ef01:192.168.254.254/48"))
     self.assertTrue(netutils.is_valid_ipv6_cidr(
         "0000:0000:0000:0000:0000:0000:0000:0001/32"))
     self.assertTrue(netutils.is_valid_ipv6_cidr(
         "0000:0000:0000:0000:0000:0000:0000:0001"))
     self.assertFalse(netutils.is_valid_ipv6_cidr("foo"))
     self.assertFalse(netutils.is_valid_ipv6_cidr("127.0.0.1"))
Esempio n. 6
0
 def process_bind_param(self, value, dialect):
     """Process/Formats the value before insert it into the db."""
     # NOTE(sdague): normalize all the inserts
     if netutils.is_valid_ipv6_cidr(value):
         return utils.get_shortened_ipv6_cidr(value)
     return value
Esempio n. 7
0
 def process_bind_param(self, value, dialect):
     """Process/Formats the value before insert it into the db."""
     # NOTE(sdague): normalize all the inserts
     if netutils.is_valid_ipv6_cidr(value):
         return utils.get_shortened_ipv6_cidr(value)
     return value