Dragonflow etcdv3数据读取方法

etcdctl命令行

执行前,你需要确认是否etcdctl api版本是v3的

确认方法:

1
2
3
stack@odf-controller:~$ etcdctl --version
etcdctl version: 3.0.15
API version: 2

etcdctl如何修改API使用v3 ?

1
2
3
4
5
stack@odf-controller:~$ export ETCDCTL_API=3
stack@odf-controller:~$ etcdctl version
etcdctl version: 3.0.15
API version: 3.0
stack@odf-controller:~$

小细节

v2 查看version使用 etcdctl —version

v3 查看version使用 etcdctl version

etcdctl读取数据的数据方法

方法1:

etcdctl –endpoints=172.16.0.31:2379 get “” –from-key

方法2:

etcdctl –endpoints=172.16.0.31:2379 get “/“ –prefix

etcdctl读取目录是/port的数据方法

etcdctl –endpoints=172.16.0.31:2379 get “/lport” –prefix

python API读取数据

1
2
3
4
5
6
7
import etcd3gw

e3gw = etcd3gw.client('172.16.0.31', 2379, ca_cert=None,
cert_cert=None, timeout=None)
print e3gw.get_prefix('/lport/')
print e3gw.get_prefix('/')
print e3gw.get('/chassis/odf-controller')

