Esempio 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_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 = net_utils.AuthenticEUI(
                        address_pair['mac_address'])
                    ip_address = net_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
Esempio 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'] = net_utils.AuthenticEUI(
             fields['mac_address'])
     return fields
Esempio n. 3
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'] = net_utils.AuthenticIPNetwork(
             fields['ip_address'])
     if 'mac_address' in fields:
         # retain string format as stored in the database
         fields['mac_address'] = net_utils.AuthenticEUI(
             fields['mac_address'])
     return fields
Esempio n. 4
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'] = net_utils.AuthenticEUI(
                fields['mac_address'])

        distributed_port_binding = fields.get('distributed_bindings')
        if distributed_port_binding:
            # TODO(ihrachys) support multiple bindings
            fields['distributed_bindings'] = fields['distributed_bindings'][0]
        else:
            fields['distributed_bindings'] = []
        return fields
Esempio n. 5
0
 def from_primitive(obj, attr, value):
     try:
         return net_utils.AuthenticEUI(value)
     except Exception:
         msg = _("Field value %s is not a netaddr.EUI") % value
         raise ValueError(msg)