コード例 #1
0
ファイル: subnet.py プロジェクト: ISCAS-VDI/neutron-base
class Route(base.NeutronDbObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    db_model = models_v2.SubnetRoute

    primary_keys = ['destination', 'nexthop', 'subnet_id']

    foreign_keys = {'subnet_id': 'id'}

    fields = {
        'subnet_id': obj_fields.UUIDField(),
        'destination': obj_fields.IPNetworkField(),
        'nexthop': obj_fields.IPAddressField()
    }

    @classmethod
    def modify_fields_from_db(cls, db_obj):
        # TODO(korzen) remove this method when IP and CIDR decorator ready
        result = super(Route, cls).modify_fields_from_db(db_obj)
        if 'destination' in result:
            result['destination'] = netaddr.IPNetwork(result['destination'])
        if 'nexthop' in result:
            result['nexthop'] = netaddr.IPAddress(result['nexthop'])
        return result

    @classmethod
    def modify_fields_to_db(cls, fields):
        # TODO(korzen) remove this method when IP and CIDR decorator ready
        result = super(Route, cls).modify_fields_to_db(fields)
        if 'destination' in result:
            result['destination'] = str(result['destination'])
        if 'nexthop' in fields:
            result['nexthop'] = str(result['nexthop'])
        return result
コード例 #2
0
ファイル: subnetpool.py プロジェクト: xiaozhuangqing/neutron
class SubnetPoolPrefix(base.NeutronDbObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    db_model = models.SubnetPoolPrefix

    fields = {
        'subnetpool_id': obj_fields.UUIDField(),
        'cidr': obj_fields.IPNetworkField(),
    }

    primary_keys = ['subnetpool_id', 'cidr']

    # TODO(ihrachys): get rid of it once we switch the db model to using CIDR
    # custom type
    @classmethod
    def modify_fields_to_db(cls, fields):
        result = super(SubnetPoolPrefix, cls).modify_fields_to_db(fields)
        if 'cidr' in result:
            result['cidr'] = str(result['cidr'])
        return result

    # TODO(ihrachys): get rid of it once we switch the db model to using CIDR
    # custom type
    @classmethod
    def modify_fields_from_db(cls, db_obj):
        fields = super(SubnetPoolPrefix, cls).modify_fields_from_db(db_obj)
        if 'cidr' in fields:
            fields['cidr'] = netaddr.IPNetwork(fields['cidr'])
        return fields
コード例 #3
0
 def setUp(self):
     super(TestIPNetwork, self).setUp()
     self.field = fields.IPNetworkField()
     self.coerce_good_values = [
         ('::1/0', netaddr.IPNetwork('::1/0')),
         ('1.2.3.4/24', netaddr.IPNetwork('1.2.3.4/24')),
         (netaddr.IPNetwork('::1/32'), netaddr.IPNetwork('::1/32'))
     ]
     self.coerce_bad_values = ['foo']
     self.to_primitive_values = [(netaddr.IPNetwork('::1/0'), '::1/0')]
     self.from_primitive_values = [('::1/0', netaddr.IPNetwork('::1/0'))]
コード例 #4
0
ファイル: route.py プロジェクト: juju812/openstack_kolla
class Route(osv_base.VersionedObject):
    """Represents a route."""
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'cidr': fields.IPNetworkField(),
        'gateway': fields.IPAddressField(),
        # TODO(mriedem): This field is never set by Nova, remove it in v2.0
        # of this object.
        'interface': fields.StringField(),
    }
コード例 #5
0
class Subnet(osv_base.VersionedObject):
    """Represents a subnet."""
    # Version 1.0: Initial version
    VERSION = '1.0'

    fields = {
        'cidr': fields.IPNetworkField(),
        'dns': osv_fields.ListOfIPAddressField(),
        'gateway': fields.IPAddressField(),
        'ips': fields.ObjectField("FixedIPList"),
        'routes': fields.ObjectField("RouteList"),
        'dhcp_server': fields.IPAddressField(),
    }
コード例 #6
0
class SecurityGroupRule(base.NeutronDbObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    db_model = sg_models.SecurityGroupRule

    fields = {
        'id': obj_fields.UUIDField(),
        'project_id': obj_fields.StringField(nullable=True),
        'security_group_id': obj_fields.UUIDField(),
        'remote_group_id': obj_fields.UUIDField(nullable=True),
        'direction': common_types.FlowDirectionEnumField(nullable=True),
        'ethertype': common_types.EtherTypeEnumField(nullable=True),
        'protocol': common_types.IpProtocolEnumField(nullable=True),
        'port_range_min': common_types.PortRangeField(nullable=True),
        'port_range_max': common_types.PortRangeField(nullable=True),
        'remote_ip_prefix': obj_fields.IPNetworkField(nullable=True),
    }

    foreign_keys = {'SecurityGroup': {'security_group_id': 'id'}}

    fields_no_update = ['project_id', 'security_group_id']

    # TODO(sayalilunkad): get rid of it once we switch the db model to using
    # custom types.
    @classmethod
    def modify_fields_to_db(cls, fields):
        result = super(SecurityGroupRule, cls).modify_fields_to_db(fields)
        remote_ip_prefix = result.get('remote_ip_prefix')
        if remote_ip_prefix:
            result['remote_ip_prefix'] = cls.filter_to_str(remote_ip_prefix)
        return result

    # TODO(sayalilunkad): get rid of it once we switch the db model to using
    # custom types.
    @classmethod
    def modify_fields_from_db(cls, db_obj):
        fields = super(SecurityGroupRule, cls).modify_fields_from_db(db_obj)
        if 'remote_ip_prefix' in fields:
            fields['remote_ip_prefix'] = (utils.AuthenticIPNetwork(
                fields['remote_ip_prefix']))
        return fields
コード例 #7
0
ファイル: subnet.py プロジェクト: ISCAS-VDI/neutron-base
class Subnet(base.NeutronDbObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    db_model = models_v2.Subnet

    fields = {
        'id':
        obj_fields.UUIDField(),
        'project_id':
        obj_fields.UUIDField(),
        'name':
        obj_fields.StringField(),
        'network_id':
        obj_fields.UUIDField(),
        'subnetpool_id':
        obj_fields.UUIDField(nullable=True),
        'ip_version':
        common_types.IPVersionEnumField(),
        'cidr':
        obj_fields.IPNetworkField(),
        'gateway_ip':
        obj_fields.IPAddressField(nullable=True),
        'allocation_pools':
        obj_fields.ListOfObjectsField('IPAllocationPool', nullable=True),
        'enable_dhcp':
        obj_fields.BooleanField(),
        'dns_nameservers':
        obj_fields.ListOfObjectsField('DNSNameServer', nullable=True),
        'host_routes':
        obj_fields.ListOfObjectsField('Route', nullable=True),
        'ipv6_ra_mode':
        common_types.IPV6ModeEnumField(nullable=True),
        'ipv6_address_mode':
        common_types.IPV6ModeEnumField(nullable=True)
    }

    synthetic_fields = ['allocation_pools', 'dns_nameservers', 'host_routes']

    foreign_keys = {'network_id': 'id'}

    fields_need_translation = {'project_id': 'tenant_id'}

    @classmethod
    def modify_fields_from_db(cls, db_obj):
        # TODO(korzen) remove this method when IP and CIDR decorator ready
        result = super(Subnet, cls).modify_fields_from_db(db_obj)
        if 'cidr' in result:
            result['cidr'] = netaddr.IPNetwork(result['cidr'])
        if 'gateway_ip' in result and result['gateway_ip'] is not None:
            result['gateway_ip'] = netaddr.IPAddress(result['gateway_ip'])
        return result

    @classmethod
    def modify_fields_to_db(cls, fields):
        # TODO(korzen) remove this method when IP and CIDR decorator ready
        result = super(Subnet, cls).modify_fields_to_db(fields)
        if 'cidr' in result:
            result['cidr'] = str(result['cidr'])
        if 'gateway_ip' in result and result['gateway_ip'] is not None:
            result['gateway_ip'] = str(result['gateway_ip'])
        return result