Ejemplo n.º 1
0
class NDPProxy(base.NeutronDbObject):
    # Version 1.0: Initial version
    VERSION = '1.0'

    db_model = models.NDPProxy

    primary_keys = ['id']
    foreign_keys = {'Router': {'router_id': id}, 'Port': {'port_id': id}}

    fields = {
        'id': common_types.UUIDField(),
        'name': obj_fields.StringField(nullable=True),
        'project_id': obj_fields.StringField(nullable=True),
        'router_id': common_types.UUIDField(nullable=False),
        'port_id': common_types.UUIDField(nullable=False),
        'ip_address': obj_fields.IPV6AddressField(),
        'description': obj_fields.StringField(nullable=True)
    }

    fields_no_update = ['id', 'project_id']

    @classmethod
    def modify_fields_from_db(cls, db_obj):
        result = super(NDPProxy, cls).modify_fields_from_db(db_obj)
        if 'ip_address' in result:
            result['ip_address'] = netaddr.IPAddress(result['ip_address'])
        return result

    @classmethod
    def modify_fields_to_db(cls, fields):
        result = super(NDPProxy, cls).modify_fields_to_db(fields)
        if 'ip_address' in result:
            if result['ip_address'] is not None:
                result['ip_address'] = cls.filter_to_str(result['ip_address'])
        return result
 def setUp(self):
     super(TestIPAddressV6, self).setUp()
     self.field = fields.IPV6AddressField()
     self.coerce_good_values = [('::1', netaddr.IPAddress('::1')),
                                (netaddr.IPAddress('::1'),
                                 netaddr.IPAddress('::1'))]
     self.coerce_bad_values = ['1.2', 'foo', '1.2.3.4']
     self.to_primitive_values = [(netaddr.IPAddress('::1'), '::1')]
     self.from_primitive_values = [('::1', netaddr.IPAddress('::1'))]