def get_first_valid_cidr(value_specs):
    # Bug 1442771, argparse does not allow optional positional parameter
    # to be separated from previous positional parameter.
    # When cidr was separated from network, the value will not be able
    # to be parsed into known_args, but saved to _values_specs instead.
    for value in value_specs:
        if netutils.is_valid_cidr(value):
            return value
Beispiel #2
0
def get_first_valid_cidr(value_specs):
    # Bug 1442771, argparse does not allow optional positional parameter
    # to be separated from previous positional parameter.
    # When cidr was separated from network, the value will not be able
    # to be parsed into known_args, but saved to _values_specs instead.
    for value in value_specs:
        if netutils.is_valid_cidr(value):
            return value
Beispiel #3
0
    def test_is_valid_cidr(self):
        self.assertTrue(netutils.is_valid_cidr('10.0.0.0/24'))
        self.assertTrue(netutils.is_valid_cidr('10.0.0.1/32'))
        self.assertTrue(netutils.is_valid_cidr('0.0.0.0/0'))
        self.assertTrue(netutils.is_valid_cidr('2600::/64'))
        self.assertTrue(netutils.is_valid_cidr(
                        '0000:0000:0000:0000:0000:0000:0000:0001/32'))

        self.assertFalse(netutils.is_valid_cidr('10.0.0.1'))
        self.assertFalse(netutils.is_valid_cidr('10.0.0.1/33'))
        self.assertFalse(netutils.is_valid_cidr(10))
Beispiel #4
0
    def test_is_valid_cidr(self):
        self.assertTrue(netutils.is_valid_cidr('10.0.0.0/24'))
        self.assertTrue(netutils.is_valid_cidr('10.0.0.1/32'))
        self.assertTrue(netutils.is_valid_cidr('0.0.0.0/0'))
        self.assertTrue(netutils.is_valid_cidr('2600::/64'))
        self.assertTrue(netutils.is_valid_cidr(
                        '0000:0000:0000:0000:0000:0000:0000:0001/32'))

        self.assertFalse(netutils.is_valid_cidr('10.0.0.1'))
        self.assertFalse(netutils.is_valid_cidr('10.0.0.1/33'))
        self.assertFalse(netutils.is_valid_cidr(10))
Beispiel #5
0
def parse_cidr(cidr):
    if not cidr:
        return '0.0.0.0/0'

    try:
        cidr = encodeutils.safe_decode(urllib.parse.unquote(cidr))
    except Exception:
        raise exception.InvalidCidr(cidr=cidr)

    if not netutils.is_valid_cidr(cidr):
        raise exception.InvalidCidr(cidr=cidr)

    return cidr
    def parse_cidr(self, cidr):
        if cidr:
            try:
                cidr = encodeutils.safe_decode(urllib.parse.unquote(cidr))
            except Exception as e:
                self.raise_invalid_cidr(cidr, e)

            if not utils.is_valid_cidr(cidr):
                self.raise_invalid_cidr(cidr)

            return cidr
        else:
            return '0.0.0.0/0'
    def args2body(self, parsed_args):
        body = super(CreatePort, self).args2body(parsed_args)
        neutron_client = self.get_client()

        if netutils.is_valid_cidr(parsed_args.nuage_floatingip):
            handle_fip_ips(neutron_client, parsed_args)
        if parsed_args.nuage_policy_groups:
            handle_pg_names(neutron_client, parsed_args,
                            during_create=True)

        port = body['port']
        _args2body(port, parsed_args)
        return body
Beispiel #8
0
    def parse_cidr(self, cidr):
        if cidr:
            try:
                cidr = encodeutils.safe_decode(urllib.parse.unquote(cidr))
            except Exception as e:
                self.raise_invalid_cidr(cidr, e)

            if not utils.is_valid_cidr(cidr):
                self.raise_invalid_cidr(cidr)

            return cidr
        else:
            return '0.0.0.0/0'
    def args2body(self, parsed_args):
        body = super(UpdatePort, self).args2body(parsed_args)
        neutron_client = self.get_client()
        parsed_args.id = neutronV20.find_resourceid_by_name_or_id(
            neutron_client, self.resource, parsed_args.id)

        if netutils.is_valid_cidr(parsed_args.nuage_floatingip):
            handle_fip_ips(neutron_client, parsed_args)
        if parsed_args.nuage_policy_groups:
            handle_pg_names(neutron_client, parsed_args)

        port = body['port']
        _args2body(port, parsed_args)
        if parsed_args.no_nuage_floatingip:
            port['nuage_floatingip'] = None
        if parsed_args.no_nuage_policy_groups:
            port['nuage_policy_groups'] = []
        if parsed_args.no_nuage_redirect_targets:
            port['nuage_redirect_targets'] = []
        return body
 def test_is_cidr(self):
     self.assertTrue(netutils.is_valid_cidr('10.10.10.0/24'))
     self.assertFalse(netutils.is_valid_cidr('10.10.10..0/24'))
     self.assertFalse(netutils.is_valid_cidr('wrong_cidr_format'))
Beispiel #11
0
 def test_is_cidr(self):
     self.assertTrue(netutils.is_valid_cidr('10.10.10.0/24'))
     self.assertFalse(netutils.is_valid_cidr('10.10.10..0/24'))
     self.assertFalse(netutils.is_valid_cidr('wrong_cidr_format'))
Beispiel #12
0
from oslo_utils import netutils

print(netutils.escape_ipv6('fe80::f493:20ff:fe5b:6cf'))

print(
    netutils.get_ipv6_addr_by_EUI64('fe80::d480:b0ff:fe33:1543/64',
                                    'f2:2c:d8:c3:73:fb'))

print(netutils.get_my_ipv4())

print(netutils.is_ipv6_enabled())

print(netutils.is_valid_cidr('10.10.10.10/24'))

code_list = []
for n in range(-5, 5):
    code_list.append(netutils.is_valid_icmp_code(n))
print(code_list)

print(
    netutils.urlsplit(
        'https://foxfox.mybluemix.net.com:8443/index.html?auto=off'))
# SplitResult(scheme='https', netloc='foxfox.mybluemix.net.com:8443', path='/index.html', query='auto=off', fragment='')