@utils.exc_wrapper(internal=True)<EOL>def update_port(context, id, port):
LOG.info("<STR_LIT>" % (id, context.tenant_id))<EOL>port_db = db_api.port_find(context, id=id, scope=db_api.ONE)<EOL>if not port_db:<EOL><INDENT>raise n_exc.PortNotFound(port_id=id)<EOL><DEDENT>port_dict = port["<STR_LIT:port>"]<EOL>fixed_ips = port_dict.pop("<STR_LIT>", None)<EOL>admin_only = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>", "<STR_LIT>",<EOL>"<STR_LIT>"]<EOL>always_filter = ["<STR_LIT>", "<STR_LIT>", "<STR_LIT>"]<EOL>utils.filter_body(context, port_dict, admin_only=admin_only,<EOL>always_filter=always_filter)<EOL>if fixed_ips:<EOL><INDENT>quota.QUOTAS.limit_check(context, context.tenant_id,<EOL>fixed_ips_per_port=len(fixed_ips))<EOL><DEDENT>new_security_groups = utils.pop_param(port_dict, "<STR_LIT>")<EOL>if new_security_groups is not None:<EOL><INDENT>if (Capabilities.TENANT_NETWORK_SG not in<EOL>CONF.QUARK.environment_capabilities):<EOL><INDENT>if not STRATEGY.is_provider_network(port_db["<STR_LIT>"]):<EOL><INDENT>raise q_exc.TenantNetworkSecurityGroupRulesNotEnabled()<EOL><DEDENT><DEDENT><DEDENT>if new_security_groups is not None and not port_db["<STR_LIT>"]:<EOL><INDENT>raise q_exc.SecurityGroupsRequireDevice()<EOL><DEDENT>group_ids, security_group_mods = _make_security_group_list(<EOL>context, new_security_groups)<EOL>quota.QUOTAS.limit_check(context, context.tenant_id,<EOL>security_groups_per_port=len(group_ids))<EOL>if fixed_ips is not None:<EOL><INDENT>ipam_driver = ipam.IPAM_REGISTRY.get_strategy(<EOL>ipam.QuarkIpamANY.get_name())<EOL>addresses, subnet_ids = [], []<EOL>ip_addresses = {}<EOL>for fixed_ip in fixed_ips:<EOL><INDENT>subnet_id = fixed_ip.get("<STR_LIT>")<EOL>ip_address = fixed_ip.get("<STR_LIT>")<EOL>if not (subnet_id or ip_address):<EOL><INDENT>raise n_exc.BadRequest(<EOL>resource="<STR_LIT>",<EOL>msg="<STR_LIT>")<EOL><DEDENT>if ip_address and not subnet_id:<EOL><INDENT>raise n_exc.BadRequest(<EOL>resource="<STR_LIT>",<EOL>msg="<STR_LIT>")<EOL><DEDENT>if subnet_id and ip_address:<EOL><INDENT>ip_netaddr = None<EOL>try:<EOL><INDENT>ip_netaddr = netaddr.IPAddress(ip_address).ipv6()<EOL><DEDENT>except netaddr.AddrFormatError:<EOL><INDENT>raise n_exc.InvalidInput(<EOL>error_message="<STR_LIT>")<EOL><DEDENT>ip_addresses[ip_netaddr] = subnet_id<EOL><DEDENT>else:<EOL><INDENT>subnet_ids.append(subnet_id)<EOL><DEDENT><DEDENT>port_ips = set([netaddr.IPAddress(int(a["<STR_LIT:address>"]))<EOL>for a in port_db["<STR_LIT>"]])<EOL>new_ips = set([a for a in ip_addresses.keys()])<EOL>ips_to_allocate = list(new_ips - port_ips)<EOL>ips_to_deallocate = list(port_ips - new_ips)<EOL>for ip in ips_to_allocate:<EOL><INDENT>if ip in ip_addresses:<EOL><INDENT>allocated = []<EOL>ipam_driver.allocate_ip_address(<EOL>context, allocated, port_db["<STR_LIT>"],<EOL>port_db["<STR_LIT:id>"], reuse_after=None, ip_addresses=[ip],<EOL>subnets=[ip_addresses[ip]])<EOL>addresses.extend(allocated)<EOL><DEDENT><DEDENT>for ip in ips_to_deallocate:<EOL><INDENT>ipam_driver.deallocate_ips_by_port(<EOL>context, port_db, ip_address=ip)<EOL><DEDENT>for subnet_id in subnet_ids:<EOL><INDENT>ipam_driver.allocate_ip_address(<EOL>context, addresses, port_db["<STR_LIT>"], port_db["<STR_LIT:id>"],<EOL>reuse_after=CONF.QUARK.ipam_reuse_after,<EOL>subnets=[subnet_id])<EOL><DEDENT>if addresses:<EOL><INDENT>port_dict["<STR_LIT>"] = port_db["<STR_LIT>"]<EOL>port_dict["<STR_LIT>"].extend(addresses)<EOL><DEDENT><DEDENT>net_driver = _get_net_driver(port_db.network, port=port_db)<EOL>base_net_driver = _get_net_driver(port_db.network)<EOL>kwargs = {}<EOL>if new_security_groups is not None:<EOL><INDENT>kwargs["<STR_LIT>"] = security_group_mods<EOL><DEDENT>net_driver.update_port(context, port_id=port_db["<STR_LIT>"],<EOL>mac_address=port_db["<STR_LIT>"],<EOL>device_id=port_db["<STR_LIT>"],<EOL>base_net_driver=base_net_driver,<EOL>**kwargs)<EOL>port_dict["<STR_LIT>"] = security_group_mods<EOL>with context.session.begin():<EOL><INDENT>port = db_api.port_update(context, port_db, **port_dict)<EOL><DEDENT>if port_db in context.session:<EOL><INDENT>context.session.expunge(port_db)<EOL><DEDENT>port_db = db_api.port_find(context, id=id, scope=db_api.ONE)<EOL>return v._make_port_dict(port_db)<EOL>
Update values of a port.

    : param context: neutron api request context
    : param id: UUID representing the port to update.
    : param port: dictionary with keys indicating fields to update.
        valid keys are those that have a value of True for 'allow_put'
        as listed in the RESOURCE_ATTRIBUTE_MAP object in
        neutron/api/v2/attributes.py.