Dragonflow etcd数据key和value

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
stack@odf-controller:~/devstack$ etcdctl --endpoints=172.16.0.31:2379 get "" --from-key
/chassis/odf-controller
{"tunnel_types": ["vxlan", "geneve", "gre"], "ip": "172.16.0.31", "id": "odf-controller"}
/chassis/pdf-compute
{"tunnel_types": ["vxlan", "geneve", "gre"], "ip": "172.16.0.34", "id": "pdf-compute"}
/lport/145cf8a3-1b0c-47f5-ab98-d791941ff901
{"dhcp_params": {"opts": {}}, "subnets": ["add073aa-bcd2-4232-a1da-40ae4695e117"], "binding_vnic_type": "normal", "name": "", "allowed_address_pairs": [], "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "enabled": true, "unique_key": 7, "binding": {"chassis": "odf-controller", "type": "chassis"}, "topic": "a5972cf299374500acd2699c8ea1cc55", "ips": ["192.168.11.1"], "device_owner": "network:router_interface", "version": 6, "port_security_enabled": false, "macs": ["fa:16:3e:02:79:97"], "id": "145cf8a3-1b0c-47f5-ab98-d791941ff901", "security_groups": [], "device_id": "99e409c7-394c-47b6-b638-41d2e8ade294"}
/lport/77978d74-4f7f-49e9-8015-2788962e500c
{"dhcp_params": {"opts": {}}, "subnets": ["add073aa-bcd2-4232-a1da-40ae4695e117"], "binding_vnic_type": "normal", "name": "", "allowed_address_pairs": [], "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "enabled": true, "unique_key": 9, "binding": {"chassis": "odf-controller", "type": "chassis"}, "topic": "a5972cf299374500acd2699c8ea1cc55", "ips": ["192.168.11.12"], "device_owner": "compute:nova", "version": 4, "port_security_enabled": true, "macs": ["fa:16:3e:e6:10:7f"], "id": "77978d74-4f7f-49e9-8015-2788962e500c", "security_groups": ["6065f7ed-e762-45f3-994f-56cfd6d0ec29"], "device_id": "77a17a11-c998-4924-9a17-e130a6a59096"}
/lport/818c15f5-fb5e-4971-9a07-237c2e2dcd75
{"dhcp_params": {"opts": {}}, "subnets": ["add073aa-bcd2-4232-a1da-40ae4695e117"], "binding_vnic_type": "normal", "name": "", "allowed_address_pairs": [], "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "unique_key": 6, "enabled": true, "topic": "a5972cf299374500acd2699c8ea1cc55", "ips": ["192.168.11.2"], "device_owner": "network:dhcp", "version": 3, "port_security_enabled": false, "macs": ["fa:16:3e:ea:40:0a"], "id": "818c15f5-fb5e-4971-9a07-237c2e2dcd75", "security_groups": [], "device_id": ""}
/lport/de8ad7ca-2635-463c-8c66-abf1cd2a6b8d
{"dhcp_params": {"opts": {}}, "subnets": ["add073aa-bcd2-4232-a1da-40ae4695e117"], "binding_vnic_type": "normal", "name": "", "allowed_address_pairs": [], "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "enabled": true, "unique_key": 8, "binding": {"chassis": "pdf-compute", "type": "chassis"}, "topic": "a5972cf299374500acd2699c8ea1cc55", "ips": ["192.168.11.3"], "device_owner": "compute:nova", "version": 4, "port_security_enabled": true, "macs": ["fa:16:3e:67:ab:ae"], "id": "de8ad7ca-2635-463c-8c66-abf1cd2a6b8d", "security_groups": ["6065f7ed-e762-45f3-994f-56cfd6d0ec29"], "device_id": "7abf2de9-e572-4fe7-a618-42374aea35a7"}
/lrouter/99e409c7-394c-47b6-b638-41d2e8ade294
{"name": "r1", "unique_key": 1, "id": "99e409c7-394c-47b6-b638-41d2e8ade294", "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 3, "routes": [], "ports": [{"network": "192.168.11.1/24", "unique_key": 7, "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "topic": "a5972cf299374500acd2699c8ea1cc55", "mac": "fa:16:3e:02:79:97", "id": "145cf8a3-1b0c-47f5-ab98-d791941ff901"}]}
/lsubnet/add073aa-bcd2-4232-a1da-40ae4695e117
{"name": "net1-subnet", "enable_dhcp": true, "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "dns_nameservers": [], "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 0, "host_routes": [], "gateway_ip": "192.168.11.1", "cidr": "192.168.11.0/24", "id": "add073aa-bcd2-4232-a1da-40ae4695e117"}
/lswitch/2c1c2b32-3fb0-423c-8910-bf075adbe331
{"name": "net1", "unique_key": 2, "segmentation_id": 100, "mtu": 1450, "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 5, "id": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "network_type": "vxlan", "is_external": false}
/lswitch/5382c5f1-4b80-4b66-b7aa-b8348b04504a
{"name": "external", "unique_key": 1, "mtu": 1500, "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 3, "physical_network": "public", "id": "5382c5f1-4b80-4b66-b7aa-b8348b04504a", "network_type": "flat", "is_external": true}
/pubsub/D
��action�set�table�lport�topic�D�value�{"dhcp_params": {"opts": {}}, "subnets": ["add073aa-bcd2-4232-a1da-40ae4695e117"], "binding_vnic_type": "normal", "name": "", "allowed_address_pairs": [], "lswitch": "2c1c2b32-3fb0-423c-8910-bf075adbe331", "enabled": true, "unique_key": 9, "binding": {"chassis": "odf-controller", "type": "chassis"}, "topic": "a5972cf299374500acd2699c8ea1cc55", "ips": ["192.168.11.12"], "device_owner": "compute:nova", "version": 4, "port_security_enabled": true, "macs": ["fa:16:3e:e6:10:7f"], "id": "77978d74-4f7f-49e9-8015-2788962e500c", "security_groups": ["6065f7ed-e762-45f3-994f-56cfd6d0ec29"], "device_id": "77a17a11-c998-4924-9a17-e130a6a59096"}�key�$77978d74-4f7f-49e9-8015-2788962e500c
/secgroup/6065f7ed-e762-45f3-994f-56cfd6d0ec29
{"name": "default", "unique_key": 1, "rules": [{"direction": "egress", "ethertype": "IPv4", "security_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 0, "id": "2cdf6659-6ccc-4bc2-9f42-b3e184233eb0"}, {"remote_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "direction": "ingress", "ethertype": "IPv6", "security_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 0, "id": "3de51a83-3a21-4356-b9b3-7035975060ff"}, {"remote_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "direction": "ingress", "ethertype": "IPv4", "security_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 0, "id": "56b98969-7ff2-44c1-a4c8-aa29c1c58681"}, {"direction": "egress", "ethertype": "IPv6", "security_group_id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29", "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 0, "id": "f9da0837-81ab-49e2-9bb9-c1ea71c89f78"}], "topic": "a5972cf299374500acd2699c8ea1cc55", "version": 4, "id": "6065f7ed-e762-45f3-994f-56cfd6d0ec29"}
/secgroup/d6017315-fb18-45c6-8b4d-9a38bdcc6e18
{"name": "default", "unique_key": 2, "rules": [{"direction": "egress", "ethertype": "IPv6", "security_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "topic": "6ea6f279297e465fa64856820fa4d3e2", "version": 0, "id": "0adea178-bf80-411f-9136-c326081879a8"}, {"remote_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "direction": "ingress", "ethertype": "IPv6", "security_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "topic": "6ea6f279297e465fa64856820fa4d3e2", "version": 0, "id": "513e5100-44d5-4a21-8873-17f44e9c48dd"}, {"direction": "egress", "ethertype": "IPv4", "security_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "topic": "6ea6f279297e465fa64856820fa4d3e2", "version": 0, "id": "5b23365d-bb46-4985-b1ea-840224980207"}, {"remote_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "direction": "ingress", "ethertype": "IPv4", "security_group_id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18", "topic": "6ea6f279297e465fa64856820fa4d3e2", "version": 0, "id": "e3ade7c3-30b6-4395-b032-164dae738285"}], "topic": "6ea6f279297e465fa64856820fa4d3e2", "version": 4, "id": "d6017315-fb18-45c6-8b4d-9a38bdcc6e18"}
/service/4a475813-5df5-5a73-b8cd-5dc866fc4f62
{"binary": "df-metadata-service", "last_seen_up": 1520408148.664552, "chassis": "pdf-compute", "id": "4a475813-5df5-5a73-b8cd-5dc866fc4f62"}
/service/b44d242e-19ee-5541-ad33-b37145edddb0
{"binary": "df-local-controller", "last_seen_up": 1520408148.002708, "chassis": "pdf-compute", "id": "b44d242e-19ee-5541-ad33-b37145edddb0"}
/service/b77172b3-095e-56c6-8592-2de542f2094d
{"binary": "df-metadata-service", "last_seen_up": 1520408142.636248, "chassis": "odf-controller", "id": "b77172b3-095e-56c6-8592-2de542f2094d"}
/service/fdbf756f-2387-5cc8-b0bb-f8010422bdbd
{"binary": "df-local-controller", "last_seen_up": 1520408124.881775, "chassis": "odf-controller", "id": "fdbf756f-2387-5cc8-b0bb-f8010422bdbd"}
/unique_key/lport
9
/unique_key/lrouter
1
/unique_key/lswitch
2
/unique_key/secgroup
2

df-db tables能够清晰展示etcd数据

dragonflow 2018新版本支持df-db命令用来显示分布式存储etcd中的数据,你可以使用这个来观看etcd数据

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
stack@odf-controller:~/devstack$ df-db tables
+-------------------------+
| DB Tables |
+-------------------------+
| activeport |
| bgp_peer |
| bgp_speaker |
| chassis |
| child_port_segmentation |
| floatingip |
| listener |
| lport |
| lrouter |
| lsubnet |
| lswitch |
| migration |
| publisher |
| qospolicy |
| secgroup |
| service |
| sfc_flowclassifier |
| sfc_portchain |
| sfc_portpair |
| sfc_portpairgroup |
| unique_key |
+-------------------------+