Exemplo n.º 1
0
    def _process_create_allowed_address_pairs(self, context, port,
                                              allowed_address_pairs):
        if not validators.is_attr_set(allowed_address_pairs):
            return []
        try:
            with db_api.context_manager.writer.using(context):
                for address_pair in allowed_address_pairs:
                    # use port.mac_address if no mac address in address pair
                    if 'mac_address' not in address_pair:
                        address_pair['mac_address'] = port['mac_address']
                    # retain string format as passed through API
                    mac_address = utils.AuthenticEUI(
                        address_pair['mac_address'])
                    ip_address = utils.AuthenticIPNetwork(
                        address_pair['ip_address'])
                    pair_obj = obj_addr_pair.AllowedAddressPair(
                        context,
                        port_id=port['id'],
                        mac_address=mac_address,
                        ip_address=ip_address)
                    pair_obj.create()
        except exceptions.NeutronDbObjectDuplicateEntry:
            raise addr_exc.DuplicateAddressPairInRequest(
                mac_address=address_pair['mac_address'],
                ip_address=address_pair['ip_address'])

        return allowed_address_pairs
Exemplo n.º 2
0
 def modify_fields_from_db(cls, db_obj):
     fields = super(DVRMacAddress, cls).modify_fields_from_db(db_obj)
     if 'mac_address' in fields:
         # NOTE(tonytan4ever): Here uses AuthenticEUI to retain the format
         # passed from API.
         fields['mac_address'] = utils.AuthenticEUI(fields['mac_address'])
     return fields
Exemplo n.º 3
0
 def modify_fields_from_db(cls, db_obj):
     fields = super(Port, cls).modify_fields_from_db(db_obj)
     if 'mac_address' in fields:
         fields['mac_address'] = utils.AuthenticEUI(fields['mac_address'])
     distributed_port_binding = fields.get('distributed_binding')
     if distributed_port_binding:
         fields['distributed_binding'] = fields['distributed_binding'][0]
     else:
         fields['distributed_binding'] = None
     return fields
Exemplo n.º 4
0
 def modify_fields_from_db(cls, db_obj):
     fields = super(AllowedAddressPair, cls).modify_fields_from_db(db_obj)
     if 'ip_address' in fields:
         # retain string format as stored in the database
         fields['ip_address'] = utils.AuthenticIPNetwork(
             fields['ip_address'])
     if 'mac_address' in fields:
         # retain string format as stored in the database
         fields['mac_address'] = utils.AuthenticEUI(fields['mac_address'])
     return fields
Exemplo n.º 5
0
    def modify_fields_from_db(cls, db_obj):
        fields = super(Port, cls).modify_fields_from_db(db_obj)

        # TODO(rossella_s): get rid of it once we switch the db model to using
        # custom types.
        if 'mac_address' in fields:
            fields['mac_address'] = utils.AuthenticEUI(fields['mac_address'])

        distributed_port_binding = fields.get('distributed_binding')
        if distributed_port_binding:
            fields['distributed_binding'] = fields['distributed_binding'][0]
        else:
            fields['distributed_binding'] = None
        return fields
Exemplo n.º 6
0
 def test_invalid_values(self):
     for mac in ('XXXX', 'ypp', 'g3:vvv'):
         with testtools.ExpectedException(netaddr.core.AddrFormatError):
             utils.AuthenticEUI(mac)
Exemplo n.º 7
0
 def test_retains_original_format(self):
     for mac_str in ('FA-16-3E-73-A2-E9', 'fa:16:3e:73:a2:e9'):
         self.assertEqual(mac_str, str(utils.AuthenticEUI(mac_str)))
Exemplo n.º 8
0
 def from_primitive(obj, attr, value):
     try:
         return utils.AuthenticEUI(value)
     except Exception:
         msg = _("Field value %s is not a netaddr.EUI") % value
         raise ValueError(msg)