在带有restframework的Django中,你可以这样做:
class Item(models.Model):
id = models.IntegerField()
name = models.CharField(max_length=32)
another_attribute = models.CharField(max_length=32)
...
(more attributes)
...
yet_another_attribute = models.CharField(max_length=32)
class ItemViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = [IsAuthenticated]
serializer_class = ItemSerializer
filterset_fields = '__all__' # <- this enables filtering on all fields
queryset = Item.objects.all()
Run Code Online (Sandbox Code Playgroud)
如果我想允许过滤,filterset_fields = '__all__'将允许我做类似的事情api/item/?(attribute)=(value)并允许我过滤任何属性
我正在阅读本教程(https://fastapi.tiangolo.com/tutorial/sql-databases/#crud-utils),看起来涉及很多手动过滤:
from fastapi_sqlalchemy import db
class Item(BaseModel):
id: int
name: str
another_attribute: str
...
(more attributes)
...
yet_another_attribute: str
# is it necessary to manually include all the fields I …Run Code Online (Sandbox Code Playgroud) 我有以下设置:
client(eth0) --- (eth2) linux bridge (eth1) --- (eth1) server
Run Code Online (Sandbox Code Playgroud)
当我使用以下命令在 linux 桥上打开 RAW 套接字时
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
Run Code Online (Sandbox Code Playgroud)
我的套接字绑定到 eth2。当客户端向服务器发送数据包时,运行在网桥上的wireshark会报告该数据包,其源MAC地址为客户端(eth0),目标MAC地址为服务器(eth1)。
当我执行 a 时read(),读取的数据的前 6 个字节是目标 MAC 地址,正确读取为 server(eth1)。
但是当我将语句更改为
fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
Run Code Online (Sandbox Code Playgroud)
当我执行 a 时read(),读取的数据的前 6 个字节显示目标 MAC 地址是 linux 桥 (eth2)。
为什么会这样呢?内核或以太网卡驱动程序是否将自己的 MAC 地址放入缓冲区,而不是使用 ETH_P_IP 读取线路?
我正在用这个进行测试:
#test.yml
- hosts: localhost
tasks:
- set_fact:
host_name: "project-specific"
- stat:
path: /home/user/work/infrastructure/{{ host_name }}
register: file_exists
- debug:
var: file_exists
- name: Dont create a file
template:
src: "{{item}}"
dest: /home/user/work/infrastructure/project-specific-2/
mode: 0755
with_fileglob: /home/user/work/infrastructure/{{ host_name }}/*
when: file_exists
Run Code Online (Sandbox Code Playgroud)
我想将所有文件复制到project-specific(project-specific-2作为演示),但前提是项目特定的目录确实存在。项目特定目录不存在,因此应该跳过此步骤。
这是输出:
user@laptop:~/work/infrastructure/ansible$ ansible-playbook test.yml
PLAY [localhost] *************************************************************************************************************************************
TASK [Gathering Facts] *******************************************************************************************************************************
ok: [localhost]
TASK [set_fact] **************************************************************************************************************************************
ok: [localhost]
TASK [stat] ******************************************************************************************************************************************
ok: [localhost]
TASK [debug] *****************************************************************************************************************************************
ok: [localhost] => {
"file_exists": {
"changed": false, …Run Code Online (Sandbox Code Playgroud) 我正在使用 k3d (docker 中的 k3s)做一些教程,我的 yml 如下所示:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
Run Code Online (Sandbox Code Playgroud)
结果节点端口为 31747:
:~$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP …Run Code Online (Sandbox Code Playgroud) ansible ×1
ethernet ×1
fastapi ×1
k3s ×1
kubernetes ×1
nginx ×1
python ×1
raw-ethernet ×1
raw-sockets ×1
rest ×1
sockets ×1