From 29df3face52306692eb6b825385ad414ae34ef5e Mon Sep 17 00:00:00 2001 From: huangyichen Date: Mon, 10 Jul 2023 14:18:11 +0800 Subject: [PATCH] Add dpvs-agent source code --- tools/dpvs-agent/.gitignore | 2 + tools/dpvs-agent/Makefile | 32 + tools/dpvs-agent/README.md | 4 + .../cmd/device/delete_device_name_addr.go | 45 + .../cmd/device/delete_device_name_netlink.go | 49 + .../device/delete_device_name_netlink_addr.go | 68 + .../cmd/device/delete_device_name_route.go | 59 + .../cmd/device/delete_device_name_vlan.go | 46 + .../cmd/device/get_device_name_nic.go | 78 + tools/dpvs-agent/cmd/device/ioctl.go | 23 + .../cmd/device/put_device_name_addr.go | 57 + .../cmd/device/put_device_name_netlink.go | 46 + .../device/put_device_name_netlink_addr.go | 72 + .../cmd/device/put_device_name_nic.go | 63 + .../cmd/device/put_device_name_route.go | 66 + .../cmd/device/put_device_name_vlan.go | 71 + .../device/todo_delete_device_name_linux.go | 25 + .../todo_delete_device_name_linux_addr.go | 117 + .../dpvs-agent/cmd/device/todo_get_device.go | 1 + .../cmd/device/todo_get_device_name_addr.go | 1 + .../cmd/device/todo_get_device_name_linux.go | 1 + .../device/todo_get_device_name_linux_addr.go | 1 + .../cmd/device/todo_get_device_name_route.go | 1 + .../cmd/device/todo_get_device_name_vlan.go | 1 + .../cmd/device/todo_put_device_name_linux.go | 3 + .../device/todo_put_device_name_linux_addr.go | 132 + .../dpvs-agent/cmd/dpvs-agent-server/Makefile | 26 + .../cmd/dpvs-agent-server/api_init.go | 181 + .../dpvs-agent/cmd/dpvs-agent-server/main.go | 55 + .../dpvs-agent/cmd/ipvs/delete_vs_vip_port.go | 45 + .../cmd/ipvs/delete_vs_vip_port_allow.go | 56 + .../cmd/ipvs/delete_vs_vip_port_deny.go | 56 + .../cmd/ipvs/delete_vs_vip_port_laddr.go | 52 + .../cmd/ipvs/delete_vs_vip_port_rs.go | 56 + tools/dpvs-agent/cmd/ipvs/get_vs.go | 71 + tools/dpvs-agent/cmd/ipvs/get_vs_vip_port.go | 79 + .../cmd/ipvs/get_vs_vip_port_laddr.go | 50 + .../cmd/ipvs/post_vs_vip_port_rs.go | 59 + tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go | 96 + .../cmd/ipvs/put_vs_vip_port_allow.go | 58 + .../cmd/ipvs/put_vs_vip_port_deny.go | 58 + .../cmd/ipvs/put_vs_vip_port_laddr.go | 55 + .../dpvs-agent/cmd/ipvs/put_vs_vip_port_rs.go | 74 + .../cmd/ipvs/todo_get_vs_vip_port_rs.go | 1 + tools/dpvs-agent/dpvs-agent-api.yaml | 1373 +++++ tools/dpvs-agent/go.mod | 40 + tools/dpvs-agent/go.sum | 232 + tools/dpvs-agent/models/acl_addr_list.go | 116 + tools/dpvs-agent/models/addr_range.go | 53 + tools/dpvs-agent/models/cert_auth_spec.go | 50 + tools/dpvs-agent/models/dest_check_spec.go | 84 + tools/dpvs-agent/models/error.go | 27 + tools/dpvs-agent/models/inet_addr_spec.go | 56 + .../models/local_address_expand_list.go | 116 + .../models/local_address_spec_expand.go | 62 + .../models/local_address_spec_tiny.go | 53 + .../models/local_address_tiny_list.go | 116 + tools/dpvs-agent/models/match_spec.go | 156 + tools/dpvs-agent/models/nic_device_detail.go | 232 + .../models/nic_device_queue_data.go | 27 + tools/dpvs-agent/models/nic_device_spec.go | 150 + .../dpvs-agent/models/nic_device_spec_list.go | 116 + tools/dpvs-agent/models/nic_device_stats.go | 342 ++ .../models/real_server_expand_list.go | 116 + .../models/real_server_spec_expand.go | 150 + .../models/real_server_spec_tiny.go | 129 + .../models/real_server_tiny_list.go | 116 + tools/dpvs-agent/models/route_spec.go | 71 + tools/dpvs-agent/models/server_stats.go | 77 + tools/dpvs-agent/models/status.go | 114 + .../dpvs-agent/models/virtual_server_list.go | 116 + .../models/virtual_server_spec_expand.go | 438 ++ .../models/virtual_server_spec_tiny.go | 183 + tools/dpvs-agent/models/vlan_spec.go | 56 + tools/dpvs-agent/pkg/ipc/pool/conn.go | 316 ++ tools/dpvs-agent/pkg/ipc/pool/pool.go | 523 ++ tools/dpvs-agent/pkg/ipc/pool/util.go | 12 + tools/dpvs-agent/pkg/ipc/proto/reader.go | 335 ++ tools/dpvs-agent/pkg/ipc/proto/writer.go | 167 + tools/dpvs-agent/pkg/ipc/types/certificate.go | 369 ++ tools/dpvs-agent/pkg/ipc/types/const.go | 334 ++ tools/dpvs-agent/pkg/ipc/types/dpvsmatch.go | 56 + tools/dpvs-agent/pkg/ipc/types/dpvsstats.go | 114 + tools/dpvs-agent/pkg/ipc/types/getmodel.go | 169 + tools/dpvs-agent/pkg/ipc/types/inetaddr.go | 571 +++ tools/dpvs-agent/pkg/ipc/types/iprange.go | 43 + tools/dpvs-agent/pkg/ipc/types/kni.go | 314 ++ tools/dpvs-agent/pkg/ipc/types/laddr.go | 492 ++ tools/dpvs-agent/pkg/ipc/types/method.go | 1 + tools/dpvs-agent/pkg/ipc/types/netif.go | 728 +++ tools/dpvs-agent/pkg/ipc/types/realserver.go | 633 +++ tools/dpvs-agent/pkg/ipc/types/route.go | 470 ++ tools/dpvs-agent/pkg/ipc/types/sockmsg.go | 132 + tools/dpvs-agent/pkg/ipc/types/utility.go | 11 + .../dpvs-agent/pkg/ipc/types/virtualserver.go | 693 +++ tools/dpvs-agent/pkg/ipc/types/vlan.go | 312 ++ .../restapi/configure_dpvs_agent.go | 172 + tools/dpvs-agent/restapi/doc.go | 19 + tools/dpvs-agent/restapi/embedded_spec.go | 4449 +++++++++++++++++ .../device/delete_device_name_addr.go | 56 + .../delete_device_name_addr_parameters.go | 145 + .../delete_device_name_addr_responses.go | 98 + .../delete_device_name_addr_urlbuilder.go | 115 + .../device/delete_device_name_netlink.go | 56 + .../device/delete_device_name_netlink_addr.go | 56 + ...ete_device_name_netlink_addr_parameters.go | 101 + ...lete_device_name_netlink_addr_responses.go | 98 + ...ete_device_name_netlink_addr_urlbuilder.go | 99 + .../delete_device_name_netlink_parameters.go | 71 + .../delete_device_name_netlink_responses.go | 98 + .../delete_device_name_netlink_urlbuilder.go | 99 + .../device/delete_device_name_route.go | 56 + .../delete_device_name_route_parameters.go | 101 + .../delete_device_name_route_responses.go | 98 + .../delete_device_name_route_urlbuilder.go | 99 + .../device/delete_device_name_vlan.go | 56 + .../delete_device_name_vlan_parameters.go | 71 + .../delete_device_name_vlan_responses.go | 98 + .../delete_device_name_vlan_urlbuilder.go | 99 + .../restapi/operations/device/get_device.go | 56 + .../operations/device/get_device_name_addr.go | 56 + .../device/get_device_name_addr_parameters.go | 153 + .../device/get_device_name_addr_responses.go | 98 + .../device/get_device_name_addr_urlbuilder.go | 124 + .../device/get_device_name_netlink.go | 56 + .../device/get_device_name_netlink_addr.go | 56 + ...get_device_name_netlink_addr_parameters.go | 116 + .../get_device_name_netlink_addr_responses.go | 98 + ...get_device_name_netlink_addr_urlbuilder.go | 115 + .../get_device_name_netlink_parameters.go | 116 + .../get_device_name_netlink_responses.go | 98 + .../get_device_name_netlink_urlbuilder.go | 115 + .../operations/device/get_device_name_nic.go | 56 + .../device/get_device_name_nic_parameters.go | 153 + .../device/get_device_name_nic_responses.go | 102 + .../device/get_device_name_nic_urlbuilder.go | 124 + .../device/get_device_name_route.go | 56 + .../get_device_name_route_parameters.go | 116 + .../device/get_device_name_route_responses.go | 98 + .../get_device_name_route_urlbuilder.go | 115 + .../operations/device/get_device_name_vlan.go | 56 + .../device/get_device_name_vlan_parameters.go | 116 + .../device/get_device_name_vlan_responses.go | 98 + .../device/get_device_name_vlan_urlbuilder.go | 115 + .../device/get_device_parameters.go | 92 + .../operations/device/get_device_responses.go | 55 + .../device/get_device_urlbuilder.go | 105 + .../operations/device/put_device_name_addr.go | 56 + .../device/put_device_name_addr_parameters.go | 145 + .../device/put_device_name_addr_responses.go | 141 + .../device/put_device_name_addr_urlbuilder.go | 115 + .../device/put_device_name_netlink.go | 56 + .../device/put_device_name_netlink_addr.go | 56 + ...put_device_name_netlink_addr_parameters.go | 101 + .../put_device_name_netlink_addr_responses.go | 98 + ...put_device_name_netlink_addr_urlbuilder.go | 99 + .../put_device_name_netlink_parameters.go | 71 + .../put_device_name_netlink_responses.go | 98 + .../put_device_name_netlink_urlbuilder.go | 99 + .../operations/device/put_device_name_nic.go | 56 + .../device/put_device_name_nic_parameters.go | 218 + .../device/put_device_name_nic_responses.go | 98 + .../device/put_device_name_nic_urlbuilder.go | 131 + .../device/put_device_name_route.go | 56 + .../put_device_name_route_parameters.go | 101 + .../device/put_device_name_route_responses.go | 141 + .../put_device_name_route_urlbuilder.go | 99 + .../operations/device/put_device_name_vlan.go | 56 + .../device/put_device_name_vlan_parameters.go | 101 + .../device/put_device_name_vlan_responses.go | 98 + .../device/put_device_name_vlan_urlbuilder.go | 99 + .../restapi/operations/dpvs_agent_api.go | 736 +++ .../virtualserver/delete_vs_vip_port.go | 56 + .../virtualserver/delete_vs_vip_port_allow.go | 56 + .../delete_vs_vip_port_allow_parameters.go | 101 + .../delete_vs_vip_port_allow_responses.go | 211 + .../delete_vs_vip_port_allow_urlbuilder.go | 99 + .../virtualserver/delete_vs_vip_port_deny.go | 56 + .../delete_vs_vip_port_deny_parameters.go | 101 + .../delete_vs_vip_port_deny_responses.go | 211 + .../delete_vs_vip_port_deny_urlbuilder.go | 99 + .../virtualserver/delete_vs_vip_port_laddr.go | 56 + .../delete_vs_vip_port_laddr_parameters.go | 101 + .../delete_vs_vip_port_laddr_responses.go | 186 + .../delete_vs_vip_port_laddr_urlbuilder.go | 99 + .../delete_vs_vip_port_parameters.go | 71 + .../delete_vs_vip_port_responses.go | 143 + .../virtualserver/delete_vs_vip_port_rs.go | 56 + .../delete_vs_vip_port_rs_parameters.go | 101 + .../delete_vs_vip_port_rs_responses.go | 211 + .../delete_vs_vip_port_rs_urlbuilder.go | 99 + .../delete_vs_vip_port_urlbuilder.go | 99 + .../operations/virtualserver/get_vs.go | 56 + .../virtualserver/get_vs_parameters.go | 92 + .../virtualserver/get_vs_responses.go | 59 + .../virtualserver/get_vs_urlbuilder.go | 105 + .../virtualserver/get_vs_vip_port.go | 56 + .../virtualserver/get_vs_vip_port_allow.go | 56 + .../get_vs_vip_port_allow_parameters.go | 71 + .../get_vs_vip_port_allow_responses.go | 98 + .../get_vs_vip_port_allow_urlbuilder.go | 99 + .../virtualserver/get_vs_vip_port_deny.go | 56 + .../get_vs_vip_port_deny_parameters.go | 71 + .../get_vs_vip_port_deny_responses.go | 98 + .../get_vs_vip_port_deny_urlbuilder.go | 99 + .../virtualserver/get_vs_vip_port_laddr.go | 56 + .../get_vs_vip_port_laddr_parameters.go | 116 + .../get_vs_vip_port_laddr_responses.go | 102 + .../get_vs_vip_port_laddr_urlbuilder.go | 115 + .../get_vs_vip_port_parameters.go | 116 + .../get_vs_vip_port_responses.go | 102 + .../virtualserver/get_vs_vip_port_rs.go | 56 + .../get_vs_vip_port_rs_parameters.go | 116 + .../get_vs_vip_port_rs_responses.go | 98 + .../get_vs_vip_port_rs_urlbuilder.go | 115 + .../get_vs_vip_port_urlbuilder.go | 115 + .../virtualserver/post_vs_vip_port_allow.go | 56 + .../post_vs_vip_port_allow_parameters.go | 101 + .../post_vs_vip_port_allow_responses.go | 229 + .../post_vs_vip_port_allow_urlbuilder.go | 99 + .../virtualserver/post_vs_vip_port_deny.go | 56 + .../post_vs_vip_port_deny_parameters.go | 101 + .../post_vs_vip_port_deny_responses.go | 229 + .../post_vs_vip_port_deny_urlbuilder.go | 99 + .../virtualserver/post_vs_vip_port_rs.go | 56 + .../post_vs_vip_port_rs_parameters.go | 101 + .../post_vs_vip_port_rs_responses.go | 229 + .../post_vs_vip_port_rs_urlbuilder.go | 99 + .../virtualserver/put_vs_vip_port.go | 56 + .../virtualserver/put_vs_vip_port_allow.go | 56 + .../put_vs_vip_port_allow_parameters.go | 101 + .../put_vs_vip_port_allow_responses.go | 229 + .../put_vs_vip_port_allow_urlbuilder.go | 99 + .../virtualserver/put_vs_vip_port_deny.go | 56 + .../put_vs_vip_port_deny_parameters.go | 101 + .../put_vs_vip_port_deny_responses.go | 229 + .../put_vs_vip_port_deny_urlbuilder.go | 99 + .../virtualserver/put_vs_vip_port_laddr.go | 56 + .../put_vs_vip_port_laddr_parameters.go | 101 + .../put_vs_vip_port_laddr_responses.go | 229 + .../put_vs_vip_port_laddr_urlbuilder.go | 99 + .../put_vs_vip_port_parameters.go | 101 + .../put_vs_vip_port_responses.go | 229 + .../virtualserver/put_vs_vip_port_rs.go | 56 + .../put_vs_vip_port_rs_parameters.go | 145 + .../put_vs_vip_port_rs_responses.go | 229 + .../put_vs_vip_port_rs_urlbuilder.go | 115 + .../put_vs_vip_port_urlbuilder.go | 99 + tools/dpvs-agent/restapi/server.go | 507 ++ 249 files changed, 34985 insertions(+) create mode 100644 tools/dpvs-agent/.gitignore create mode 100644 tools/dpvs-agent/Makefile create mode 100644 tools/dpvs-agent/README.md create mode 100644 tools/dpvs-agent/cmd/device/delete_device_name_addr.go create mode 100644 tools/dpvs-agent/cmd/device/delete_device_name_netlink.go create mode 100644 tools/dpvs-agent/cmd/device/delete_device_name_netlink_addr.go create mode 100644 tools/dpvs-agent/cmd/device/delete_device_name_route.go create mode 100644 tools/dpvs-agent/cmd/device/delete_device_name_vlan.go create mode 100644 tools/dpvs-agent/cmd/device/get_device_name_nic.go create mode 100644 tools/dpvs-agent/cmd/device/ioctl.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_addr.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_netlink.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_netlink_addr.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_nic.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_route.go create mode 100644 tools/dpvs-agent/cmd/device/put_device_name_vlan.go create mode 100644 tools/dpvs-agent/cmd/device/todo_delete_device_name_linux.go create mode 100644 tools/dpvs-agent/cmd/device/todo_delete_device_name_linux_addr.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device_name_addr.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device_name_linux.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device_name_linux_addr.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device_name_route.go create mode 100644 tools/dpvs-agent/cmd/device/todo_get_device_name_vlan.go create mode 100644 tools/dpvs-agent/cmd/device/todo_put_device_name_linux.go create mode 100644 tools/dpvs-agent/cmd/device/todo_put_device_name_linux_addr.go create mode 100644 tools/dpvs-agent/cmd/dpvs-agent-server/Makefile create mode 100644 tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go create mode 100644 tools/dpvs-agent/cmd/dpvs-agent-server/main.go create mode 100644 tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port.go create mode 100644 tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/cmd/ipvs/get_vs.go create mode 100644 tools/dpvs-agent/cmd/ipvs/get_vs_vip_port.go create mode 100644 tools/dpvs-agent/cmd/ipvs/get_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/cmd/ipvs/post_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go create mode 100644 tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/cmd/ipvs/todo_get_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/dpvs-agent-api.yaml create mode 100644 tools/dpvs-agent/go.mod create mode 100644 tools/dpvs-agent/go.sum create mode 100644 tools/dpvs-agent/models/acl_addr_list.go create mode 100644 tools/dpvs-agent/models/addr_range.go create mode 100644 tools/dpvs-agent/models/cert_auth_spec.go create mode 100644 tools/dpvs-agent/models/dest_check_spec.go create mode 100644 tools/dpvs-agent/models/error.go create mode 100644 tools/dpvs-agent/models/inet_addr_spec.go create mode 100644 tools/dpvs-agent/models/local_address_expand_list.go create mode 100644 tools/dpvs-agent/models/local_address_spec_expand.go create mode 100644 tools/dpvs-agent/models/local_address_spec_tiny.go create mode 100644 tools/dpvs-agent/models/local_address_tiny_list.go create mode 100644 tools/dpvs-agent/models/match_spec.go create mode 100644 tools/dpvs-agent/models/nic_device_detail.go create mode 100644 tools/dpvs-agent/models/nic_device_queue_data.go create mode 100644 tools/dpvs-agent/models/nic_device_spec.go create mode 100644 tools/dpvs-agent/models/nic_device_spec_list.go create mode 100644 tools/dpvs-agent/models/nic_device_stats.go create mode 100644 tools/dpvs-agent/models/real_server_expand_list.go create mode 100644 tools/dpvs-agent/models/real_server_spec_expand.go create mode 100644 tools/dpvs-agent/models/real_server_spec_tiny.go create mode 100644 tools/dpvs-agent/models/real_server_tiny_list.go create mode 100644 tools/dpvs-agent/models/route_spec.go create mode 100644 tools/dpvs-agent/models/server_stats.go create mode 100644 tools/dpvs-agent/models/status.go create mode 100644 tools/dpvs-agent/models/virtual_server_list.go create mode 100644 tools/dpvs-agent/models/virtual_server_spec_expand.go create mode 100644 tools/dpvs-agent/models/virtual_server_spec_tiny.go create mode 100644 tools/dpvs-agent/models/vlan_spec.go create mode 100644 tools/dpvs-agent/pkg/ipc/pool/conn.go create mode 100644 tools/dpvs-agent/pkg/ipc/pool/pool.go create mode 100644 tools/dpvs-agent/pkg/ipc/pool/util.go create mode 100644 tools/dpvs-agent/pkg/ipc/proto/reader.go create mode 100644 tools/dpvs-agent/pkg/ipc/proto/writer.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/certificate.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/const.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/dpvsmatch.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/dpvsstats.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/getmodel.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/inetaddr.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/iprange.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/kni.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/laddr.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/method.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/netif.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/realserver.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/route.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/sockmsg.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/utility.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/virtualserver.go create mode 100644 tools/dpvs-agent/pkg/ipc/types/vlan.go create mode 100644 tools/dpvs-agent/restapi/configure_dpvs_agent.go create mode 100644 tools/dpvs-agent/restapi/doc.go create mode 100644 tools/dpvs-agent/restapi/embedded_spec.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_route.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_route_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_route_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_route_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_nic.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_nic_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_nic_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_nic_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_route.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_route_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_route_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_route_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_vlan.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/get_device_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_nic.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_nic_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_nic_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_route.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_route_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_route_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_route_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_vlan.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/dpvs_agent_api.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_parameters.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_responses.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_urlbuilder.go create mode 100644 tools/dpvs-agent/restapi/server.go diff --git a/tools/dpvs-agent/.gitignore b/tools/dpvs-agent/.gitignore new file mode 100644 index 000000000..496ec7999 --- /dev/null +++ b/tools/dpvs-agent/.gitignore @@ -0,0 +1,2 @@ +bin/ +cmd/dpvs-agent-server/dpvs-agent diff --git a/tools/dpvs-agent/Makefile b/tools/dpvs-agent/Makefile new file mode 100644 index 000000000..fb8e5ff18 --- /dev/null +++ b/tools/dpvs-agent/Makefile @@ -0,0 +1,32 @@ +MAKE = make +SUBDIRS = cmd/dpvs-agent-server +INSDIR = $(PWD)/bin +export INSDIR + +OPENAPISPEC = dpvs-agent-api.yaml + +all: + for i in $(SUBDIRS); do $(MAKE) -C $$i || exit 1; done + +clean: + for i in $(SUBDIRS); do $(MAKE) -C $$i clean || exit 1; done + +install:all + -mkdir -p $(INSDIR) + for i in $(SUBDIRS); do $(MAKE) -C $$i install || exit 1; done + +uninstall: + for i in $(SUBDIRS); do $(MAKE) -C $$i uninstall || exit 1; done + +openapi: $(OPENAPISPEC) +ifeq ($(shell swagger version),) + $(error "golang `swagger` command not found. You can install it with `go get github.com/go-swagger/go-swagger@v0.30.4`") +endif + swagger generate server -A dpvs-agent -f $< + git checkout cmd/dpvs-agent-server/main.go + +license: +ifeq ($(shell addlicense 2>&1|grep Usage),) + $(error "`addlicense` command not found. You can install it with `go install github.com/google/addlicense`") +endif + @addlicense -check -c "IQiYi Inc." -l apache -ignore dpvs/** . || /bin/true diff --git a/tools/dpvs-agent/README.md b/tools/dpvs-agent/README.md new file mode 100644 index 000000000..0c25a01d1 --- /dev/null +++ b/tools/dpvs-agent/README.md @@ -0,0 +1,4 @@ +#build +``` +swagger generate server -A dpvs-agent -f ./dpvs-agent-api.yaml +``` diff --git a/tools/dpvs-agent/cmd/device/delete_device_name_addr.go b/tools/dpvs-agent/cmd/device/delete_device_name_addr.go new file mode 100644 index 000000000..68635af05 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/delete_device_name_addr.go @@ -0,0 +1,45 @@ +package device + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delDeviceAddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelDeviceAddr(cp *pool.ConnPool, parentLogger hclog.Logger) *delDeviceAddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelDeviceAddr") + } + return &delDeviceAddr{connPool: cp, logger: logger} +} + +// dpip addr add 192.168.88.16/32 dev dpdk0.102 +func (h *delDeviceAddr) Handle(params apiDevice.DeleteDeviceNameAddrParams) middleware.Responder { + addr := types.NewInetAddrDetail() + addr.SetAddr(params.Spec.Addr) + addr.SetIfName(params.Name) + + result := addr.Del(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Delete addr from device success.", "Device Name", params.Name, "Addr", params.Spec.Addr) + return apiDevice.NewDeleteDeviceNameAddrOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("Delete a not exist addr from device done.", "Device Name", params.Name, "Addr", params.Spec.Addr, "result", result.String()) + return apiDevice.NewDeleteDeviceNameAddrOK() + default: + h.logger.Error("Delete addr from device failed.", "Device Name", params.Name, "Addr", params.Spec.Addr, "result", result.String()) + } + + return apiDevice.NewDeleteDeviceNameAddrInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/delete_device_name_netlink.go b/tools/dpvs-agent/cmd/device/delete_device_name_netlink.go new file mode 100644 index 000000000..d4fd6ba54 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/delete_device_name_netlink.go @@ -0,0 +1,49 @@ +package device + +import ( + "fmt" + + "github.com/vishvananda/netlink" + + "github.com/dpvs-agent/pkg/ipc/pool" + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +// ip link set xxx down +type setDeviceNetlinkDown struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewSetDeviceNetlinkDown(cp *pool.ConnPool, parentLogger hclog.Logger) *setDeviceNetlinkDown { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("SetDeviceNetlinkDown") + } + return &setDeviceNetlinkDown{connPool: cp, logger: logger} +} + +func (h *setDeviceNetlinkDown) Handle(params apiDevice.DeleteDeviceNameNetlinkParams) middleware.Responder { + cmd := fmt.Sprintf("ip link set %s down", params.Name) + dev, err := netlink.LinkByName(params.Name) + if err != nil { + h.logger.Error("Get iface failed.", "Name", params.Name, "Error", err.Error()) + return apiDevice.NewDeleteDeviceNameNetlinkInternalServerError() + } + + if err := netlink.LinkSetDown(dev); err != nil { + h.logger.Error("Set iface down failed.", "cmd", cmd, "Error", err.Error()) + return apiDevice.NewDeleteDeviceNameNetlinkInternalServerError() + } + + if err := netlink.LinkDel(dev); err != nil { + h.logger.Error("Delete iface failed.", "Name", params.Name, "Error", err.Error()) + return apiDevice.NewDeleteDeviceNameNetlinkInternalServerError() + } + + h.logger.Info("Set down and remove iface success.", "cmd", cmd) + return apiDevice.NewDeleteDeviceNameNetlinkOK() +} diff --git a/tools/dpvs-agent/cmd/device/delete_device_name_netlink_addr.go b/tools/dpvs-agent/cmd/device/delete_device_name_netlink_addr.go new file mode 100644 index 000000000..0ed8b943e --- /dev/null +++ b/tools/dpvs-agent/cmd/device/delete_device_name_netlink_addr.go @@ -0,0 +1,68 @@ +package device + +import ( + "fmt" + "net" + "strings" + + "github.com/vishvananda/netlink" + + "github.com/dpvs-agent/pkg/ipc/pool" + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delDeviceNetlinkAddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelDeviceNetlinkAddr(cp *pool.ConnPool, parentLogger hclog.Logger) *delDeviceNetlinkAddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelDeviceNetlinkAddr") + } + return &delDeviceNetlinkAddr{connPool: cp, logger: logger} +} + +func (h *delDeviceNetlinkAddr) Handle(params apiDevice.DeleteDeviceNameNetlinkAddrParams) middleware.Responder { + var cidr string + if strings.Count(params.Spec.Addr, "/") == 0 { + ip := net.ParseIP(params.Spec.Addr) + if ip == nil { + return apiDevice.NewDeleteDeviceNameNetlinkAddrInternalServerError() + } + + if ip.To4() != nil { + cidr = params.Spec.Addr + "/32" + } else { + cidr = params.Spec.Addr + "/128" + } + } + + ip, ipnet, err := net.ParseCIDR(cidr) + if err != nil { + return apiDevice.NewDeleteDeviceNameNetlinkAddrInternalServerError() + } + + cmd := fmt.Sprintf("ip addr del %s dev %s", cidr, params.Name) + + ipnet.IP = ip + addr := &netlink.Addr{IPNet: ipnet} + + link, err := netlink.LinkByName(params.Name) + if err != nil { + h.logger.Error("Get linux network device by name failed.", "device Name", params.Name, "Error", err.Error()) + return apiDevice.NewDeleteDeviceNameNetlinkAddrInternalServerError() + } + + if err := netlink.AddrDel(link, addr); err != nil { + h.logger.Error("linux network operation failed.", "cmd", cmd, "Error", err.Error()) + return apiDevice.NewDeleteDeviceNameNetlinkAddrInternalServerError() + } + + h.logger.Info("linux network operation success.", "cmd", cmd) + return apiDevice.NewDeleteDeviceNameNetlinkAddrOK() +} diff --git a/tools/dpvs-agent/cmd/device/delete_device_name_route.go b/tools/dpvs-agent/cmd/device/delete_device_name_route.go new file mode 100644 index 000000000..eabc0f976 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/delete_device_name_route.go @@ -0,0 +1,59 @@ +package device + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delDeviceRoute struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelDeviceRoute(cp *pool.ConnPool, parentLogger hclog.Logger) *delDeviceRoute { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelDeviceRoute") + } + return &delDeviceRoute{connPool: cp, logger: logger} +} + +// dpip del route 192.168.88.16/32 dev dpdk0.102 +func (h *delDeviceRoute) Handle(params apiDevice.DeleteDeviceNameRouteParams) middleware.Responder { + + // dest [addr], [mask] and [dev name] is useful of delete route only + route := types.NewRouteDetail() + route.SetDevice(params.Name) + if params.Spec == nil { + // FIXME: front error + return apiDevice.NewDeleteDeviceNameRouteInternalServerError() + } + + route.SetDst(params.Spec.Dst) + route.SetScope(params.Spec.Scope) + /* + route.SetSrc(params.Spec.Src) + route.SetGateway(params.Spec.Gateway) + route.SetScope(params.Spec.Scope) + route.SetMtu(params.Spec.Mtu) + route.SetMetric(params.Spec.Metric) + */ + result := route.Del(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Delete route success.", "Device Name", params.Name, "route Dst", params.Spec.Dst) + return apiDevice.NewDeleteDeviceNameRouteOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("Delete not exist route done.", "Device Name", params.Name, "route Dst", params.Spec.Dst, "result", result.String()) + return apiDevice.NewDeleteDeviceNameRouteOK() + default: + h.logger.Error("Delete route failed.", "Device Name", params.Name, "route Dst", params.Spec.Dst, "result", result.String()) + } + + return apiDevice.NewDeleteDeviceNameRouteInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/delete_device_name_vlan.go b/tools/dpvs-agent/cmd/device/delete_device_name_vlan.go new file mode 100644 index 000000000..abd2e5620 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/delete_device_name_vlan.go @@ -0,0 +1,46 @@ +package device + +import ( + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delDeviceVlan struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelDeviceVlan(cp *pool.ConnPool, parentLogger hclog.Logger) *delDeviceVlan { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelDeviceVlan") + } + return &delDeviceVlan{connPool: cp, logger: logger} +} + +// dpip vlan del dpdk0.102 +func (h *delDeviceVlan) Handle(params apiDevice.DeleteDeviceNameVlanParams) middleware.Responder { + // vlan device delete is need device name only + vlan := types.NewVlanDevice() + vlan.SetIfName(params.Name) + + result := vlan.Del(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Delete dpvs vlan success.", "Vlan Name", params.Name) + return apiDevice.NewDeleteDeviceNameVlanOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("Delete dpvs vlan done.", "Vlan Name", params.Name, "result", result.String()) + return apiDevice.NewDeleteDeviceNameVlanOK() + default: + h.logger.Error("Delete dpvs vlan failed.", "Vlan Name", params.Name, "result", result.String()) + } + + return apiDevice.NewDeleteDeviceNameVlanInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/get_device_name_nic.go b/tools/dpvs-agent/cmd/device/get_device_name_nic.go new file mode 100644 index 000000000..2cedd92a2 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/get_device_name_nic.go @@ -0,0 +1,78 @@ +package device + +import ( + "strings" + + "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type getDeviceNameNic struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewGetDeviceNameNic(cp *pool.ConnPool, parentLogger hclog.Logger) *getDeviceNameNic { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("GetDeviceNameNic") + } + return &getDeviceNameNic{connPool: cp, logger: logger} +} + +// dpip link show xxx +func (h *getDeviceNameNic) Handle(params apiDevice.GetDeviceNameNicParams) middleware.Responder { + name := make([]byte, 0x10) + copy(name[:], params.Name[:]) + + desc := types.NewNetifNicDesc() + list, err := desc.GetPortList(h.connPool, h.logger) + if err != types.EDPVS_OK { + h.logger.Info("Get netif ports failed.", "Error", err.String()) + return apiDevice.NewGetDeviceNameNicInternalServerError() + } + + h.logger.Info("Get netif port success.", "port list", list) + exist := false + specModels := new(models.NicDeviceSpecList) + specModels.Items = make([]*models.NicDeviceSpec, len(list.Entries)) + + for i, entry := range list.Entries { + specModels.Items[i] = new(models.NicDeviceSpec) + if strings.EqualFold(strings.ToLower(string(name)), strings.ToLower(entry.GetName())) { + exist = true + } + + portName := entry.GetName() + desc.SetName(portName) + detail, err := desc.GetPortBasic(h.connPool, h.logger) + if err != types.EDPVS_OK { + h.logger.Error("Get netif port base info failed.", "portName", portName, "Error", err.String()) + return apiDevice.NewGetDeviceNameNicInternalServerError() + } + h.logger.Info("Get netif port base info success.", "portName", portName, "port detail", detail) + + stats, err := desc.GetPortStats(h.connPool, h.logger) + if err != types.EDPVS_OK { + h.logger.Error("Get netif port stats info failed.", "portName", portName, "Error", err.String()) + return apiDevice.NewGetDeviceNameNicInternalServerError() + } + h.logger.Info("Get netif port stats info success.", "portName", portName, "port stats", stats) + + specModels.Items[i].Detail = detail.GetModel() + specModels.Items[i].Stats = stats.GetModel() + } + + if exist { + if *params.Stats { + } + } + + return apiDevice.NewGetDeviceNameNicOK().WithPayload(specModels) +} diff --git a/tools/dpvs-agent/cmd/device/ioctl.go b/tools/dpvs-agent/cmd/device/ioctl.go new file mode 100644 index 000000000..ab3297857 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/ioctl.go @@ -0,0 +1,23 @@ +package device + +import ( + "golang.org/x/sys/unix" +) + +func ioctl(fd int, code, data uintptr) error { + _, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), code, data) + if errno != 0 { + return errno + } + return nil +} + +type socketAddr4Request struct { + name [unix.IFNAMSIZ]byte + addr unix.RawSockaddrInet4 +} + +type socketAddr6Request struct { + name [unix.IFNAMSIZ]byte + addr unix.RawSockaddrInet6 +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_addr.go b/tools/dpvs-agent/cmd/device/put_device_name_addr.go new file mode 100644 index 000000000..03cd75c82 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_addr.go @@ -0,0 +1,57 @@ +package device + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putDeviceAddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutDeviceAddr(cp *pool.ConnPool, parentLogger hclog.Logger) *putDeviceAddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutDeviceAddr") + } + return &putDeviceAddr{connPool: cp, logger: logger} +} + +// dpip addr add 192.168.88.16/32 dev dpdk0.102 +func (h *putDeviceAddr) Handle(params apiDevice.PutDeviceNameAddrParams) middleware.Responder { + addr := types.NewInetAddrDetail() + + if params.Spec == nil { + return apiDevice.NewPutDeviceNameAddrInternalServerError() + } + + addr.SetAddr(params.Spec.Addr) + addr.SetScope(params.Spec.Scope) + addr.SetBCast(params.Spec.Broadcast) + addr.SetIfName(params.Name) + if params.Sapool != nil && *params.Sapool { + addr.SetFlags("sapool") + } + // addr.SetValidLft(prarms.Spec.ValidLft) + // addr.SetPreferedLft(prarms.Spec.ValidLft) + + result := addr.Add(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Add addr from device success.", "Device Name", params.Name, "Addr", params.Spec.Addr) + return apiDevice.NewPutDeviceNameAddrOK() + case types.EDPVS_EXIST: + h.logger.Warn("Device already exist addr, add done.", "Device Name", params.Name, "Addr", params.Spec.Addr, "result", result.String()) + return apiDevice.NewPutDeviceNameAddrOK() + default: + h.logger.Error("Add addr from device failed.", "Device Name", params.Name, "Addr", params.Spec.Addr, "result", result.String()) + } + + return apiDevice.NewPutDeviceNameAddrInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_netlink.go b/tools/dpvs-agent/cmd/device/put_device_name_netlink.go new file mode 100644 index 000000000..1a643647c --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_netlink.go @@ -0,0 +1,46 @@ +package device + +import ( + "fmt" + "syscall" + + "github.com/vishvananda/netlink" + + "github.com/dpvs-agent/pkg/ipc/pool" + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +// ip link set xxx up +type setDeviceNetlinkUp struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewSetDeviceNetlinkUp(cp *pool.ConnPool, parentLogger hclog.Logger) *setDeviceNetlinkUp { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("SetDeviceNetlinkUp") + } + return &setDeviceNetlinkUp{connPool: cp, logger: logger} +} + +func (h *setDeviceNetlinkUp) Handle(params apiDevice.PutDeviceNameNetlinkParams) middleware.Responder { + dev := &netlink.Device{LinkAttrs: netlink.LinkAttrs{MTU: 1500, Name: params.Name}} + + if err := netlink.LinkAdd(dev); err != syscall.EEXIST { + h.logger.Error("Check device isExist failed.", "Device Name", params.Name, "Error", err.Error()) + return apiDevice.NewPutDeviceNameNetlinkInternalServerError() + } + + if err := netlink.LinkSetUp(dev); err != nil { + h.logger.Error("Set device link up failed.", "Device Name", params.Name, "Error", err.Error()) + return apiDevice.NewPutDeviceNameNetlinkInternalServerError() + } + + cmd := fmt.Sprintf("ip link set %s up", params.Name) + h.logger.Info("Set device link up success.", "cmd", cmd) + return apiDevice.NewPutDeviceNameNetlinkOK() +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_netlink_addr.go b/tools/dpvs-agent/cmd/device/put_device_name_netlink_addr.go new file mode 100644 index 000000000..a114ba8fe --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_netlink_addr.go @@ -0,0 +1,72 @@ +package device + +import ( + "fmt" + "net" + "strings" + + "github.com/vishvananda/netlink" + + "github.com/dpvs-agent/pkg/ipc/pool" + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putDeviceNetlinkAddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutDeviceNetlinkAddr(cp *pool.ConnPool, parentLogger hclog.Logger) *putDeviceNetlinkAddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutDeviceNetlinkAddr") + } + return &putDeviceNetlinkAddr{connPool: cp, logger: logger} +} + +// ip addr add 10.0.0.1/32 dev eth0 +func (h *putDeviceNetlinkAddr) Handle(params apiDevice.PutDeviceNameNetlinkAddrParams) middleware.Responder { + // h.logger.Info("/v2/device/", params.Name, "/netlink/addr ", params.Spec.Addr) + var cidr string + if strings.Count(params.Spec.Addr, "/") == 0 { + ip := net.ParseIP(params.Spec.Addr) + if ip == nil { + h.logger.Info("Parse IP failed.", "Addr", params.Spec.Addr) + return apiDevice.NewPutDeviceNameNetlinkAddrInternalServerError() + } + if ip.To4() != nil { + cidr = params.Spec.Addr + "/32" + } else { + cidr = params.Spec.Addr + "/128" + } + } else { + cidr = params.Spec.Addr + } + + ip, ipnet, err := net.ParseCIDR(cidr) + if err != nil { + h.logger.Error("Parse CIDR failed.", "cidr", cidr, "Error", err.Error()) + return apiDevice.NewPutDeviceNameNetlinkAddrInternalServerError() + } + + ipnet.IP = ip + addr := &netlink.Addr{IPNet: ipnet} + + link, err := netlink.LinkByName(params.Name) + if err != nil { + h.logger.Error("netlink.LinkByName() failed.", "Device Name", params.Name, "Error", err.Error()) + return apiDevice.NewPutDeviceNameNetlinkAddrInternalServerError() + } + + if err := netlink.AddrAdd(link, addr); err != nil { + h.logger.Error("netlink.AddrAdd() failed.", "Error", err.Error()) + return apiDevice.NewPutDeviceNameNetlinkAddrInternalServerError() + } + + cmd := fmt.Sprintf("ip addr add %s dev %s", cidr, params.Name) + h.logger.Info("Device add Addr success.", "cmd", cmd) + return apiDevice.NewPutDeviceNameNetlinkAddrOK() +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_nic.go b/tools/dpvs-agent/cmd/device/put_device_name_nic.go new file mode 100644 index 000000000..419026058 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_nic.go @@ -0,0 +1,63 @@ +package device + +import ( + "fmt" + + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putDeviceNameNic struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutDeviceNameNic(cp *pool.ConnPool, parentLogger hclog.Logger) *putDeviceNameNic { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutDeviceNameNic") + } + return &putDeviceNameNic{connPool: cp, logger: logger} +} + +// ITEM [promisc|forward2kni|tc-ingress|tc-egress] / [link] +// VALUE [on|off] / [up|down] +// dpip link set nic-name $ITEM $VALUE +func (h *putDeviceNameNic) Handle(params apiDevice.PutDeviceNameNicParams) middleware.Responder { + set := false + cmd := "" + desc := types.NewNetifNicDesc() + if !set { + set = desc.SetFwd2Kni(params.Name, *params.Forward2Kni) + cmd = fmt.Sprintf("dpip link set %s %s", params.Name, params.Forward2Kni) + } + if !set { + set = desc.SetLink(params.Name, *params.Link) + cmd = fmt.Sprintf("dpip link set %s %s", params.Name, params.Link) + } + if !set { + set = desc.SetPromisc(params.Name, *params.Promisc) + cmd = fmt.Sprintf("dpip link set %s %s", params.Name, params.Promisc) + } + + if !set { + h.logger.Error("dpdk link port set failed.", "Name", params.Name) + return apiDevice.NewPutDeviceNameNicInternalServerError() + } + + result := desc.Set(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Set dpdk port success.", "cmd", cmd) + return apiDevice.NewPutDeviceNameNicOK() + default: + h.logger.Info("Set dpdk port failed.", "cmd", cmd, "result", result.String()) + } + + return apiDevice.NewPutDeviceNameNicInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_route.go b/tools/dpvs-agent/cmd/device/put_device_name_route.go new file mode 100644 index 000000000..d9ddea942 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_route.go @@ -0,0 +1,66 @@ +package device + +import ( + "fmt" + + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putDeviceRoute struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutDeviceRoute(cp *pool.ConnPool, parentLogger hclog.Logger) *putDeviceRoute { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutDeviceRoute") + } + return &putDeviceRoute{connPool: cp, logger: logger} +} + +// dpip route add 192.168.88.16/32 dev dpdk0.102 scope kni_host +func (h *putDeviceRoute) Handle(params apiDevice.PutDeviceNameRouteParams) middleware.Responder { + + // dest [addr], [mask] and [dev name] is useful of delete route only + route := types.NewRouteDetail() + route.SetDevice(params.Name) + if params.Spec == nil { + // FIXME return front invalid + return apiDevice.NewPutDeviceNameRouteInternalServerError() + } + + src := "" + route.SetDst(params.Spec.Dst) + if route.SetSrc(params.Spec.Src) { + src = fmt.Sprintf("src %s", params.Spec.Src) + } + + gateway := "" + if route.SetGateway(params.Spec.Gateway) { + gateway = fmt.Sprintf("via %s", params.Spec.Gateway) + } + route.SetScope(params.Spec.Scope) + route.SetMtu(params.Spec.Mtu) + route.SetMetric(params.Spec.Metric) + + cmd := fmt.Sprintf("dpip route add %s %s dev %s %s", params.Spec.Dst, gateway, params.Name, src) + result := route.Add(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Set dpdk route success.", "cmd", cmd) + return apiDevice.NewPutDeviceNameRouteCreated() + // case types.EDPVS_EXIST: + // FIXME: update ? return apiDevice.NewPutDeviceNameRouteOK() + default: + h.logger.Info("Set dpdk route failed.", "cmd", cmd, "result", result.String()) + } + + return apiDevice.NewPutDeviceNameRouteInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/put_device_name_vlan.go b/tools/dpvs-agent/cmd/device/put_device_name_vlan.go new file mode 100644 index 000000000..4ec011bd7 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/put_device_name_vlan.go @@ -0,0 +1,71 @@ +package device + +import ( + "fmt" + "strconv" + "strings" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putDeviceVlan struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutDeviceVlan(cp *pool.ConnPool, parentLogger hclog.Logger) *putDeviceVlan { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutDeviceVlan") + } + return &putDeviceVlan{connPool: cp, logger: logger} +} + +// dpip vlan add dpdk0.102 link dpdk0 id 102 +func (h *putDeviceVlan) Handle(params apiDevice.PutDeviceNameVlanParams) middleware.Responder { + vlanName := strings.ToLower(params.Name) + + items := strings.Split(vlanName, ".") + if len(items) != 2 { + return apiDevice.NewPutDeviceNameVlanInternalServerError() + } + + dev := params.Spec.Device + if len(dev) == 0 { + dev = items[0] + } + + id := params.Spec.ID + if len(id) == 0 { + id = items[1] + } + + cmd := fmt.Sprintf("dpip vlan add %s link %s id %s", params.Name, dev, id) + + vlan := types.NewVlanDevice() + vlan.SetIfName(vlanName) + vlan.SetRealDev(dev) + i, err := strconv.Atoi(id) + if err != nil { + return apiDevice.NewPutDeviceNameVlanInternalServerError() + } + vlan.SetId(uint16(i)) + + result := vlan.Add(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Set dpdk vlan success.", "cmd", cmd) + return apiDevice.NewDeleteDeviceNameVlanOK() + default: + h.logger.Error("Set dpdk vlan failed.", "cmd", cmd, "result", result.String()) + } + + return apiDevice.NewDeleteDeviceNameVlanInternalServerError() +} diff --git a/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux.go b/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux.go new file mode 100644 index 000000000..9e8771521 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux.go @@ -0,0 +1,25 @@ +package device + +/* +import ( + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" +) + +type putDeviceLinux struct { + connPool *pool.ConnPool +} + +func NewPutDeviceLinux(cp *pool.ConnPool) *putDeviceLinux { + return &putDeviceVlan{connPool: cp} +} + +// dpip vlan add dpdk0.102 link dpdk0 id 102 +func (h *putDeviceLinux) Handle(params apiDevice.PutDeviceNameLinuxParams) middleware.Responder { +} +*/ diff --git a/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux_addr.go b/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux_addr.go new file mode 100644 index 000000000..ce1c644e4 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_delete_device_name_linux_addr.go @@ -0,0 +1,117 @@ +package device + +/* +// SIOCDIFADDR + +import ( + "net" + "strconv" + "strings" + "unsafe" + + "golang.org/x/sys/unix" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" +) + +type deleteDeviceNameLinuxAddr struct { + connPool *pool.ConnPool +} + +func NewDeleteDeviceNameLinuxAddr(cp *pool.ConnPool) *deleteDeviceNameLinuxAddr { + return &deleteDeviceNameLinuxAddr{connPool: cp} +} + +func (h *deleteDeviceNameLinuxAddr) Handler(params *apiDevice.DeleteDeviceNameLinuxAddrParams) middleware.Responder { + if len(params.Spec.Addr) == 0 { + return apiDevice.NewDeleteDeviceNameLinuxAddrInternalServerError() + } + + items := strings.Split(params.Spec.Addr, "/") + + addr := net.ParseIP(items[0]) + if addr == nil { + return apiDevice.NewDeleteDeviceNameLinuxAddrInternalServerError() + } + + if addr.To4() != nil { + mask := 32 + if len(items) > 1 { + m, err := strconv.Atoi(items[1]) + if err == nil { + mask = m + } + } + if err := delAddr4(params.Name, addr, mask); err != nil { + return apiDevice.NewDeleteDeviceNameLinuxAddrInternalServerError() + } + } else { + mask := 128 + if len(items) > 1 { + m, err := strconv.Atoi(items[1]) + if err == nil { + mask = m + } + } + if err := setAddr6(params.Name, addr, mask); err != nil { + return apiDevice.NewDeleteDeviceNameLinuxAddrInternalServerError() + } + } + return apiDevice.NewDeleteDeviceNameLinuxAddrOK() +} + +func delAddr4(name string, ip net.IP, mask int) error { + fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0) + if err != nil { + return err + } + + defer unix.Close(fd) + sa := socketAddr4Request{} + sa.addr.Family = unix.AF_INET + copy(sa.name[:], name) + + buf, err := ip.MarshalText() + if err != nil { + return err + } + + copy(sa.addr.Addr[:], buf) + // delete address + if err := ioctl(fd, unix.SIOCDIFADDR, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + return nil +} + +func delAddr6(name string, ip net.IP, mask int) error { + fd, err := unix.Socket(unix.AF_INET6, unix.SOCK_DGRAM, 0) + if err != nil { + return err + } + + defer unix.Close(fd) + sa := socketAddr6Request{} + sa.addr.Family = unix.AF_INET6 + copy(sa.name[:], name) + + buf, err := ip.MarshalText() + if err != nil { + return err + } + + copy(sa.addr.Addr[:], buf) + // delete address + if err := ioctl(fd, unix.SIOCDIFADDR, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + return nil +} +*/ diff --git a/tools/dpvs-agent/cmd/device/todo_get_device.go b/tools/dpvs-agent/cmd/device/todo_get_device.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_get_device_name_addr.go b/tools/dpvs-agent/cmd/device/todo_get_device_name_addr.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device_name_addr.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_get_device_name_linux.go b/tools/dpvs-agent/cmd/device/todo_get_device_name_linux.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device_name_linux.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_get_device_name_linux_addr.go b/tools/dpvs-agent/cmd/device/todo_get_device_name_linux_addr.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device_name_linux_addr.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_get_device_name_route.go b/tools/dpvs-agent/cmd/device/todo_get_device_name_route.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device_name_route.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_get_device_name_vlan.go b/tools/dpvs-agent/cmd/device/todo_get_device_name_vlan.go new file mode 100644 index 000000000..76a9bfa32 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_get_device_name_vlan.go @@ -0,0 +1 @@ +package device diff --git a/tools/dpvs-agent/cmd/device/todo_put_device_name_linux.go b/tools/dpvs-agent/cmd/device/todo_put_device_name_linux.go new file mode 100644 index 000000000..a1f95a889 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_put_device_name_linux.go @@ -0,0 +1,3 @@ +package device + +// http://blog.pytool.com/language/clang/socket/linux-socket-ifreq/ diff --git a/tools/dpvs-agent/cmd/device/todo_put_device_name_linux_addr.go b/tools/dpvs-agent/cmd/device/todo_put_device_name_linux_addr.go new file mode 100644 index 000000000..b56f455b6 --- /dev/null +++ b/tools/dpvs-agent/cmd/device/todo_put_device_name_linux_addr.go @@ -0,0 +1,132 @@ +package device + +/* +import ( + "net" + "strconv" + "strings" + "unsafe" + + "golang.org/x/sys/unix" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + + apiDevice "github.com/dpvs-agent/restapi/operations/device" + + "github.com/go-openapi/runtime/middleware" +) + +// ip addr add 192.168.88.68/32 dev dpdk0.102.kni + +type putDeviceNameLinuxAddr struct { + connPool *pool.ConnPool +} + +func NewPutDeviceNameLinux(cp *pool.ConnPool) *putDeviceNameLinuxAddr { + return &putDeviceNameLinuxAddr{connPool: cp} +} + +func (h *putDeviceNameLinuxAddr) Handler(params *apiDevice.PutDeviceNameLinuxAddrParams) middleware.Responder { + if len(params.Spec.Addr) == 0 { + return apiDevice.NewPutDeviceNameLinuxAddrInternalServerError() + } + + items := strings.Split(params.Spec.Addr, "/") + + addr := net.ParseIP(items[0]) + if addr == nil { + return apiDevice.NewPutDeviceNameLinuxAddrInternalServerError() + } + + if addr.To4() != nil { + mask := 32 + if len(items) > 1 { + m, err := strconv.Atoi(items[1]) + if err == nil { + mask = m + } + } + if err := setAddr4(params.Name, addr, mask); err != nil { + return apiDevice.NewPutDeviceNameLinuxAddrInternalServerError() + } + } else { + mask := 128 + if len(items) > 1 { + m, err := strconv.Atoi(items[1]) + if err == nil { + mask = m + } + } + if err := setAddr6(params.Name, addr, mask); err != nil { + return apiDevice.NewPutDeviceNameLinuxAddrInternalServerError() + } + } + + return apiDevice.NewPutDeviceNameLinuxAddrOK() +} + +func setAddr4(name string, ip net.IP, mask int) error { + fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0) + if err != nil { + return err + } + + defer unix.Close(fd) + sa := socketAddr4Request{} + sa.addr.Family = unix.AF_INET + copy(sa.name[:], name) + + buf, err := ip.MarshalText() + if err != nil { + return err + } + + copy(sa.addr.Addr[:], buf) + // Set address + if err := ioctl(fd, unix.SIOCSIFADDR, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + // Set netmask + mbuf := net.CIDRMask(mask, 32) + copy(sa.addr.Addr[:], []byte(mbuf)) + if err := ioctl(fd, unix.SIOCSIFNETMASK, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + return nil +} + +func setAddr6(name string, ip net.IP, mask int) error { + fd, err := unix.Socket(unix.AF_INET6, unix.SOCK_DGRAM, 0) + if err != nil { + return err + } + + defer unix.Close(fd) + sa := socketAddr6Request{} + sa.addr.Family = unix.AF_INET6 + copy(sa.name[:], name) + + buf, err := ip.MarshalText() + if err != nil { + return err + } + + copy(sa.addr.Addr[:], buf) + // Set address + if err := ioctl(fd, unix.SIOCSIFADDR, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + // Set netmask + mbuf := net.CIDRMask(mask, 128) + copy(sa.addr.Addr[:], []byte(mbuf)) + if err := ioctl(fd, unix.SIOCSIFNETMASK, uintptr(unsafe.Pointer(&sa))); err != nil { + return err + } + + return nil +} +*/ diff --git a/tools/dpvs-agent/cmd/dpvs-agent-server/Makefile b/tools/dpvs-agent/cmd/dpvs-agent-server/Makefile new file mode 100644 index 000000000..9ba2dd914 --- /dev/null +++ b/tools/dpvs-agent/cmd/dpvs-agent-server/Makefile @@ -0,0 +1,26 @@ +TARGET := dpvs-agent + +GO ?= go +LD_FLAGS = -ldflags="-s -w" +GO_BUILD = CGO_ENABLED=0 $(GO) build $(LD_FLAGS) +GO_CLEAN = $(GO) clean +INSTALL = install +RM = rm + +.PHONY: all $(TARGET) clean install + +all: $(TARGET) + +$(TARGET): + $(GO_BUILD) -o $@ + +clean: + $(GO_CLEAN) + -$(RM) $(TARGET) + +install: $(TARGET) + $(INSTALL) -m 0755 -d $(INSDIR) + $(INSTALL) -m 0744 $(TARGET) $(INSDIR) + +uninstall: + -$(RM) -f $(TARGET) $(INSDIR)/$(TARGET) diff --git a/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go b/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go new file mode 100644 index 000000000..f4d5393e9 --- /dev/null +++ b/tools/dpvs-agent/cmd/dpvs-agent-server/api_init.go @@ -0,0 +1,181 @@ +package main + +import ( + "context" + "errors" + "net" + "os" + "strings" + "time" + + "github.com/hashicorp/go-hclog" + "github.com/lestrrat-go/file-rotatelogs" + + "github.com/dpvs-agent/cmd/device" + "github.com/dpvs-agent/cmd/ipvs" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/restapi" + "github.com/dpvs-agent/restapi/operations" +) + +var ( + IpcSocket string = "/var/run/dpvs.ipc" +) + +type DpvsAgentServer struct { + LogDir string `long:"log-dir" description:"default log dir is /var/log/ And log name dpvs-agent.log" default:"/var/log/"` + IpcSocketPath string `long:"ipc-sockopt-path" description:"default ipc socket path /var/run/dpvs.ipc" default:"/var/run/dpvs.ipc"` + restapi.Server +} + +func unixDialer(ctx context.Context) (net.Conn, error) { + retry := 0 + d := net.Dialer{Timeout: 10 * time.Second} + raddr := net.UnixAddr{Name: "/var/run/dpvs.ipc", Net: "unix"} + for { + conn, err := d.DialContext(ctx, "unix", raddr.String()) + if err == nil { + return conn, nil + } + // FIXME: A weird fact was observed in tests of large concurrency that the previous + // "DailContext" returned the error "resource temporarily unavailable" occasionally. + // No solution to it has found yet, thus just retry as a compromise. + if strings.Contains(err.Error(), "resource temporarily unavailable") != true { + return nil, err + } + retry++ + if retry > 10 { + return nil, err + } + } + return nil, errors.New("unknown error") +} + +func (agent *DpvsAgentServer) instantiateAPI(restAPI *operations.DpvsAgentAPI) { + if strings.HasSuffix(agent.IpcSocketPath, ".ipc") { + s, err := os.Stat(agent.IpcSocketPath) + if err == nil { + if !s.IsDir() { + IpcSocket = agent.IpcSocketPath + } + } + } + + cp := pool.NewConnPool(&pool.Options{ + Dialer: unixDialer, + PoolSize: 1024, + // PoolTimeout: -1, + // IdleTimeout: -1, + // IdleCheckFrequency: -1, + }) + + logDir := "/var/log/" + if len(agent.LogDir) > 1 { // avoid root path '/' set + s, err := os.Stat(agent.LogDir) + if err == nil { + if s.IsDir() { + logDir = agent.LogDir + } + } + } + + sep := "/" + if strings.HasSuffix(logDir, "/") { + sep = "" + } + + logFile := strings.Join([]string{logDir, "dpvs-agent.log"}, sep) + // logOpt := &hclog.LoggerOptions{Name: logFile} + var logOpt *hclog.LoggerOptions + logFileNamePattern := strings.Join([]string{logFile, "%Y%m%d%H%M"}, "-") + logRotationInterval := 1 * time.Hour + + logF, err := rotatelogs.New( + logFileNamePattern, + rotatelogs.WithLinkName(logFile), + rotatelogs.WithRotationTime(logRotationInterval), + ) + // f, err := os.Create(logFile) + if err == nil { + logOpt = &hclog.LoggerOptions{Name: logFile, Output: logF} + } else { + os.Exit(-1) + } + + hclog.SetDefault(hclog.New(logOpt)) + + logger := hclog.Default().Named("main") + + // delete + restAPI.VirtualserverDeleteVsVipPortHandler = ipvs.NewDelVsItem(cp, logger) + restAPI.VirtualserverDeleteVsVipPortLaddrHandler = ipvs.NewDelVsLaddr(cp, logger) + restAPI.VirtualserverDeleteVsVipPortRsHandler = ipvs.NewDelVsRs(cp, logger) + restAPI.VirtualserverDeleteVsVipPortDenyHandler = ipvs.NewDelVsDeny(cp, logger) + restAPI.VirtualserverDeleteVsVipPortAllowHandler = ipvs.NewDelVsAllow(cp, logger) + + // get + restAPI.VirtualserverGetVsHandler = ipvs.NewGetVs(cp, logger) + restAPI.VirtualserverGetVsVipPortHandler = ipvs.NewGetVsVipPort(cp, logger) + restAPI.VirtualserverGetVsVipPortLaddrHandler = ipvs.NewGetVsLaddr(cp, logger) + + // put + restAPI.VirtualserverPutVsVipPortHandler = ipvs.NewPutVsItem(cp, logger) + restAPI.VirtualserverPutVsVipPortLaddrHandler = ipvs.NewPutVsLaddr(cp, logger) + restAPI.VirtualserverPutVsVipPortRsHandler = ipvs.NewPutVsRs(cp, logger) + restAPI.VirtualserverPutVsVipPortDenyHandler = ipvs.NewPutVsDeny(cp, logger) + restAPI.VirtualserverPutVsVipPortAllowHandler = ipvs.NewPutVsAllow(cp, logger) + + // post + restAPI.VirtualserverPostVsVipPortRsHandler = ipvs.NewPostVsRs(cp, logger) + + // get + // restAPI.DeviceGetDeviceNameAddrHandler + // restAPI.DeviceGetDeviceNameRouteHandler + // restAPI.DeviceGetDeviceNameVlanHandler + restAPI.DeviceGetDeviceNameNicHandler = device.NewGetDeviceNameNic(cp, logger) + + // put + restAPI.DevicePutDeviceNameNetlinkHandler = device.NewSetDeviceNetlinkUp(cp, logger) + restAPI.DevicePutDeviceNameAddrHandler = device.NewPutDeviceAddr(cp, logger) + restAPI.DevicePutDeviceNameRouteHandler = device.NewPutDeviceRoute(cp, logger) + restAPI.DevicePutDeviceNameVlanHandler = device.NewPutDeviceVlan(cp, logger) + restAPI.DevicePutDeviceNameNetlinkAddrHandler = device.NewPutDeviceNetlinkAddr(cp, logger) + restAPI.DevicePutDeviceNameNicHandler = device.NewPutDeviceNameNic(cp, logger) + + // delete + restAPI.DeviceDeleteDeviceNameAddrHandler = device.NewDelDeviceAddr(cp, logger) + restAPI.DeviceDeleteDeviceNameRouteHandler = device.NewDelDeviceRoute(cp, logger) + restAPI.DeviceDeleteDeviceNameVlanHandler = device.NewDelDeviceVlan(cp, logger) + restAPI.DeviceDeleteDeviceNameNetlinkAddrHandler = device.NewDelDeviceNetlinkAddr(cp, logger) +} + +func (agent *DpvsAgentServer) InstantiateServer(api *operations.DpvsAgentAPI) *restapi.Server { + agent.instantiateAPI(api) + + server := restapi.NewServer(api) + server.ConfigureAPI() + + server.EnabledListeners = make([]string, len(agent.EnabledListeners)) + copy(server.EnabledListeners, agent.EnabledListeners) + server.CleanupTimeout = agent.CleanupTimeout + server.GracefulTimeout = agent.GracefulTimeout + server.MaxHeaderSize = agent.MaxHeaderSize + server.SocketPath = agent.SocketPath + server.Host = agent.Host + server.Port = agent.Port + server.ListenLimit = agent.ListenLimit + server.KeepAlive = agent.KeepAlive + server.ReadTimeout = agent.ReadTimeout + server.WriteTimeout = agent.WriteTimeout + server.TLSHost = agent.TLSHost + server.TLSPort = agent.TLSPort + server.TLSCertificate = agent.TLSCertificate + server.TLSCertificateKey = agent.TLSCertificateKey + server.TLSCACertificate = agent.TLSCACertificate + server.TLSListenLimit = agent.TLSListenLimit + server.TLSKeepAlive = agent.TLSKeepAlive + server.TLSReadTimeout = agent.TLSReadTimeout + server.TLSWriteTimeout = agent.TLSWriteTimeout + + return server +} diff --git a/tools/dpvs-agent/cmd/dpvs-agent-server/main.go b/tools/dpvs-agent/cmd/dpvs-agent-server/main.go new file mode 100644 index 000000000..11912e77e --- /dev/null +++ b/tools/dpvs-agent/cmd/dpvs-agent-server/main.go @@ -0,0 +1,55 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package main + +import ( + "log" + "os" + + "github.com/go-openapi/loads" + flags "github.com/jessevdk/go-flags" + + "github.com/dpvs-agent/restapi" + "github.com/dpvs-agent/restapi/operations" +) + +// This file was generated by the swagger tool. +// Make sure not to overwrite this file after you generated it because all your edits would be lost! +func main() { + swaggerSpec, err := loads.Embedded(restapi.SwaggerJSON, restapi.FlatSwaggerJSON) + if err != nil { + log.Fatalln(err) + } + + api := operations.NewDpvsAgentAPI(swaggerSpec) + + agent := &DpvsAgentServer{} + + parser := flags.NewParser(agent, flags.Default) + parser.ShortDescription = "dpvs agent" + parser.LongDescription = "dpvs agent api" + for _, optsGroup := range api.CommandLineOptionsGroups { + _, err := parser.AddGroup(optsGroup.ShortDescription, optsGroup.LongDescription, optsGroup.Options) + if err != nil { + log.Fatalln(err) + } + } + + if _, err := parser.Parse(); err != nil { + code := 1 + if fe, ok := err.(*flags.Error); ok { + if fe.Type == flags.ErrHelp { + code = 0 + } + } + os.Exit(code) + } + + server := agent.InstantiateServer(api) + defer server.Shutdown() + + if err := server.Serve(); err != nil { + log.Fatalln(err) + } + +} diff --git a/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port.go b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port.go new file mode 100644 index 000000000..f9c4a645c --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port.go @@ -0,0 +1,45 @@ +package ipvs + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delVsItem struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelVsItem(cp *pool.ConnPool, parentLogger hclog.Logger) *delVsItem { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelVsVipPort") + } + return &delVsItem{connPool: cp, logger: logger} +} + +func (h *delVsItem) Handle(params apiVs.DeleteVsVipPortParams) middleware.Responder { + vs := types.NewVirtualServerSpec() + if err := vs.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewDeleteVsVipPortFailure() + } + + result := vs.Del(h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Del virtual server success.", "VipPort", params.VipPort) + return apiVs.NewDeleteVsVipPortOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("Del a not exist virtual server done.", "VipPort", params.VipPort, "result", result.String()) + return apiVs.NewDeleteVsVipPortNotFound() + default: + h.logger.Error("Del virtual server failed.", "VipPort", params.VipPort, "result", result.String()) + } + return apiVs.NewDeleteVsVipPortFailure() +} diff --git a/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_allow.go b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_allow.go new file mode 100644 index 000000000..0d8678f2b --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_allow.go @@ -0,0 +1,56 @@ +package ipvs + +import ( + "net" + + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delVsAllow struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelVsAllow(cp *pool.ConnPool, parentLogger hclog.Logger) *delVsAllow { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelVsVipPortAllow") + } + return &delVsAllow{connPool: cp, logger: logger} +} + +func (h *delVsAllow) Handle(params apiVs.DeleteVsVipPortAllowParams) middleware.Responder { + spec := types.NewCertificateAuthoritySpec() + if err := spec.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewDeleteVsVipPortAllowInvalidFrontend() + } + + failed := false + for _, allow := range params.ACL.Items { + if net.ParseIP(allow.Addr) == nil { + h.logger.Error("Invalid ip addr del.", "VipPort", params.VipPort, "Addr", allow.Addr) + return apiVs.NewDeleteVsVipPortAllowInvalidFrontend() + } + spec.SetSrc(allow.Addr) + + if result := spec.Del(h.connPool, false, h.logger); result != types.EDPVS_OK { + failed = true + h.logger.Error("IP Addr delete from white list failed.", "VipPort", params.VipPort, "Addr", allow.Addr, "result", result.String()) + continue + } + h.logger.Info("IP Addr delete from white list success.", "VipPort", params.VipPort, "Addr", allow.Addr) + } + + if failed { + return apiVs.NewDeleteVsVipPortAllowInvalidBackend() + } + + return apiVs.NewDeleteVsVipPortAllowOK() +} diff --git a/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_deny.go b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_deny.go new file mode 100644 index 000000000..1352386d8 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_deny.go @@ -0,0 +1,56 @@ +package ipvs + +import ( + "net" + + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delVsDeny struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelVsDeny(cp *pool.ConnPool, parentLogger hclog.Logger) *delVsDeny { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelVsVipPortDeny") + } + return &delVsDeny{connPool: cp, logger: logger} +} + +func (h *delVsDeny) Handle(params apiVs.DeleteVsVipPortDenyParams) middleware.Responder { + spec := types.NewCertificateAuthoritySpec() + if err := spec.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewDeleteVsVipPortDenyInvalidFrontend() + } + + failed := false + for _, deny := range params.ACL.Items { + if net.ParseIP(deny.Addr) == nil { + h.logger.Error("Invalid ip addr del.", "VipPort", params.VipPort, "Addr", deny.Addr) + return apiVs.NewDeleteVsVipPortDenyInvalidFrontend() + } + spec.SetSrc(deny.Addr) + + if result := spec.Del(h.connPool, true, h.logger); result != types.EDPVS_OK { + h.logger.Error("IP Addr delete from black list failed.", "VipPort", params.VipPort, "Addr", deny.Addr, "result", result.String()) + failed = true + continue + } + h.logger.Info("IP Addr delete from black list success.", "VipPort", params.VipPort, "Addr", deny.Addr) + } + + if failed { + return apiVs.NewDeleteVsVipPortDenyInvalidBackend() + } + + return apiVs.NewDeleteVsVipPortDenyOK() +} diff --git a/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_laddr.go b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_laddr.go new file mode 100644 index 000000000..4780c7424 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_laddr.go @@ -0,0 +1,52 @@ +package ipvs + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delVsLaddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelVsLaddr(cp *pool.ConnPool, parentLogger hclog.Logger) *delVsLaddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelVsVipPortLaddr") + } + return &delVsLaddr{connPool: cp, logger: logger} +} + +func (h *delVsLaddr) Handle(params apiVs.DeleteVsVipPortLaddrParams) middleware.Responder { + laddr := types.NewLocalAddrFront() + if err := laddr.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewDeleteVsVipPortLaddrInvalidFrontend() + } + + lds := make([]*types.LocalAddrDetail, 1) + lds[0] = types.NewLocalAddrDetail() + lds[0].SetAfByAddr(params.Spec.Addr) + lds[0].SetAddr(params.Spec.Addr) + lds[0].SetIfName(params.Spec.Device) + + result := laddr.Del(lds, h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Delete local ip from virtual server success.", "VipPort", params.VipPort, "Addr", params.Spec.Addr, "Device", params.Spec.Device) + return apiVs.NewDeleteVsVipPortLaddrOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("Delete not exist local ip from virtual server done.", "VipPort", params.VipPort, "Addr", params.Spec.Addr, "Device", params.Spec.Device) + return apiVs.NewDeleteVsVipPortLaddrOK() + default: + h.logger.Error("Delete local ip from virtual server failed.", "VipPort", params.VipPort, "Addr", params.Spec.Addr, "Device", params.Spec.Device, "result", result.String()) + } + + return apiVs.NewDeleteVsVipPortLaddrFailure() +} diff --git a/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_rs.go b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_rs.go new file mode 100644 index 000000000..222635645 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/delete_vs_vip_port_rs.go @@ -0,0 +1,56 @@ +package ipvs + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type delVsRs struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewDelVsRs(cp *pool.ConnPool, parentLogger hclog.Logger) *delVsRs { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("DelVsVipPortRs") + } + return &delVsRs{connPool: cp, logger: logger} +} + +func (h *delVsRs) Handle(params apiVs.DeleteVsVipPortRsParams) middleware.Responder { + rs := types.NewRealServerFront() + if err := rs.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewDeleteVsVipPortRsInvalidFrontend() + } + + rss := make([]*types.RealServerSpec, len(params.Rss.Items)) + for i, s := range params.Rss.Items { + rss[i] = types.NewRealServerSpec() + rss[i].SetAf(rs.GetAf()) + rss[i].SetProto(rs.GetProto()) + rss[i].SetPort(s.Port) + rss[i].SetAddr(s.IP) + rss[i].SetWeight(uint32(s.Weight)) + // rss[i].SetConnFlags(types.DPVS_FWD_MODE_FNAT) + } + result := rs.Del(rss, h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Del rs from virtual server success.", "VipPort", params.VipPort, "rss", rss) + return apiVs.NewDeleteVsVipPortRsOK() + case types.EDPVS_NOTEXIST: + h.logger.Warn("There is some not exist rs with virtual server delete done.", "VipPort", params.VipPort, "rss", rss) + return apiVs.NewDeleteVsVipPortRsOK() + default: + h.logger.Error("Del rs from virtual server failed.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + } + + return apiVs.NewDeleteVsVipPortRsFailure() +} diff --git a/tools/dpvs-agent/cmd/ipvs/get_vs.go b/tools/dpvs-agent/cmd/ipvs/get_vs.go new file mode 100644 index 000000000..a6d8c1025 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/get_vs.go @@ -0,0 +1,71 @@ +package ipvs + +import ( + "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type getVs struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewGetVs(cp *pool.ConnPool, parentLogger hclog.Logger) *getVs { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("GetVs") + } + return &getVs{connPool: cp, logger: logger} +} + +func (h *getVs) Handle(params apiVs.GetVsParams) middleware.Responder { + front := types.NewVirtualServerFront() + vss, err := front.Get(h.connPool, h.logger) + if err != nil { + h.logger.Error("Get virtual server list failed.", "Error", err.Error()) + // FIXME: Invalid + return apiVs.NewGetVsOK() + } + + h.logger.Info("Get all virtual server done.", "vss", vss) + vsModels := new(models.VirtualServerList) + vsModels.Items = make([]*models.VirtualServerSpecExpand, len(vss)) + for i, vs := range vss { + front := types.NewRealServerFront() + + err := front.ParseVipPortProto(vs.ID()) + if err != nil { + h.logger.Error("Convert to virtual server failed. virtual server", "ID", vs.ID(), "Error", err.Error()) + continue + } + front.SetNumDests(vs.GetNumDests()) + + rss, err := front.Get(h.connPool, h.logger) + if err != nil { + h.logger.Error("Get real server list of virtual server failed.", "ID", vs.ID(), "Error", err.Error()) + continue + } + + h.logger.Info("Get real server list of virtual server success.", "ID", vs.ID(), "rss", rss) + + vsModels.Items[i] = vs.GetModel() + vsStats := (*types.ServerStats)(vsModels.Items[i].Stats) + vsModels.Items[i].RSs = new(models.RealServerExpandList) + vsModels.Items[i].RSs.Items = make([]*models.RealServerSpecExpand, len(rss)) + + for j, rs := range rss { + rsModel := rs.GetModel() + rsStats := (*types.ServerStats)(rsModel.Stats) + vsModels.Items[i].RSs.Items[j] = rsModel + vsStats.Increase(rsStats) + } + } + + return apiVs.NewGetVsOK().WithPayload(vsModels) +} diff --git a/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port.go b/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port.go new file mode 100644 index 000000000..873e6d533 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port.go @@ -0,0 +1,79 @@ +package ipvs + +import ( + "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type getVsVipPort struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewGetVsVipPort(cp *pool.ConnPool, parentLogger hclog.Logger) *getVsVipPort { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("GetVsVipPort") + } + return &getVsVipPort{connPool: cp, logger: logger} +} + +func (h *getVsVipPort) Handle(params apiVs.GetVsVipPortParams) middleware.Responder { + var vss []*types.VirtualServerSpec + spec := types.NewVirtualServerSpec() + err := spec.ParseVipPortProto(params.VipPort) + if err != nil { + h.logger.Warn("Convert to virtual server failed. Get All virtual server.", "VipPort", params.VipPort, "Error", err.Error()) + front := types.NewVirtualServerFront() + vss, err = front.Get(h.connPool, h.logger) + } else { + vss, err = spec.Get(h.connPool, h.logger) + } + + if err != nil { + h.logger.Error("Get virtual server list failed.", "Error", err.Error()) + return apiVs.NewGetVsVipPortNotFound() + } + + vsModels := new(models.VirtualServerList) + vsModels.Items = make([]*models.VirtualServerSpecExpand, len(vss)) + + for i, vs := range vss { + front := types.NewRealServerFront() + + err := front.ParseVipPortProto(vs.ID()) + if err != nil { + h.logger.Error("Convert to virtual server failed. virtual server", "ID", vs.ID(), "Error", err.Error()) + continue + } + front.SetNumDests(vs.GetNumDests()) + + rss, err := front.Get(h.connPool, h.logger) + if err != nil { + h.logger.Error("Get real server list of virtual server failed.", "ID", vs.ID(), "Error", err.Error()) + continue + } + + h.logger.Info("Get real server list of virtual server success.", "ID", vs.ID(), "rss", rss) + + vsModels.Items[i] = vs.GetModel() + vsStats := (*types.ServerStats)(vsModels.Items[i].Stats) + vsModels.Items[i].RSs = new(models.RealServerExpandList) + vsModels.Items[i].RSs.Items = make([]*models.RealServerSpecExpand, len(rss)) + + for j, rs := range rss { + rsModel := rs.GetModel() + rsStats := (*types.ServerStats)(rsModel.Stats) + vsModels.Items[i].RSs.Items[j] = rsModel + vsStats.Increase(rsStats) + } + } + + return apiVs.NewGetVsVipPortOK().WithPayload(vsModels) +} diff --git a/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port_laddr.go b/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port_laddr.go new file mode 100644 index 000000000..adac60936 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/get_vs_vip_port_laddr.go @@ -0,0 +1,50 @@ +package ipvs + +import ( + "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type getVsLaddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewGetVsLaddr(cp *pool.ConnPool, parentLogger hclog.Logger) *getVsLaddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("GetVsVipPortLaddr") + } + return &getVsLaddr{connPool: cp, logger: logger} +} + +func (h *getVsLaddr) Handle(params apiVs.GetVsVipPortLaddrParams) middleware.Responder { + laddr := types.NewLocalAddrFront() + if err := laddr.ParseVipPortProto(params.VipPort); err != nil { + // FIXME: return all laddr + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewGetVsVipPortLaddrNotFound() + } + + lds, err := laddr.Get(h.connPool, h.logger) + if err != nil { + h.logger.Error("Get virtual server laddr failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewGetVsVipPortLaddrNotFound() + } + + h.logger.Info("Get virtual server laddr success.", "VipPort", params.VipPort, "local addr details", "lds", lds) + laddrModels := new(models.LocalAddressExpandList) + laddrModels.Items = make([]*models.LocalAddressSpecExpand, len(lds)) + for i, detail := range lds { + h.logger.Info("Virtual Server", "VipPort", params.VipPort, "detail", detail) + laddrModels.Items[i] = detail.GetModel() + } + + return apiVs.NewGetVsVipPortLaddrOK().WithPayload(laddrModels) +} diff --git a/tools/dpvs-agent/cmd/ipvs/post_vs_vip_port_rs.go b/tools/dpvs-agent/cmd/ipvs/post_vs_vip_port_rs.go new file mode 100644 index 000000000..4f577cca0 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/post_vs_vip_port_rs.go @@ -0,0 +1,59 @@ +package ipvs + +import ( + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type postVsRs struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPostVsRs(cp *pool.ConnPool, parentLogger hclog.Logger) *postVsRs { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PostVsVipPortRs") + } + return &postVsRs{connPool: cp, logger: logger} +} + +func (h *postVsRs) Handle(params apiVs.PostVsVipPortRsParams) middleware.Responder { + front := types.NewRealServerFront() + if err := front.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPostVsVipPortRsInvalidFrontend() + } + + rss := make([]*types.RealServerSpec, len(params.Rss.Items)) + for i, rs := range params.Rss.Items { + var fwdmode types.DpvsFwdMode + fwdmode.FromString(rs.Mode) + rss[i] = types.NewRealServerSpec() + rss[i].SetAf(front.GetAf()) + rss[i].SetPort(rs.Port) + rss[i].SetWeight(uint32(rs.Weight)) + rss[i].SetProto(front.GetProto()) + rss[i].SetAddr(rs.IP) + rss[i].SetInhibited(rs.Inhibited) + rss[i].SetOverloaded(rs.Inhibited) + rss[i].SetFwdMode(fwdmode) + } + + result := front.Update(rss, h.connPool, h.logger) + switch result { + case types.EDPVS_EXIST, types.EDPVS_OK: + h.logger.Info("Set real server to virtual server success.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + return apiVs.NewPostVsVipPortRsOK() + default: + h.logger.Error("Set real server to virtual server failed.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + return apiVs.NewPostVsVipPortRsFailure() + } + return apiVs.NewPostVsVipPortRsInvalidBackend() +} diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go new file mode 100644 index 000000000..c6c09f285 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port.go @@ -0,0 +1,96 @@ +package ipvs + +import ( + "strings" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + "golang.org/x/sys/unix" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putVsItem struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutVsItem(cp *pool.ConnPool, parentLogger hclog.Logger) *putVsItem { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutVsVipPort") + } + return &putVsItem{connPool: cp, logger: logger} +} + +// ipvsadm -A vip:port -s wrr +func (h *putVsItem) Handle(params apiVs.PutVsVipPortParams) middleware.Responder { + vs := types.NewVirtualServerSpec() + err := vs.ParseVipPortProto(params.VipPort) + if err != nil { + h.logger.Error("Convert to virtual server failed", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPutVsVipPortInvalidFrontend() + } + + schedName := "" + + if params.Spec != nil { + schedName = params.Spec.SchedName + + vs.SetFwmark(params.Spec.Fwmark) + vs.SetConnTimeout(params.Spec.ConnTimeout) // establish time out + vs.SetBps(params.Spec.Bps) + vs.SetLimitProportion(params.Spec.LimitProportion) + + if params.Spec.Timeout != 0 { + vs.SetTimeout(params.Spec.Timeout) // persistence time out + vs.SetFlagsPersistent() + } + + if params.Spec.ExpireQuiescent != nil && *params.Spec.ExpireQuiescent { + vs.SetFlagsExpireQuiescent() + } + + if params.Spec.SyncProxy != nil && *params.Spec.SyncProxy { + vs.SetFlagsSyncProxy() + } + } + + vs.SetSchedName(schedName) + if strings.EqualFold(vs.GetSchedName(), "conhash") { + vs.SetFlagsHashSrcIP() + + if vs.GetProto() == unix.IPPROTO_UDP { + // if strings.EqualFold(strings.ToLower(params.Spec.HashTaget), "qid") {vs.SetFlagsHashQuicID()} + } + } + + result := vs.Add(h.connPool, h.logger) + h.logger.Info("Add virtual server done.", "vs", vs, "result", result.String()) + switch result { + case types.EDPVS_OK: + // return 201 + h.logger.Info("Created new virtual server success.", "VipPort", params.VipPort) + return apiVs.NewPutVsVipPortCreated() + case types.EDPVS_EXIST: + h.logger.Info("The virtual server already exist! Try to update.", "VipPort", params.VipPort) + reason := vs.Update(h.connPool, h.logger) + if reason != types.EDPVS_OK { + // return 461 + h.logger.Error("Update virtual server failed.", "VipPort", params.VipPort, "reason", reason.String()) + return apiVs.NewPutVsVipPortInvalidBackend() + } + h.logger.Info("Update virtual server success.", "VipPort", params.VipPort) + // return 200 + return apiVs.NewPutVsVipPortOK() + default: + h.logger.Error("Add virtual server failed.", "result", result.String()) + return apiVs.NewPutVsVipPortInvalidBackend() + } + + return apiVs.NewPutVsVipPortOK() +} diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_allow.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_allow.go new file mode 100644 index 000000000..dabcc000b --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_allow.go @@ -0,0 +1,58 @@ +package ipvs + +import ( + // "fmt" + "net" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putVsAllow struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutVsAllow(cp *pool.ConnPool, parentLogger hclog.Logger) *putVsAllow { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutVsVipPortAllow") + } + return &putVsAllow{connPool: cp, logger: logger} +} + +func (h *putVsAllow) Handle(params apiVs.PutVsVipPortAllowParams) middleware.Responder { + spec := types.NewCertificateAuthoritySpec() + if err := spec.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPutVsVipPortAllowInvalidFrontend() + } + + failed := false + for _, allow := range params.ACL.Items { + if net.ParseIP(allow.Addr) == nil { + h.logger.Error("Invalid ip addr add.", "VipPort", params.VipPort, "Addr", allow.Addr) + return apiVs.NewPutVsVipPortAllowInvalidFrontend() + } + spec.SetSrc(allow.Addr) + + if result := spec.Add(h.connPool, false, h.logger); result != types.EDPVS_OK { + failed = true + h.logger.Error("Add ip addr to white list failed.", "VipPort", params.VipPort, "Addr", allow.Addr, "result", result.String()) + continue + } + h.logger.Info("Add ip addr to white list success.", "VipPort", params.VipPort, "Addr", allow.Addr) + } + + if failed { + return apiVs.NewPutVsVipPortAllowInvalidBackend() + } + + return apiVs.NewPutVsVipPortAllowOK() +} diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_deny.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_deny.go new file mode 100644 index 000000000..984dff17a --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_deny.go @@ -0,0 +1,58 @@ +package ipvs + +import ( + // "fmt" + "net" + + // "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putVsDeny struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutVsDeny(cp *pool.ConnPool, parentLogger hclog.Logger) *putVsDeny { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutVsVipPortDeny") + } + return &putVsDeny{connPool: cp, logger: logger} +} + +func (h *putVsDeny) Handle(params apiVs.PutVsVipPortDenyParams) middleware.Responder { + spec := types.NewCertificateAuthoritySpec() + if err := spec.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPutVsVipPortDenyInvalidFrontend() + } + + failed := false + for _, deny := range params.ACL.Items { + if net.ParseIP(deny.Addr) == nil { + h.logger.Error("Invalid ip addr add.", "VipPort", params.VipPort, "Addr", deny.Addr) + return apiVs.NewPutVsVipPortDenyInvalidFrontend() + } + spec.SetSrc(deny.Addr) + + if result := spec.Add(h.connPool, true, h.logger); result != types.EDPVS_OK { + h.logger.Error("Add ip addr to black list failed.", "VipPort", params.VipPort, "Addr", deny.Addr, "result", result.String()) + failed = true + continue + } + h.logger.Info("Add ip addr to black list success.", "VipPort", params.VipPort, "Addr", deny.Addr) + } + + if failed { + return apiVs.NewPutVsVipPortDenyInvalidBackend() + } + + return apiVs.NewPutVsVipPortDenyOK() +} diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go new file mode 100644 index 000000000..6551abea3 --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_laddr.go @@ -0,0 +1,55 @@ +package ipvs + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putVsLaddr struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutVsLaddr(cp *pool.ConnPool, parentLogger hclog.Logger) *putVsLaddr { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutVsVipPortLaddr") + } + return &putVsLaddr{connPool: cp, logger: logger} +} + +func (h *putVsLaddr) Handle(params apiVs.PutVsVipPortLaddrParams) middleware.Responder { + laddr := types.NewLocalAddrFront() + + err := laddr.ParseVipPortProto(params.VipPort) + if err != nil { + h.logger.Error("Convert to virtual server failed.", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPutVsVipPortLaddrInvalidFrontend() + } + + lds := make([]*types.LocalAddrDetail, 1) + + lds[0] = types.NewLocalAddrDetail() + lds[0].SetAf(laddr.GetAf()) + lds[0].SetAddr(params.Spec.Addr) + lds[0].SetIfName(params.Spec.Device) + + result := laddr.Add(lds, h.connPool, h.logger) + switch result { + case types.EDPVS_OK: + h.logger.Info("Set virtual server Local IP success.", "VipPort", params.VipPort, "Local Addr", params.Spec.Addr) + return apiVs.NewPutVsVipPortLaddrOK() + case types.EDPVS_EXIST: + h.logger.Warn("Local IP already exist.", "VipPort", params.VipPort, "Local Addr", params.Spec.Addr, "result", result.String()) + return apiVs.NewPutVsVipPortLaddrOK() + default: + h.logger.Error("Set virtual server Local IP failed.", "VipPort", params.VipPort, "Local Addr", params.Spec.Addr, "result", result.String()) + } + + return apiVs.NewPutVsVipPortLaddrFailure() +} diff --git a/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_rs.go b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_rs.go new file mode 100644 index 000000000..05380108c --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/put_vs_vip_port_rs.go @@ -0,0 +1,74 @@ +package ipvs + +import ( + "github.com/dpvs-agent/pkg/ipc/pool" + "github.com/dpvs-agent/pkg/ipc/types" + + apiVs "github.com/dpvs-agent/restapi/operations/virtualserver" + + "github.com/go-openapi/runtime/middleware" + "github.com/hashicorp/go-hclog" +) + +type putVsRs struct { + connPool *pool.ConnPool + logger hclog.Logger +} + +func NewPutVsRs(cp *pool.ConnPool, parentLogger hclog.Logger) *putVsRs { + logger := hclog.Default() + if parentLogger != nil { + logger = parentLogger.Named("PutVsVipPortRs") + } + return &putVsRs{connPool: cp, logger: logger} +} + +func (h *putVsRs) Handle(params apiVs.PutVsVipPortRsParams) middleware.Responder { + front := types.NewRealServerFront() + if err := front.ParseVipPortProto(params.VipPort); err != nil { + h.logger.Error("Convert to virtual server failed", "VipPort", params.VipPort, "Error", err.Error()) + return apiVs.NewPutVsVipPortRsInvalidFrontend() + } + + var rss []*types.RealServerSpec + if params.Rss != nil { + rss = make([]*types.RealServerSpec, len(params.Rss.Items)) + for i, rs := range params.Rss.Items { + var fwdmode types.DpvsFwdMode + fwdmode.FromString(rs.Mode) + rss[i] = types.NewRealServerSpec() + rss[i].SetAf(front.GetAf()) + rss[i].SetAddr(rs.IP) + rss[i].SetPort(rs.Port) + rss[i].SetProto(front.GetProto()) + rss[i].SetWeight(uint32(rs.Weight)) + rss[i].SetFwdMode(fwdmode) + rss[i].SetInhibited(rs.Inhibited) + rss[i].SetOverloaded(rs.Inhibited) + } + } + + healthCheck := false + if params.Healthcheck != nil { + healthCheck = *params.Healthcheck + } + + result := front.Edit(healthCheck, rss, h.connPool, h.logger) + + // h.logger.Info("Set real server sets done.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + switch result { + case types.EDPVS_EXIST, types.EDPVS_OK: + h.logger.Info("Set real server sets success.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + return apiVs.NewPutVsVipPortRsOK() + case types.EDPVS_NOTEXIST: + if healthCheck { + h.logger.Error("Edit not exist real server.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + return apiVs.NewPutVsVipPortRsInvalidFrontend() + } + h.logger.Error("Unreachable branch") + default: + h.logger.Error("Set real server sets failed.", "VipPort", params.VipPort, "rss", rss, "result", result.String()) + return apiVs.NewPutVsVipPortRsInvalidBackend() + } + return apiVs.NewPutVsVipPortRsFailure() +} diff --git a/tools/dpvs-agent/cmd/ipvs/todo_get_vs_vip_port_rs.go b/tools/dpvs-agent/cmd/ipvs/todo_get_vs_vip_port_rs.go new file mode 100644 index 000000000..91ce6808a --- /dev/null +++ b/tools/dpvs-agent/cmd/ipvs/todo_get_vs_vip_port_rs.go @@ -0,0 +1 @@ +package ipvs diff --git a/tools/dpvs-agent/dpvs-agent-api.yaml b/tools/dpvs-agent/dpvs-agent-api.yaml new file mode 100644 index 000000000..230751c80 --- /dev/null +++ b/tools/dpvs-agent/dpvs-agent-api.yaml @@ -0,0 +1,1373 @@ +swagger: "2.0" +info: + description: "dpvs agent api" + version: "1.0.0" + title: "dpvs agent" +host: "petstore.swagger.io" +basePath: "/v2" +tags: +- name: "virtualserver" + description: "virtualserver" +- name: "route" + description: "route" +- name: "laddr" + description: "laddr" +- name: "tunnel" + description: "tunnel" +- name: "inetaddr" + description: "inet addr" +- name: "white_list" + description: "white list" +- name: "black_list" + description: "black list" +- name: "arp" + description: "arp" +schemes: +- "http" +parameters: + service-id: + name: VipPort + in: path + type: string + required: true + realserver-id: + name: RipPort + in: path + type: string + required: true + device-name: + name: name + in: path + type: string + required: true + vs-config: + name: spec + in: body + schema: + "$ref": "#/definitions/VirtualServerSpecTiny" + rs-config: + name: spec + in: body + schema: + "$ref": "#/definitions/RealServerSpecTiny" + rss-config: + name: rss + in: body + schema: + "$ref": "#/definitions/RealServerTinyList" + acl-config: + name: acl + in: body + schema: + "$ref": "#/definitions/AclAddrList" + laddr-config: + name: spec + in: body + schema: + "$ref": "#/definitions/LocalAddressSpecTiny" + route-config: + name: spec + in: body + schema: + "$ref": "#/definitions/RouteSpec" + vlan-config: + name: spec + in: body + schema: + "$ref": "#/definitions/VlanSpec" + device-addr: + name: spec + in: body + schema: + "$ref": "#/definitions/InetAddrSpec" + healthcheck: + name: healthcheck + in: query + type: boolean + default: false + required: false + stats: + name: stats + in: query + type: boolean + default: false + required: false + verbose: + name: verbose + in: query + type: boolean + default: false + required: false + sapool: + name: sapool + in: query + type: boolean + default: false + required: false + promisc: + name: promisc + in: query + type: string + enum: + - unset + - on + - off + default: unset + required: false + link: + name: link + in: query + type: string + enum: + - unset + - up + - down + default: unset + required: false + forward2kni: + name: forward2Kni + in: query + type: string + enum: + - unset + - on + - off + default: unset + required: false +definitions: + CertAuthSpec: + properties: + addr: + type: string + InetAddrSpec: + properties: + addr: + type: string + broadcast: + type: string + scope: + type: string + VlanSpec: + properties: + name: + type: string + device: + type: string + id: + type: string + RouteSpec: + properties: + src: + type: string + dst: + type: string + gateway: + type: string + prefixSrc: + type: string + device: + type: string + scope: + type: string + mtu: + type: integer + format: uint32 + metric: + type: integer + format: uint32 + LocalAddressSpecExpand: + type: object + properties: + af: + type: integer + format: uint32 + conns: + type: integer + format: uint32 + portConflict: + type: integer + format: uint64 + addr: + type: string + device: + type: string + LocalAddressSpecTiny: + properties: + addr: + type: string + device: + type: string + AclAddrList: + type: object + properties: + Items: + type: array + items: + "$ref": "#/definitions/CertAuthSpec" + LocalAddressExpandList: + properties: + Items: + type: array + items: + "$ref": "#/definitions/LocalAddressSpecExpand" + LocalAddressTinyList: + properties: + Items: + type: array + items: + "$ref": "#/definitions/LocalAddressSpecTiny" + RealServerTinyList: + type: object + properties: + Items: + type: array + items: + "$ref": "#/definitions/RealServerSpecTiny" + RealServerExpandList: + type: "object" + properties: + Items: + type: array + items: + "$ref": "#/definitions/RealServerSpecExpand" + RealServerSpecExpand: + type: object + properties: + Spec: + "$ref": "#/definitions/RealServerSpecTiny" + Stats: + "$ref": "#/definitions/ServerStats" + RealServerSpecTiny: + type: object + properties: + ip: + type: "string" + port: + type: "integer" + format: "uint16" + x-omitempty: false + weight: + type: "integer" + format: "uint16" + x-omitempty: false + mode: + type: "string" + enum: + - "FNAT" + - "SNAT" + - "DR" + - "TUNNEL" + - "NAT" + inhibited: + type: "boolean" + default: false + overloaded: + type: "boolean" + default: false + NicDeviceSpecList: + type: object + properties: + Items: + type: array + items: + "$ref": "#/definitions/NicDeviceSpec" + NicDeviceSpec: + type: object + properties: + detail: + "$ref": "#/definitions/NicDeviceDetail" + stats: + "$ref": "#/definitions/NicDeviceStats" + #extra: + # "$ref": "#/definitions/NicDeviceStats" + #NicDeviceExtra: padding + NicDeviceDetail: + type: object + properties: + name: + type: string + addr: + type: string + status: + type: string + enum: + - "UP" + - "DOWN" + duplex: + type: string + enum: + - "half-duplex" + - "full-duplex" + autoneg: + type: string + enum: + - "fixed-nego" + - "auto-nego" + speed: + type: integer + format: uint32 + nRxQ: + type: integer + format: uint8 + nTxQ: + type: integer + format: uint8 + socketID: + type: integer + format: uint8 + ID: + type: integer + format: uint16 + MTU: + type: integer + format: uint16 + Flags: + type: integer + format: uint16 + NicDeviceStats: + type: object + properties: + id: + type: integer + format: "uint16" + bufAvail: + type: integer + format: "uint32" + bufInuse: + type: integer + format: "uint32" + inPkts: + type: integer + format: "uint64" + outPkts: + type: integer + format: "uint64" + inBytes: + type: integer + format: "uint64" + outBytes: + type: integer + format: "uint64" + inMissed: + type: integer + format: "uint64" + inErrors: + type: integer + format: "uint64" + outErrors: + type: integer + format: "uint64" + rxNoMbuf: + type: integer + format: "uint64" + inPktsQ: + type: array + items: + "$ref": "#/definitions/NicDeviceQueueData" + outPktsQ: + type: array + items: + "$ref": "#/definitions/NicDeviceQueueData" + inBytesQ: + type: array + items: + "$ref": "#/definitions/NicDeviceQueueData" + outBytesQ: + type: array + items: + "$ref": "#/definitions/NicDeviceQueueData" + errorBytesQ: + type: array + items: + "$ref": "#/definitions/NicDeviceQueueData" + NicDeviceQueueData: + type: integer + format: "uint64" + Error: + type: "string" + Status: + description: Status of an individual component + type: object + properties: + state: + type: string + description: State the component is in + enum: + - Ok + - Warning + - Failure + - Disabled + msg: + type: string + description: Human readable status/error/warning message + ServerStats: + type: "object" + properties: + Conns: + type: "integer" + format: "uint64" + InPkts: + type: "integer" + format: "uint64" + InBytes: + type: "integer" + format: "uint64" + OutPkts: + type: "integer" + format: "uint64" + OutBytes: + type: "integer" + format: "uint64" + Cps: + type: "integer" + format: "uint32" + InPps: + type: "integer" + format: "uint32" + InBps: + type: "integer" + format: "uint32" + OutPps: + type: "integer" + format: "uint32" + OutBps: + type: "integer" + format: "uint32" + AddrRange: + type: "object" + properties: + Start: + type: "string" + End: + type: "string" + MatchSpec: + type: "object" + properties: + Src: + "$ref": "#/definitions/AddrRange" + Dest: + "$ref": "#/definitions/AddrRange" + InIfName: + type: string + OutIfName: + type: string + DestCheckSpec: + type: "string" + enum: + - passive + - tcp + - udp + - ping + + VirtualServerList: + type: object + properties: + Items: + type: array + items: + "$ref": "#/definitions/VirtualServerSpecExpand" + VirtualServerSpecExpand: + type: "object" + properties: + Af: + type: "integer" + format: "uint32" + Proto: + type: "integer" + format: "uint16" + Port: + type: "integer" + format: "uint16" + Fwmark: + type: "integer" + format: "uint32" + Flags: + type: "string" + SyncProxy: + type: "string" + enum: + - "true" + - "false" + ExpireQuiescent: + type: "string" + enum: + - "true" + - "false" + Timeout: + type: "integer" + format: "uint32" + ConnTimeout: + type: "integer" + format: "uint32" + Netmask: + type: "integer" + format: "uint32" + Bps: + type: "integer" + format: "uint32" + LimitProportion: + type: "integer" + format: "uint32" + Addr: + type: "string" + SchedName: + type: "string" + enum: + - rr + - wrr + - wlc + - connhash + DestCheck: + type: array + items: + "$ref": "#/definitions/DestCheckSpec" + Stats: + "$ref": "#/definitions/ServerStats" + RSs: + "$ref": "#/definitions/RealServerExpandList" + Match: + "$ref": "#/definitions/MatchSpec" + VirtualServerSpecTiny: + type: "object" + properties: + #Af: + # type: "integer" + # format: "uint16" + #Port: + # type: "integer" + # format: "uint16" + Fwmark: + type: "integer" + format: "uint32" + #Flags: + # type: "integer" + # format: "uint32" + SyncProxy: + type: "boolean" + default: false + ExpireQuiescent: + type: "boolean" + default: false + Timeout: + type: "integer" + format: "uint32" + ConnTimeout: + type: "integer" + format: "uint32" + #Netmask: + # type: "integer" + # format: "uint32" + Bps: + type: "integer" + format: "uint32" + LimitProportion: + type: "integer" + format: "uint32" + #Addr: + # type: "string" + SchedName: + type: "string" + enum: + - rr + - wrr + - wlc + - connhash + Match: + "$ref": "#/definitions/MatchSpec" +paths: + /device: + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/stats" + summary: "display all net device list" + responses: + '200': + description: Success + schema: + type: string + /device/{name}/addr: + #description: dpip addr add 192.168.88.16/32 dev dpdk0.102 + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/stats" + - "$ref": "#/parameters/verbose" + - "$ref": "#/parameters/device-name" + summary: "display special net device ip addr" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Not Found + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/sapool" + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/device-addr" + summary: "add/update special net device ip addr" + responses: + '200': + description: Update exist ip addr Success + schema: + type: string + '201': + description: Add new ip addr Success + schema: + type: string + '500': + description: Failed + schema: + type: string + delete: + tags: + - "device" + parameters: + - "$ref": "#/parameters/sapool" + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/device-addr" + summary: "delete special net device ip addr" + responses: + '200': + description: delete ip addr from device Success + schema: + type: string + '500': + description: Failed + schema: + type: string + /device/{name}/route: + #description: dpip route add 192.168.88.16/32 dev dpdk0.102 scope kni_host + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/stats" + - "$ref": "#/parameters/device-name" + summary: "display special net device route" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Not Found + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/route-config" + summary: "add/update special net device route" + responses: + '200': + description: Update exist route Success + schema: + type: string + '201': + description: Add new route Success + schema: + type: string + '500': + description: Failed + schema: + type: string + delete: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/route-config" + summary: "delete special net device route" + responses: + '200': + description: delete route Success + schema: + type: string + '500': + description: Failed + schema: + type: string + /device/{name}/netlink: + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/stats" + summary: "ip link show dev ${name}" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Not Found + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + summary: "ip link set ${name} up" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Not Found + schema: + type: string + delete: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + summary: "ip link set ${name} down" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Not Found + schema: + type: string + /device/{name}/netlink/addr: + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/stats" + summary: "ip addr show lo: Display special linux net device addr detail" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Not Found + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/device-addr" + summary: "ip addr add 10.0.0.1/32 dev eth0: Set ip cird to linux net device" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Not Found + schema: + type: string + delete: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/device-addr" + summary: "ip addr del 10.0.0.1/32 dev eth0: Delete ip cird fron linux net device" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Not Found + schema: + type: string + #/device/{name}/cpu + /device/{name}/nic: + #description: dpip link show + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/verbose" + - "$ref": "#/parameters/stats" + summary: "dpip link show ${nic-name} -s -v" + responses: + '200': + description: Success + schema: + #type: string + "$ref": "#/definitions/NicDeviceSpecList" + '500': + description: Failure + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/forward2kni" + - "$ref": "#/parameters/link" + - "$ref": "#/parameters/promisc" + summary: "dpip link set ${nic-name} [forward2kni,link,promisc,tc-ingress,tc-egress] [on/up,off/down]" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Failure + schema: + type: string + /device/{name}/vlan: + #description: dpip vlan add dpdk0.102 link dpdk0 id 102 + get: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/stats" + summary: "display all net device list" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Not Found + schema: + type: string + put: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + - "$ref": "#/parameters/vlan-config" + summary: "add/update special net device " + responses: + '200': + description: Success + schema: + type: string + '500': + description: Failed + schema: + type: string + delete: + tags: + - "device" + parameters: + - "$ref": "#/parameters/device-name" + summary: "delete special net device" + responses: + '200': + description: Success + schema: + type: string + '500': + description: Failed + schema: + type: string + /vs: + get: + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/stats" + summary: "display all vip:port:proto and rsip:port list" + responses: + '200': + description: Success + schema: + "$ref": "#/definitions/VirtualServerList" + # items: + # "$ref": "#/definitions/VirtualServer" + /vs/{VipPort}: + get: + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/stats" + summary: "get a specific virtual server" + responses: + '200': + description: Success + schema: + # type: string + # items: + "$ref": "#/definitions/VirtualServerList" + '404': + description: Service not found + schema: + type: string + delete: + summary: "Delete a vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + responses: + '200': + description: Success + schema: + type: string + '404': + description: Service not found + schema: + type: string + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + put: + summary: "create or update virtual server" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/vs-config" + responses: + '200': + description: Updated + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: "Error while creating virtual server" + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + /vs/{VipPort}/laddr: + get: + tags: + - "virtualserver" + parameters: + #- "$ref": "#/parameters/realserver-id" + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/stats" + responses: + '200': + description: Success + schema: + "$ref": "#/definitions/LocalAddressExpandList" + #type: string + #items: + # "$ref": "#/definitions/VirtualServer" + '404': + description: Service not found + schema: + type: string + put: + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/laddr-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: "Error while creating virtual server" + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + delete: + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/laddr-config" + responses: + '200': + description: Success + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: "Error while creating virtual server" + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + /vs/{VipPort}/rs: + get: + tags: + - "virtualserver" + parameters: + #- "$ref": "#/parameters/realserver-id" + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/stats" + responses: + '200': + description: Success + schema: + type: string + #items: + # "$ref": "#/definitions/VirtualServer" + '404': + description: Service not found + schema: + type: string + delete: + summary: "Delete a set of real server from vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/rss-config" + responses: + '200': + description: Success + '404': + description: Service not found + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + put: + summary: "Add a set of real server to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/rss-config" + - "$ref": "#/parameters/healthcheck" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + post: + summary: "Update fully real server list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/rss-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + /vs/{VipPort}/deny: + get: + tags: + - "virtualserver" + parameters: + #- "$ref": "#/parameters/realserver-id" + - "$ref": "#/parameters/service-id" + responses: + '200': + description: Success + schema: + type: string + #items: + # "$ref": "#/definitions/VirtualServer" + '404': + description: Service not found + schema: + type: string + delete: + summary: "Delete a set of ip form black list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + '404': + description: Service not found + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + put: + summary: "Add a set of ip from black list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + post: + summary: "Update a fully black ip list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + /vs/{VipPort}/allow: + get: + tags: + - "virtualserver" + parameters: + #- "$ref": "#/parameters/realserver-id" + - "$ref": "#/parameters/service-id" + responses: + '200': + description: Success + schema: + type: string + #items: + # "$ref": "#/definitions/VirtualServer" + '404': + description: Service not found + schema: + type: string + delete: + summary: "Delete a set of ip form white list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + '404': + description: Service not found + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + put: + summary: "Add a set of ip from white list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" + post: + summary: "Update a fully white ip list to vip:port:proto" + tags: + - "virtualserver" + parameters: + - "$ref": "#/parameters/service-id" + - "$ref": "#/parameters/acl-config" + responses: + '200': + description: Success + schema: + type: string + '201': + description: Created + schema: + type: string + '460': + description: Invalid frontend in service configuration + x-go-name: InvalidFrontend + schema: + "$ref": "#/definitions/Error" + '461': + description: Invalid backend in service configuration + x-go-name: InvalidBackend + schema: + "$ref": "#/definitions/Error" + '500': + description: Service deletion failed + x-go-name: Failure + schema: + "$ref": "#/definitions/Error" diff --git a/tools/dpvs-agent/go.mod b/tools/dpvs-agent/go.mod new file mode 100644 index 000000000..b5198bfc6 --- /dev/null +++ b/tools/dpvs-agent/go.mod @@ -0,0 +1,40 @@ +module github.com/dpvs-agent + +go 1.20 + +require ( + github.com/go-openapi/errors v0.20.3 + github.com/go-openapi/loads v0.21.2 + github.com/go-openapi/runtime v0.26.0 + github.com/go-openapi/spec v0.20.9 + github.com/go-openapi/strfmt v0.21.7 + github.com/go-openapi/swag v0.22.3 + github.com/go-openapi/validate v0.22.1 + github.com/hashicorp/go-hclog v1.5.0 + github.com/jessevdk/go-flags v1.5.0 + github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible + github.com/vishvananda/netlink v1.1.0 + golang.org/x/net v0.10.0 + golang.org/x/sys v0.8.0 +) + +require ( + github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/fatih/color v1.13.0 // indirect + github.com/go-openapi/analysis v0.21.4 // indirect + github.com/go-openapi/jsonpointer v0.19.5 // indirect + github.com/go-openapi/jsonreference v0.20.0 // indirect + github.com/jonboulle/clockwork v0.4.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/lestrrat-go/strftime v1.0.6 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + github.com/oklog/ulid v1.3.1 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df // indirect + go.mongodb.org/mongo-driver v1.11.3 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/tools/dpvs-agent/go.sum b/tools/dpvs-agent/go.sum new file mode 100644 index 000000000..f6f0a32b6 --- /dev/null +++ b/tools/dpvs-agent/go.sum @@ -0,0 +1,232 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= +github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= +github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so= +github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= +github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= +github.com/go-openapi/analysis v0.21.2/go.mod h1:HZwRk4RRisyG8vx2Oe6aqeSQcoxRp47Xkp3+K6q+LdY= +github.com/go-openapi/analysis v0.21.4 h1:ZDFLvSNxpDaomuCueM0BlSXxpANBlFYiBvr+GXrvIHc= +github.com/go-openapi/analysis v0.21.4/go.mod h1:4zQ35W4neeZTqh3ol0rv/O8JBbka9QyAgQRPp9y3pfo= +github.com/go-openapi/errors v0.19.8/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= +github.com/go-openapi/errors v0.19.9/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= +github.com/go-openapi/errors v0.20.2/go.mod h1:cM//ZKUKyO06HSwqAelJ5NsEMMcpa6VpXe8DOa1Mi1M= +github.com/go-openapi/errors v0.20.3 h1:rz6kiC84sqNQoqrtulzaL/VERgkoCyB6WdEkc2ujzUc= +github.com/go-openapi/errors v0.20.3/go.mod h1:Z3FlZ4I8jEGxjUK+bugx3on2mIAk4txuAOhlsB1FSgk= +github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY= +github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= +github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns= +github.com/go-openapi/jsonreference v0.20.0 h1:MYlu0sBgChmCfJxxUKZ8g1cPWFOB37YSZqewK7OKeyA= +github.com/go-openapi/jsonreference v0.20.0/go.mod h1:Ag74Ico3lPc+zR+qjn4XBUmXymS4zJbYVCZmcgkasdo= +github.com/go-openapi/loads v0.21.1/go.mod h1:/DtAMXXneXFjbQMGEtbamCZb+4x7eGwkvZCvBmwUG+g= +github.com/go-openapi/loads v0.21.2 h1:r2a/xFIYeZ4Qd2TnGpWDIQNcP80dIaZgf704za8enro= +github.com/go-openapi/loads v0.21.2/go.mod h1:Jq58Os6SSGz0rzh62ptiu8Z31I+OTHqmULx5e/gJbNw= +github.com/go-openapi/runtime v0.26.0 h1:HYOFtG00FM1UvqrcxbEJg/SwvDRvYLQKGhw2zaQjTcc= +github.com/go-openapi/runtime v0.26.0/go.mod h1:QgRGeZwrUcSHdeh4Ka9Glvo0ug1LC5WyE+EV88plZrQ= +github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I= +github.com/go-openapi/spec v0.20.6/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/spec v0.20.9 h1:xnlYNQAwKd2VQRRfwTEI0DcK+2cbuvI/0c7jx3gA8/8= +github.com/go-openapi/spec v0.20.9/go.mod h1:2OpW+JddWPrpXSCIX8eOx7lZ5iyuWj3RYR6VaaBKcWA= +github.com/go-openapi/strfmt v0.21.0/go.mod h1:ZRQ409bWMj+SOgXofQAGTIo2Ebu72Gs+WaRADcS5iNg= +github.com/go-openapi/strfmt v0.21.1/go.mod h1:I/XVKeLc5+MM5oPNN7P6urMOpuLXEcNrCX/rPGuWb0k= +github.com/go-openapi/strfmt v0.21.3/go.mod h1:k+RzNO0Da+k3FrrynSNN8F7n/peCmQQqbbXjtDfvmGg= +github.com/go-openapi/strfmt v0.21.7 h1:rspiXgNWgeUzhjo1YU01do6qsahtJNByjLVbPLNHb8k= +github.com/go-openapi/strfmt v0.21.7/go.mod h1:adeGTkxE44sPyLk0JV235VQAO/ZXUr8KAzYjclFs3ew= +github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= +github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.21.1/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= +github.com/go-openapi/swag v0.22.3 h1:yMBqmnQ0gyZvEb/+KzuWZOXgllrXT4SADYbvDaXHv/g= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/validate v0.22.1 h1:G+c2ub6q47kfX1sOBLwIQwzBVt8qmOAARyo/9Fqs9NU= +github.com/go-openapi/validate v0.22.1/go.mod h1:rjnrwK57VJ7A8xqfpAOEKRH8yQSGUriMu5/zuPSQ1hg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= +github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY= +github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg= +github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI= +github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs= +github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI= +github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk= +github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28= +github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo= +github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk= +github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw= +github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360= +github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg= +github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE= +github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8= +github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc= +github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4= +github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ= +github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0= +github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw= +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= +github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c= +github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= +github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= +github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4= +github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA= +github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8= +github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc/go.mod h1:kopuH9ugFRkIXf3YoqHKyrJ9YfUFsckUU9S7B+XP+is= +github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkLibYKgg+SwmyFU9dF2hn6MdTj4= +github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA= +github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ= +github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw= +github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE= +github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= +github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/mitchellh/mapstructure v1.3.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= +github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= +github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= +github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0= +github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= +github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k= +github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+hCSs= +github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= +github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= +github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= +github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= +go.mongodb.org/mongo-driver v1.7.3/go.mod h1:NqaYOwnXWr5Pm7AOpO5QFxKJ503nbMse/R79oO62zWg= +go.mongodb.org/mongo-driver v1.7.5/go.mod h1:VXEWRZ6URJIkUq2SCAyapmhH0ZLRBP+FT4xhp5Zvxng= +go.mongodb.org/mongo-driver v1.10.0/go.mod h1:wsihk0Kdgv8Kqu1Anit4sfK+22vSFbUrAVEYRhCXrA8= +go.mongodb.org/mongo-driver v1.11.3 h1:Ql6K6qYHEzB6xvu4+AU0BoRoqf9vFPcc4o7MUIdPW8Y= +go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tools/dpvs-agent/models/acl_addr_list.go b/tools/dpvs-agent/models/acl_addr_list.go new file mode 100644 index 000000000..06f092792 --- /dev/null +++ b/tools/dpvs-agent/models/acl_addr_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ACLAddrList Acl addr list +// +// swagger:model AclAddrList +type ACLAddrList struct { + + // items + Items []*CertAuthSpec `json:"Items"` +} + +// Validate validates this Acl addr list +func (m *ACLAddrList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ACLAddrList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this Acl addr list based on the context it is used +func (m *ACLAddrList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *ACLAddrList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *ACLAddrList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ACLAddrList) UnmarshalBinary(b []byte) error { + var res ACLAddrList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/addr_range.go b/tools/dpvs-agent/models/addr_range.go new file mode 100644 index 000000000..4324dde7a --- /dev/null +++ b/tools/dpvs-agent/models/addr_range.go @@ -0,0 +1,53 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// AddrRange addr range +// +// swagger:model AddrRange +type AddrRange struct { + + // end + End string `json:"End,omitempty"` + + // start + Start string `json:"Start,omitempty"` +} + +// Validate validates this addr range +func (m *AddrRange) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this addr range based on context it is used +func (m *AddrRange) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *AddrRange) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *AddrRange) UnmarshalBinary(b []byte) error { + var res AddrRange + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/cert_auth_spec.go b/tools/dpvs-agent/models/cert_auth_spec.go new file mode 100644 index 000000000..61648012e --- /dev/null +++ b/tools/dpvs-agent/models/cert_auth_spec.go @@ -0,0 +1,50 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// CertAuthSpec cert auth spec +// +// swagger:model CertAuthSpec +type CertAuthSpec struct { + + // addr + Addr string `json:"addr,omitempty"` +} + +// Validate validates this cert auth spec +func (m *CertAuthSpec) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this cert auth spec based on context it is used +func (m *CertAuthSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *CertAuthSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *CertAuthSpec) UnmarshalBinary(b []byte) error { + var res CertAuthSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/dest_check_spec.go b/tools/dpvs-agent/models/dest_check_spec.go new file mode 100644 index 000000000..2e2e9cf9a --- /dev/null +++ b/tools/dpvs-agent/models/dest_check_spec.go @@ -0,0 +1,84 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" +) + +// DestCheckSpec dest check spec +// +// swagger:model DestCheckSpec +type DestCheckSpec string + +func NewDestCheckSpec(value DestCheckSpec) *DestCheckSpec { + return &value +} + +// Pointer returns a pointer to a freshly-allocated DestCheckSpec. +func (m DestCheckSpec) Pointer() *DestCheckSpec { + return &m +} + +const ( + + // DestCheckSpecPassive captures enum value "passive" + DestCheckSpecPassive DestCheckSpec = "passive" + + // DestCheckSpecTCP captures enum value "tcp" + DestCheckSpecTCP DestCheckSpec = "tcp" + + // DestCheckSpecUDP captures enum value "udp" + DestCheckSpecUDP DestCheckSpec = "udp" + + // DestCheckSpecPing captures enum value "ping" + DestCheckSpecPing DestCheckSpec = "ping" +) + +// for schema +var destCheckSpecEnum []interface{} + +func init() { + var res []DestCheckSpec + if err := json.Unmarshal([]byte(`["passive","tcp","udp","ping"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + destCheckSpecEnum = append(destCheckSpecEnum, v) + } +} + +func (m DestCheckSpec) validateDestCheckSpecEnum(path, location string, value DestCheckSpec) error { + if err := validate.EnumCase(path, location, value, destCheckSpecEnum, true); err != nil { + return err + } + return nil +} + +// Validate validates this dest check spec +func (m DestCheckSpec) Validate(formats strfmt.Registry) error { + var res []error + + // value enum + if err := m.validateDestCheckSpecEnum("", "body", m); err != nil { + return err + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// ContextValidate validates this dest check spec based on context it is used +func (m DestCheckSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} diff --git a/tools/dpvs-agent/models/error.go b/tools/dpvs-agent/models/error.go new file mode 100644 index 000000000..f0f02dcac --- /dev/null +++ b/tools/dpvs-agent/models/error.go @@ -0,0 +1,27 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" +) + +// Error error +// +// swagger:model Error +type Error string + +// Validate validates this error +func (m Error) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this error based on context it is used +func (m Error) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} diff --git a/tools/dpvs-agent/models/inet_addr_spec.go b/tools/dpvs-agent/models/inet_addr_spec.go new file mode 100644 index 000000000..9a4e53e75 --- /dev/null +++ b/tools/dpvs-agent/models/inet_addr_spec.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// InetAddrSpec inet addr spec +// +// swagger:model InetAddrSpec +type InetAddrSpec struct { + + // addr + Addr string `json:"addr,omitempty"` + + // broadcast + Broadcast string `json:"broadcast,omitempty"` + + // scope + Scope string `json:"scope,omitempty"` +} + +// Validate validates this inet addr spec +func (m *InetAddrSpec) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this inet addr spec based on context it is used +func (m *InetAddrSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *InetAddrSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *InetAddrSpec) UnmarshalBinary(b []byte) error { + var res InetAddrSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/local_address_expand_list.go b/tools/dpvs-agent/models/local_address_expand_list.go new file mode 100644 index 000000000..c4e52dca9 --- /dev/null +++ b/tools/dpvs-agent/models/local_address_expand_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// LocalAddressExpandList local address expand list +// +// swagger:model LocalAddressExpandList +type LocalAddressExpandList struct { + + // items + Items []*LocalAddressSpecExpand `json:"Items"` +} + +// Validate validates this local address expand list +func (m *LocalAddressExpandList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *LocalAddressExpandList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this local address expand list based on the context it is used +func (m *LocalAddressExpandList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *LocalAddressExpandList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *LocalAddressExpandList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *LocalAddressExpandList) UnmarshalBinary(b []byte) error { + var res LocalAddressExpandList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/local_address_spec_expand.go b/tools/dpvs-agent/models/local_address_spec_expand.go new file mode 100644 index 000000000..0b25fb723 --- /dev/null +++ b/tools/dpvs-agent/models/local_address_spec_expand.go @@ -0,0 +1,62 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// LocalAddressSpecExpand local address spec expand +// +// swagger:model LocalAddressSpecExpand +type LocalAddressSpecExpand struct { + + // addr + Addr string `json:"addr,omitempty"` + + // af + Af uint32 `json:"af,omitempty"` + + // conns + Conns uint32 `json:"conns,omitempty"` + + // device + Device string `json:"device,omitempty"` + + // port conflict + PortConflict uint64 `json:"portConflict,omitempty"` +} + +// Validate validates this local address spec expand +func (m *LocalAddressSpecExpand) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this local address spec expand based on context it is used +func (m *LocalAddressSpecExpand) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *LocalAddressSpecExpand) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *LocalAddressSpecExpand) UnmarshalBinary(b []byte) error { + var res LocalAddressSpecExpand + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/local_address_spec_tiny.go b/tools/dpvs-agent/models/local_address_spec_tiny.go new file mode 100644 index 000000000..79806b25e --- /dev/null +++ b/tools/dpvs-agent/models/local_address_spec_tiny.go @@ -0,0 +1,53 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// LocalAddressSpecTiny local address spec tiny +// +// swagger:model LocalAddressSpecTiny +type LocalAddressSpecTiny struct { + + // addr + Addr string `json:"addr,omitempty"` + + // device + Device string `json:"device,omitempty"` +} + +// Validate validates this local address spec tiny +func (m *LocalAddressSpecTiny) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this local address spec tiny based on context it is used +func (m *LocalAddressSpecTiny) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *LocalAddressSpecTiny) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *LocalAddressSpecTiny) UnmarshalBinary(b []byte) error { + var res LocalAddressSpecTiny + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/local_address_tiny_list.go b/tools/dpvs-agent/models/local_address_tiny_list.go new file mode 100644 index 000000000..3c04085a4 --- /dev/null +++ b/tools/dpvs-agent/models/local_address_tiny_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// LocalAddressTinyList local address tiny list +// +// swagger:model LocalAddressTinyList +type LocalAddressTinyList struct { + + // items + Items []*LocalAddressSpecTiny `json:"Items"` +} + +// Validate validates this local address tiny list +func (m *LocalAddressTinyList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *LocalAddressTinyList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this local address tiny list based on the context it is used +func (m *LocalAddressTinyList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *LocalAddressTinyList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *LocalAddressTinyList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *LocalAddressTinyList) UnmarshalBinary(b []byte) error { + var res LocalAddressTinyList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/match_spec.go b/tools/dpvs-agent/models/match_spec.go new file mode 100644 index 000000000..8d78ed4ca --- /dev/null +++ b/tools/dpvs-agent/models/match_spec.go @@ -0,0 +1,156 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// MatchSpec match spec +// +// swagger:model MatchSpec +type MatchSpec struct { + + // dest + Dest *AddrRange `json:"Dest,omitempty"` + + // in if name + InIfName string `json:"InIfName,omitempty"` + + // out if name + OutIfName string `json:"OutIfName,omitempty"` + + // src + Src *AddrRange `json:"Src,omitempty"` +} + +// Validate validates this match spec +func (m *MatchSpec) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateDest(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSrc(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *MatchSpec) validateDest(formats strfmt.Registry) error { + if swag.IsZero(m.Dest) { // not required + return nil + } + + if m.Dest != nil { + if err := m.Dest.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Dest") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Dest") + } + return err + } + } + + return nil +} + +func (m *MatchSpec) validateSrc(formats strfmt.Registry) error { + if swag.IsZero(m.Src) { // not required + return nil + } + + if m.Src != nil { + if err := m.Src.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Src") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Src") + } + return err + } + } + + return nil +} + +// ContextValidate validate this match spec based on the context it is used +func (m *MatchSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateDest(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateSrc(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *MatchSpec) contextValidateDest(ctx context.Context, formats strfmt.Registry) error { + + if m.Dest != nil { + if err := m.Dest.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Dest") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Dest") + } + return err + } + } + + return nil +} + +func (m *MatchSpec) contextValidateSrc(ctx context.Context, formats strfmt.Registry) error { + + if m.Src != nil { + if err := m.Src.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Src") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Src") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *MatchSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *MatchSpec) UnmarshalBinary(b []byte) error { + var res MatchSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/nic_device_detail.go b/tools/dpvs-agent/models/nic_device_detail.go new file mode 100644 index 000000000..ee0a65216 --- /dev/null +++ b/tools/dpvs-agent/models/nic_device_detail.go @@ -0,0 +1,232 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// NicDeviceDetail nic device detail +// +// swagger:model NicDeviceDetail +type NicDeviceDetail struct { + + // flags + Flags uint16 `json:"Flags,omitempty"` + + // ID + ID uint16 `json:"ID,omitempty"` + + // m t u + MTU uint16 `json:"MTU,omitempty"` + + // addr + Addr string `json:"addr,omitempty"` + + // autoneg + // Enum: [fixed-nego auto-nego] + Autoneg string `json:"autoneg,omitempty"` + + // duplex + // Enum: [half-duplex full-duplex] + Duplex string `json:"duplex,omitempty"` + + // n rx q + NRxQ uint8 `json:"nRxQ,omitempty"` + + // n tx q + NTxQ uint8 `json:"nTxQ,omitempty"` + + // name + Name string `json:"name,omitempty"` + + // socket ID + SocketID uint8 `json:"socketID,omitempty"` + + // speed + Speed uint32 `json:"speed,omitempty"` + + // status + // Enum: [UP DOWN] + Status string `json:"status,omitempty"` +} + +// Validate validates this nic device detail +func (m *NicDeviceDetail) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateAutoneg(formats); err != nil { + res = append(res, err) + } + + if err := m.validateDuplex(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStatus(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var nicDeviceDetailTypeAutonegPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["fixed-nego","auto-nego"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + nicDeviceDetailTypeAutonegPropEnum = append(nicDeviceDetailTypeAutonegPropEnum, v) + } +} + +const ( + + // NicDeviceDetailAutonegFixedDashNego captures enum value "fixed-nego" + NicDeviceDetailAutonegFixedDashNego string = "fixed-nego" + + // NicDeviceDetailAutonegAutoDashNego captures enum value "auto-nego" + NicDeviceDetailAutonegAutoDashNego string = "auto-nego" +) + +// prop value enum +func (m *NicDeviceDetail) validateAutonegEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, nicDeviceDetailTypeAutonegPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *NicDeviceDetail) validateAutoneg(formats strfmt.Registry) error { + if swag.IsZero(m.Autoneg) { // not required + return nil + } + + // value enum + if err := m.validateAutonegEnum("autoneg", "body", m.Autoneg); err != nil { + return err + } + + return nil +} + +var nicDeviceDetailTypeDuplexPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["half-duplex","full-duplex"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + nicDeviceDetailTypeDuplexPropEnum = append(nicDeviceDetailTypeDuplexPropEnum, v) + } +} + +const ( + + // NicDeviceDetailDuplexHalfDashDuplex captures enum value "half-duplex" + NicDeviceDetailDuplexHalfDashDuplex string = "half-duplex" + + // NicDeviceDetailDuplexFullDashDuplex captures enum value "full-duplex" + NicDeviceDetailDuplexFullDashDuplex string = "full-duplex" +) + +// prop value enum +func (m *NicDeviceDetail) validateDuplexEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, nicDeviceDetailTypeDuplexPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *NicDeviceDetail) validateDuplex(formats strfmt.Registry) error { + if swag.IsZero(m.Duplex) { // not required + return nil + } + + // value enum + if err := m.validateDuplexEnum("duplex", "body", m.Duplex); err != nil { + return err + } + + return nil +} + +var nicDeviceDetailTypeStatusPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["UP","DOWN"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + nicDeviceDetailTypeStatusPropEnum = append(nicDeviceDetailTypeStatusPropEnum, v) + } +} + +const ( + + // NicDeviceDetailStatusUP captures enum value "UP" + NicDeviceDetailStatusUP string = "UP" + + // NicDeviceDetailStatusDOWN captures enum value "DOWN" + NicDeviceDetailStatusDOWN string = "DOWN" +) + +// prop value enum +func (m *NicDeviceDetail) validateStatusEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, nicDeviceDetailTypeStatusPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *NicDeviceDetail) validateStatus(formats strfmt.Registry) error { + if swag.IsZero(m.Status) { // not required + return nil + } + + // value enum + if err := m.validateStatusEnum("status", "body", m.Status); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this nic device detail based on context it is used +func (m *NicDeviceDetail) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *NicDeviceDetail) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NicDeviceDetail) UnmarshalBinary(b []byte) error { + var res NicDeviceDetail + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/nic_device_queue_data.go b/tools/dpvs-agent/models/nic_device_queue_data.go new file mode 100644 index 000000000..ac8deb299 --- /dev/null +++ b/tools/dpvs-agent/models/nic_device_queue_data.go @@ -0,0 +1,27 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" +) + +// NicDeviceQueueData nic device queue data +// +// swagger:model NicDeviceQueueData +type NicDeviceQueueData uint64 + +// Validate validates this nic device queue data +func (m NicDeviceQueueData) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this nic device queue data based on context it is used +func (m NicDeviceQueueData) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} diff --git a/tools/dpvs-agent/models/nic_device_spec.go b/tools/dpvs-agent/models/nic_device_spec.go new file mode 100644 index 000000000..ee30a33d5 --- /dev/null +++ b/tools/dpvs-agent/models/nic_device_spec.go @@ -0,0 +1,150 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NicDeviceSpec nic device spec +// +// swagger:model NicDeviceSpec +type NicDeviceSpec struct { + + // detail + Detail *NicDeviceDetail `json:"detail,omitempty"` + + // stats + Stats *NicDeviceStats `json:"stats,omitempty"` +} + +// Validate validates this nic device spec +func (m *NicDeviceSpec) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateDetail(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStats(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceSpec) validateDetail(formats strfmt.Registry) error { + if swag.IsZero(m.Detail) { // not required + return nil + } + + if m.Detail != nil { + if err := m.Detail.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("detail") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("detail") + } + return err + } + } + + return nil +} + +func (m *NicDeviceSpec) validateStats(formats strfmt.Registry) error { + if swag.IsZero(m.Stats) { // not required + return nil + } + + if m.Stats != nil { + if err := m.Stats.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("stats") + } + return err + } + } + + return nil +} + +// ContextValidate validate this nic device spec based on the context it is used +func (m *NicDeviceSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateDetail(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateStats(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceSpec) contextValidateDetail(ctx context.Context, formats strfmt.Registry) error { + + if m.Detail != nil { + if err := m.Detail.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("detail") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("detail") + } + return err + } + } + + return nil +} + +func (m *NicDeviceSpec) contextValidateStats(ctx context.Context, formats strfmt.Registry) error { + + if m.Stats != nil { + if err := m.Stats.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("stats") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NicDeviceSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NicDeviceSpec) UnmarshalBinary(b []byte) error { + var res NicDeviceSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/nic_device_spec_list.go b/tools/dpvs-agent/models/nic_device_spec_list.go new file mode 100644 index 000000000..47ed4981f --- /dev/null +++ b/tools/dpvs-agent/models/nic_device_spec_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NicDeviceSpecList nic device spec list +// +// swagger:model NicDeviceSpecList +type NicDeviceSpecList struct { + + // items + Items []*NicDeviceSpec `json:"Items"` +} + +// Validate validates this nic device spec list +func (m *NicDeviceSpecList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceSpecList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this nic device spec list based on the context it is used +func (m *NicDeviceSpecList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceSpecList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NicDeviceSpecList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NicDeviceSpecList) UnmarshalBinary(b []byte) error { + var res NicDeviceSpecList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/nic_device_stats.go b/tools/dpvs-agent/models/nic_device_stats.go new file mode 100644 index 000000000..27e518db6 --- /dev/null +++ b/tools/dpvs-agent/models/nic_device_stats.go @@ -0,0 +1,342 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NicDeviceStats nic device stats +// +// swagger:model NicDeviceStats +type NicDeviceStats struct { + + // buf avail + BufAvail uint32 `json:"bufAvail,omitempty"` + + // buf inuse + BufInuse uint32 `json:"bufInuse,omitempty"` + + // error bytes q + ErrorBytesQ []NicDeviceQueueData `json:"errorBytesQ"` + + // id + ID uint16 `json:"id,omitempty"` + + // in bytes + InBytes uint64 `json:"inBytes,omitempty"` + + // in bytes q + InBytesQ []NicDeviceQueueData `json:"inBytesQ"` + + // in errors + InErrors uint64 `json:"inErrors,omitempty"` + + // in missed + InMissed uint64 `json:"inMissed,omitempty"` + + // in pkts + InPkts uint64 `json:"inPkts,omitempty"` + + // in pkts q + InPktsQ []NicDeviceQueueData `json:"inPktsQ"` + + // out bytes + OutBytes uint64 `json:"outBytes,omitempty"` + + // out bytes q + OutBytesQ []NicDeviceQueueData `json:"outBytesQ"` + + // out errors + OutErrors uint64 `json:"outErrors,omitempty"` + + // out pkts + OutPkts uint64 `json:"outPkts,omitempty"` + + // out pkts q + OutPktsQ []NicDeviceQueueData `json:"outPktsQ"` + + // rx no mbuf + RxNoMbuf uint64 `json:"rxNoMbuf,omitempty"` +} + +// Validate validates this nic device stats +func (m *NicDeviceStats) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateErrorBytesQ(formats); err != nil { + res = append(res, err) + } + + if err := m.validateInBytesQ(formats); err != nil { + res = append(res, err) + } + + if err := m.validateInPktsQ(formats); err != nil { + res = append(res, err) + } + + if err := m.validateOutBytesQ(formats); err != nil { + res = append(res, err) + } + + if err := m.validateOutPktsQ(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceStats) validateErrorBytesQ(formats strfmt.Registry) error { + if swag.IsZero(m.ErrorBytesQ) { // not required + return nil + } + + for i := 0; i < len(m.ErrorBytesQ); i++ { + + if err := m.ErrorBytesQ[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("errorBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("errorBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) validateInBytesQ(formats strfmt.Registry) error { + if swag.IsZero(m.InBytesQ) { // not required + return nil + } + + for i := 0; i < len(m.InBytesQ); i++ { + + if err := m.InBytesQ[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) validateInPktsQ(formats strfmt.Registry) error { + if swag.IsZero(m.InPktsQ) { // not required + return nil + } + + for i := 0; i < len(m.InPktsQ); i++ { + + if err := m.InPktsQ[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inPktsQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inPktsQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) validateOutBytesQ(formats strfmt.Registry) error { + if swag.IsZero(m.OutBytesQ) { // not required + return nil + } + + for i := 0; i < len(m.OutBytesQ); i++ { + + if err := m.OutBytesQ[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("outBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("outBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) validateOutPktsQ(formats strfmt.Registry) error { + if swag.IsZero(m.OutPktsQ) { // not required + return nil + } + + for i := 0; i < len(m.OutPktsQ); i++ { + + if err := m.OutPktsQ[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("outPktsQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("outPktsQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +// ContextValidate validate this nic device stats based on the context it is used +func (m *NicDeviceStats) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateErrorBytesQ(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateInBytesQ(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateInPktsQ(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateOutBytesQ(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateOutPktsQ(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *NicDeviceStats) contextValidateErrorBytesQ(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.ErrorBytesQ); i++ { + + if err := m.ErrorBytesQ[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("errorBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("errorBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) contextValidateInBytesQ(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.InBytesQ); i++ { + + if err := m.InBytesQ[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) contextValidateInPktsQ(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.InPktsQ); i++ { + + if err := m.InPktsQ[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("inPktsQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("inPktsQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) contextValidateOutBytesQ(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.OutBytesQ); i++ { + + if err := m.OutBytesQ[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("outBytesQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("outBytesQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *NicDeviceStats) contextValidateOutPktsQ(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.OutPktsQ); i++ { + + if err := m.OutPktsQ[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("outPktsQ" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("outPktsQ" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *NicDeviceStats) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *NicDeviceStats) UnmarshalBinary(b []byte) error { + var res NicDeviceStats + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/real_server_expand_list.go b/tools/dpvs-agent/models/real_server_expand_list.go new file mode 100644 index 000000000..4593c3b21 --- /dev/null +++ b/tools/dpvs-agent/models/real_server_expand_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// RealServerExpandList real server expand list +// +// swagger:model RealServerExpandList +type RealServerExpandList struct { + + // items + Items []*RealServerSpecExpand `json:"Items"` +} + +// Validate validates this real server expand list +func (m *RealServerExpandList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerExpandList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this real server expand list based on the context it is used +func (m *RealServerExpandList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerExpandList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *RealServerExpandList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *RealServerExpandList) UnmarshalBinary(b []byte) error { + var res RealServerExpandList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/real_server_spec_expand.go b/tools/dpvs-agent/models/real_server_spec_expand.go new file mode 100644 index 000000000..ba2a517db --- /dev/null +++ b/tools/dpvs-agent/models/real_server_spec_expand.go @@ -0,0 +1,150 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// RealServerSpecExpand real server spec expand +// +// swagger:model RealServerSpecExpand +type RealServerSpecExpand struct { + + // spec + Spec *RealServerSpecTiny `json:"Spec,omitempty"` + + // stats + Stats *ServerStats `json:"Stats,omitempty"` +} + +// Validate validates this real server spec expand +func (m *RealServerSpecExpand) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateSpec(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStats(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerSpecExpand) validateSpec(formats strfmt.Registry) error { + if swag.IsZero(m.Spec) { // not required + return nil + } + + if m.Spec != nil { + if err := m.Spec.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Spec") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Spec") + } + return err + } + } + + return nil +} + +func (m *RealServerSpecExpand) validateStats(formats strfmt.Registry) error { + if swag.IsZero(m.Stats) { // not required + return nil + } + + if m.Stats != nil { + if err := m.Stats.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Stats") + } + return err + } + } + + return nil +} + +// ContextValidate validate this real server spec expand based on the context it is used +func (m *RealServerSpecExpand) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateSpec(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateStats(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerSpecExpand) contextValidateSpec(ctx context.Context, formats strfmt.Registry) error { + + if m.Spec != nil { + if err := m.Spec.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Spec") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Spec") + } + return err + } + } + + return nil +} + +func (m *RealServerSpecExpand) contextValidateStats(ctx context.Context, formats strfmt.Registry) error { + + if m.Stats != nil { + if err := m.Stats.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Stats") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *RealServerSpecExpand) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *RealServerSpecExpand) UnmarshalBinary(b []byte) error { + var res RealServerSpecExpand + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/real_server_spec_tiny.go b/tools/dpvs-agent/models/real_server_spec_tiny.go new file mode 100644 index 000000000..592c97d95 --- /dev/null +++ b/tools/dpvs-agent/models/real_server_spec_tiny.go @@ -0,0 +1,129 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// RealServerSpecTiny real server spec tiny +// +// swagger:model RealServerSpecTiny +type RealServerSpecTiny struct { + + // inhibited + Inhibited *bool `json:"inhibited,omitempty"` + + // ip + IP string `json:"ip,omitempty"` + + // mode + // Enum: [FNAT SNAT DR TUNNEL NAT] + Mode string `json:"mode,omitempty"` + + // overloaded + Overloaded *bool `json:"overloaded,omitempty"` + + // port + Port uint16 `json:"port"` + + // weight + Weight uint16 `json:"weight"` +} + +// Validate validates this real server spec tiny +func (m *RealServerSpecTiny) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMode(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var realServerSpecTinyTypeModePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["FNAT","SNAT","DR","TUNNEL","NAT"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + realServerSpecTinyTypeModePropEnum = append(realServerSpecTinyTypeModePropEnum, v) + } +} + +const ( + + // RealServerSpecTinyModeFNAT captures enum value "FNAT" + RealServerSpecTinyModeFNAT string = "FNAT" + + // RealServerSpecTinyModeSNAT captures enum value "SNAT" + RealServerSpecTinyModeSNAT string = "SNAT" + + // RealServerSpecTinyModeDR captures enum value "DR" + RealServerSpecTinyModeDR string = "DR" + + // RealServerSpecTinyModeTUNNEL captures enum value "TUNNEL" + RealServerSpecTinyModeTUNNEL string = "TUNNEL" + + // RealServerSpecTinyModeNAT captures enum value "NAT" + RealServerSpecTinyModeNAT string = "NAT" +) + +// prop value enum +func (m *RealServerSpecTiny) validateModeEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, realServerSpecTinyTypeModePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *RealServerSpecTiny) validateMode(formats strfmt.Registry) error { + if swag.IsZero(m.Mode) { // not required + return nil + } + + // value enum + if err := m.validateModeEnum("mode", "body", m.Mode); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this real server spec tiny based on context it is used +func (m *RealServerSpecTiny) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *RealServerSpecTiny) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *RealServerSpecTiny) UnmarshalBinary(b []byte) error { + var res RealServerSpecTiny + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/real_server_tiny_list.go b/tools/dpvs-agent/models/real_server_tiny_list.go new file mode 100644 index 000000000..3d6780b77 --- /dev/null +++ b/tools/dpvs-agent/models/real_server_tiny_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// RealServerTinyList real server tiny list +// +// swagger:model RealServerTinyList +type RealServerTinyList struct { + + // items + Items []*RealServerSpecTiny `json:"Items"` +} + +// Validate validates this real server tiny list +func (m *RealServerTinyList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerTinyList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this real server tiny list based on the context it is used +func (m *RealServerTinyList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *RealServerTinyList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *RealServerTinyList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *RealServerTinyList) UnmarshalBinary(b []byte) error { + var res RealServerTinyList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/route_spec.go b/tools/dpvs-agent/models/route_spec.go new file mode 100644 index 000000000..2a7b401b1 --- /dev/null +++ b/tools/dpvs-agent/models/route_spec.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// RouteSpec route spec +// +// swagger:model RouteSpec +type RouteSpec struct { + + // device + Device string `json:"device,omitempty"` + + // dst + Dst string `json:"dst,omitempty"` + + // gateway + Gateway string `json:"gateway,omitempty"` + + // metric + Metric uint32 `json:"metric,omitempty"` + + // mtu + Mtu uint32 `json:"mtu,omitempty"` + + // prefix src + PrefixSrc string `json:"prefixSrc,omitempty"` + + // scope + Scope string `json:"scope,omitempty"` + + // src + Src string `json:"src,omitempty"` +} + +// Validate validates this route spec +func (m *RouteSpec) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this route spec based on context it is used +func (m *RouteSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *RouteSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *RouteSpec) UnmarshalBinary(b []byte) error { + var res RouteSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/server_stats.go b/tools/dpvs-agent/models/server_stats.go new file mode 100644 index 000000000..e2ba38b74 --- /dev/null +++ b/tools/dpvs-agent/models/server_stats.go @@ -0,0 +1,77 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// ServerStats server stats +// +// swagger:model ServerStats +type ServerStats struct { + + // conns + Conns uint64 `json:"Conns,omitempty"` + + // cps + Cps uint32 `json:"Cps,omitempty"` + + // in bps + InBps uint32 `json:"InBps,omitempty"` + + // in bytes + InBytes uint64 `json:"InBytes,omitempty"` + + // in pkts + InPkts uint64 `json:"InPkts,omitempty"` + + // in pps + InPps uint32 `json:"InPps,omitempty"` + + // out bps + OutBps uint32 `json:"OutBps,omitempty"` + + // out bytes + OutBytes uint64 `json:"OutBytes,omitempty"` + + // out pkts + OutPkts uint64 `json:"OutPkts,omitempty"` + + // out pps + OutPps uint32 `json:"OutPps,omitempty"` +} + +// Validate validates this server stats +func (m *ServerStats) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this server stats based on context it is used +func (m *ServerStats) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *ServerStats) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *ServerStats) UnmarshalBinary(b []byte) error { + var res ServerStats + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/status.go b/tools/dpvs-agent/models/status.go new file mode 100644 index 000000000..4b4f3a97d --- /dev/null +++ b/tools/dpvs-agent/models/status.go @@ -0,0 +1,114 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// Status Status of an individual component +// +// swagger:model Status +type Status struct { + + // Human readable status/error/warning message + Msg string `json:"msg,omitempty"` + + // State the component is in + // Enum: [Ok Warning Failure Disabled] + State string `json:"state,omitempty"` +} + +// Validate validates this status +func (m *Status) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateState(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +var statusTypeStatePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["Ok","Warning","Failure","Disabled"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + statusTypeStatePropEnum = append(statusTypeStatePropEnum, v) + } +} + +const ( + + // StatusStateOk captures enum value "Ok" + StatusStateOk string = "Ok" + + // StatusStateWarning captures enum value "Warning" + StatusStateWarning string = "Warning" + + // StatusStateFailure captures enum value "Failure" + StatusStateFailure string = "Failure" + + // StatusStateDisabled captures enum value "Disabled" + StatusStateDisabled string = "Disabled" +) + +// prop value enum +func (m *Status) validateStateEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, statusTypeStatePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *Status) validateState(formats strfmt.Registry) error { + if swag.IsZero(m.State) { // not required + return nil + } + + // value enum + if err := m.validateStateEnum("state", "body", m.State); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this status based on context it is used +func (m *Status) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *Status) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *Status) UnmarshalBinary(b []byte) error { + var res Status + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/virtual_server_list.go b/tools/dpvs-agent/models/virtual_server_list.go new file mode 100644 index 000000000..1880596b5 --- /dev/null +++ b/tools/dpvs-agent/models/virtual_server_list.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// VirtualServerList virtual server list +// +// swagger:model VirtualServerList +type VirtualServerList struct { + + // items + Items []*VirtualServerSpecExpand `json:"Items"` +} + +// Validate validates this virtual server list +func (m *VirtualServerList) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateItems(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerList) validateItems(formats strfmt.Registry) error { + if swag.IsZero(m.Items) { // not required + return nil + } + + for i := 0; i < len(m.Items); i++ { + if swag.IsZero(m.Items[i]) { // not required + continue + } + + if m.Items[i] != nil { + if err := m.Items[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// ContextValidate validate this virtual server list based on the context it is used +func (m *VirtualServerList) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateItems(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerList) contextValidateItems(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Items); i++ { + + if m.Items[i] != nil { + if err := m.Items[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Items" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Items" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + + return nil +} + +// MarshalBinary interface implementation +func (m *VirtualServerList) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *VirtualServerList) UnmarshalBinary(b []byte) error { + var res VirtualServerList + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/virtual_server_spec_expand.go b/tools/dpvs-agent/models/virtual_server_spec_expand.go new file mode 100644 index 000000000..dd887a72d --- /dev/null +++ b/tools/dpvs-agent/models/virtual_server_spec_expand.go @@ -0,0 +1,438 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + "strconv" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// VirtualServerSpecExpand virtual server spec expand +// +// swagger:model VirtualServerSpecExpand +type VirtualServerSpecExpand struct { + + // addr + Addr string `json:"Addr,omitempty"` + + // af + Af uint32 `json:"Af,omitempty"` + + // bps + Bps uint32 `json:"Bps,omitempty"` + + // conn timeout + ConnTimeout uint32 `json:"ConnTimeout,omitempty"` + + // dest check + DestCheck []DestCheckSpec `json:"DestCheck"` + + // expire quiescent + // Enum: [true false] + ExpireQuiescent string `json:"ExpireQuiescent,omitempty"` + + // flags + Flags string `json:"Flags,omitempty"` + + // fwmark + Fwmark uint32 `json:"Fwmark,omitempty"` + + // limit proportion + LimitProportion uint32 `json:"LimitProportion,omitempty"` + + // match + Match *MatchSpec `json:"Match,omitempty"` + + // netmask + Netmask uint32 `json:"Netmask,omitempty"` + + // port + Port uint16 `json:"Port,omitempty"` + + // proto + Proto uint16 `json:"Proto,omitempty"` + + // r ss + RSs *RealServerExpandList `json:"RSs,omitempty"` + + // sched name + // Enum: [rr wrr wlc connhash] + SchedName string `json:"SchedName,omitempty"` + + // stats + Stats *ServerStats `json:"Stats,omitempty"` + + // sync proxy + // Enum: [true false] + SyncProxy string `json:"SyncProxy,omitempty"` + + // timeout + Timeout uint32 `json:"Timeout,omitempty"` +} + +// Validate validates this virtual server spec expand +func (m *VirtualServerSpecExpand) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateDestCheck(formats); err != nil { + res = append(res, err) + } + + if err := m.validateExpireQuiescent(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMatch(formats); err != nil { + res = append(res, err) + } + + if err := m.validateRSs(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSchedName(formats); err != nil { + res = append(res, err) + } + + if err := m.validateStats(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSyncProxy(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerSpecExpand) validateDestCheck(formats strfmt.Registry) error { + if swag.IsZero(m.DestCheck) { // not required + return nil + } + + for i := 0; i < len(m.DestCheck); i++ { + + if err := m.DestCheck[i].Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("DestCheck" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("DestCheck" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +var virtualServerSpecExpandTypeExpireQuiescentPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["true","false"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + virtualServerSpecExpandTypeExpireQuiescentPropEnum = append(virtualServerSpecExpandTypeExpireQuiescentPropEnum, v) + } +} + +const ( + + // VirtualServerSpecExpandExpireQuiescentTrue captures enum value "true" + VirtualServerSpecExpandExpireQuiescentTrue string = "true" + + // VirtualServerSpecExpandExpireQuiescentFalse captures enum value "false" + VirtualServerSpecExpandExpireQuiescentFalse string = "false" +) + +// prop value enum +func (m *VirtualServerSpecExpand) validateExpireQuiescentEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, virtualServerSpecExpandTypeExpireQuiescentPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *VirtualServerSpecExpand) validateExpireQuiescent(formats strfmt.Registry) error { + if swag.IsZero(m.ExpireQuiescent) { // not required + return nil + } + + // value enum + if err := m.validateExpireQuiescentEnum("ExpireQuiescent", "body", m.ExpireQuiescent); err != nil { + return err + } + + return nil +} + +func (m *VirtualServerSpecExpand) validateMatch(formats strfmt.Registry) error { + if swag.IsZero(m.Match) { // not required + return nil + } + + if m.Match != nil { + if err := m.Match.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Match") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Match") + } + return err + } + } + + return nil +} + +func (m *VirtualServerSpecExpand) validateRSs(formats strfmt.Registry) error { + if swag.IsZero(m.RSs) { // not required + return nil + } + + if m.RSs != nil { + if err := m.RSs.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("RSs") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("RSs") + } + return err + } + } + + return nil +} + +var virtualServerSpecExpandTypeSchedNamePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["rr","wrr","wlc","connhash"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + virtualServerSpecExpandTypeSchedNamePropEnum = append(virtualServerSpecExpandTypeSchedNamePropEnum, v) + } +} + +const ( + + // VirtualServerSpecExpandSchedNameRr captures enum value "rr" + VirtualServerSpecExpandSchedNameRr string = "rr" + + // VirtualServerSpecExpandSchedNameWrr captures enum value "wrr" + VirtualServerSpecExpandSchedNameWrr string = "wrr" + + // VirtualServerSpecExpandSchedNameWlc captures enum value "wlc" + VirtualServerSpecExpandSchedNameWlc string = "wlc" + + // VirtualServerSpecExpandSchedNameConnhash captures enum value "connhash" + VirtualServerSpecExpandSchedNameConnhash string = "connhash" +) + +// prop value enum +func (m *VirtualServerSpecExpand) validateSchedNameEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, virtualServerSpecExpandTypeSchedNamePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *VirtualServerSpecExpand) validateSchedName(formats strfmt.Registry) error { + if swag.IsZero(m.SchedName) { // not required + return nil + } + + // value enum + if err := m.validateSchedNameEnum("SchedName", "body", m.SchedName); err != nil { + return err + } + + return nil +} + +func (m *VirtualServerSpecExpand) validateStats(formats strfmt.Registry) error { + if swag.IsZero(m.Stats) { // not required + return nil + } + + if m.Stats != nil { + if err := m.Stats.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Stats") + } + return err + } + } + + return nil +} + +var virtualServerSpecExpandTypeSyncProxyPropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["true","false"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + virtualServerSpecExpandTypeSyncProxyPropEnum = append(virtualServerSpecExpandTypeSyncProxyPropEnum, v) + } +} + +const ( + + // VirtualServerSpecExpandSyncProxyTrue captures enum value "true" + VirtualServerSpecExpandSyncProxyTrue string = "true" + + // VirtualServerSpecExpandSyncProxyFalse captures enum value "false" + VirtualServerSpecExpandSyncProxyFalse string = "false" +) + +// prop value enum +func (m *VirtualServerSpecExpand) validateSyncProxyEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, virtualServerSpecExpandTypeSyncProxyPropEnum, true); err != nil { + return err + } + return nil +} + +func (m *VirtualServerSpecExpand) validateSyncProxy(formats strfmt.Registry) error { + if swag.IsZero(m.SyncProxy) { // not required + return nil + } + + // value enum + if err := m.validateSyncProxyEnum("SyncProxy", "body", m.SyncProxy); err != nil { + return err + } + + return nil +} + +// ContextValidate validate this virtual server spec expand based on the context it is used +func (m *VirtualServerSpecExpand) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateDestCheck(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateMatch(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateRSs(ctx, formats); err != nil { + res = append(res, err) + } + + if err := m.contextValidateStats(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerSpecExpand) contextValidateDestCheck(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.DestCheck); i++ { + + if err := m.DestCheck[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("DestCheck" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("DestCheck" + "." + strconv.Itoa(i)) + } + return err + } + + } + + return nil +} + +func (m *VirtualServerSpecExpand) contextValidateMatch(ctx context.Context, formats strfmt.Registry) error { + + if m.Match != nil { + if err := m.Match.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Match") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Match") + } + return err + } + } + + return nil +} + +func (m *VirtualServerSpecExpand) contextValidateRSs(ctx context.Context, formats strfmt.Registry) error { + + if m.RSs != nil { + if err := m.RSs.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("RSs") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("RSs") + } + return err + } + } + + return nil +} + +func (m *VirtualServerSpecExpand) contextValidateStats(ctx context.Context, formats strfmt.Registry) error { + + if m.Stats != nil { + if err := m.Stats.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Stats") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Stats") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *VirtualServerSpecExpand) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *VirtualServerSpecExpand) UnmarshalBinary(b []byte) error { + var res VirtualServerSpecExpand + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/virtual_server_spec_tiny.go b/tools/dpvs-agent/models/virtual_server_spec_tiny.go new file mode 100644 index 000000000..3ebfd849c --- /dev/null +++ b/tools/dpvs-agent/models/virtual_server_spec_tiny.go @@ -0,0 +1,183 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + "encoding/json" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// VirtualServerSpecTiny virtual server spec tiny +// +// swagger:model VirtualServerSpecTiny +type VirtualServerSpecTiny struct { + + // bps + Bps uint32 `json:"Bps,omitempty"` + + // conn timeout + ConnTimeout uint32 `json:"ConnTimeout,omitempty"` + + // expire quiescent + ExpireQuiescent *bool `json:"ExpireQuiescent,omitempty"` + + // fwmark + Fwmark uint32 `json:"Fwmark,omitempty"` + + // limit proportion + LimitProportion uint32 `json:"LimitProportion,omitempty"` + + // match + Match *MatchSpec `json:"Match,omitempty"` + + // sched name + // Enum: [rr wrr wlc connhash] + SchedName string `json:"SchedName,omitempty"` + + // sync proxy + SyncProxy *bool `json:"SyncProxy,omitempty"` + + // timeout + Timeout uint32 `json:"Timeout,omitempty"` +} + +// Validate validates this virtual server spec tiny +func (m *VirtualServerSpecTiny) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMatch(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSchedName(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerSpecTiny) validateMatch(formats strfmt.Registry) error { + if swag.IsZero(m.Match) { // not required + return nil + } + + if m.Match != nil { + if err := m.Match.Validate(formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Match") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Match") + } + return err + } + } + + return nil +} + +var virtualServerSpecTinyTypeSchedNamePropEnum []interface{} + +func init() { + var res []string + if err := json.Unmarshal([]byte(`["rr","wrr","wlc","connhash"]`), &res); err != nil { + panic(err) + } + for _, v := range res { + virtualServerSpecTinyTypeSchedNamePropEnum = append(virtualServerSpecTinyTypeSchedNamePropEnum, v) + } +} + +const ( + + // VirtualServerSpecTinySchedNameRr captures enum value "rr" + VirtualServerSpecTinySchedNameRr string = "rr" + + // VirtualServerSpecTinySchedNameWrr captures enum value "wrr" + VirtualServerSpecTinySchedNameWrr string = "wrr" + + // VirtualServerSpecTinySchedNameWlc captures enum value "wlc" + VirtualServerSpecTinySchedNameWlc string = "wlc" + + // VirtualServerSpecTinySchedNameConnhash captures enum value "connhash" + VirtualServerSpecTinySchedNameConnhash string = "connhash" +) + +// prop value enum +func (m *VirtualServerSpecTiny) validateSchedNameEnum(path, location string, value string) error { + if err := validate.EnumCase(path, location, value, virtualServerSpecTinyTypeSchedNamePropEnum, true); err != nil { + return err + } + return nil +} + +func (m *VirtualServerSpecTiny) validateSchedName(formats strfmt.Registry) error { + if swag.IsZero(m.SchedName) { // not required + return nil + } + + // value enum + if err := m.validateSchedNameEnum("SchedName", "body", m.SchedName); err != nil { + return err + } + + return nil +} + +// ContextValidate validate this virtual server spec tiny based on the context it is used +func (m *VirtualServerSpecTiny) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateMatch(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *VirtualServerSpecTiny) contextValidateMatch(ctx context.Context, formats strfmt.Registry) error { + + if m.Match != nil { + if err := m.Match.ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("Match") + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("Match") + } + return err + } + } + + return nil +} + +// MarshalBinary interface implementation +func (m *VirtualServerSpecTiny) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *VirtualServerSpecTiny) UnmarshalBinary(b []byte) error { + var res VirtualServerSpecTiny + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/models/vlan_spec.go b/tools/dpvs-agent/models/vlan_spec.go new file mode 100644 index 000000000..ef77bf716 --- /dev/null +++ b/tools/dpvs-agent/models/vlan_spec.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// VlanSpec vlan spec +// +// swagger:model VlanSpec +type VlanSpec struct { + + // device + Device string `json:"device,omitempty"` + + // id + ID string `json:"id,omitempty"` + + // name + Name string `json:"name,omitempty"` +} + +// Validate validates this vlan spec +func (m *VlanSpec) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this vlan spec based on context it is used +func (m *VlanSpec) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *VlanSpec) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *VlanSpec) UnmarshalBinary(b []byte) error { + var res VlanSpec + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/tools/dpvs-agent/pkg/ipc/pool/conn.go b/tools/dpvs-agent/pkg/ipc/pool/conn.go new file mode 100644 index 000000000..6f7034653 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/pool/conn.go @@ -0,0 +1,316 @@ +package pool + +import ( + "bufio" + "context" + "net" + "sync/atomic" + "time" + + "github.com/dpvs-agent/pkg/ipc/proto" +) + +type BadConnError struct { + wrapped error +} + +var _ error = (*BadConnError)(nil) + +func (e BadConnError) Error() string { + s := "dpvs: Conn is in a bad state" + if e.wrapped != nil { + s += ": " + e.wrapped.Error() + } + return s +} + +func (e BadConnError) Unwrap() error { + return e.wrapped +} + +//-------------------------------------- + +var noDeadline = time.Time{} + +type Conn struct { + usedAt int64 // atomic + netConn net.Conn + + rd *proto.Reader + bw *bufio.Writer + wr *proto.Writer + + Inited bool + pooled bool + createdAt time.Time +} + +func NewConn(netConn net.Conn) *Conn { + cn := &Conn{ + netConn: netConn, + createdAt: time.Now(), + } + cn.rd = proto.NewReader(netConn) + cn.bw = bufio.NewWriter(netConn) + cn.wr = proto.NewWriter(cn.bw) + cn.SetUsedAt(time.Now()) + return cn +} + +func (cn *Conn) UsedAt() time.Time { + unix := atomic.LoadInt64(&cn.usedAt) + return time.Unix(unix, 0) +} + +func (cn *Conn) SetUsedAt(tm time.Time) { + atomic.StoreInt64(&cn.usedAt, tm.Unix()) +} + +func (cn *Conn) SetNetConn(netConn net.Conn) { + cn.netConn = netConn + cn.rd.Reset(netConn) + cn.bw.Reset(netConn) +} + +/* +func (cn *Conn) Write(b []byte) (int, error) { + offset := 0 + left := len(b) + for left > 0 { + written, err := cn.write(b[offset:]) + if err != nil { + return offset, err + } + left -= written + offset += written + } + return offset, nil +} +*/ + +type ConnWriteIf interface { + Sizeof() uint64 +} + +func (cn *Conn) Write(o ConnWriteIf) error { + buf := Package(o) + _, err := cn.writeN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +func (cn *Conn) WriteN(b []byte, n int) (int, error) { + return cn.writeN(b, n) +} + +func (cn *Conn) writeN(b []byte, n int) (int, error) { + if n > 0 && n <= len(b) { + if err := cn.SetWriteBuffer(n); err != nil { + return 0, err + } + } + + return cn.write(b) +} + +/* +func (cn *Conn) Read(b []byte) (int, error) { + offset := 0 + left := len(b) + for left > 0 { + readed, err := cn.read(b[offset:]) + if err != nil { + return offset, err + } + offset += readed + left -= readed + } + return offset, nil +} +*/ + +type ConnReadIf interface { + Sizeof() uint64 + Dump([]byte) bool +} + +func (cn *Conn) Read(o ConnReadIf) error { + buf, err := cn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + o.Dump(buf) + + return nil +} + +func (cn *Conn) Release(n int) { + cn.ReadN(n) +} + +func (cn *Conn) ReadN(n int) ([]byte, error) { + return cn.readN(n) +} + +func (cn *Conn) readN(n int) ([]byte, error) { + if err := cn.SetReadBuffer(n); err != nil { + return nil, err + } + + b := make([]byte, n) + readed, err := cn.read(b) + if err != nil || readed != n { + return nil, err + } + return b, nil +} + +func (cn *Conn) write(b []byte) (int, error) { + return cn.netConn.Write(b) +} + +func (cn *Conn) read(b []byte) (int, error) { + return cn.netConn.Read(b) +} + +func (cn *Conn) SetWriteBuffer(bytes int) error { + conn := cn.netConn + if unix, ok := conn.(*net.UnixConn); ok { + return unix.SetWriteBuffer(bytes) + } + if tc, ok := conn.(*net.TCPConn); ok { + return tc.SetWriteBuffer(bytes) + } + if uc, ok := conn.(*net.UDPConn); ok { + return uc.SetWriteBuffer(bytes) + } + if ic, ok := conn.(*net.IPConn); ok { + return ic.SetWriteBuffer(bytes) + } + return nil +} + +func (cn *Conn) SetReadBuffer(bytes int) error { + conn := cn.netConn + if unix, ok := conn.(*net.UnixConn); ok { + return unix.SetReadBuffer(bytes) + } + if tc, ok := conn.(*net.TCPConn); ok { + return tc.SetReadBuffer(bytes) + } + if uc, ok := conn.(*net.UDPConn); ok { + return uc.SetReadBuffer(bytes) + } + if ic, ok := conn.(*net.IPConn); ok { + return ic.SetReadBuffer(bytes) + } + return nil +} + +func (cn *Conn) RemoteAddr() net.Addr { + if cn.netConn != nil { + return cn.netConn.RemoteAddr() + } + return nil +} + +func (cn *Conn) Close() error { + return cn.netConn.Close() +} + +func (cn *Conn) deadline(ctx context.Context, timeout time.Duration) time.Time { + tm := time.Now() + cn.SetUsedAt(tm) + + if timeout > 0 { + tm = tm.Add(timeout) + } + + if ctx != nil { + deadline, ok := ctx.Deadline() + if ok { + if timeout == 0 { + return deadline + } + if deadline.Before(tm) { + return deadline + } + return tm + } + } + + if timeout > 0 { + return tm + } + + return noDeadline +} + +func (cn *Conn) WithWriter(ctx context.Context, timeout time.Duration, fn func(wr *proto.Writer) error) error { + if err := cn.netConn.SetDeadline(cn.deadline(ctx, timeout)); err != nil { + return err + } + + if cn.bw.Buffered() > 0 { + cn.bw.Reset(cn.netConn) + } + + if err := fn(cn.wr); err != nil { + return err + } + + if err := cn.bw.Flush(); err != nil { + return err + } + + return nil + /* + return internal.WithSpan(ctx, "dpvs-agent.with_writer", func(ctx context.Context, span trace.Span) error { + if err := cn.netConn.SetWriteDeadline(cn.deadline(ctx, timeout)); err != nil { + return internal.RecordError(ctx, span, err) + } + + if cn.bw.Buffered() > 0 { + cn.bw.Reset(cn.netConn) + } + + if err := fn(cn.wr); err != nil { + return internal.RecordError(ctx, span, err) + } + + if err := cn.bw.Flush(); err != nil { + return internal.RecordError(ctx, span, err) + } + + internal.WritesCounter.Add(ctx, 1) + + return nil + }) + */ +} + +func (cn *Conn) WithReader(ctx context.Context, timeout time.Duration, fn func(rd *proto.Reader) error) error { + if err := cn.netConn.SetDeadline(cn.deadline(ctx, timeout)); err != nil { + return err + } + + if err := fn(cn.rd); err != nil { + return err + } + + return nil + /* + return internal.WithSpan(ctx, "dpvs-agent.with_reader", func(ctx context.Context, span trace.Span) error { + if err := cn.netConn.SetReadDeadline(cn.deadline(ctx, timeout)); err != nil { + return internal.RecordError(ctx, span, err) + } + if err := fn(cn.rd); err != nil { + return internal.RecordError(ctx, span, err) + } + return nil + }) + */ +} diff --git a/tools/dpvs-agent/pkg/ipc/pool/pool.go b/tools/dpvs-agent/pkg/ipc/pool/pool.go new file mode 100644 index 000000000..c88d9d82d --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/pool/pool.go @@ -0,0 +1,523 @@ +package pool + +import ( + "context" + "errors" + "net" + "sync" + "sync/atomic" + "time" +) + +var ( + ErrClosed = errors.New("client is closed") + ErrPoolTimeout = errors.New("connection pool timeout") +) + +var timers = sync.Pool{ + New: func() interface{} { + t := time.NewTimer(time.Hour) + t.Stop() + return t + }, +} + +// Stats contains pool state information and accumulated stats. +type Stats struct { + Hits uint32 // number of times free connection was found in the pool + Misses uint32 // number of times free connection was NOT found in the pool + Timeouts uint32 // number of times a wait timeout occurred + + TotalConns uint32 // number of total connections in the pool + IdleConns uint32 // number of idle connections in the pool + StaleConns uint32 // number of stale connections removed from the pool +} + +type Pooler interface { + NewConn(context.Context) (*Conn, error) + CloseConn(*Conn) error + + Get(context.Context) (*Conn, error) + Put(context.Context, *Conn) + Remove(context.Context, *Conn, error) + + Len() int + IdleLen() int + Stats() *Stats + + Close() error +} + +type Options struct { + Dialer func(context.Context) (net.Conn, error) + OnClose func(*Conn) error + + PoolSize int + MinIdleConns int + MaxConnAge time.Duration + PoolTimeout time.Duration + IdleTimeout time.Duration + IdleCheckFrequency time.Duration +} + +type lastDialErrorWrap struct { + err error +} + +type ConnPool struct { + opt *Options + + dialErrorsNum uint32 // atomic + + lastDialError atomic.Value + + queue chan struct{} + + connsMu sync.Mutex + conns []*Conn + idleConns []*Conn + poolSize int + idleConnsLen int + + stats Stats + + _closed uint32 // atomic + closedCh chan struct{} +} + +var _ Pooler = (*ConnPool)(nil) + +func NewConnPool(opt *Options) *ConnPool { + p := &ConnPool{ + opt: opt, + + queue: make(chan struct{}, opt.PoolSize), + conns: make([]*Conn, 0, opt.PoolSize), + idleConns: make([]*Conn, 0, opt.PoolSize), + closedCh: make(chan struct{}), + } + + p.connsMu.Lock() + p.checkMinIdleConns() + p.connsMu.Unlock() + + if opt.IdleTimeout > 0 && opt.IdleCheckFrequency > 0 { + go p.reaper(opt.IdleCheckFrequency) + } + + return p +} + +func (p *ConnPool) checkMinIdleConns() { + if p.opt.MinIdleConns == 0 { + return + } + for p.poolSize < p.opt.PoolSize && p.idleConnsLen < p.opt.MinIdleConns { + p.poolSize++ + p.idleConnsLen++ + go func() { + err := p.addIdleConn() + if err != nil { + p.connsMu.Lock() + p.poolSize-- + p.idleConnsLen-- + p.connsMu.Unlock() + } + }() + } +} + +func (p *ConnPool) addIdleConn() error { + cn, err := p.dialConn(context.TODO(), true) + if err != nil { + return err + } + + p.connsMu.Lock() + p.conns = append(p.conns, cn) + p.idleConns = append(p.idleConns, cn) + p.connsMu.Unlock() + return nil +} + +func (p *ConnPool) NewConn(ctx context.Context) (*Conn, error) { + return p.newConn(ctx, false) +} + +func (p *ConnPool) newConn(ctx context.Context, pooled bool) (*Conn, error) { + cn, err := p.dialConn(ctx, pooled) + if err != nil { + return nil, err + } + + p.connsMu.Lock() + p.conns = append(p.conns, cn) + if pooled { + // If pool is full remove the cn on next Put. + if p.poolSize >= p.opt.PoolSize { + cn.pooled = false + } else { + p.poolSize++ + } + } + p.connsMu.Unlock() + + return cn, nil +} + +func (p *ConnPool) dialConn(ctx context.Context, pooled bool) (*Conn, error) { + if p.closed() { + return nil, ErrClosed + } + + if atomic.LoadUint32(&p.dialErrorsNum) >= uint32(p.opt.PoolSize) { + return nil, p.getLastDialError() + } + + netConn, err := p.opt.Dialer(ctx) + if err != nil { + p.setLastDialError(err) + if atomic.AddUint32(&p.dialErrorsNum, 1) == uint32(p.opt.PoolSize) { + go p.tryDial() + } + return nil, err + } + + // internal.NewConnectionsCounter.Add(ctx, 1) + cn := NewConn(netConn) + cn.pooled = pooled + return cn, nil +} + +func (p *ConnPool) tryDial() { + for { + if p.closed() { + return + } + + conn, err := p.opt.Dialer(context.Background()) + if err != nil { + p.setLastDialError(err) + time.Sleep(time.Second) + continue + } + + atomic.StoreUint32(&p.dialErrorsNum, 0) + _ = conn.Close() + return + } +} + +func (p *ConnPool) setLastDialError(err error) { + p.lastDialError.Store(&lastDialErrorWrap{err: err}) +} + +func (p *ConnPool) getLastDialError() error { + err, _ := p.lastDialError.Load().(*lastDialErrorWrap) + if err != nil { + return err.err + } + return nil +} + +// Get returns existed connection from the pool or creates a new one. +func (p *ConnPool) Get(ctx context.Context) (*Conn, error) { + if p.closed() { + return nil, ErrClosed + } + + err := p.waitTurn(ctx) + if err != nil { + return nil, err + } + + for { + p.connsMu.Lock() + cn := p.popIdle() + p.connsMu.Unlock() + + if cn == nil { + break + } + + if p.isStaleConn(cn) { + _ = p.CloseConn(cn) + continue + } + + atomic.AddUint32(&p.stats.Hits, 1) + return cn, nil + } + + atomic.AddUint32(&p.stats.Misses, 1) + + newcn, err := p.newConn(ctx, true) + if err != nil { + p.freeTurn() + return nil, err + } + + return newcn, nil +} + +func (p *ConnPool) getTurn() { + p.queue <- struct{}{} +} + +func (p *ConnPool) waitTurn(ctx context.Context) error { + select { + case <-ctx.Done(): + return ctx.Err() + default: + } + + select { + case p.queue <- struct{}{}: + return nil + default: + } + + timer := timers.Get().(*time.Timer) + timer.Reset(p.opt.PoolTimeout) + + select { + case <-ctx.Done(): + if !timer.Stop() { + <-timer.C + } + timers.Put(timer) + return ctx.Err() + case p.queue <- struct{}{}: + if !timer.Stop() { + <-timer.C + } + timers.Put(timer) + return nil + case <-timer.C: + timers.Put(timer) + atomic.AddUint32(&p.stats.Timeouts, 1) + return ErrPoolTimeout + } +} + +func (p *ConnPool) freeTurn() { + <-p.queue +} + +func (p *ConnPool) popIdle() *Conn { + if len(p.idleConns) == 0 { + return nil + } + + idx := len(p.idleConns) - 1 + cn := p.idleConns[idx] + p.idleConns = p.idleConns[:idx] + p.idleConnsLen-- + p.checkMinIdleConns() + return cn +} + +func (p *ConnPool) Put(ctx context.Context, cn *Conn) { + if cn.rd.Buffered() > 0 { + // internal.Logger.Printf(ctx, "Conn has unread data") + p.Remove(ctx, cn, BadConnError{}) + return + } + + if !cn.pooled { + p.Remove(ctx, cn, nil) + return + } + + p.connsMu.Lock() + p.idleConns = append(p.idleConns, cn) + p.idleConnsLen++ + p.connsMu.Unlock() + p.freeTurn() +} + +func (p *ConnPool) Remove(ctx context.Context, cn *Conn, reason error) { + p.removeConnWithLock(cn) + p.freeTurn() + _ = p.closeConn(cn) +} + +func (p *ConnPool) CloseConn(cn *Conn) error { + p.removeConnWithLock(cn) + return p.closeConn(cn) +} + +func (p *ConnPool) removeConnWithLock(cn *Conn) { + p.connsMu.Lock() + p.removeConn(cn) + p.connsMu.Unlock() +} + +func (p *ConnPool) removeConn(cn *Conn) { + for i, c := range p.conns { + if c == cn { + p.conns = append(p.conns[:i], p.conns[i+1:]...) + if cn.pooled { + p.poolSize-- + p.checkMinIdleConns() + } + return + } + } +} + +func (p *ConnPool) closeConn(cn *Conn) error { + if p.opt.OnClose != nil { + _ = p.opt.OnClose(cn) + } + return cn.Close() +} + +// Len returns total number of connections. +func (p *ConnPool) Len() int { + p.connsMu.Lock() + n := len(p.conns) + p.connsMu.Unlock() + return n +} + +// IdleLen returns number of idle connections. +func (p *ConnPool) IdleLen() int { + p.connsMu.Lock() + n := p.idleConnsLen + p.connsMu.Unlock() + return n +} + +func (p *ConnPool) Stats() *Stats { + idleLen := p.IdleLen() + return &Stats{ + Hits: atomic.LoadUint32(&p.stats.Hits), + Misses: atomic.LoadUint32(&p.stats.Misses), + Timeouts: atomic.LoadUint32(&p.stats.Timeouts), + + TotalConns: uint32(p.Len()), + IdleConns: uint32(idleLen), + StaleConns: atomic.LoadUint32(&p.stats.StaleConns), + } +} + +func (p *ConnPool) closed() bool { + return atomic.LoadUint32(&p._closed) == 1 +} + +func (p *ConnPool) Filter(fn func(*Conn) bool) error { + p.connsMu.Lock() + defer p.connsMu.Unlock() + + var firstErr error + for _, cn := range p.conns { + if fn(cn) { + if err := p.closeConn(cn); err != nil && firstErr == nil { + firstErr = err + } + } + } + return firstErr +} + +func (p *ConnPool) Close() error { + if !atomic.CompareAndSwapUint32(&p._closed, 0, 1) { + return ErrClosed + } + close(p.closedCh) + + var firstErr error + p.connsMu.Lock() + for _, cn := range p.conns { + if err := p.closeConn(cn); err != nil && firstErr == nil { + firstErr = err + } + } + p.conns = nil + p.poolSize = 0 + p.idleConns = nil + p.idleConnsLen = 0 + p.connsMu.Unlock() + + return firstErr +} + +func (p *ConnPool) reaper(frequency time.Duration) { + ticker := time.NewTicker(frequency) + defer ticker.Stop() + + for { + select { + case <-ticker.C: + // It is possible that ticker and closedCh arrive together, + // and select pseudo-randomly pick ticker case, we double + // check here to prevent being executed after closed. + if p.closed() { + return + } + _, err := p.ReapStaleConns() + if err != nil { + // internal.Logger.Printf(context.Background(), "ReapStaleConns failed: %s", err) + continue + } + case <-p.closedCh: + return + } + } +} + +func (p *ConnPool) ReapStaleConns() (int, error) { + var n int + for { + p.getTurn() + + p.connsMu.Lock() + cn := p.reapStaleConn() + p.connsMu.Unlock() + + p.freeTurn() + + if cn != nil { + _ = p.closeConn(cn) + n++ + } else { + break + } + } + atomic.AddUint32(&p.stats.StaleConns, uint32(n)) + return n, nil +} + +func (p *ConnPool) reapStaleConn() *Conn { + if len(p.idleConns) == 0 { + return nil + } + + cn := p.idleConns[0] + if !p.isStaleConn(cn) { + return nil + } + + p.idleConns = append(p.idleConns[:0], p.idleConns[1:]...) + p.idleConnsLen-- + p.removeConn(cn) + + return cn +} + +func (p *ConnPool) isStaleConn(cn *Conn) bool { + if p.opt.IdleTimeout == 0 && p.opt.MaxConnAge == 0 { + return false + } + + now := time.Now() + if p.opt.IdleTimeout > 0 && now.Sub(cn.UsedAt()) >= p.opt.IdleTimeout { + return true + } + if p.opt.MaxConnAge > 0 && now.Sub(cn.createdAt) >= p.opt.MaxConnAge { + return true + } + + return false +} diff --git a/tools/dpvs-agent/pkg/ipc/pool/util.go b/tools/dpvs-agent/pkg/ipc/pool/util.go new file mode 100644 index 000000000..3bd67fbed --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/pool/util.go @@ -0,0 +1,12 @@ +package pool + +import ( + "bytes" + "encoding/binary" +) + +func Package(o ConnWriteIf) []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} diff --git a/tools/dpvs-agent/pkg/ipc/proto/reader.go b/tools/dpvs-agent/pkg/ipc/proto/reader.go new file mode 100644 index 000000000..b77dee8d1 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/proto/reader.go @@ -0,0 +1,335 @@ +package proto + +import ( + "bufio" + "fmt" + "io" +) + +const ( + ErrorReply = '-' + StatusReply = '+' + IntReply = ':' + StringReply = '$' + ArrayReply = '*' +) + +//------------------------------------------------------------------------------ + +const Nil = DpvsError("dpvs: nil") + +type DpvsError string + +func (e DpvsError) Error() string { return string(e) } + +func (DpvsError) DpvsError() {} + +//------------------------------------------------------------------------------ + +type MultiBulkParse func(*Reader, int64) (interface{}, error) + +type Reader struct { + rd *bufio.Reader + _buf []byte +} + +func NewReader(rd io.Reader) *Reader { + return &Reader{ + rd: bufio.NewReader(rd), + _buf: make([]byte, 64), + } +} + +func (r *Reader) Buffered() int { + return r.rd.Buffered() +} + +func (r *Reader) Peek(n int) ([]byte, error) { + return r.rd.Peek(n) +} + +func (r *Reader) Reset(rd io.Reader) { + r.rd.Reset(rd) +} + +func (r *Reader) buf(n int) []byte { + if n <= cap(r._buf) { + return r._buf[:n] + } + d := n - cap(r._buf) + r._buf = append(r._buf, make([]byte, d)...) + return r._buf +} + +func (r *Reader) ReadReply(m MultiBulkParse) (interface{}, error) { + /* + line, err := r.ReadLine() + + if err != nil { + return nil, err + } + + switch line[0] { + case ErrorReply: + return nil, ParseErrorReply(line) + case StatusReply: + return string(line[1:]), nil + case IntReply: + return util.ParseInt(line[1:], 10, 64) + case StringReply: + return r.readStringReply(line) + case ArrayReply: + n, err := parseArrayLen(line) + if err != nil { + return nil, err + } + if m == nil { + err := fmt.Errorf("dpvs: got %.100q, but multi bulk parser is nil", line) + return nil, err + } + return m(r, n) + } + */ + return nil, fmt.Errorf("dpvs read failed") +} + +/* +func (r *Reader) ReadLine() ([]byte, error) { + line, err := r.readLine() + if err != nil { + return nil, err + } + if isNilReply(line) { + return nil, Nil + } + return line, nil +} + +// readLine that returns an error if: +// - there is a pending read error; +// - or line does not end with \r\n. +func (r *Reader) readLine() ([]byte, error) { + b, err := r.rd.ReadSlice('\n') + if err != nil { + if err != bufio.ErrBufferFull { + return nil, err + } + + full := make([]byte, len(b)) + copy(full, b) + + b, err = r.rd.ReadBytes('\n') + if err != nil { + return nil, err + } + + full = append(full, b...) + b = full + } + if len(b) <= 2 || b[len(b)-1] != '\n' || b[len(b)-2] != '\r' { + return nil, fmt.Errorf("dpvs: invalid reply: %q", b) + } + return b[:len(b)-2], nil +} + +func (r *Reader) ReadIntReply() (int64, error) { + line, err := r.ReadLine() + if err != nil { + return 0, err + } + switch line[0] { + case ErrorReply: + return 0, ParseErrorReply(line) + case IntReply: + return util.ParseInt(line[1:], 10, 64) + default: + return 0, fmt.Errorf("dpvs: can't parse int reply: %.100q", line) + } +} + +func (r *Reader) ReadString() (string, error) { + line, err := r.ReadLine() + if err != nil { + return "", err + } + switch line[0] { + case ErrorReply: + return "", ParseErrorReply(line) + case StringReply: + return r.readStringReply(line) + case StatusReply: + return string(line[1:]), nil + case IntReply: + return string(line[1:]), nil + default: + return "", fmt.Errorf("dpvs: can't parse reply=%.100q reading string", line) + } +} + +func (r *Reader) readStringReply(line []byte) (string, error) { + if isNilReply(line) { + return "", Nil + } + + replyLen, err := util.Atoi(line[1:]) + if err != nil { + return "", err + } + + b := make([]byte, replyLen+2) + _, err = io.ReadFull(r.rd, b) + if err != nil { + return "", err + } + + return util.BytesToString(b[:replyLen]), nil +} + +func (r *Reader) ReadArrayReply(m MultiBulkParse) (interface{}, error) { + line, err := r.ReadLine() + if err != nil { + return nil, err + } + switch line[0] { + case ErrorReply: + return nil, ParseErrorReply(line) + case ArrayReply: + n, err := parseArrayLen(line) + if err != nil { + return nil, err + } + return m(r, n) + default: + return nil, fmt.Errorf("dpvs: can't parse array reply: %.100q", line) + } +} + +func (r *Reader) ReadArrayLen() (int, error) { + line, err := r.ReadLine() + if err != nil { + return 0, err + } + switch line[0] { + case ErrorReply: + return 0, ParseErrorReply(line) + case ArrayReply: + n, err := parseArrayLen(line) + if err != nil { + return 0, err + } + return int(n), nil + default: + return 0, fmt.Errorf("dpvs: can't parse array reply: %.100q", line) + } +} +func (r *Reader) ReadScanReply() ([]string, uint64, error) { + n, err := r.ReadArrayLen() + if err != nil { + return nil, 0, err + } + if n != 2 { + return nil, 0, fmt.Errorf("dpvs: got %d elements in scan reply, expected 2", n) + } + + cursor, err := r.ReadUint() + if err != nil { + return nil, 0, err + } + + n, err = r.ReadArrayLen() + if err != nil { + return nil, 0, err + } + + keys := make([]string, n) + + for i := 0; i < n; i++ { + key, err := r.ReadString() + if err != nil { + return nil, 0, err + } + keys[i] = key + } + + return keys, cursor, err +} +*/ +/* +func (r *Reader) ReadInt() (int64, error) { + b, err := r.readTmpBytesReply() + if err != nil { + return 0, err + } + return util.ParseInt(b, 10, 64) +} + +func (r *Reader) ReadUint() (uint64, error) { + b, err := r.readTmpBytesReply() + if err != nil { + return 0, err + } + return util.ParseUint(b, 10, 64) +} + +func (r *Reader) ReadFloatReply() (float64, error) { + b, err := r.readTmpBytesReply() + if err != nil { + return 0, err + } + return util.ParseFloat(b, 64) +} + +func (r *Reader) readTmpBytesReply() ([]byte, error) { + line, err := r.ReadLine() + if err != nil { + return nil, err + } + switch line[0] { + case ErrorReply: + return nil, ParseErrorReply(line) + case StringReply: + return r._readTmpBytesReply(line) + case StatusReply: + return line[1:], nil + default: + return nil, fmt.Errorf("dpvs: can't parse string reply: %.100q", line) + } +} + +func (r *Reader) _readTmpBytesReply(line []byte) ([]byte, error) { + if isNilReply(line) { + return nil, Nil + } + + replyLen, err := util.Atoi(line[1:]) + if err != nil { + return nil, err + } + + buf := r.buf(replyLen + 2) + _, err = io.ReadFull(r.rd, buf) + if err != nil { + return nil, err + } + + return buf[:replyLen], nil +} +*/ +/* +func isNilReply(b []byte) bool { + return len(b) == 3 && + (b[0] == StringReply || b[0] == ArrayReply) && + b[1] == '-' && b[2] == '1' +} + +func ParseErrorReply(line []byte) error { + return DpvsError(string(line[1:])) +} + +func parseArrayLen(line []byte) (int64, error) { + if isNilReply(line) { + return 0, Nil + } + return util.ParseInt(line[1:], 10, 64) +} +*/ diff --git a/tools/dpvs-agent/pkg/ipc/proto/writer.go b/tools/dpvs-agent/pkg/ipc/proto/writer.go new file mode 100644 index 000000000..a4aced90d --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/proto/writer.go @@ -0,0 +1,167 @@ +package proto + +import ( + "encoding" + "fmt" + "io" + "strconv" + "time" + "unsafe" +) + +// BytesToString converts byte slice to string. +func BytesToString(b []byte) string { + return *(*string)(unsafe.Pointer(&b)) +} + +// StringToBytes converts string to byte slice. +func StringToBytes(s string) []byte { + return *(*[]byte)(unsafe.Pointer( + &struct { + string + Cap int + }{s, len(s)}, + )) +} + +type writer interface { + io.Writer + io.ByteWriter + // io.StringWriter + WriteString(s string) (n int, err error) +} + +type Writer struct { + writer + + lenBuf []byte + numBuf []byte +} + +func NewWriter(wr writer) *Writer { + return &Writer{ + writer: wr, + + lenBuf: make([]byte, 64), + numBuf: make([]byte, 64), + } +} + +func (w *Writer) WriteArgs(args []interface{}) error { + if err := w.WriteByte(ArrayReply); err != nil { + return err + } + + if err := w.writeLen(len(args)); err != nil { + return err + } + + for _, arg := range args { + if err := w.WriteArg(arg); err != nil { + return err + } + } + + return nil +} + +func (w *Writer) writeLen(n int) error { + w.lenBuf = strconv.AppendUint(w.lenBuf[:0], uint64(n), 10) + w.lenBuf = append(w.lenBuf, '\r', '\n') + _, err := w.Write(w.lenBuf) + return err +} + +func (w *Writer) WriteArg(v interface{}) error { + switch v := v.(type) { + case nil: + return w.string("") + case string: + return w.string(v) + case []byte: + return w.bytes(v) + case int: + return w.int(int64(v)) + case int8: + return w.int(int64(v)) + case int16: + return w.int(int64(v)) + case int32: + return w.int(int64(v)) + case int64: + return w.int(v) + case uint: + return w.uint(uint64(v)) + case uint8: + return w.uint(uint64(v)) + case uint16: + return w.uint(uint64(v)) + case uint32: + return w.uint(uint64(v)) + case uint64: + return w.uint(v) + case float32: + return w.float(float64(v)) + case float64: + return w.float(v) + case bool: + if v { + return w.int(1) + } + return w.int(0) + case time.Time: + w.numBuf = v.AppendFormat(w.numBuf[:0], time.RFC3339Nano) + return w.bytes(w.numBuf) + case encoding.BinaryMarshaler: + b, err := v.MarshalBinary() + if err != nil { + return err + } + return w.bytes(b) + default: + return fmt.Errorf( + "dpvs-agent: can't marshal %T (implement encoding.BinaryMarshaler)", v) + } +} + +func (w *Writer) bytes(b []byte) error { + if err := w.WriteByte(StringReply); err != nil { + return err + } + + if err := w.writeLen(len(b)); err != nil { + return err + } + + if _, err := w.Write(b); err != nil { + return err + } + + return w.crlf() +} + +func (w *Writer) string(s string) error { + return w.bytes(StringToBytes(s)) +} + +func (w *Writer) uint(n uint64) error { + w.numBuf = strconv.AppendUint(w.numBuf[:0], n, 10) + return w.bytes(w.numBuf) +} + +func (w *Writer) int(n int64) error { + w.numBuf = strconv.AppendInt(w.numBuf[:0], n, 10) + return w.bytes(w.numBuf) +} + +func (w *Writer) float(f float64) error { + w.numBuf = strconv.AppendFloat(w.numBuf[:0], f, 'f', -1, 64) + return w.bytes(w.numBuf) +} + +func (w *Writer) crlf() error { + if err := w.WriteByte('\r'); err != nil { + return err + } + return w.WriteByte('\n') +} diff --git a/tools/dpvs-agent/pkg/ipc/types/certificate.go b/tools/dpvs-agent/pkg/ipc/types/certificate.go new file mode 100644 index 000000000..b0b7b74a4 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/certificate.go @@ -0,0 +1,369 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type CertificateAuthoritySpec struct { + src [0x10]byte + dst [0x10]byte + af uint32 + fwmark uint32 + port uint16 + proto uint8 + padding uint8 +} + +type CertificateAuthorityFront struct { + count uint32 +} + +func NewCertificateAuthoritySpec() *CertificateAuthoritySpec { + return &CertificateAuthoritySpec{} +} + +func NewCertificateAuthorityFront() *CertificateAuthorityFront { + return &CertificateAuthorityFront{} +} + +func (o *CertificateAuthoritySpec) Copy(src *CertificateAuthoritySpec) bool { + o.af = src.af + o.fwmark = src.fwmark + o.port = src.port + o.proto = src.proto + copy(o.src[:], src.src[:]) + copy(o.dst[:], src.dst[:]) + return true +} + +func (o *CertificateAuthoritySpec) ParseVipPortProto(vipport string) error { + items := strings.Split(vipport, "-") + if len(items) != 3 { + return errors.New("invalid vip-port-proto string") + } + + proto := items[2] + + switch strings.ToLower(proto) { + case "udp": + o.proto = unix.IPPROTO_UDP + case "tcp": + fallthrough + default: + o.proto = unix.IPPROTO_TCP + } + + // port := items[1] + port, err := strconv.Atoi(items[1]) + if err != nil { + return err + } + o.SetPort(uint16(port)) + + vip := items[0] + if net.ParseIP(vip) == nil { + return errors.New(fmt.Sprintf("invalid ip addr: %s\n", vip)) + } + + o.SetDst(vip) + + return nil +} + +func (o *CertificateAuthorityFront) Copy(src *CertificateAuthorityFront) bool { + o.count = src.count + return true +} + +func (o *CertificateAuthoritySpec) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *CertificateAuthorityFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *CertificateAuthoritySpec) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *CertificateAuthoritySpec = *(**CertificateAuthoritySpec)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *CertificateAuthorityFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *CertificateAuthorityFront = *(**CertificateAuthorityFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *CertificateAuthoritySpec) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *CertificateAuthorityFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *CertificateAuthorityFront) SetCount(count uint32) { + o.count = count +} + +func (o *CertificateAuthorityFront) GetCount() uint32 { + return o.count +} + +func (o *CertificateAuthoritySpec) SetAf(af uint32) { + o.af = af +} + +func (o *CertificateAuthoritySpec) SetSrc(addr string) { + if strings.Contains(addr, ":") { + o.SetAf(unix.AF_INET6) + copy(o.src[:], net.ParseIP(addr)) + return + } + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.src[:], buf.Bytes()[12:]) +} + +func (o *CertificateAuthoritySpec) SetDst(addr string) { + if strings.Contains(addr, ":") { + o.SetAf(unix.AF_INET6) + copy(o.dst[:], net.ParseIP(addr)) + return + } + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.dst[:], buf.Bytes()[12:]) +} + +func (o *CertificateAuthoritySpec) SetFwmark(fwmark uint32) { + o.fwmark = fwmark +} + +func (o *CertificateAuthoritySpec) SetPort(port uint16) { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(port)) + o.port = binary.BigEndian.Uint16(buf.Bytes()) +} + +func (o *CertificateAuthoritySpec) SetProto(proto string) { + switch strings.ToLower(proto) { + case "udp": + o.proto = unix.IPPROTO_UDP + default: + o.proto = unix.IPPROTO_TCP + } +} + +func (o *CertificateAuthorityFront) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*CertificateAuthorityFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to CertificateAuthorityFront") + } + + fronts := make([]*CertificateAuthorityFront, cnt) + + for i := 0; i < int(cnt); i++ { + fronts[i] = NewCertificateAuthorityFront() + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *CertificateAuthoritySpec) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*CertificateAuthoritySpec, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to CertificateAuthoritySpec") + } + + calst := make([]*CertificateAuthoritySpec, cnt) + for i := 0; i < int(cnt); i++ { + calst[i] = NewCertificateAuthoritySpec() + + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + calst[i].Dump(buf) + } + + return calst, nil +} + +func (o *CertificateAuthoritySpec) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +func (o *CertificateAuthoritySpec) Add(cp *pool.ConnPool, blk bool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var ADD uint32 + SOCKOPT_STRING := "SOCKOPT_SET_BLKLST_ADD" + ADD = SOCKOPT_SET_BLKLST_ADD + if !blk { + SOCKOPT_STRING = "SOCKOPT_SET_WHTLST_ADD" + ADD = SOCKOPT_SET_WHTLST_ADD + } + + msg := NewSockMsg(SOCKOPT_VERSION, ADD, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write proto header Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + err = o.write(conn, logger) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write specific auth user Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s reply msg Read Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + logger.Info(fmt.Sprintf("Sockopt %s Done:%s", SOCKOPT_STRING, errCode.String())) + return errCode +} + +func (o *CertificateAuthoritySpec) Del(cp *pool.ConnPool, blk bool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var DEL uint32 + SOCKOPT_STRING := "SOCKOPT_SET_BLKLST_DEL" + DEL = SOCKOPT_SET_BLKLST_DEL + if !blk { + SOCKOPT_STRING = "SOCKOPT_SET_WHTLST_DEL" + DEL = SOCKOPT_SET_WHTLST_DEL + } + + msg := NewSockMsg(SOCKOPT_VERSION, DEL, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write proto header Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + err = o.write(conn, logger) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write specific auth user Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s reply msg Read Error: %s", SOCKOPT_STRING, err.Error())) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + logger.Info(fmt.Sprintf("Sockopt %s Done:%s", SOCKOPT_STRING, errCode.String())) + return errCode +} + +func (o *CertificateAuthoritySpec) Get(cp *pool.ConnPool, blk bool, logger hclog.Logger) ([]*CertificateAuthoritySpec, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + var GET uint32 + SOCKOPT_STRING := "SOCKOPT_GET_BLKLST_GETALL" + GET = SOCKOPT_GET_BLKLST_GETALL + if !blk { + GET = SOCKOPT_GET_WHTLST_GETALL + SOCKOPT_STRING = "SOCKOPT_GET_WHTLST_GETALL" + } + + msg := NewSockMsg(SOCKOPT_VERSION, GET, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write proto header Error: %s", SOCKOPT_STRING, err.Error())) + return nil, err + } + + if err := o.write(conn, logger); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write specific auth user Error: %s", SOCKOPT_STRING, err.Error())) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s reply msg Read Error: %s", SOCKOPT_STRING, err.Error())) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + err = fmt.Errorf("Sockopt %s reply ErrorCode: %s", SOCKOPT_STRING, reply.GetErrStr()) + logger.Error(err.Error()) + return nil, err + } + + front := NewCertificateAuthorityFront() + _, err = front.read(conn, front.Sizeof(), logger) + if err != nil { + logger.Error(fmt.Sprintf("Sockopt %s read auth user table header Error: %s", SOCKOPT_STRING, err.Error())) + return nil, err + } + + return o.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} diff --git a/tools/dpvs-agent/pkg/ipc/types/const.go b/tools/dpvs-agent/pkg/ipc/types/const.go new file mode 100644 index 000000000..9cbc3d49a --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/const.go @@ -0,0 +1,334 @@ +package types + +import ( + "strings" +) + +type lcoreid_t uint8 +type SockoptType uint32 +type DpvsErrType int32 +type DpvsFwdMode uint32 + +const ( + DPVS_FWD_MASQ DpvsFwdMode = iota + DPVS_FWD_LOCALNODE + DPVS_FWD_MODE_TUNNEL + DPVS_FWD_MODE_DR + DPVS_FWD_MODE_BYPASS + DPVS_FWD_MODE_FNAT + DPVS_FWD_MODE_SNAT +) +const DPVS_FWD_MODE_NAT DpvsFwdMode = DPVS_FWD_MASQ + +const ( + DPVS_SVC_F_PERSISTENT = 0x1 << iota + DPVS_SVC_F_HASHED + DPVS_SVC_F_ONEPACKET + DPVS_SVC_F_SCHED1 + DPVS_SVC_F_SCHED2 + DPVS_SVC_F_SCHED3 +) + +const ( + DPVS_SVC_F_SIP_HASH uint32 = 0x100 << iota + DPVS_SVC_F_QID_HASH + DPVS_SVC_F_MATCH +) + +const ( + DPVS_DEST_HC_PASSIVE = 0x1 << iota + DPVS_DEST_HC_TCP + DPVS_DEST_HC_UDP + DPVS_DEST_HC_PING +) + +const ( + DPVS_DEST_F_AVAILABLE = 0x1 << iota + DPVS_DEST_F_OVERLOAD + DPVS_DEST_F_INHIBITED +) + +const ( + DPVS_CONN_F_MASQ = iota + DPVS_CONN_F_LOCALNODE + DPVS_CONN_F_TUNNEL + DPVS_CONN_F_DROUTE + DPVS_CONN_F_BYPASS + DPVS_CONN_F_FULLNAT + DPVS_CONN_F_SNAT + DPVS_CONN_F_FWD_MASK +) + +const ( + DPVS_CONN_F_SYNPROXY = 0x10 << iota + DPVS_CONN_F_EXPIRE_QUIESCENT + _ + _ + DPVS_CONN_F_HASHED + DPVS_CONN_F_INACTIVE + DPVS_CONN_F_TEMPLATE + DPVS_CONN_F_ONE_PACKET + DPVS_CONN_F_IN_TIMER + DPVS_CONN_F_REDIRECT_HASHED + DPVS_CONN_F_NOFASTXMIT +) + +func (e *DpvsFwdMode) String() string { + switch *e { + case DPVS_FWD_MASQ: // DPVS_FWD_MASQ == DPVS_FWD_MODE_NAT + return "MASQ" + case DPVS_FWD_LOCALNODE: + return "LOCALNODE" + case DPVS_FWD_MODE_DR: + return "DR" + case DPVS_FWD_MODE_TUNNEL: + return "TUNNLE" + case DPVS_FWD_MODE_BYPASS: + return "BYPASS" + case DPVS_FWD_MODE_SNAT: + return "SNAT" + case DPVS_FWD_MODE_FNAT: + return "FNAT" + } + return "UNKNOW" +} + +func (e *DpvsFwdMode) FromString(name string) { + switch strings.ToUpper(name) { + case "MASQ": + *e = DPVS_FWD_MASQ + case "LOCALNODE": + *e = DPVS_FWD_LOCALNODE + case "DR": + *e = DPVS_FWD_MODE_DR + case "TUNNLE": + *e = DPVS_FWD_MODE_TUNNEL + case "BYPASS": + *e = DPVS_FWD_MODE_BYPASS + case "SNAT": + *e = DPVS_FWD_MODE_SNAT + case "NAT": + *e = DPVS_FWD_MODE_NAT + case "FNAT": + *e = DPVS_FWD_MODE_FNAT + default: + *e = DPVS_FWD_MODE_FNAT + } +} + +const ( + EDPVS_INPROGRESS DpvsErrType = 2 - iota + EDPVS_KNICONTINUE + EDPVS_OK + EDPVS_INVAL + EDPVS_NOMEM + EDPVS_EXIST + EDPVS_NOTEXIST + EDPVS_INVPKT + EDPVS_DROP + EDPVS_NOPROT + EDPVS_NOROUTE + EDPVS_DEFRAG + EDPVS_FRAG + EDPVS_DPDKAPIFAIL + EDPVS_IDLE + EDPVS_BUSY + EDPVS_NOTSUPP + EDPVS_RESOURCE + EDPVS_OVERLOAD + EDPVS_NOSERV + EDPVS_DISABLED + EDPVS_NOROOM + EDPVS_NONEALCORE + EDPVS_CALLBACKFAIL + EDPVS_IO + EDPVS_MSG_FAIL + EDPVS_MSG_DROP + EDPVS_PKTSTOLEN + EDPVS_SYSCALL + EDPVS_NODEV +) + +var dpvsErrNames = [...]string{"EDPVS_INPROGRESS", "EDPVS_KNICONTINUE", "EDPVS_OK", "EDPVS_INVAL", "EDPVS_NOMEM", "EDPVS_EXIST", "EDPVS_NOTEXIST", "EDPVS_INVPKT", "EDPVS_DROP", "EDPVS_NOPROT", "EDPVS_NOROUTE", "EDPVS_DEFRAG", "EDPVS_FRAG", "EDPVS_DPDKAPIFAIL", "EDPVS_IDLE", "EDPVS_BUSY", "EDPVS_NOTSUPP", "EDPVS_RESOURCE", "EDPVS_OVERLOAD", "EDPVS_NOSERV", "EDPVS_DISABLED", "EDPVS_NOROOM", "EDPVS_NONEALCORE", "EDPVS_CALLBACKFAIL", "EDPVS_IO", "EDPVS_MSG_FAIL", "EDPVS_MSG_DROP", "EDPVS_PKTSTOLEN", "EDPVS_SYSCALL", "EDPVS_NODEV"} + +func (e *DpvsErrType) String() string { + return dpvsErrNames[EDPVS_INPROGRESS-*e] +} + +const ( + SOCKOPT_VERSION = 0x10000 +) + +const ( + SOCKOPT_GET SockoptType = iota + SOCKOPT_SET + SOCKOPT_TYPE_MAX +) + +const ( + SOCKOPT_SET_LADDR_ADD = iota + SOCKOPT_SET_LADDR_DEL + SOCKOPT_SET_LADDR_FLUSH + SOCKOPT_GET_LADDR_GETALL + SOCKOPT_GET_LADDR_MAX + + DPVSAGENT_VS_GET_LADDR + DPVSAGENT_VS_ADD_LADDR + DPVSAGENT_VS_DEL_LADDR + + DPVS_SO_SET_FLUSH + DPVS_SO_SET_ZERO + DPVS_SO_SET_ADD + DPVS_SO_SET_EDIT + DPVS_SO_SET_DEL + DPVS_SO_SET_ADDDEST + DPVS_SO_SET_EDITDEST + DPVS_SO_SET_DELDEST + DPVS_SO_SET_GRATARP + DPVS_SO_GET_VERSION + DPVS_SO_GET_INFO + DPVS_SO_GET_SERVICES + DPVS_SO_GET_SERVICE + DPVS_SO_GET_DESTS + DPVSAGENT_SO_GET_SERVICES + SOCKOPT_SVC_MAX + + DPVSAGENT_VS_GET_DESTS + DPVSAGENT_VS_ADD_DESTS + DPVSAGENT_VS_EDIT_DESTS + DPVSAGENT_VS_DEL_DESTS + + SOCKOPT_SET_ROUTE_ADD + SOCKOPT_SET_ROUTE_DEL + SOCKOPT_SET_ROUTE_SET + SOCKOPT_SET_ROUTE_FLUSH + SOCKOPT_GET_ROUTE_SHOW + + SOCKOPT_SET_ROUTE6_ADD_DEL + SOCKOPT_SET_ROUTE6_FLUSH + SOCKOPT_GET_ROUTE6_SHOW + + DPVSAGENT_ROUTE_GET + DPVSAGENT_ROUTE_ADD + DPVSAGENT_ROUTE_DEL + DPVSAGENT_ROUTE6_GET + DPVSAGENT_ROUTE6_ADD + DPVSAGENT_ROUTE6_DEL + + DPVSAGENT_IFADDR_GET_BASE + DPVSAGENT_IFADDR_GET_STATS + DPVSAGENT_IFADDR_GET_VERBOSE + DPVSAGENT_IFADDR_ADD + DPVSAGENT_IFADDR_DEL + + SOCKOPT_SET_IFADDR_ADD + SOCKOPT_SET_IFADDR_DEL + SOCKOPT_SET_IFADDR_SET + SOCKOPT_SET_IFADDR_FLUSH + SOCKOPT_GET_IFADDR_SHOW + + SOCKOPT_NETIF_SET_LCORE + SOCKOPT_NETIF_SET_PORT + SOCKOPT_NETIF_SET_BOND + SOCKOPT_NETIF_SET_MAX + SOCKOPT_NETIF_GET_LCORE_MASK + SOCKOPT_NETIF_GET_LCORE_BASIC + SOCKOPT_NETIF_GET_LCORE_STATS + SOCKOPT_NETIF_GET_PORT_LIST + SOCKOPT_NETIF_GET_PORT_BASIC + SOCKOPT_NETIF_GET_PORT_STATS + SOCKOPT_NETIF_GET_PORT_XSTATS + SOCKOPT_NETIF_GET_PORT_EXT_INFO + SOCKOPT_NETIF_GET_BOND_STATUS + SOCKOPT_NETIF_GET_MAX + + SOCKOPT_SET_NEIGH_ADD + SOCKOPT_SET_NEIGH_DEL + SOCKOPT_GET_NEIGH_SHOW + + SOCKOPT_SET_BLKLST_ADD + SOCKOPT_SET_BLKLST_DEL + SOCKOPT_SET_BLKLST_FLUSH + SOCKOPT_GET_BLKLST_GETALL + + SOCKOPT_SET_WHTLST_ADD + SOCKOPT_SET_WHTLST_DEL + SOCKOPT_SET_WHTLST_FLUSH + SOCKOPT_GET_WHTLST_GETALL + + SOCKOPT_SET_VLAN_ADD + SOCKOPT_SET_VLAN_DEL + SOCKOPT_GET_VLAN_SHOW + + SOCKOPT_TC_ADD + SOCKOPT_TC_DEL + SOCKOPT_TC_CHANGE + SOCKOPT_TC_REPLACE + SOCKOPT_TC_SHOW + + SOCKOPT_SET_CONN + SOCKOPT_GET_CONN_ALL + SOCKOPT_GET_CONN_SPECIFIED + + SOCKOPT_IP6_SET + SOCKOPT_IP6_STATS + + SOCKOPT_TUNNEL_ADD + SOCKOPT_TUNNEL_DEL + SOCKOPT_TUNNEL_CHANGE + SOCKOPT_TUNNEL_REPLACE + SOCKOPT_TUNNEL_SHOW + + SOCKOPT_SET_KNI_ADD + SOCKOPT_SET_KNI_DEL + SOCKOPT_SET_KNI_FLUSH + SOCKOPT_GET_KNI_LIST + + SOCKOPT_SET_IPSET + SOCKOPT_GET_IPSET_TEST + SOCKOPT_GET_IPSET_LIST + + SOCKOPT_SET_IFTRAF_ADD + SOCKOPT_SET_IFTRAF_DEL + SOCKOPT_GET_IFTRAF_SHOW +) + +const ( + NETIF_NIC_PROMISC_ON = 1 << iota + NETIF_NIC_PROMISC_OFF + NETIF_NIC_LINK_UP + NETIF_NIC_LINK_DOWN + NETIF_NIC_FWD2KNI_ON + NETIF_NIC_FWD2KNI_OFF + NETIF_NIC_TC_EGRESS_ON + NETIF_NIC_TC_EGRESS_OFF + NETIF_NIC_TC_INGRESS_ON + NETIF_NIC_TC_INGRESS_OFF +) + +const ( + RTF_UP = 1 << iota + RTF_GATEWAY + RTF_HOST + RTF_REINSTATE + RTF_DYNAMIC + RTF_MODIFIED + RTF_MTU + RTF_WINDOW + RTF_IRTT + RTF_REJECT + + RTF_FORWARD + RTF_LOCALIN + RTF_DEFAULT + RTF_KNI + RTF_OUTWALL +) + +const ( + IFA_SCOPE_GLOBAL uint8 = iota + IFA_SCOPE_SITE + IFA_SCOPE_LINK + IFA_SCOPE_HOST + IFA_SCOPE_NONE = 255 +) diff --git a/tools/dpvs-agent/pkg/ipc/types/dpvsmatch.go b/tools/dpvs-agent/pkg/ipc/types/dpvsmatch.go new file mode 100644 index 000000000..97c180ce7 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/dpvsmatch.go @@ -0,0 +1,56 @@ +package types + +type dpvsMatch struct { + af uint32 + srange ipRange + drange ipRange + iIfName [0x10]byte + oIfName [0x10]byte +} + +func (m *dpvsMatch) Copy(src *dpvsMatch) bool { + if src == nil { + return false + } + + m.af = src.af + + copy(m.iIfName[:], src.iIfName[:]) + copy(m.oIfName[:], src.oIfName[:]) + + if !m.srange.Copy(&src.srange) { + return false + } + if !m.drange.Copy(&src.drange) { + return false + } + return true +} + +func (m *dpvsMatch) SetAf(af uint32) { + m.af = af +} + +func (m *dpvsMatch) SetSrange(r *ipRange) { + m.srange.Copy(r) +} + +func (m *dpvsMatch) SetDrange(r *ipRange) { + m.drange.Copy(r) +} + +func (m *dpvsMatch) SetIifName(name []byte) { + copy(m.iIfName[:], name) +} + +func (m *dpvsMatch) SetOifName(name []byte) { + copy(m.oIfName[:], name) +} + +func (m *dpvsMatch) GetIifName() string { + return TrimRightZeros(string(m.iIfName[:])) +} + +func (m *dpvsMatch) GetOifName() string { + return TrimRightZeros(string(m.oIfName[:])) +} diff --git a/tools/dpvs-agent/pkg/ipc/types/dpvsstats.go b/tools/dpvs-agent/pkg/ipc/types/dpvsstats.go new file mode 100644 index 000000000..dfd02c1e0 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/dpvsstats.go @@ -0,0 +1,114 @@ +package types + +type dpvsStats struct { + conns uint64 + inPkts uint64 + inBytes uint64 + outPkts uint64 + outBytes uint64 + + cps uint32 + inPps uint32 + inBps uint32 + outPps uint32 + outBps uint32 + nop uint32 +} + +func (s *dpvsStats) Copy(src *dpvsStats) bool { + if src == nil { + return false + } + s.conns = src.conns + s.inPkts = src.inPkts + s.inBytes = src.inBytes + s.outPkts = src.outPkts + s.outBytes = src.outBytes + + s.cps = src.cps + s.inPps = src.inPps + s.inBps = src.inBps + s.outPps = src.outPps + s.outBps = src.outBps + return true +} + +func (s *dpvsStats) SetConns(c uint64) { + s.conns = c +} + +func (s *dpvsStats) SetInPkts(p uint64) { + s.inPkts = p +} + +func (s *dpvsStats) SetInBytes(b uint64) { + s.inBytes = b +} + +func (s *dpvsStats) SetOutPkts(p uint64) { + s.outPkts = p +} + +func (s *dpvsStats) SetOutBytes(b uint64) { + s.outBytes = b +} + +func (s *dpvsStats) SetCps(c uint32) { + s.cps = c +} + +func (s *dpvsStats) SetInPps(p uint32) { + s.inPps = p +} + +func (s *dpvsStats) SetInBps(b uint32) { + s.inBps = b +} + +func (s *dpvsStats) SetOutPps(p uint32) { + s.outPps = p +} + +func (s *dpvsStats) SetOutBps(b uint32) { + s.outBps = b +} + +func (s *dpvsStats) GetConns() uint64 { + return s.conns +} + +func (s *dpvsStats) GetInPkts() uint64 { + return s.inPkts +} + +func (s *dpvsStats) GetInBytes() uint64 { + return s.inBytes +} + +func (s *dpvsStats) GetOutPkts() uint64 { + return s.outPkts +} + +func (s *dpvsStats) GetOutBytes() uint64 { + return s.outBytes +} + +func (s *dpvsStats) GetCps() uint32 { + return s.cps +} + +func (s *dpvsStats) GetInPps() uint32 { + return s.inPps +} + +func (s *dpvsStats) GetInBps() uint32 { + return s.inBps +} + +func (s *dpvsStats) GetOutPps() uint32 { + return s.outPps +} + +func (s *dpvsStats) GetOutBps() uint32 { + return s.outBps +} diff --git a/tools/dpvs-agent/pkg/ipc/types/getmodel.go b/tools/dpvs-agent/pkg/ipc/types/getmodel.go new file mode 100644 index 000000000..6196594b2 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/getmodel.go @@ -0,0 +1,169 @@ +package types + +import ( + "github.com/dpvs-agent/models" +) + +func (vs *VirtualServerSpec) GetModel() *models.VirtualServerSpecExpand { + modelVs := &models.VirtualServerSpecExpand{ + Addr: vs.GetAddr(), + Af: vs.GetAf(), + Bps: vs.GetBps(), + ConnTimeout: vs.GetConnTimeout(), + LimitProportion: vs.GetLimitProportion(), + Netmask: vs.GetNetMask(), + Port: vs.GetPort(), + Proto: vs.GetProto(), + Fwmark: vs.GetFwmark(), + SyncProxy: "false", + ExpireQuiescent: "false", + SchedName: vs.GetSchedName(), + Timeout: vs.GetTimeout(), + Match: vs.match.GetModel(), + Stats: vs.stats.GetModel(), + DestCheck: vs.GetDestCheck(), + } + + flags := "" + if (vs.GetFlags() & DPVS_CONN_F_SYNPROXY) != 0 { + modelVs.SyncProxy = "true" + flags += "SynProxy|" + } + + if (vs.GetFlags() & DPVS_CONN_F_EXPIRE_QUIESCENT) != 0 { + modelVs.ExpireQuiescent = "true" + flags += "ExpireQuiescent|" + } + + if (vs.GetFlags() & DPVS_SVC_F_QID_HASH) != 0 { + flags += "ConHashByQuicID|" + } + if (vs.GetFlags() & DPVS_SVC_F_SIP_HASH) != 0 { + flags += "ConHashBySrcIP|" + } + + modelVs.Flags = flags + + return modelVs +} + +func (ir *ipRange) GetModel() *models.AddrRange { + return &models.AddrRange{ + Start: ir.GetMinAddr(), + End: ir.GetMaxAddr(), + } +} + +func (dm *dpvsMatch) GetModel() *models.MatchSpec { + return &models.MatchSpec{ + Dest: dm.drange.GetModel(), + Src: dm.srange.GetModel(), + InIfName: dm.GetIifName(), + OutIfName: dm.GetOifName(), + } +} + +func (rs *RealServerSpec) GetModel() *models.RealServerSpecExpand { + overloaded := rs.GetOverloaded() + inhibited := rs.GetInhibited() + return &models.RealServerSpecExpand{ + Spec: &models.RealServerSpecTiny{ + IP: rs.GetAddr(), + Mode: rs.GetFwdModeString(), + Port: rs.GetPort(), + Weight: (uint16)(rs.GetWeight()), + Overloaded: &overloaded, + Inhibited: &inhibited, + }, + Stats: rs.stats.GetModel(), + } +} + +type ServerStats models.ServerStats + +func (dst *ServerStats) Increase(src *ServerStats) { + dst.Conns += src.Conns + dst.InPkts += src.InPkts + dst.InBytes += src.InBytes + dst.OutPkts += src.OutPkts + dst.OutBytes += src.OutBytes + + dst.Cps += src.Cps + dst.InBps += src.InBps + dst.InPps += src.InPps + dst.OutBps += src.OutBps + dst.OutPps += src.OutPps +} + +func (stats *dpvsStats) GetModel() *models.ServerStats { + return &models.ServerStats{ + Conns: stats.GetConns(), + InPkts: stats.GetInPkts(), + InBytes: stats.GetInBytes(), + OutPkts: stats.GetOutPkts(), + OutBytes: stats.GetOutBytes(), + + Cps: stats.GetCps(), + InBps: stats.GetInBps(), + InPps: stats.GetInPps(), + OutBps: stats.GetOutBps(), + OutPps: stats.GetOutPps(), + } +} + +func (nic *NetifNicQueue) GetModel() []models.NicDeviceQueueData { + nicDataQueue := make([]models.NicDeviceQueueData, len(nic.queue)) + for i, data := range nic.queue { + nicDataQueue[i] = (models.NicDeviceQueueData)(data) + } + return nicDataQueue +} + +func (stats *NetifNicStats) GetModel() *models.NicDeviceStats { + nicStats := &models.NicDeviceStats{ + BufAvail: stats.GetMBufAvail(), + BufInuse: stats.GetMBufInuse(), + ID: stats.GetID(), + InBytes: stats.GetInBytes(), + InErrors: stats.GetInErrors(), + InMissed: stats.GetInMissed(), + InPkts: stats.GetInPkts(), + OutBytes: stats.GetOutBytes(), + OutPkts: stats.GetOutPkts(), + OutErrors: stats.GetOutErrors(), + RxNoMbuf: stats.GetRxNoMbuf(), + InBytesQ: stats.inBytesQ.GetModel(), + InPktsQ: stats.inPktsQ.GetModel(), + OutBytesQ: stats.outBytesQ.GetModel(), + OutPktsQ: stats.outPktsQ.GetModel(), + ErrorBytesQ: stats.errorQ.GetModel(), + } + return nicStats +} + +func (detail *NetifNicDetail) GetModel() *models.NicDeviceDetail { + return &models.NicDeviceDetail{ + Flags: detail.GetFlags(), + ID: detail.GetID(), + MTU: detail.GetMTU(), + Addr: detail.GetAddr(), + Autoneg: detail.GetLinkAutoNeg(), + Duplex: detail.GetLinkDuplex(), + NRxQ: detail.GetRxQueueCount(), + NTxQ: detail.GetTxQueueCount(), + Name: detail.GetName(), + SocketID: detail.GetSocketID(), + Speed: detail.GetSpeed(), + Status: detail.GetStatus(), + } +} + +func (laddr *LocalAddrDetail) GetModel() *models.LocalAddressSpecExpand { + return &models.LocalAddressSpecExpand{ + Af: laddr.GetAf(), + Addr: laddr.GetAddr(), + Conns: laddr.GetConns(), + Device: laddr.GetIfName(), + PortConflict: laddr.GetPortConflict(), + } +} diff --git a/tools/dpvs-agent/pkg/ipc/types/inetaddr.go b/tools/dpvs-agent/pkg/ipc/types/inetaddr.go new file mode 100644 index 000000000..661c31f09 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/inetaddr.go @@ -0,0 +1,571 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type InetAddrFront struct { + count uint32 +} + +func NewInetAddrFront() *InetAddrFront { + return &InetAddrFront{} +} + +func (o *InetAddrFront) GetCount() uint32 { + return o.count +} + +func (o *InetAddrFront) SetCount(c uint32) { + o.count = c +} + +func (o *InetAddrFront) Copy(src *InetAddrFront) bool { + o.count = src.count + return true +} + +func (o *InetAddrFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *InetAddrFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *InetAddrFront = *(**InetAddrFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *InetAddrFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *InetAddrFront) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*InetAddrFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to InetAddrFront") + } + + fronts := make([]*InetAddrFront, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i] = NewInetAddrFront() + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *InetAddrFront) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +type InetAddrStats struct { + addr [0x10]byte + used uint32 + free uint32 + miss uint32 +} + +func NewInetAddrStats() *InetAddrStats { + return &InetAddrStats{} +} + +func (o *InetAddrStats) GetUsed() uint32 { + return o.used +} + +func (o *InetAddrStats) GetFree() uint32 { + return o.free +} + +func (o *InetAddrStats) GetMiss() uint32 { + return o.miss +} + +func (o *InetAddrStats) Copy(src *InetAddrStats) bool { + o.used = src.used + o.free = src.free + o.miss = src.miss + copy(o.addr[:], src.addr[:]) + return true +} + +func (o *InetAddrStats) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *InetAddrStats) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *InetAddrStats = *(**InetAddrStats)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *InetAddrStats) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *InetAddrStats) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*InetAddrStats, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to InetAddrStats") + } + + stats := make([]*InetAddrStats, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + stats[i] = NewInetAddrStats() + stats[i].Dump(buf) + } + + return stats, nil +} + +func (o *InetAddrStats) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +type InetAddrDetail struct { + af uint32 + validLft uint32 + preferedLft uint32 + flags uint32 + ifName [0x10]byte + bcast [0x10]byte + addr [0x10]byte + plen uint8 + scope uint8 + cid uint8 + nop uint8 +} + +func NewInetAddrDetail() *InetAddrDetail { + return &InetAddrDetail{} +} + +func (o *InetAddrDetail) Copy(src *InetAddrDetail) bool { + o.af = src.af + o.validLft = src.validLft + o.preferedLft = src.preferedLft + o.flags = src.flags + o.plen = src.plen + o.scope = src.scope + o.cid = src.cid + + copy(o.ifName[:], src.ifName[:]) + copy(o.addr[:], src.addr[:]) + copy(o.bcast[:], src.bcast[:]) + + return true +} + +func (o *InetAddrDetail) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *InetAddrDetail) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *InetAddrDetail = *(**InetAddrDetail)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *InetAddrDetail) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *InetAddrDetail) GetAddr() string { + var addr net.IP + + if o.af == unix.AF_INET { + addr = net.IPv4(o.addr[0], o.addr[1], o.addr[2], o.addr[3]) + return addr.String() + } + + addr = net.IP{o.addr[0x0], o.addr[0x1], o.addr[0x2], o.addr[0x3], + o.addr[0x4], o.addr[0x5], o.addr[0x6], o.addr[0x7], + o.addr[0x8], o.addr[0x9], o.addr[0xa], o.addr[0xb], + o.addr[0xc], o.addr[0xd], o.addr[0xe], o.addr[0xf], + } + return addr.String() +} + +func (o *InetAddrDetail) GetIfName() string { + return TrimRightZeros(string(o.ifName[:])) +} + +func (o *InetAddrDetail) SetAf(af uint32) { + o.af = af +} + +func (o *InetAddrDetail) SetValidLft(lft string) error { + if strings.EqualFold(strings.ToLower(lft), "forever") { + o.validLft = 0 + } else { + i, err := strconv.Atoi(lft) + if err != nil { + return err + } + o.validLft = uint32(i) + } + return nil +} + +func (o *InetAddrDetail) SetPreferedLft(lft string) error { + if strings.EqualFold(strings.ToLower(lft), "forever") { + o.preferedLft = 0 + } else { + i, err := strconv.Atoi(lft) + if err != nil { + return err + } + o.preferedLft = uint32(i) + } + return nil +} + +func (o *InetAddrDetail) SetPlen(len uint8) { + o.plen = len +} + +const ( + IFA_F_SAPOOL uint32 = 0x10000 + IFA_F_OPS_VERBOSE uint32 = 0x0001 + IFA_F_OPS_STATS uint32 = 0x0002 +) + +func (o *InetAddrDetail) SetFlags(flags string) { + switch strings.ToLower(flags) { + case "verbose": + o.flags |= IFA_F_OPS_VERBOSE + case "stats": + o.flags |= IFA_F_OPS_STATS + case "sapool": + o.flags |= IFA_F_SAPOOL + } +} + +func (o *InetAddrDetail) SetScope(scope string) { + value, err := strconv.ParseUint(scope, 10, 8) + if err == nil { + o.scope = uint8(value) + return + } + + switch strings.ToLower(scope) { + case "host": + o.scope = IFA_SCOPE_HOST + case "link": + o.scope = IFA_SCOPE_LINK + case "global": + fallthrough + default: + o.scope = IFA_SCOPE_GLOBAL + // o.scope = 255 + } +} + +func (o *InetAddrDetail) SetCid(cid uint8) { + o.cid = cid +} + +func (o *InetAddrDetail) SetIfName(name string) { + copy(o.ifName[:], name[:]) +} + +func (o *InetAddrDetail) setAddr(addr string) { + if strings.Contains(addr, ":") { + copy(o.addr[:], net.ParseIP(addr)) + o.af = unix.AF_INET6 + return + } + + o.af = unix.AF_INET + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.addr[:], buf.Bytes()[12:]) +} + +func (o *InetAddrDetail) SetAddr(addr string) { + var plen, ip string + + if strings.Index(addr, "/") != -1 { + plen = addr[strings.Index(addr, "/")+1:] + ip = addr[:strings.Index(addr, "/")] + } else { + ip = addr + plen = "32" + + if strings.Contains(ip, ":") { + plen = "128" + } + } + + o.setAddr(ip) + + value, err := strconv.ParseUint(plen, 10, 8) + if err == nil { + o.SetPlen(uint8(value)) + } +} + +func (o *InetAddrDetail) SetBCast(addr string) { + if len(addr) == 0 { + return + } + if strings.Contains(addr, ":") { + copy(o.bcast[:], net.ParseIP(addr)) + } else { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.bcast[:], buf.Bytes()[12:]) + } +} + +func (o *InetAddrDetail) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*InetAddrDetail, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to InetAddrDetail") + } + + details := make([]*InetAddrDetail, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + details[i] = NewInetAddrDetail() + details[i].Dump(buf) + } + + return details, nil +} + +func (o *InetAddrDetail) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +/**************** +****************/ +func (o *InetAddrDetail) Get(cp *pool.ConnPool, logger hclog.Logger) ([]*InetAddrDetail, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_IFADDR_GET_BASE, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_BASE Write proto header failed", "Error", err.Error()) + return nil, err + } + + if err := o.write(conn, logger); err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_BASE Write specific inetaddr failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_BASE reply msg Read failed", "Error", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + result := reply.GetErrStr() + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_BASE failed", "result", result) + err = fmt.Errorf("Sockopt DPVSAGENT_IFADDR_GET_BASE reply ErrorCode: %s", result) + return nil, err + } + + front := NewInetAddrFront() + _, err = front.read(conn, front.Sizeof(), logger) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_BASE read table header failed", "Error", err.Error()) + return nil, err + } + + return o.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} + +func (o *InetAddrDetail) Add(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + traceName := fmt.Sprintf("dpip addr add %s dev %s", o.GetAddr(), o.GetIfName()) + logger := hclog.Default().Named(traceName) + if parentLogger != nil { + logger = parentLogger.Named(traceName) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_IFADDR_ADD, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_ADD Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + err = o.write(conn, logger) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_ADD write inetaddr detail failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_ADD reply msg Read failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + addr := o.GetAddr() + logger.Info("Sockopt DPVSAGENT_IFADDR_ADD done", "addr", addr, "result", result) + return errCode +} + +func (o *InetAddrDetail) Del(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + traceName := fmt.Sprintf("dpip addr del %s dev %s", o.GetAddr(), o.GetIfName()) + logger := hclog.Default().Named(traceName) + if parentLogger != nil { + logger = parentLogger.Named(traceName) + } + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_IFADDR_DEL, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_DEL Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + err = o.write(conn, logger) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_DEL write del inetaddr detail failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_DEL Read failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + addr := o.GetAddr() + logger.Info("Sockopt DPVSAGENT_IFADDR_DEL done", "addr", addr, "del", "result", result) + return errCode +} + +func (o *InetAddrStats) Get(cp *pool.ConnPool, logger hclog.Logger) ([]*InetAddrStats, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_IFADDR_GET_STATS, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_STATS Write proto header failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_IFADDR_GET_STATS reply msg Read failed", "Error", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + result := reply.GetErrStr() + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST failed", "result", result) + err = fmt.Errorf("Sockopt SOCKOPT_GET_KNI_LIST failed. ErrorCode: %s", reply.GetErrStr()) + return nil, err + } + + front := NewInetAddrFront() + _, err = front.read(conn, front.Sizeof(), logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST read table header failed", "Error", err.Error()) + return nil, err + } + + return o.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} diff --git a/tools/dpvs-agent/pkg/ipc/types/iprange.go b/tools/dpvs-agent/pkg/ipc/types/iprange.go new file mode 100644 index 000000000..d35182498 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/iprange.go @@ -0,0 +1,43 @@ +package types + +type ipRange struct { + minAddr [0x10]byte + maxAddr [0x10]byte + minPort uint16 + maxPort uint16 +} + +func (r *ipRange) Copy(src *ipRange) bool { + if src == nil { + return false + } + copy(r.minAddr[:], src.minAddr[:]) + copy(r.maxAddr[:], src.maxAddr[:]) + r.minPort = src.minPort + r.maxPort = src.maxPort + return true +} + +func (r *ipRange) SetMinAddr(addr []byte) { + copy(r.minAddr[:], addr) +} + +func (r *ipRange) SetMaxAddr(addr []byte) { + copy(r.maxAddr[:], addr) +} + +func (r *ipRange) GetMinAddr() string { + return TrimRightZeros(string(r.minAddr[:])) +} + +func (r *ipRange) GetMaxAddr() string { + return TrimRightZeros(string(r.maxAddr[:])) +} + +func (r *ipRange) SetMinPort(port uint16) { + r.minPort = port +} + +func (r *ipRange) SetMaxPort(port uint16) { + r.maxPort = port +} diff --git a/tools/dpvs-agent/pkg/ipc/types/kni.go b/tools/dpvs-agent/pkg/ipc/types/kni.go new file mode 100644 index 000000000..afa2d0cff --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/kni.go @@ -0,0 +1,314 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type KniAddrFlowFront struct { + count uint32 +} + +type KniAddrFlowEntry struct { + af uint32 + addr [0x10]byte +} + +type KniAddrFlowSpec struct { + flags uint32 + ifName [0x10]byte + entry KniAddrFlowEntry +} + +func NewKniAddrFlowFront() *KniAddrFlowFront { + return &KniAddrFlowFront{} +} + +func NewKniAddrFlowSpec() *KniAddrFlowSpec { + return &KniAddrFlowSpec{flags: 1} +} + +func NewKniAddrFlowEntry() *KniAddrFlowEntry { + return &KniAddrFlowEntry{} +} + +func (o *KniAddrFlowSpec) Copy(src *KniAddrFlowSpec) bool { + o.flags = src.flags + copy(o.ifName[:], src.ifName[:]) + return o.entry.Copy(&src.entry) +} + +func (o *KniAddrFlowEntry) Copy(src *KniAddrFlowEntry) bool { + o.af = src.af + copy(o.addr[:], src.addr[:]) + return true +} + +func (o *KniAddrFlowFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *KniAddrFlowSpec) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *KniAddrFlowEntry) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *KniAddrFlowFront) Copy(src *KniAddrFlowFront) bool { + o.count = src.count + return true +} + +func (o *KniAddrFlowFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *KniAddrFlowFront = *(**KniAddrFlowFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *KniAddrFlowSpec) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *KniAddrFlowSpec = *(**KniAddrFlowSpec)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *KniAddrFlowEntry) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *KniAddrFlowEntry = *(**KniAddrFlowEntry)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *KniAddrFlowFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *KniAddrFlowSpec) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *KniAddrFlowEntry) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *KniAddrFlowSpec) SetFlags(flags uint32) { + o.flags = 1 // must be 1 +} + +func (o *KniAddrFlowSpec) SetDevice(name string) { + copy(o.ifName[:], name[:]) +} + +func (o *KniAddrFlowEntry) SetAf(af uint32) { + o.af = af +} + +func (o *KniAddrFlowEntry) SetAddr(addr string) { + if strings.Contains(addr, ":") { + o.SetAf(unix.AF_INET6) + copy(o.addr[:], net.ParseIP(addr)) + return + } + + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.addr[:], buf.Bytes()[12:]) +} + +func (o *KniAddrFlowFront) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*KniAddrFlowFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("buffer may not convert to KniAddrFlowFront") + } + + fronts := make([]*KniAddrFlowFront, cnt) + for i := 0; i < int(cnt); i++ { + fronts[i] = NewKniAddrFlowFront() + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *KniAddrFlowSpec) write(conn *pool.Conn) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +func (o *KniAddrFlowEntry) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*KniAddrFlowEntry, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("buffer may not convert to KniAddrFlowEntry") + } + + entries := make([]*KniAddrFlowEntry, cnt) + for i := 0; i < int(cnt); i++ { + entries[i] = NewKniAddrFlowEntry() + err := conn.Read(entries[i]) + if err != nil { + continue + } + } + + logger.Info("Get Kni Addr success", "entries", entries) + return entries, nil +} + +func (o *KniAddrFlowSpec) Get(cp *pool.ConnPool, logger hclog.Logger) ([]*KniAddrFlowEntry, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, SOCKOPT_GET_KNI_LIST, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST Write proto header failed", "Error", err.Error()) + return nil, err + } + + if err := o.write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST write spec kni failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST Read reply failed", "Error", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + result := reply.GetErrStr() + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST failed", "result", result) + err = fmt.Errorf("Sockopt SOCKOPT_GET_KNI_LIST reply ErrorCode: %s", reply.GetErrStr()) + return nil, err + } + + front := NewKniAddrFlowFront() + _, err = front.read(conn, front.Sizeof(), logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_GET_KNI_LIST read table header failed", "Error", err.Error()) + return nil, err + } + + entry := NewKniAddrFlowEntry() + return entry.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} + +func (o *KniAddrFlowSpec) Add(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var ADD uint32 + ADD = SOCKOPT_SET_KNI_ADD + + msg := NewSockMsg(SOCKOPT_VERSION, ADD, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_ADD Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + err = o.write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_ADD write spec kni failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_ADD Read reply failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + logger.Info("Sockopt SOCKOPT_SET_KNI_ADD Done:", errCode.String()) + return errCode +} + +func (o *KniAddrFlowSpec) Del(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_DEL Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var DEL uint32 + DEL = SOCKOPT_SET_KNI_DEL + + msg := NewSockMsg(SOCKOPT_VERSION, DEL, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_DEL Write spec kni failed", "Error", err.Error()) + return EDPVS_IO + } + err = o.write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_DEL write spec kni failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_KNI_DEL Read reply failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("Sockopt SOCKOPT_SET_KNI_DEL Done", "result", result) + return errCode +} diff --git a/tools/dpvs-agent/pkg/ipc/types/laddr.go b/tools/dpvs-agent/pkg/ipc/types/laddr.go new file mode 100644 index 000000000..7e16f8763 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/laddr.go @@ -0,0 +1,492 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type LocalAddrFront struct { + af uint32 + port uint32 + proto uint32 + fwmark uint32 + cid uint32 + count uint32 + addr [0x10]byte + match dpvsMatch + nop uint32 +} + +func NewLocalAddrFront() *LocalAddrFront { + return &LocalAddrFront{} +} + +func (o *LocalAddrFront) ID() string { + proto := "tcp" + if o.proto == unix.IPPROTO_UDP { + proto = "udp" + } + return fmt.Sprintf("%s-%d-%s", o.GetAddr(), o.GetPort(), proto) +} + +func (o *LocalAddrFront) GetPort() uint32 { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(o.port)) + port := binary.BigEndian.Uint16(buf.Bytes()) + return uint32(port) +} + +func (o *LocalAddrFront) GetAddr() string { + var addr net.IP + + if o.af == unix.AF_INET { + addr = net.IPv4(o.addr[0], o.addr[1], o.addr[2], o.addr[3]) + return addr.String() + } + + addr = net.IP{o.addr[0x0], o.addr[0x1], o.addr[0x2], o.addr[0x3], + o.addr[0x4], o.addr[0x5], o.addr[0x6], o.addr[0x7], + o.addr[0x8], o.addr[0x9], o.addr[0xa], o.addr[0xb], + o.addr[0xc], o.addr[0xd], o.addr[0xe], o.addr[0xf], + } + return addr.String() +} + +func (o *LocalAddrFront) GetAf() uint32 { + return o.af +} + +func (o *LocalAddrFront) SetAf(af uint32) { + o.af = af +} +func (o *LocalAddrFront) SetAfByAddr(addr string) { + i := strings.Index(addr, "/") + if i != -1 { + i = len(addr) + } + + if strings.Count(addr[:i], ".") == 3 { + o.af = unix.AF_INET + } + if strings.Count(addr[:i], ":") >= 2 { + o.af = unix.AF_INET6 + } +} +func (o *LocalAddrFront) SetPort(port uint32) { + o.port = port +} +func (o *LocalAddrFront) SetProto(proto uint32) { + o.proto = proto +} +func (o *LocalAddrFront) SetFwmark(fwmark uint32) { + o.fwmark = fwmark +} + +func (o *LocalAddrFront) ParseVipPortProto(vipport string) error { + vip := strings.Split(vipport, "-")[0] + port := strings.Split(vipport, "-")[1] + proto := strings.Split(vipport, "-")[2] + + switch strings.ToLower(proto) { + case "udp": + o.proto = unix.IPPROTO_UDP + default: + o.proto = unix.IPPROTO_TCP + } + + value, err := strconv.Atoi(port) + if err != nil { + return err + } + + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(value)) + + o.port = uint32(binary.BigEndian.Uint16(buf.Bytes())) + if strings.Contains(vipport, ":") { + o.af = unix.AF_INET6 + copy(o.addr[:], net.ParseIP(vip)) + } else { + o.af = unix.AF_INET + + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(vip)) + copy(o.addr[:], buf.Bytes()[12:]) + } + + return nil +} + +func (o *LocalAddrFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *LocalAddrFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *LocalAddrFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *LocalAddrFront = *(**LocalAddrFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *LocalAddrFront) Copy(src *LocalAddrFront) bool { + if src == nil { + return false + } + + o.af = src.af + o.port = src.port + o.proto = src.proto + o.fwmark = src.fwmark + o.cid = src.cid + o.count = src.count + + copy(o.addr[:], src.addr[:]) + + return o.match.Copy(&src.match) +} + +func (o *LocalAddrFront) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*LocalAddrFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("buffer may not convert to LocalAddrFront") + } + + fronts := make([]*LocalAddrFront, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i] = NewLocalAddrFront() + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *LocalAddrFront) write(conn *pool.Conn) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +type LocalAddrDetail struct { + af uint32 + conns uint32 + portConflict uint64 + addr [0x10]byte + ifName [unix.IFNAMSIZ]byte +} + +func NewLocalAddrDetail() *LocalAddrDetail { + return &LocalAddrDetail{} +} + +func (o *LocalAddrDetail) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *LocalAddrDetail) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *LocalAddrDetail) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *LocalAddrDetail = *(**LocalAddrDetail)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *LocalAddrDetail) SetAf(af uint32) { + o.af = af +} + +func (o *LocalAddrDetail) GetAf() uint32 { + return o.af +} + +func (o *LocalAddrDetail) GetConns() uint32 { + return o.conns +} + +func (o *LocalAddrDetail) GetPortConflict() uint64 { + return o.portConflict +} + +func (o *LocalAddrDetail) SetAfByAddr(addr string) { + i := strings.Index(addr, "/") + if i != -1 { + i = len(addr) + } + + if strings.Count(addr[:i], ":") >= 2 { + o.af = unix.AF_INET6 + } + if strings.Count(addr[:i], ".") == 3 { + o.af = unix.AF_INET + } +} + +func (o *LocalAddrDetail) GetAddr() string { + var addr net.IP + + if o.af == unix.AF_INET { + addr = net.IPv4(o.addr[0], o.addr[1], o.addr[2], o.addr[3]) + return addr.String() + } + + addr = net.IP{o.addr[0x0], o.addr[0x1], o.addr[0x2], o.addr[0x3], + o.addr[0x4], o.addr[0x5], o.addr[0x6], o.addr[0x7], + o.addr[0x8], o.addr[0x9], o.addr[0xa], o.addr[0xb], + o.addr[0xc], o.addr[0xd], o.addr[0xe], o.addr[0xf], + } + return addr.String() +} + +func (o *LocalAddrDetail) SetAddr(addr string) { + if strings.Contains(addr, ":") { + copy(o.addr[:], net.ParseIP(addr)) + } else { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.addr[:], buf.Bytes()[12:]) + } +} + +func (o *LocalAddrDetail) GetIfName() string { + return TrimRightZeros(string(o.ifName[:])) +} + +func (o *LocalAddrDetail) SetIfName(name string) { + copy(o.ifName[:], name[:]) +} + +func (o *LocalAddrDetail) Copy(src *LocalAddrDetail) bool { + if src == nil { + return false + } + + o.af = src.af + o.conns = src.conns + o.portConflict = src.portConflict + + copy(o.addr[:], src.addr[:]) + copy(o.ifName[:], src.ifName[:]) + + return true +} + +func (o *LocalAddrDetail) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*LocalAddrDetail, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("buffer may not convert to LocalAddrEntry") + } + + details := make([]*LocalAddrDetail, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + // logger.Info(fmt.Sprintf("fetch RAW local address from dpvs (%d): %x", o.Sizeof(), buf)) + details[i] = NewLocalAddrDetail() + details[i].Dump(buf) + } + + logger.Info("Get Local Addr Done", "details", details) + return details, nil +} + +func (o *LocalAddrDetail) write(conn *pool.Conn) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +/**************** +****************/ +func (o *LocalAddrFront) Get(cp *pool.ConnPool, parentLogger hclog.Logger) ([]*LocalAddrDetail, error) { + logger := hclog.Default().Named(o.ID()) + if parentLogger != nil { + logger = parentLogger.Named(o.ID()) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_GET_LADDR, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_LADDR write proto header failed", "Error", err.Error()) + return nil, err + } + + if err := o.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_LADDR write laddr table header failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_LADDR Read sockmsg failed", "Error", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + result := reply.GetErrStr() + logger.Error("Sockopt DPVSAGENT_VS_GET_LADDR failed", "result", result) + err = fmt.Errorf("Sockopt DPVSAGENT_VS_GET_LADDR reply ErrorCode: %s", result) + return nil, err + } + + _, err = o.read(conn, o.Sizeof(), logger) + if err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_LADDR read table header failed", "Error", err.Error()) + return nil, err + } + + detail := NewLocalAddrDetail() + return detail.read(conn, uint64(reply.GetLen())-o.Sizeof(), logger) +} + +func (o *LocalAddrFront) Add(details []*LocalAddrDetail, cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(o.ID()) + if parentLogger != nil { + logger = parentLogger.Named(o.ID()) + } + + if len(details) == 0 { + logger.Info("There are No laddr to set, return immediately") + return EDPVS_OK + } + o.count = uint32(len(details)) + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_ADD_LADDR, SOCKOPT_SET, o.Sizeof()+uint64(len(details))*details[0].Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_LADDR write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + if err := o.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_LADDR write laddr table header failed", "Error", err.Error()) + return EDPVS_IO + } + + for _, detail := range details { + if err := detail.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_LADDR write spec laddr failed", "Error", err.Error()) + return EDPVS_IO + } + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_LADDR Read reply failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("DPVSAGENT_VS_ADD_LADDR Done", "details", details, "result", result) + return errCode +} + +func (o *LocalAddrFront) Del(details []*LocalAddrDetail, cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(o.ID()) + if parentLogger != nil { + logger = parentLogger.Named(o.ID()) + } + + if len(details) == 0 { + logger.Info("There are No laddr to del, return immediately") + return EDPVS_OK + } + o.count = uint32(len(details)) + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_DEL_LADDR, SOCKOPT_SET, o.Sizeof()+uint64(len(details))*details[0].Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_LADDR Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + if err := o.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_LADDR write laddr table header failed", "Error", err.Error()) + return EDPVS_IO + } + + for _, detail := range details { + if err := detail.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_LADDR write spec laddr failed", "Error", err.Error()) + return EDPVS_IO + } + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_LADDR Read failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("DPVSAGENT_VS_DEL_LADDR", "details", details, " Done", "result", result) + return errCode +} diff --git a/tools/dpvs-agent/pkg/ipc/types/method.go b/tools/dpvs-agent/pkg/ipc/types/method.go new file mode 100644 index 000000000..ab1254f4c --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/method.go @@ -0,0 +1 @@ +package types diff --git a/tools/dpvs-agent/pkg/ipc/types/netif.go b/tools/dpvs-agent/pkg/ipc/types/netif.go new file mode 100644 index 000000000..f403ebb03 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/netif.go @@ -0,0 +1,728 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + // "errors" + "fmt" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type NetifNicDesc struct { + name [0x20]byte + mac [0x12]byte + flags uint16 +} + +func NewNetifNicDesc() *NetifNicDesc { + return &NetifNicDesc{} +} + +func (o *NetifNicDesc) Copy(src *NetifNicDesc) bool { + o.flags = src.flags + copy(o.name[:], src.name[:]) + copy(o.mac[:], src.mac[:]) + return true +} + +func (o *NetifNicDesc) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *NetifNicDesc) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *NetifNicDesc = *(**NetifNicDesc)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *NetifNicDesc) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *NetifNicDesc) SetName(device string) { + copy(o.name[:], device[:]) +} + +func (o *NetifNicDesc) SetMac(mac string) { + // not set in user plane +} + +func (o *NetifNicDesc) SetPromisc(device, flags string) bool { + o.SetName(device) + switch strings.ToLower(flags) { + case "on", "up", "true": + o.setFlags("promisc_on") + return true + case "off", "down", "false": + o.setFlags("promisc_off") + return true + case "unset": + return false + default: + return false + } + return false +} + +func (o *NetifNicDesc) SetLink(device, flags string) bool { + o.SetName(device) + switch strings.ToLower(flags) { + case "on", "up", "true": + o.setFlags("link_status_up") + return true + case "off", "down", "false": + o.setFlags("link_status_down") + return true + case "unset": + return false + default: + return false + } + return false +} + +func (o *NetifNicDesc) SetFwd2Kni(device, flags string) bool { + o.SetName(device) + switch strings.ToLower(flags) { + case "on", "up", "true": + o.setFlags("forward2kni_on") + return true + case "off", "down", "false": + o.setFlags("forward2kni_off") + return true + case "unset": + return false + default: + return false + } + return false +} + +func (o *NetifNicDesc) SetTcEgress(device, flags string) bool { + o.SetName(device) + switch strings.ToLower(flags) { + case "on", "up", "true": + o.setFlags("tc_egress_on") + return true + case "off", "down", "false": + o.setFlags("tc_egress_off") + return true + case "unset": + return false + default: + return false + } + return false +} + +func (o *NetifNicDesc) SetTcIngress(device, flags string) bool { + o.SetName(device) + switch strings.ToLower(flags) { + case "on", "up", "true": + o.setFlags("tc_ingress_on") + return true + case "off", "down", "false": + o.setFlags("tc_ingress_off") + return true + case "unset": + return false + default: + return false + } + return false +} + +func (o *NetifNicDesc) setFlags(flags string) { + bak := o.flags + + o.flags = o.flags ^ o.flags + + switch strings.ToLower(flags) { + case "promisc_on": + o.flags |= NETIF_NIC_PROMISC_ON + case "promisc_off": + o.flags |= NETIF_NIC_PROMISC_OFF + case "link_status_up": + o.flags |= NETIF_NIC_LINK_UP + case "link_status_down": + o.flags |= NETIF_NIC_LINK_DOWN + case "forward2kni_on": + o.flags |= NETIF_NIC_FWD2KNI_ON + case "forward2kni_off": + o.flags |= NETIF_NIC_FWD2KNI_OFF + case "tc_egress_on": + o.flags |= NETIF_NIC_TC_EGRESS_ON + case "tc_egress_off": + o.flags |= NETIF_NIC_TC_EGRESS_OFF + case "tc_ingress_on": + o.flags |= NETIF_NIC_TC_INGRESS_ON + case "tc_ingress_off": + o.flags |= NETIF_NIC_TC_INGRESS_OFF + default: + o.flags |= bak + } +} + +func (o *NetifNicDesc) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +func (o *NetifNicDesc) Set(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var SET uint32 + SET = SOCKOPT_NETIF_SET_PORT + + msg := NewSockMsg(SOCKOPT_VERSION, SET, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_SET_PORT Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + err = o.write(conn, logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_SET_PORT write specific port failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_SET_PORT reply msg Read failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("Sockopt SOCKOPT_NETIF_SET_PORT Done", "result", result) + return errCode +} + +type NetifNicEntryFront struct { + count uint16 + phyBase uint16 + phyEnd uint16 + bondBase uint16 + bondEnd uint16 +} + +func NewNetifNicEntryFront() *NetifNicEntryFront { + return &NetifNicEntryFront{} +} + +func (o *NetifNicEntryFront) Copy(src *NetifNicEntryFront) bool { + o.count = src.count + o.phyBase = src.phyBase + o.phyEnd = src.phyEnd + o.bondBase = src.bondBase + o.bondEnd = src.bondEnd + return true +} + +func (o *NetifNicEntryFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *NetifNicEntryFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *NetifNicEntryFront = *(**NetifNicEntryFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *NetifNicEntryFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *NetifNicEntryFront) read(conn *pool.Conn, logger hclog.Logger) error { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + o.Dump(buf) + + return nil +} + +type NetifNicEntry struct { + id uint16 + name [0x10]byte +} + +func (o *NetifNicEntry) GetID() uint16 { + return o.id +} + +func (o *NetifNicEntry) GetName() string { + return TrimRightZeros(string(o.name[:])) +} + +func NewNetifNicEntry() *NetifNicEntry { + return &NetifNicEntry{} +} + +func (o *NetifNicEntry) Copy(src *NetifNicEntry) bool { + copy(o.name[:], src.name[:]) + o.id = src.id + return true +} + +func (o *NetifNicEntry) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *NetifNicEntry) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *NetifNicEntry = *(**NetifNicEntry)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *NetifNicEntry) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *NetifNicEntry) read(conn *pool.Conn, logger hclog.Logger) error { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + o.Dump(buf) + + return nil +} + +type NetifNicEntries struct { + Front *NetifNicEntryFront + Entries []*NetifNicEntry +} + +func NewNetifNicEntries() *NetifNicEntries { + return &NetifNicEntries{Front: NewNetifNicEntryFront()} +} + +func (o *NetifNicDesc) GetPortList(cp *pool.ConnPool, logger hclog.Logger) (*NetifNicEntries, DpvsErrType) { + var GET uint32 + GET = SOCKOPT_NETIF_GET_PORT_LIST + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, GET, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_LIST Write proto header failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if err := o.write(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_LIST write specific port failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_LIST reply msg Read failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if reply.GetErrCode() != EDPVS_OK { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_LIST failed.", "reply", reply.GetErrStr()) + return nil, reply.GetErrCode() + } + + nic := NewNetifNicEntries() + + err = nic.Front.read(conn, logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_LIST table header read failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if nic.Front.count <= 0 { + return nic, EDPVS_OK + } + + entry := NewNetifNicEntry() + resLen := int(reply.GetLen()) - int(nic.Front.Sizeof()) + if resLen != int(entry.Sizeof())*int(nic.Front.count) { + conn.Release(resLen) + logger.Error(fmt.Sprintf("buffer may not convert to %d count NetifNicEntry", nic.Front.count)) + return nil, EDPVS_IO + } + + nic.Entries = make([]*NetifNicEntry, nic.Front.count) + + for i := 0; i < int(nic.Front.count); i++ { + nic.Entries[i] = NewNetifNicEntry() + nic.Entries[i].read(conn, logger) + } + return nic, EDPVS_OK +} + +type NetifNicDetail struct { + name [0x20]byte + addr [0x20]byte + status [0x10]byte + duplex [0x10]byte + autoneg [0x10]byte + speed uint32 + nrxq uint8 + ntxq uint8 + padding [0x3]uint8 + socketId uint8 + id uint16 + mtu uint16 + flags uint16 +} + +func NewNetifNicDetail() *NetifNicDetail { + return &NetifNicDetail{} +} + +func (o *NetifNicDetail) Copy(src *NetifNicDetail) bool { + o.speed = src.speed + o.nrxq = src.nrxq + o.ntxq = src.ntxq + o.socketId = src.socketId + o.id = src.id + o.mtu = src.mtu + o.flags = src.flags + copy(o.name[:], src.name[:]) + copy(o.addr[:], src.addr[:]) + copy(o.status[:], src.status[:]) + copy(o.duplex[:], src.duplex[:]) + copy(o.autoneg[:], src.autoneg[:]) + return true +} + +func (o *NetifNicDetail) GetSpeed() uint32 { + return o.speed +} + +func (o *NetifNicDetail) GetSocketID() uint8 { + return o.socketId +} + +func (o *NetifNicDetail) GetTxQueueCount() uint8 { + return o.ntxq +} + +func (o *NetifNicDetail) GetRxQueueCount() uint8 { + return o.nrxq +} + +func (o *NetifNicDetail) GetStatus() string { + return TrimRightZeros(string(o.status[:])) +} + +func (o *NetifNicDetail) GetName() string { + return TrimRightZeros(string(o.name[:])) +} + +func (o *NetifNicDetail) GetLinkDuplex() string { + return TrimRightZeros(string(o.duplex[:])) +} + +func (o *NetifNicDetail) GetLinkAutoNeg() string { + return TrimRightZeros(string(o.autoneg[:])) +} + +func (o *NetifNicDetail) GetAddr() string { + return TrimRightZeros(string(o.addr[:])) +} + +func (o *NetifNicDetail) GetMTU() uint16 { + return o.mtu +} + +func (o *NetifNicDetail) GetID() uint16 { + return o.id +} + +func (o *NetifNicDetail) GetFlags() uint16 { + return o.flags +} + +func (o *NetifNicDetail) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *NetifNicDetail) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *NetifNicDetail = *(**NetifNicDetail)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *NetifNicDetail) read(conn *pool.Conn, logger hclog.Logger) error { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + o.Dump(buf) + + return nil +} + +func (o *NetifNicDesc) GetPortBasic(cp *pool.ConnPool, logger hclog.Logger) (*NetifNicDetail, DpvsErrType) { + var GET uint32 + GET = SOCKOPT_NETIF_GET_PORT_BASIC + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return nil, EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, GET, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC Write proto header failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if err := o.write(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC write specific port failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC reply msg Read failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if reply.GetErrCode() != EDPVS_OK { + logger.Error(fmt.Sprintf("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC reply ErrorCode: %s", reply.GetErrStr())) + return nil, reply.GetErrCode() + } + + detail := NewNetifNicDetail() + if err := detail.read(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC spec port read failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + logger.Info("Sockopt SOCKOPT_NETIF_GET_PORT_BASIC read Done") + return detail, EDPVS_OK +} + +type NetifNicQueue struct { + queue [0x10]uint64 +} + +func (o *NetifNicQueue) Copy(src *NetifNicQueue) bool { + if src == nil { + return false + } + + for i := 0; i < len(o.queue); i++ { + o.queue[i] = src.queue[i] + } + + return true +} + +type NetifNicStats struct { + mBufAvail uint32 + mBufInuse uint32 + inPkts uint64 + outPkts uint64 + inBytes uint64 + outBytes uint64 + inMissed uint64 + inErrors uint64 + outErrors uint64 + rxNoMbuf uint64 + inPktsQ NetifNicQueue + outPktsQ NetifNicQueue + inBytesQ NetifNicQueue + outBytesQ NetifNicQueue + errorQ NetifNicQueue + padding [0x3]uint16 + id uint16 +} + +func NewNetifNicStats() *NetifNicStats { + return &NetifNicStats{} +} + +func (o *NetifNicStats) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *NetifNicStats) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *NetifNicStats = *(**NetifNicStats)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *NetifNicStats) Copy(src *NetifNicStats) bool { + o.id = src.id + o.mBufAvail = src.mBufAvail + o.mBufInuse = src.mBufInuse + o.inPkts = src.inPkts + o.outPkts = src.outPkts + o.inBytes = src.inBytes + o.outBytes = src.outBytes + o.inMissed = src.inMissed + o.inErrors = src.inErrors + o.outErrors = src.outErrors + o.rxNoMbuf = src.rxNoMbuf + o.inPktsQ.Copy(&src.inPktsQ) + o.outPktsQ.Copy(&src.outPktsQ) + o.inBytesQ.Copy(&src.inBytesQ) + o.outBytesQ.Copy(&src.outBytesQ) + o.errorQ.Copy(&src.errorQ) + return true +} + +func (o *NetifNicStats) GetID() uint16 { + return o.id +} + +func (o *NetifNicStats) GetRxNoMbuf() uint64 { + return o.rxNoMbuf +} + +func (o *NetifNicStats) GetOutErrors() uint64 { + return o.outErrors +} + +func (o *NetifNicStats) GetInErrors() uint64 { + return o.inErrors +} + +func (o *NetifNicStats) GetInMissed() uint64 { + return o.inMissed +} + +func (o *NetifNicStats) GetOutBytes() uint64 { + return o.outBytes +} + +func (o *NetifNicStats) GetInBytes() uint64 { + return o.inBytes +} + +func (o *NetifNicStats) GetOutPkts() uint64 { + return o.outPkts +} + +func (o *NetifNicStats) GetInPkts() uint64 { + return o.inPkts +} + +func (o *NetifNicStats) GetMBufInuse() uint32 { + return o.mBufInuse +} + +func (o *NetifNicStats) GetMBufAvail() uint32 { + return o.mBufAvail +} + +func (o *NetifNicStats) read(conn *pool.Conn, logger hclog.Logger) error { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + o.Dump(buf) + + return nil +} + +func (o *NetifNicDesc) GetPortStats(cp *pool.ConnPool, logger hclog.Logger) (*NetifNicStats, DpvsErrType) { + var GET uint32 + GET = SOCKOPT_NETIF_GET_PORT_STATS + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, GET, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_STATS Write proto header failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + if err := o.write(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_STATS Write specific port failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_STATS reply msg Read failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + stats := NewNetifNicStats() + if err := stats.read(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_NETIF_GET_PORT_STATS read port stats failed", "Error", err.Error()) + return nil, EDPVS_IO + } + + logger.Info("Sockopt SOCKOPT_NETIF_GET_PORT_STATS read Done") + return stats, EDPVS_OK +} + +/* +func (o *NetifNicDesc) GetPortExtra(cp *pool.ConnPool) DpvsErrType { + var GET uint32 + GET = SOCKOPT_NETIF_GET_PORT_EXT_INFO +} +*/ diff --git a/tools/dpvs-agent/pkg/ipc/types/realserver.go b/tools/dpvs-agent/pkg/ipc/types/realserver.go new file mode 100644 index 000000000..bd56a7eb6 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/realserver.go @@ -0,0 +1,633 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type RealServerSpec struct { + af uint32 + port uint16 + proto uint16 + weight uint32 + addr [0x10]byte + connFlags uint16 + flags uint16 + fwdmode DpvsFwdMode + maxConn uint32 + minConn uint32 + actConns uint32 + inActConns uint32 + presistConns uint32 + stats dpvsStats +} + +func NewRealServerSpec() *RealServerSpec { + return &RealServerSpec{} +} + +func (rs *RealServerSpec) SetAf(af uint32) { + rs.af = af +} + +func (rs *RealServerSpec) SetProto(proto uint16) { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(proto)) + rs.proto = binary.BigEndian.Uint16(buf.Bytes()) +} + +func (rs *RealServerSpec) SetPort(port uint16) { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(port)) + rs.port = binary.BigEndian.Uint16(buf.Bytes()) +} + +func (rs *RealServerSpec) SetWeight(weight uint32) { + rs.weight = weight +} + +func (rs *RealServerSpec) GetWeight() uint32 { + return rs.weight +} + +func (rs *RealServerSpec) SetAddr(addr string) { + if strings.Contains(addr, ":") { + rs.af = unix.AF_INET6 + copy(rs.addr[:], net.ParseIP(addr)) + } else { + rs.af = unix.AF_INET + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(rs.addr[:], buf.Bytes()[12:]) + } +} + +func (rs *RealServerSpec) SetFlags(flags uint16) { + rs.flags = flags +} + +func (rs *RealServerSpec) setConnFlags(connFlags uint16) { + rs.connFlags = connFlags +} + +func (rs *RealServerSpec) SetFwdMode(fwdmode DpvsFwdMode) { + rs.setConnFlags(uint16(fwdmode) & DPVS_CONN_F_FWD_MASK) + rs.fwdmode = fwdmode +} + +func (rs *RealServerSpec) SetMaxConn(conns uint32) { + rs.maxConn = conns +} + +func (rs *RealServerSpec) SetMinConn(conns uint32) { + rs.minConn = conns +} + +func (rs *RealServerSpec) SetPresistConns(conns uint32) { + rs.presistConns = conns +} + +func (rs *RealServerSpec) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*rs)) +} + +func (rs *RealServerSpec) Copy(src *RealServerSpec) bool { + if src == nil { + return false + } + + copy(rs.addr[:], src.addr[:]) + + rs.af = src.af + rs.proto = src.proto + rs.port = src.port + rs.weight = src.weight + rs.flags = src.flags + rs.connFlags = src.connFlags + rs.fwdmode = src.fwdmode + rs.maxConn = src.maxConn + rs.minConn = src.minConn + rs.actConns = src.actConns + rs.inActConns = src.inActConns + rs.presistConns = src.presistConns + + return rs.stats.Copy(&src.stats) +} + +func (rs *RealServerSpec) Dump(buf []byte) bool { + if len(buf) != int(rs.Sizeof()) { + return false + } + + var tmp *RealServerSpec = *(**RealServerSpec)(unsafe.Pointer(&buf)) + + return rs.Copy(tmp) +} + +func (rs *RealServerSpec) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, rs) + return buf.Bytes() +} + +func (rs *RealServerSpec) write(conn *pool.Conn) error { + buf := rs.Package() + _, err := conn.WriteN(buf, int(rs.Sizeof())) + if err != nil { + // return errors.New("real server desc write failure(", written, "/", len(buf), ")") + return err + } + return nil +} + +func (rs *RealServerSpec) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*RealServerSpec, error) { + res := len % rs.Sizeof() + cnt := len / rs.Sizeof() + if res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to RealServerSpec") + } + + rss := make([]*RealServerSpec, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(rs.Sizeof())) + if err != nil { + continue + } + + rss[i] = NewRealServerSpec() + rss[i].Dump(buf) + spec := *rss[i] + logger.Info("get real server success", "spec", spec) + } + + return rss, nil +} + +func (rs *RealServerSpec) GetAddr() string { + if rs.af == unix.AF_INET { + addr := net.IPv4(rs.addr[0], rs.addr[1], rs.addr[2], rs.addr[3]) + return addr.String() + } + return "" +} + +func (rs *RealServerSpec) GetPort() uint16 { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(rs.port)) + return binary.BigEndian.Uint16(buf.Bytes()) +} + +func (rs *RealServerSpec) GetConnFlags() uint16 { + return rs.connFlags +} + +func (rs *RealServerSpec) GetOverloaded() bool { + return rs.flags&DPVS_DEST_F_OVERLOAD != 0 +} + +func (rs *RealServerSpec) SetOverloaded(overloaded *bool) { + if overloaded == nil { + return + } + if *overloaded { + rs.flags |= DPVS_DEST_F_OVERLOAD + } else { + rs.flags &= ^uint16(DPVS_DEST_F_OVERLOAD) + } +} + +func (rs *RealServerSpec) GetInhibited() bool { + return rs.flags&DPVS_DEST_F_INHIBITED != 0 +} + +func (rs *RealServerSpec) SetInhibited(inhibited *bool) { + if inhibited == nil { + return + } + if *inhibited { + rs.flags |= DPVS_DEST_F_INHIBITED + } else { + rs.flags &= ^uint16(DPVS_DEST_F_INHIBITED) + } +} + +func (rs *RealServerSpec) GetFwdModeString() string { + return rs.fwdmode.String() +} + +func (rs *RealServerSpec) ID() string { + return fmt.Sprintf("%s:%d", rs.GetAddr(), rs.port) +} + +func (rs *RealServerSpec) Format(kind string) string { + /* + -> RIP:RPORT\t\t\tFNAT\tWeight\tActive\tInactive + */ + return fmt.Sprintf(" -> %s:%d\t\t\t%s\t%d\t%d\t%d", rs.GetAddr(), rs.GetPort(), rs.GetFwdModeString(), rs.weight, rs.actConns, rs.inActConns) +} + +type RealServerFront struct { + af uint32 + proto uint16 + port uint16 + fwmark uint32 + addr [0x10]byte + numDests uint32 + match dpvsMatch + cid uint32 + index uint32 +} + +func NewRealServerFront() *RealServerFront { + return &RealServerFront{} +} + +func (rs *RealServerFront) SetNumDests(n uint32) { + rs.numDests = n +} + +func (rs *RealServerFront) ID() string { + proto := "tcp" + if rs.proto == unix.IPPROTO_UDP { + proto = "udp" + } + return fmt.Sprintf("%s-%d-%s", rs.GetAddr(), rs.GetPort(), proto) +} + +func (rs *RealServerFront) GetAddr() string { + var addr net.IP + + if rs.af == unix.AF_INET { + addr = net.IPv4(rs.addr[0], rs.addr[1], rs.addr[2], rs.addr[3]) + return addr.String() + } + + addr = net.IP{rs.addr[0x0], rs.addr[0x1], rs.addr[0x2], rs.addr[0x3], + rs.addr[0x4], rs.addr[0x5], rs.addr[0x6], rs.addr[0x7], + rs.addr[0x8], rs.addr[0x9], rs.addr[0xa], rs.addr[0xb], + rs.addr[0xc], rs.addr[0xd], rs.addr[0xe], rs.addr[0xf], + } + return addr.String() +} + +func (rs *RealServerFront) GetAf() uint32 { + return rs.af +} + +func (rs *RealServerFront) GetPort() uint16 { + return rs.port +} + +func (rs *RealServerFront) GetProto() uint16 { + return rs.proto +} + +func (rs *RealServerFront) Dump(buf []byte) bool { + if len(buf) != int(rs.Sizeof()) { + return false + } + + var tmp *RealServerFront = *(**RealServerFront)(unsafe.Pointer(&buf)) + + return rs.Copy(tmp) +} + +func (rs *RealServerFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, rs) + return buf.Bytes() +} + +func (rs *RealServerFront) write(conn *pool.Conn) error { + buf := rs.Package() + _, err := conn.WriteN(buf, int(rs.Sizeof())) + if err != nil { + return err + } + return nil +} + +func (rs *RealServerFront) read(conn *pool.Conn, logger hclog.Logger) error { + conn.SetReadBuffer(int(rs.Sizeof())) + buf, err := conn.ReadN(int(rs.Sizeof())) + if err != nil { + return err + } + + if !rs.Dump(buf) { + return errors.New("Dump RealServerFront failed") + } + + return nil +} + +func (rs *RealServerFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*rs)) +} + +func (o *RealServerFront) ParseVipPortProto(vipport string) error { + vip := strings.Split(vipport, "-")[0] + port := strings.Split(vipport, "-")[1] + proto := strings.Split(vipport, "-")[2] + + switch strings.ToLower(proto) { + case "tcp": + o.proto = unix.IPPROTO_TCP + case "udp": + o.proto = unix.IPPROTO_UDP + default: + } + + value, err := strconv.Atoi(port) + if err != nil { + return err + } + + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(value)) + + o.port = binary.BigEndian.Uint16(buf.Bytes()) + if strings.Contains(vipport, ":") { + o.af = unix.AF_INET6 + copy(o.addr[:], net.ParseIP(vip)) + } else { + o.af = unix.AF_INET + + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(vip)) + copy(o.addr[:], buf.Bytes()[12:]) + } + + return nil +} + +func (rs *RealServerFront) Copy(src *RealServerFront) bool { + if src == nil { + return false + } + + copy(rs.addr[:], src.addr[:]) + + rs.af = src.af + rs.proto = src.proto + rs.port = src.port + rs.fwmark = src.fwmark + rs.numDests = src.numDests + rs.cid = src.cid + + return rs.match.Copy(&src.match) +} + +/***************** +******************/ + +func (front *RealServerFront) Get(cp *pool.ConnPool, parentLogger hclog.Logger) ([]*RealServerSpec, error) { + logger := hclog.Default().Named(front.ID()) + if parentLogger != nil { + logger = parentLogger.Named(front.ID()) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_GET_DESTS, SOCKOPT_GET, front.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_DESTs write proto header failed", "Error", err.Error()) + return nil, err + } + + if err := front.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_DESTs write body failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_DESTs Read sockmsg failed", "Error", err.Error()) + return nil, err + } + + if err := front.read(conn, logger); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_GET_DESTs read table header failed", "Error", err.Error()) + return nil, err + } + + rs := NewRealServerSpec() + + return rs.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} + +// put +func (front *RealServerFront) Edit(existOnly bool, rss []*RealServerSpec, cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(front.ID()) + if parentLogger != nil { + logger = parentLogger.Named(front.ID()) + } + + if len(rss) == 0 { + return EDPVS_OK + } + + sEdit := "DPVSAGENT_VS_EDIT_DESTS" + var EDIT uint32 = DPVSAGENT_VS_EDIT_DESTS + + if !existOnly { + EDIT = DPVSAGENT_VS_ADD_DESTS + sEdit = "DPVSAGENT_VS_ADD_DESTS" + } + + front.numDests = uint32(len(rss)) + + ctx := context.Background() + conn, err := cp.Get(ctx) + + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return EDPVS_IO + } + + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, EDIT, SOCKOPT_SET, front.Sizeof()+rss[0].Sizeof()*uint64(len(rss))) + + if err := msg.Write(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write proto header failed Error=%s", sEdit, err.Error())) + return EDPVS_IO + } + + if err := front.write(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write rss table header failed Error=%s", sEdit, err.Error())) + return EDPVS_IO + } + + for _, rs := range rss { + if err := rs.write(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Write rs %v header failed Error=%s", sEdit, *rs, err.Error())) + return EDPVS_IO + } + } + + reply := NewReplySockMsg() + + if err := reply.Read(conn); err != nil { + logger.Error(fmt.Sprintf("Sockopt %s Read sockmsg failed Error=%s", sEdit, err.Error())) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + logger.Info(fmt.Sprintf("%s %v Done result=%s", sEdit, rss, errCode.String())) + return errCode +} + +func (front *RealServerFront) add(rss []*RealServerSpec, cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + if len(rss) == 0 { + return EDPVS_OK + } + + front.numDests = uint32(len(rss)) + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_ADD_DESTS, SOCKOPT_SET, front.Sizeof()+rss[0].Sizeof()*uint64(len(rss))) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_DESTs write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + if err := front.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_DESTs write rss table header failed", "Error", err.Error()) + return EDPVS_IO + } + + for _, rs := range rss { + if err := rs.write(conn); err != nil { + // backend error + logger.Error("Sockopt DPVSAGENT_VS_ADD_DESTs write spec rs failed", "Error", err.Error()) + return EDPVS_IO + } + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_ADD_DESTs Read sockmsg failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("DPVSAGENT_VS_ADD_DESTs Done", "result", result) + return errCode +} + +func (front *RealServerFront) Del(rss []*RealServerSpec, cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + if len(rss) == 0 { + logger.Info("No Real server need delete, return immediately") + return EDPVS_OK + } + + front.numDests = uint32(len(rss)) + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_VS_DEL_DESTS, SOCKOPT_SET, front.Sizeof()+rss[0].Sizeof()*uint64(len(rss))) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_DESTs write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + if err := front.write(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_DESTs write rss table header failed", "Error", err.Error()) + return EDPVS_IO + } + + for _, rs := range rss { + if err := rs.write(conn); err != nil { + // backend error + logger.Error("Sockopt DPVSAGENT_VS_DEL_DESTs write spec rs failed", "Error", err.Error()) + return EDPVS_IO + } + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_VS_DEL_DESTs Read sockmsg failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("DPVSAGENT_VS_ADD_DESTs Done", "result", result) + return errCode +} + +// post +func (front *RealServerFront) Update(rss []*RealServerSpec, cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(front.ID()) + if parentLogger != nil { + logger = parentLogger.Named(front.ID()) + } + + if len(rss) == 0 { + logger.Warn("Remove all RS ! ! !") + } + + running, err := front.Get(cp, logger) + if err != nil { + logger.Error("Get realserver failed", "Error", err.Error()) + return EDPVS_IO + } + + reserved := make(map[string]*RealServerSpec) + for _, rs := range rss { + reserved[rs.ID()] = rs + } + + unreserved := make([]*RealServerSpec, 0) + for _, expire := range running { + if _, ok := reserved[expire.ID()]; !ok { + unreserved = append(unreserved, expire) + } + } + logger.Info("reserved", reserved, "unreserved", unreserved) + + status := front.add(rss, cp, logger) + if status != EDPVS_OK { + return status + } + + errCode := front.Del(unreserved, cp, logger) + result := errCode.String() + logger.Info("Set", "rss", rss, "Done", "result", result) + return errCode +} diff --git a/tools/dpvs-agent/pkg/ipc/types/route.go b/tools/dpvs-agent/pkg/ipc/types/route.go new file mode 100644 index 000000000..e428ff621 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/route.go @@ -0,0 +1,470 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type RouteAddr struct { + addr [0x10]byte + plen uint32 // prefix len +} + +func (o *RouteAddr) Copy(src *RouteAddr) bool { + o.plen = src.plen + copy(o.addr[:], src.addr[:]) + return true +} + +type RouteDetail struct { + af uint32 + mtu uint32 + flags uint32 + metric uint32 + dst RouteAddr + src RouteAddr + gateway RouteAddr + prefSrc RouteAddr + ifName [0x10]byte +} + +func NewRouteDetail() *RouteDetail { + return &RouteDetail{} +} + +func (o *RouteDetail) GetIfName() string { + return TrimRightZeros(string(o.ifName[:])) +} + +func (o *RouteDetail) GetSrc() string { + var addr net.IP + + if o.af == unix.AF_INET { + addr = net.IPv4(o.src.addr[0], o.src.addr[1], o.src.addr[2], o.src.addr[3]) + return addr.String() + } + + addr = net.IP{o.src.addr[0x0], o.src.addr[0x1], o.src.addr[0x2], o.src.addr[0x3], + o.src.addr[0x4], o.src.addr[0x5], o.src.addr[0x6], o.src.addr[0x7], + o.src.addr[0x8], o.src.addr[0x9], o.src.addr[0xa], o.src.addr[0xb], + o.src.addr[0xc], o.src.addr[0xd], o.src.addr[0xe], o.src.addr[0xf], + } + return addr.String() +} + +func (o *RouteDetail) GetDst() string { + var addr net.IP + + if o.af == unix.AF_INET { + addr = net.IPv4(o.dst.addr[0], o.dst.addr[1], o.dst.addr[2], o.dst.addr[3]) + return addr.String() + } + + addr = net.IP{o.dst.addr[0x0], o.dst.addr[0x1], o.dst.addr[0x2], o.dst.addr[0x3], + o.dst.addr[0x4], o.dst.addr[0x5], o.dst.addr[0x6], o.dst.addr[0x7], + o.dst.addr[0x8], o.dst.addr[0x9], o.dst.addr[0xa], o.dst.addr[0xb], + o.dst.addr[0xc], o.dst.addr[0xd], o.dst.addr[0xe], o.dst.addr[0xf], + } + return addr.String() +} + +func (o *RouteDetail) Copy(src *RouteDetail) bool { + o.af = src.af + o.mtu = src.mtu + o.flags = src.flags + o.metric = src.metric + o.dst.Copy(&src.dst) + o.src.Copy(&src.src) + o.gateway.Copy(&src.gateway) + o.prefSrc.Copy(&src.prefSrc) + copy(o.ifName[:], src.ifName[:]) + return true +} + +func (o *RouteDetail) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *RouteDetail) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *RouteDetail = *(**RouteDetail)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *RouteDetail) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *RouteDetail) SetAf(af uint32) { + o.af = af +} + +func (o *RouteDetail) SetMtu(mtu uint32) { + o.mtu = mtu +} + +func (o *RouteDetail) SetFlags(flags uint32) { + // FIXME o.flags ^= o.flags first ??? + o.flags |= flags +} + +func (o *RouteDetail) SetMetric(metric uint32) { + o.metric = metric +} + +func (o *RouteDetail) SetScope(scope string) { + switch strings.ToLower(scope) { + case "host": + o.SetFlags(RTF_LOCALIN) + case "kni_host": + o.SetFlags(RTF_KNI) + default: + /*case "global":*/ + /*case "link":*/ + o.SetFlags(RTF_FORWARD) + } +} + +func (o *RouteDetail) SetDst(dst string) { + addr := dst + plen := "32" + if strings.Index(dst, "/") != -1 { + addr = dst[:strings.Index(dst, "/")] + plen = dst[strings.Index(dst, "/")+1:] + } + + if strings.Contains(addr, ":") { + o.SetAf(unix.AF_INET6) + copy(o.dst.addr[:], net.ParseIP(addr)) + } else { + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(o.dst.addr[:], buf.Bytes()[12:]) + } + + mask, err := strconv.Atoi(plen) + if err != nil { + o.dst.plen = 32 + } + o.dst.plen = uint32(mask) +} + +func (o *RouteDetail) SetSrc(src string) bool { + if len(src) == 0 { + return false + } + + if strings.Contains(src, ":") { + o.SetAf(unix.AF_INET6) + copy(o.src.addr[:], net.ParseIP(src)) + } else { + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(src)) + copy(o.src.addr[:], buf.Bytes()[12:]) + } + + return true +} + +func (o *RouteDetail) SetGateway(gw string) bool { + if len(gw) == 0 { + return false + } + + if strings.Contains(gw, ":") { + o.SetAf(unix.AF_INET6) + copy(o.gateway.addr[:], net.ParseIP(gw)) + } else { + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(gw)) + copy(o.gateway.addr[:], buf.Bytes()[12:]) + } + return true +} + +func (o *RouteDetail) SetPrefSrc(pref string) { + if len(pref) == 0 { + return + } + + if strings.Contains(pref, ":") { + o.SetAf(unix.AF_INET6) + copy(o.prefSrc.addr[:], net.ParseIP(pref)) + } else { + o.SetAf(unix.AF_INET) + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(pref)) + copy(o.prefSrc.addr[:], buf.Bytes()[12:]) + } +} + +func (o *RouteDetail) SetDevice(name string) { + copy(o.ifName[:], name[:]) +} + +func (o *RouteDetail) Read(conn *pool.Conn, len uint64) ([]*RouteDetail, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to RouteDetail") + } + + details := make([]*RouteDetail, cnt) + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + details[i] = NewRouteDetail() + details[i].Dump(buf) + } + + return details, nil +} + +func (o *RouteDetail) Write(conn *pool.Conn) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +type RouteFront struct { + count uint32 +} + +func NewRouteFront() *RouteFront { + return &RouteFront{} +} + +func (o *RouteFront) Copy(src *RouteFront) bool { + o.count = src.count + return true +} + +func (o *RouteFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *RouteFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *RouteFront = *(**RouteFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *RouteFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *RouteFront) SetCount(c uint32) { + o.count = c +} + +func (o *RouteFront) GetCount() uint32 { + return o.count +} + +func (o *RouteFront) Read(conn *pool.Conn, len uint64) ([]*RouteFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to RouteFront") + } + + fronts := make([]*RouteFront, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i] = NewRouteFront() + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *RouteFront) Write(conn *pool.Conn) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +/**************** +****************/ +func (o *RouteDetail) Get(cp *pool.ConnPool, parentLogger hclog.Logger) ([]*RouteDetail, error) { + traceName := o.GetIfName() + logger := hclog.Default().Named(traceName) + if parentLogger != nil { + logger = parentLogger.Named(traceName) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + var GET uint32 + GET = DPVSAGENT_ROUTE_GET + if o.af == unix.AF_INET6 { + GET = DPVSAGENT_ROUTE6_GET + } + + msg := NewSockMsg(SOCKOPT_VERSION, GET, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt ", GET, "Write proto header failed", "Error", err.Error()) + return nil, err + } + + if err := o.Write(conn); err != nil { + logger.Error("Sockopt ", GET, "Write proto body failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt ", GET, "Read proto header failed", "Error", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + result := reply.GetErrStr() + logger.Error("Sockopt ", GET, " failed", "result", result) + err := fmt.Errorf("Sockopt %s reply ErrorCode: %s", GET, result) + return nil, err + } + + front := NewRouteFront() + _, err = front.Read(conn, front.Sizeof()) + if err != nil { + logger.Error("Sockopt ", GET, "read list header failed", "Error", err.Error()) + return nil, err + } + + return o.Read(conn, uint64(reply.GetLen())-front.Sizeof()) +} + +func (o *RouteDetail) Add(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + traceName := fmt.Sprintf("add %s via %s dev %s", o.GetSrc(), o.GetDst(), o.GetIfName()) + logger := hclog.Default().Named(traceName) + if parentLogger != nil { + logger = parentLogger.Named(traceName) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var ADD uint32 + ADD = DPVSAGENT_ROUTE_ADD + if o.af == unix.AF_INET6 { + ADD = DPVSAGENT_ROUTE6_ADD + } + + msg := NewSockMsg(SOCKOPT_VERSION, ADD, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt ", ADD, "Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + err = o.Write(conn) + if err != nil { + logger.Error("Sockopt ", ADD, "Write proto body failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt ", ADD, "reply failed", "Error", err.Error()) + return EDPVS_IO + } + + return reply.GetErrCode() +} + +func (o *RouteDetail) Del(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + traceName := fmt.Sprintf("del %s via %s dev %s", o.GetSrc(), o.GetDst(), o.GetIfName()) + logger := hclog.Default().Named(traceName) + if parentLogger != nil { + logger = parentLogger.Named(traceName) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + var DEL uint32 + DEL = DPVSAGENT_ROUTE_DEL + if o.af == unix.AF_INET6 { + DEL = DPVSAGENT_ROUTE6_DEL + } + + msg := NewSockMsg(SOCKOPT_VERSION, DEL, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt ", DEL, "Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + err = o.Write(conn) + if err != nil { + logger.Error("Sockopt ", DEL, "Write proto body failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt ", DEL, "reply failed", "Error", err.Error()) + return EDPVS_IO + } + + return reply.GetErrCode() +} diff --git a/tools/dpvs-agent/pkg/ipc/types/sockmsg.go b/tools/dpvs-agent/pkg/ipc/types/sockmsg.go new file mode 100644 index 000000000..3db2543e5 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/sockmsg.go @@ -0,0 +1,132 @@ +package types + +import ( + "bytes" + "encoding/binary" + "errors" + "unsafe" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type SockMsg struct { + version uint32 + id uint32 + sockopt SockoptType + nop uint32 + len uint64 +} + +type ReplySockMsg struct { + version uint32 + id uint32 + sockopt SockoptType + errCode DpvsErrType + errStr [0x40]byte + len uint32 + nop uint32 +} + +func NewSockMsg(version, id uint32, sockopt SockoptType, len uint64) *SockMsg { + return &SockMsg{version: version, id: id, sockopt: sockopt, len: len} +} + +func (msg *SockMsg) GetLen() uint64 { + return msg.len +} + +func NewReplySockMsg() *ReplySockMsg { + return &ReplySockMsg{} +} + +func (msg *ReplySockMsg) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*msg)) +} + +func (msg *ReplySockMsg) Dump(buf []byte) bool { + if len(buf) != int(msg.Sizeof()) { + return false + } + + var tmp *ReplySockMsg = *(**ReplySockMsg)(unsafe.Pointer(&buf)) + msg.version = tmp.version + msg.id = tmp.id + msg.sockopt = tmp.sockopt + msg.errCode = tmp.errCode + msg.len = tmp.len + copy(msg.errStr[:], tmp.errStr[:]) + msg.ZeroPadding() + + return true +} + +func (msg *ReplySockMsg) SetVersion(version uint32) { + msg.version = version +} + +func (msg *ReplySockMsg) SetID(id uint32) { + msg.id = id +} + +func (msg *ReplySockMsg) SetSockopt(opt SockoptType) { + msg.sockopt = opt +} + +func (msg *ReplySockMsg) SetErrCode(code DpvsErrType) { + msg.errCode = code +} + +func (msg *ReplySockMsg) SetErrStr(err []byte) { + copy(msg.errStr[:], err) +} + +func (msg *ReplySockMsg) SetLen(len uint32) { + msg.len = len +} + +func (msg *ReplySockMsg) ZeroPadding() { + msg.nop = 0 +} + +func (msg *ReplySockMsg) GetErrCode() DpvsErrType { + return msg.errCode +} + +func (msg *ReplySockMsg) GetErrStr() string { + return TrimRightZeros(string(msg.errStr[:])) +} + +func (msg *ReplySockMsg) GetLen() uint32 { + return msg.len +} + +func (msg *SockMsg) Package() []byte { + hdr := new(bytes.Buffer) + binary.Write(hdr, binary.LittleEndian, msg) + return hdr.Bytes() +} + +func (msg *SockMsg) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*msg)) +} + +func (msg *SockMsg) Write(conn *pool.Conn) error { + buf := msg.Package() + _, err := conn.WriteN(buf, len(buf)) + if err != nil { + return err + } + return nil +} + +func (msg *ReplySockMsg) Read(conn *pool.Conn) error { + buf, err := conn.ReadN(int(msg.Sizeof())) + if err != nil { + return err + } + + if !msg.Dump(buf) { + return errors.New("dump reply msg failed") + } + return nil +} diff --git a/tools/dpvs-agent/pkg/ipc/types/utility.go b/tools/dpvs-agent/pkg/ipc/types/utility.go new file mode 100644 index 000000000..d887d9a19 --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/utility.go @@ -0,0 +1,11 @@ +package types + +import "strings" + +func TrimRightZeros(s string) string { + idx := strings.IndexByte(s, 0) + if idx >= 0 { + return s[:idx] + } + return s +} diff --git a/tools/dpvs-agent/pkg/ipc/types/virtualserver.go b/tools/dpvs-agent/pkg/ipc/types/virtualserver.go new file mode 100644 index 000000000..bb7cc409d --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/virtualserver.go @@ -0,0 +1,693 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "net" + "strconv" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/models" + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type VirtualServerFront struct { + cid uint8 + index uint8 + count uint16 + padding uint32 +} + +func NewVirtualServerFront() *VirtualServerFront { + return &VirtualServerFront{} +} + +func (o *VirtualServerFront) Copy(src *VirtualServerFront) bool { + if src == nil { + return false + } + + o.cid = src.cid + o.index = src.index + o.count = src.count + + return true +} + +func (o *VirtualServerFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *VirtualServerFront = *(**VirtualServerFront)(unsafe.Pointer(&buf)) + return o.Copy(tmp) +} + +func (o *VirtualServerFront) SetCid(cid uint8) { + o.cid = cid +} + +func (o *VirtualServerFront) SetIndex(index uint8) { + o.index = index +} + +func (o *VirtualServerFront) SetCount(count uint16) { + o.count = count +} + +func (o *VirtualServerFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *VirtualServerFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *VirtualServerFront) read(conn *pool.Conn, logger hclog.Logger) error { + conn.SetReadBuffer(int(o.Sizeof())) + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + return err + } + + if !o.Dump(buf) { + return errors.New("dump reply virtual server front failed") + } + logger.Info("Get Virtual Server Count success", "count", o.count) + + return nil +} +func (o *VirtualServerFront) Write(conn *pool.Conn) error { + buf := o.Package() + + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + + return nil +} + +type dpvsDestCheck struct { + types uint8 + padding [7]byte +} + +type VirtualServerSpec struct { + af uint32 + proto uint16 + port uint16 + fwmark uint32 + flags uint32 + timeout uint32 + connTimeout uint32 + netmask uint32 + bps uint32 + limitProportion uint32 + addr [0x10]byte + schedName [0x10]byte + match dpvsMatch + numDests uint32 + numLaddrs uint32 + cid uint64 + stats dpvsStats + hc dpvsDestCheck +} + +func NewVirtualServerSpec() *VirtualServerSpec { + return &VirtualServerSpec{} +} + +func (vs *VirtualServerSpec) Convert2NewRsFront() *RealServerFront { + front := NewRealServerFront() + + front.af = vs.af + front.port = vs.port + front.proto = vs.proto + front.fwmark = vs.fwmark + front.numDests = vs.numDests + front.cid = uint32(vs.cid) + + front.match.Copy(&vs.match) + copy(front.addr[:], vs.addr[:]) + + return front +} + +func (vs *VirtualServerSpec) Copy(src *VirtualServerSpec) bool { + if src == nil { + return false + } + + vs.af = src.af + vs.proto = src.proto + vs.port = src.port + vs.fwmark = src.fwmark + vs.flags = src.flags + vs.timeout = src.timeout + vs.connTimeout = src.connTimeout + vs.netmask = src.netmask + vs.bps = src.bps + vs.limitProportion = src.limitProportion + vs.numDests = src.numDests + vs.numLaddrs = src.numLaddrs + vs.cid = src.cid + vs.hc = src.hc + + copy(vs.addr[:], src.addr[:]) + copy(vs.schedName[:], src.schedName[:]) + + if !vs.match.Copy(&src.match) { + return false + } + if !vs.stats.Copy(&src.stats) { + return false + } + return true +} + +func (vs *VirtualServerSpec) ID() string { + proto := "tcp" + if vs.proto == unix.IPPROTO_UDP { + proto = "udp" + } + return fmt.Sprintf("%s-%d-%s", vs.GetAddr(), vs.GetPort(), proto) +} + +func (vs *VirtualServerSpec) Format(kind string) string { + /* + TCP VIP:PORT sched + -> RIP:RPORT Fnat weight actConn inActConn + -> RIP:RPORT Fnat weight actConn inActConn + ... + */ + + var vipport string + vip := vs.GetAddr() + if vip == "" { + return "" + } + port := vs.GetPort() + + vipport = fmt.Sprintf("%s:%d", vip, port) + if vs.proto == unix.IPPROTO_TCP { + vsHeader := fmt.Sprintf("TCP %s %s\r\n", vipport, string(vs.schedName[:])) + return vsHeader + } + + return "" +} + +func (vs *VirtualServerSpec) Dump(buf []byte) bool { + if len(buf) != int(vs.Sizeof()) { + return false + } + + var tmp *VirtualServerSpec = *(**VirtualServerSpec)(unsafe.Pointer(&buf)) + + return vs.Copy(tmp) +} + +func (vs *VirtualServerSpec) SetAf(af uint32) { + vs.af = af +} +func (vs *VirtualServerSpec) GetAf() uint32 { + return vs.af +} + +func (vs *VirtualServerSpec) SetProto(proto uint16) { + vs.proto = proto +} + +func (vs *VirtualServerSpec) SetPort(port uint16) { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(port)) + vs.port = binary.BigEndian.Uint16(buf.Bytes()) +} + +func (vs *VirtualServerSpec) GetPort() uint16 { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, uint16(vs.port)) + return binary.BigEndian.Uint16(buf.Bytes()) +} + +func (vs *VirtualServerSpec) GetProto() uint16 { + return vs.proto +} + +func (vs *VirtualServerSpec) SetFwmark(fwmark uint32) { + vs.fwmark = fwmark +} +func (vs *VirtualServerSpec) GetFwmark() uint32 { + return vs.fwmark +} + +func (vs *VirtualServerSpec) SetFlagsSyncProxy() { + vs.setFlags(DPVS_CONN_F_SYNPROXY) +} + +func (vs *VirtualServerSpec) SetFlagsExpireQuiescent() { + vs.setFlags(DPVS_CONN_F_EXPIRE_QUIESCENT) +} + +func (vs *VirtualServerSpec) SetFlagsPersistent() { + vs.setFlags(DPVS_SVC_F_PERSISTENT) +} + +func (vs *VirtualServerSpec) SetFlagsHashSrcIP() { + vs.flags &= (uint32)(^DPVS_SVC_F_QID_HASH) + vs.flags &= (uint32)(^DPVS_SVC_F_SIP_HASH) + + vs.setFlags(DPVS_SVC_F_SIP_HASH) +} + +func (vs *VirtualServerSpec) SetFlagsHashQuicID() { + vs.flags &= (uint32)(^DPVS_SVC_F_QID_HASH) + vs.flags &= (uint32)(^DPVS_SVC_F_SIP_HASH) + + vs.setFlags(DPVS_SVC_F_QID_HASH) +} + +func (vs *VirtualServerSpec) setFlags(flags uint32) { + vs.flags |= flags +} + +func (vs *VirtualServerSpec) GetFlags() uint32 { + return vs.flags +} + +func (vs *VirtualServerSpec) SetTimeout(t uint32) { + vs.timeout = t +} +func (vs *VirtualServerSpec) GetTimeout() uint32 { + return vs.timeout +} + +func (vs *VirtualServerSpec) SetConnTimeout(ct uint32) { + vs.connTimeout = ct +} + +func (vs *VirtualServerSpec) GetConnTimeout() uint32 { + return vs.connTimeout +} + +func (vs *VirtualServerSpec) SetNetMask(mask uint32) { + vs.netmask = mask +} + +func (vs *VirtualServerSpec) GetNetMask() uint32 { + return vs.netmask +} + +func (vs *VirtualServerSpec) SetBps(bps uint32) { + vs.bps = bps +} + +func (vs *VirtualServerSpec) GetBps() uint32 { + return vs.bps +} + +func (vs *VirtualServerSpec) SetLimitProportion(limit uint32) { + vs.limitProportion = limit +} + +func (vs *VirtualServerSpec) GetLimitProportion() uint32 { + return vs.limitProportion +} + +func (vs *VirtualServerSpec) SetNumDests(num uint32) { + vs.numDests = num +} + +func (vs *VirtualServerSpec) GetNumDests() uint32 { + return vs.numDests +} + +func (vs *VirtualServerSpec) SetNumLaddrs(num uint32) { + vs.numLaddrs = num +} + +func (vs *VirtualServerSpec) SetCid(cid uint64) { + vs.cid = cid +} + +func (vs *VirtualServerSpec) setNetmask(mask uint32) { + vs.netmask = mask +} + +func (vs *VirtualServerSpec) SetAddr(addr string) { + if strings.Contains(addr, ":") { + copy(vs.addr[:], net.ParseIP(addr)) + vs.af = unix.AF_INET6 + vs.setNetmask(128) + return + } + + vs.af = unix.AF_INET + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, net.ParseIP(addr)) + copy(vs.addr[:], buf.Bytes()[12:]) + vs.setNetmask(0xFFFFFFFF) +} + +func (vs *VirtualServerSpec) GetAddr() string { + var addr net.IP + + if vs.af == unix.AF_INET { + addr = net.IPv4(vs.addr[0], vs.addr[1], vs.addr[2], vs.addr[3]) + return addr.String() + } + + addr = net.IP{vs.addr[0x0], vs.addr[0x1], vs.addr[0x2], vs.addr[0x3], + vs.addr[0x4], vs.addr[0x5], vs.addr[0x6], vs.addr[0x7], + vs.addr[0x8], vs.addr[0x9], vs.addr[0xa], vs.addr[0xb], + vs.addr[0xc], vs.addr[0xd], vs.addr[0xe], vs.addr[0xf], + } + return addr.String() +} + +func (vs *VirtualServerSpec) GetSchedName() string { + return TrimRightZeros(string(vs.schedName[:])) +} + +func (vs *VirtualServerSpec) GetDestCheck() []models.DestCheckSpec { + var res []models.DestCheckSpec + if vs.hc.types&DPVS_DEST_HC_PASSIVE != 0 { + res = append(res, models.DestCheckSpecPassive) + } + if vs.hc.types&DPVS_DEST_HC_TCP != 0 { + res = append(res, models.DestCheckSpecTCP) + } + if vs.hc.types&DPVS_DEST_HC_UDP != 0 { + res = append(res, models.DestCheckSpecUDP) + } + if vs.hc.types&DPVS_DEST_HC_PING != 0 { + res = append(res, models.DestCheckSpecPing) + } + return res +} + +func (vs *VirtualServerSpec) SetSchedName(name string) { + sched := strings.ToLower(name) + + switch strings.ToLower(name) { + case "rr": + case "wlc": + case "conhash": + case "fo": + case "mh": + default: + sched = "wrr" + } + copy(vs.schedName[:], []byte(sched)) +} + +func (vs *VirtualServerSpec) SetMatch(m *dpvsMatch) { + vs.match.Copy(m) +} + +func (vs *VirtualServerSpec) SetStats(s *dpvsStats) { + vs.stats.Copy(s) +} + +func (vs *VirtualServerSpec) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*vs)) +} + +func (vs *VirtualServerSpec) ParseVipPortProto(vipport string) error { + items := strings.Split(vipport, "-") + if len(items) != 3 { + return errors.New("invalid vip-port-proto string") + } + + proto := items[2] + + switch strings.ToLower(proto) { + case "udp": + vs.proto = unix.IPPROTO_UDP + case "tcp": + fallthrough + default: + vs.proto = unix.IPPROTO_TCP + } + + // port := items[1] + port, err := strconv.Atoi(items[1]) + if err != nil { + return err + } + vs.SetPort(uint16(port)) + + vip := items[0] + if net.ParseIP(vip) == nil { + return errors.New(fmt.Sprintf("invalid ip addr: %s\n", vip)) + } + vs.SetAddr(vip) + + return nil +} + +func (vs *VirtualServerSpec) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*VirtualServerSpec, error) { + res := len % vs.Sizeof() + cnt := len / vs.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + err := errors.New("the buffer may not convert to VirtualServerSpec") + logger.Error("Read failed", "Error", err.Error()) + return nil, err + } + + vss := make([]*VirtualServerSpec, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(vs.Sizeof())) + if err != nil { + logger.Error("Read VirtualServerSpec() failed", "Error", err.Error()) + return nil, err + } + + vss[i] = NewVirtualServerSpec() + if !vss[i].Dump(buf) { + logger.Error("Dump byte as VirtualServerSpec failed") + return nil, errors.New("dump reply virtual server failed") + } + spec := *vss[i] + logger.Info("get virtual server success", "spec", spec) + } + + return vss, nil +} + +func (vs *VirtualServerSpec) Write(conn *pool.Conn) error { + buf := vs.Package() + + _, err := conn.WriteN(buf, int(vs.Sizeof())) + if err != nil { + return err + } + + return nil +} + +func (vs *VirtualServerSpec) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, vs) + return buf.Bytes() +} + +/***************** +******************/ + +func (front *VirtualServerFront) Get(cp *pool.ConnPool, logger hclog.Logger) ([]*VirtualServerSpec, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVSAGENT_SO_GET_SERVICES, SOCKOPT_GET, front.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_SO_GET_SERVICEs Write proto header failed", "Error", err.Error()) + return nil, err + } + + err = front.Write(conn) + if err != nil { + logger.Error("Sockopt DPVSAGENT_SO_GET_SERVICEs Write proto bodyfailed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVSAGENT_SO_GET_SERVICEs Read proto header failed", "Error", err.Error()) + return nil, err + } + + if err := front.read(conn, logger); err != nil { + logger.Error("Sockopt DPVSAGENT_SO_GET_SERVICEs Read vss table header failed", "Error", err.Error()) + return nil, err + } + + vs := NewVirtualServerSpec() + return vs.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} + +func (vs *VirtualServerSpec) Get(cp *pool.ConnPool, parentLogger hclog.Logger) ([]*VirtualServerSpec, error) { + logger := hclog.Default().Named(vs.ID()) + if parentLogger != nil { + logger = parentLogger.Named(vs.ID()) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + msg := NewSockMsg(SOCKOPT_VERSION, DPVS_SO_GET_SERVICE, SOCKOPT_GET, vs.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_GET_SERVICE Write proto header failed", "Error", err.Error()) + return nil, err + } + + err = vs.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_GET_SERVICE Write proto body failed", "Error", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVS_SO_GET_SERVICE Read failed", "Error", err.Error()) + return nil, err + } + + return vs.read(conn, uint64(reply.GetLen()), logger) +} + +func (vs *VirtualServerSpec) Update(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(vs.ID()) + if parentLogger != nil { + logger = parentLogger.Named(vs.ID()) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVS_SO_SET_EDIT, SOCKOPT_SET, vs.Sizeof()) + + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_EDIT Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + err = vs.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_EDIT Write proto body failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_EDIT Read failed", "Error", err.Error()) + return EDPVS_IO + } + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("DPVS_SO_SET_EDIT Done", "result", result) + return errCode +} + +func (vs *VirtualServerSpec) Add(cp *pool.ConnPool, parentLogger hclog.Logger) DpvsErrType { + logger := hclog.Default().Named(vs.ID()) + if parentLogger != nil { + logger = parentLogger.Named(vs.ID()) + } + + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVS_SO_SET_ADD, SOCKOPT_SET, vs.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_ADD Write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + err = vs.Write(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_ADD Write proto body failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt DPVS_SO_SET_ADD Read failed", "Error", err.Error()) + return EDPVS_IO + } + errCode := reply.GetErrCode() + result := errCode.String() + + logger.Info("DPVS_SO_SET_ADD Done", "result", result) + return errCode +} + +func (vs *VirtualServerSpec) Del(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, DPVS_SO_SET_DEL, SOCKOPT_SET, vs.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt DPVS_SO_SET_DEL write proto header failed", "Error", err.Error()) + return EDPVS_IO + } + + if err := vs.Write(conn); err != nil { + logger.Error("Sockopt DPVS_SO_SET_DEL Write body failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt DPVS_SO_SET_DEL Read reply failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + + logger.Info("DPVS_SO_SET_DEL Done", "result", result) + return errCode +} diff --git a/tools/dpvs-agent/pkg/ipc/types/vlan.go b/tools/dpvs-agent/pkg/ipc/types/vlan.go new file mode 100644 index 000000000..ece83c0ef --- /dev/null +++ b/tools/dpvs-agent/pkg/ipc/types/vlan.go @@ -0,0 +1,312 @@ +package types + +import ( + "bytes" + "context" + "encoding/binary" + "errors" + "fmt" + "strings" + "unsafe" + + "github.com/hashicorp/go-hclog" + "golang.org/x/sys/unix" + + "github.com/dpvs-agent/pkg/ipc/pool" +) + +type VlanFront struct { + count uint32 +} + +func NewVlanFront() *VlanFront { + return &VlanFront{} +} + +func (o *VlanFront) GetCount() uint32 { + return o.count +} + +func (o *VlanFront) SetCount(c uint32) { + o.count = c +} + +func (o *VlanFront) Copy(src *VlanFront) bool { + o.count = src.count + return true +} + +func (o *VlanFront) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *VlanFront) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *VlanFront = *(**VlanFront)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *VlanFront) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *VlanFront) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*VlanFront, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to VlanFront") + } + + fronts := make([]*VlanFront, cnt) + + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + fronts[i] = NewVlanFront() + fronts[i].Dump(buf) + } + + return fronts, nil +} + +func (o *VlanFront) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +type VlanDevice struct { + realDev [0x10]byte + ifName [0x10]byte + proto uint16 + id uint16 +} + +func NewVlanDevice() *VlanDevice { + return &VlanDevice{proto: unix.ETH_P_8021Q} +} + +func (o *VlanDevice) Copy(src *VlanDevice) bool { + copy(o.realDev[:], src.realDev[:]) + copy(o.ifName[:], src.ifName[:]) + o.proto = src.proto + o.id = src.id + return true +} + +func (o *VlanDevice) Sizeof() uint64 { + return uint64(unsafe.Sizeof(*o)) +} + +func (o *VlanDevice) Dump(buf []byte) bool { + if len(buf) != int(o.Sizeof()) { + return false + } + + var tmp *VlanDevice = *(**VlanDevice)(unsafe.Pointer(&buf)) + + return o.Copy(tmp) +} + +func (o *VlanDevice) Package() []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, o) + return buf.Bytes() +} + +func (o *VlanDevice) SetRealDev(name string) { + copy(o.realDev[:], name[:]) +} + +func (o *VlanDevice) SetId(id uint16) { + o.id = id +} + +func (o *VlanDevice) SetIfName(name string) { + copy(o.ifName[:], name[:]) +} + +func (o *VlanDevice) SetProto(proto string) { + p := strings.ToLower(proto) + switch p { + case "vlan": + fallthrough + case "802.1q": + o.proto = unix.ETH_P_8021Q + case "qinq": + fallthrough + case "802.1ad": + o.proto = unix.ETH_P_8021AD + default: + } +} + +func (o *VlanDevice) ValidProto(proto string) bool { + // p := strings.ToLower(proto) + switch strings.ToLower(proto) { + case "vlan": + return true + case "802.1q": + return true + case "qinq": + return true + case "802.1ad": + return true + default: + return false + } + return false +} + +func (o *VlanDevice) read(conn *pool.Conn, len uint64, logger hclog.Logger) ([]*VlanDevice, error) { + res := len % o.Sizeof() + cnt := len / o.Sizeof() + if cnt <= 0 || res != 0 { + conn.Release(int(len)) + return nil, errors.New("Wrong buffer size to read, may not convert to VlanDevice") + } + + devices := make([]*VlanDevice, cnt) + for i := 0; i < int(cnt); i++ { + buf, err := conn.ReadN(int(o.Sizeof())) + if err != nil { + continue + } + devices[i] = NewVlanDevice() + devices[i].Dump(buf) + } + + return devices, nil +} + +func (o *VlanDevice) write(conn *pool.Conn, logger hclog.Logger) error { + buf := o.Package() + _, err := conn.WriteN(buf, int(o.Sizeof())) + if err != nil { + return err + } + return nil +} + +/**************** +****************/ +func (o *VlanDevice) Get(cp *pool.ConnPool, logger hclog.Logger) ([]*VlanDevice, error) { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return nil, err + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, SOCKOPT_GET_VLAN_SHOW, SOCKOPT_GET, o.Sizeof()) + if err := msg.Write(conn); err != nil { + logger.Error("Sockopt SOCKOPT_GET_VLAN_SHOW Write proto header Error:", err.Error()) + return nil, err + } + + if err := o.write(conn, logger); err != nil { + logger.Error("Sockopt SOCKOPT_GET_VLAN_SHOW write specific vlan Error:", err.Error()) + return nil, err + } + + reply := NewReplySockMsg() + if err := reply.Read(conn); err != nil { + logger.Error("Sockopt SOCKOPT_GET_VLAN_SHOW reply msg Read failed:", err.Error()) + return nil, err + } + + if reply.GetErrCode() != EDPVS_OK { + err = fmt.Errorf("Sockopt SOCKOPT_GET_VLAN_SHOW reply ErrorCode: %s", reply.GetErrStr()) + logger.Error(err.Error()) + return nil, err + } + + front := VlanFront{} + _, err = front.read(conn, front.Sizeof(), logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_GET_VLAN_SHOW read table header failed:", err.Error()) + return nil, err + } + + return o.read(conn, uint64(reply.GetLen())-front.Sizeof(), logger) +} + +func (o *VlanDevice) Add(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed", "Error", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, SOCKOPT_SET_VLAN_ADD, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_ADD Write proto header Error failed", "Error", err.Error()) + return EDPVS_IO + } + + err = o.write(conn, logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_ADD write specific vlan Error failed", "Error", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_ADD reply msg Read failed", "Error", err.Error()) + return EDPVS_IO + } + + errCode := reply.GetErrCode() + result := errCode.String() + logger.Info("Sockopt SOCKOPT_SET_VLAN_ADD Done", "result", result) + return errCode +} + +func (o *VlanDevice) Del(cp *pool.ConnPool, logger hclog.Logger) DpvsErrType { + ctx := context.Background() + conn, err := cp.Get(ctx) + if err != nil { + logger.Error("Get conn from pool failed:", err.Error()) + return EDPVS_IO + } + defer cp.Remove(ctx, conn, nil) + + msg := NewSockMsg(SOCKOPT_VERSION, SOCKOPT_SET_VLAN_DEL, SOCKOPT_SET, o.Sizeof()) + err = msg.Write(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_DEL Write proto header Error:", err.Error()) + return EDPVS_IO + } + + err = o.write(conn, logger) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_DEL write specific vlan Error:", err.Error()) + return EDPVS_IO + } + + reply := NewReplySockMsg() + err = reply.Read(conn) + if err != nil { + logger.Error("Sockopt SOCKOPT_SET_VLAN_DEL reply msg Read failed:", err.Error()) + return EDPVS_IO + } + + return reply.GetErrCode() +} diff --git a/tools/dpvs-agent/restapi/configure_dpvs_agent.go b/tools/dpvs-agent/restapi/configure_dpvs_agent.go new file mode 100644 index 000000000..f37abf18a --- /dev/null +++ b/tools/dpvs-agent/restapi/configure_dpvs_agent.go @@ -0,0 +1,172 @@ +// This file is safe to edit. Once it exists it will not be overwritten + +package restapi + +import ( + "crypto/tls" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + + "github.com/dpvs-agent/restapi/operations" + "github.com/dpvs-agent/restapi/operations/device" + "github.com/dpvs-agent/restapi/operations/virtualserver" +) + +//go:generate swagger generate server --target ../../dpvs-agent --name DpvsAgent --spec ../dpvs-agent-api.yaml --principal interface{} + +func configureFlags(api *operations.DpvsAgentAPI) { + // api.CommandLineOptionsGroups = []swag.CommandLineOptionsGroup{ ... } +} + +func configureAPI(api *operations.DpvsAgentAPI) http.Handler { + // configure the api here + api.ServeError = errors.ServeError + + // Set your custom logger if needed. Default one is log.Printf + // Expected interface func(string, ...interface{}) + // + // Example: + // api.Logger = log.Printf + + api.UseSwaggerUI() + // To continue using redoc as your UI, uncomment the following line + // api.UseRedoc() + + api.JSONConsumer = runtime.JSONConsumer() + + api.JSONProducer = runtime.JSONProducer() + + if api.DeviceDeleteDeviceNameAddrHandler == nil { + api.DeviceDeleteDeviceNameAddrHandler = device.DeleteDeviceNameAddrHandlerFunc(func(params device.DeleteDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameAddr has not yet been implemented") + }) + } + if api.DeviceDeleteDeviceNameRouteHandler == nil { + api.DeviceDeleteDeviceNameRouteHandler = device.DeleteDeviceNameRouteHandlerFunc(func(params device.DeleteDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameRoute has not yet been implemented") + }) + } + if api.DeviceDeleteDeviceNameVlanHandler == nil { + api.DeviceDeleteDeviceNameVlanHandler = device.DeleteDeviceNameVlanHandlerFunc(func(params device.DeleteDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameVlan has not yet been implemented") + }) + } + if api.VirtualserverDeleteVsVipPortHandler == nil { + api.VirtualserverDeleteVsVipPortHandler = virtualserver.DeleteVsVipPortHandlerFunc(func(params virtualserver.DeleteVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPort has not yet been implemented") + }) + } + if api.VirtualserverDeleteVsVipPortLaddrHandler == nil { + api.VirtualserverDeleteVsVipPortLaddrHandler = virtualserver.DeleteVsVipPortLaddrHandlerFunc(func(params virtualserver.DeleteVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortLaddr has not yet been implemented") + }) + } + if api.VirtualserverDeleteVsVipPortRsHandler == nil { + api.VirtualserverDeleteVsVipPortRsHandler = virtualserver.DeleteVsVipPortRsHandlerFunc(func(params virtualserver.DeleteVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortRs has not yet been implemented") + }) + } + if api.DeviceGetDeviceHandler == nil { + api.DeviceGetDeviceHandler = device.GetDeviceHandlerFunc(func(params device.GetDeviceParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDevice has not yet been implemented") + }) + } + if api.DeviceGetDeviceNameAddrHandler == nil { + api.DeviceGetDeviceNameAddrHandler = device.GetDeviceNameAddrHandlerFunc(func(params device.GetDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameAddr has not yet been implemented") + }) + } + if api.DeviceGetDeviceNameRouteHandler == nil { + api.DeviceGetDeviceNameRouteHandler = device.GetDeviceNameRouteHandlerFunc(func(params device.GetDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameRoute has not yet been implemented") + }) + } + if api.DeviceGetDeviceNameVlanHandler == nil { + api.DeviceGetDeviceNameVlanHandler = device.GetDeviceNameVlanHandlerFunc(func(params device.GetDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameVlan has not yet been implemented") + }) + } + if api.VirtualserverGetVsHandler == nil { + api.VirtualserverGetVsHandler = virtualserver.GetVsHandlerFunc(func(params virtualserver.GetVsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVs has not yet been implemented") + }) + } + if api.VirtualserverGetVsVipPortHandler == nil { + api.VirtualserverGetVsVipPortHandler = virtualserver.GetVsVipPortHandlerFunc(func(params virtualserver.GetVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPort has not yet been implemented") + }) + } + if api.VirtualserverGetVsVipPortLaddrHandler == nil { + api.VirtualserverGetVsVipPortLaddrHandler = virtualserver.GetVsVipPortLaddrHandlerFunc(func(params virtualserver.GetVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortLaddr has not yet been implemented") + }) + } + if api.VirtualserverGetVsVipPortRsHandler == nil { + api.VirtualserverGetVsVipPortRsHandler = virtualserver.GetVsVipPortRsHandlerFunc(func(params virtualserver.GetVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortRs has not yet been implemented") + }) + } + if api.DevicePutDeviceNameAddrHandler == nil { + api.DevicePutDeviceNameAddrHandler = device.PutDeviceNameAddrHandlerFunc(func(params device.PutDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameAddr has not yet been implemented") + }) + } + if api.DevicePutDeviceNameRouteHandler == nil { + api.DevicePutDeviceNameRouteHandler = device.PutDeviceNameRouteHandlerFunc(func(params device.PutDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameRoute has not yet been implemented") + }) + } + if api.DevicePutDeviceNameVlanHandler == nil { + api.DevicePutDeviceNameVlanHandler = device.PutDeviceNameVlanHandlerFunc(func(params device.PutDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameVlan has not yet been implemented") + }) + } + if api.VirtualserverPutVsVipPortHandler == nil { + api.VirtualserverPutVsVipPortHandler = virtualserver.PutVsVipPortHandlerFunc(func(params virtualserver.PutVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPort has not yet been implemented") + }) + } + if api.VirtualserverPutVsVipPortLaddrHandler == nil { + api.VirtualserverPutVsVipPortLaddrHandler = virtualserver.PutVsVipPortLaddrHandlerFunc(func(params virtualserver.PutVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortLaddr has not yet been implemented") + }) + } + if api.VirtualserverPutVsVipPortRsHandler == nil { + api.VirtualserverPutVsVipPortRsHandler = virtualserver.PutVsVipPortRsHandlerFunc(func(params virtualserver.PutVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortRs has not yet been implemented") + }) + } + + api.PreServerShutdown = func() {} + + api.ServerShutdown = func() {} + + return setupGlobalMiddleware(api.Serve(setupMiddlewares)) +} + +// The TLS configuration before HTTPS server starts. +func configureTLS(tlsConfig *tls.Config) { + // Make all necessary changes to the TLS configuration here. +} + +// As soon as server is initialized but not run yet, this function will be called. +// If you need to modify a config, store server instance to stop it individually later, this is the place. +// This function can be called multiple times, depending on the number of serving schemes. +// scheme value will be set accordingly: "http", "https" or "unix". +func configureServer(s *http.Server, scheme, addr string) { +} + +// The middleware configuration is for the handler executors. These do not apply to the swagger.json document. +// The middleware executes after routing but before authentication, binding and validation. +func setupMiddlewares(handler http.Handler) http.Handler { + return handler +} + +// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. +// So this is a good place to plug in a panic handling middleware, logging and metrics. +func setupGlobalMiddleware(handler http.Handler) http.Handler { + return handler +} diff --git a/tools/dpvs-agent/restapi/doc.go b/tools/dpvs-agent/restapi/doc.go new file mode 100644 index 000000000..d70edbc94 --- /dev/null +++ b/tools/dpvs-agent/restapi/doc.go @@ -0,0 +1,19 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// Package restapi dpvs agent +// +// dpvs agent api +// Schemes: +// http +// Host: petstore.swagger.io +// BasePath: /v2 +// Version: 1.0.0 +// +// Consumes: +// - application/json +// +// Produces: +// - application/json +// +// swagger:meta +package restapi diff --git a/tools/dpvs-agent/restapi/embedded_spec.go b/tools/dpvs-agent/restapi/embedded_spec.go new file mode 100644 index 000000000..488b7f0fe --- /dev/null +++ b/tools/dpvs-agent/restapi/embedded_spec.go @@ -0,0 +1,4449 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restapi + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "encoding/json" +) + +var ( + // SwaggerJSON embedded version of the swagger document used at generation time + SwaggerJSON json.RawMessage + // FlatSwaggerJSON embedded flattened version of the swagger document used at generation time + FlatSwaggerJSON json.RawMessage +) + +func init() { + SwaggerJSON = json.RawMessage([]byte(`{ + "schemes": [ + "http" + ], + "swagger": "2.0", + "info": { + "description": "dpvs agent api", + "title": "dpvs agent", + "version": "1.0.0" + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "paths": { + "/device": { + "get": { + "tags": [ + "device" + ], + "summary": "display all net device list", + "parameters": [ + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/addr": { + "get": { + "tags": [ + "device" + ], + "summary": "display special net device ip addr", + "parameters": [ + { + "$ref": "#/parameters/stats" + }, + { + "$ref": "#/parameters/verbose" + }, + { + "$ref": "#/parameters/device-name" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device ip addr", + "parameters": [ + { + "$ref": "#/parameters/sapool" + }, + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/device-addr" + } + ], + "responses": { + "200": { + "description": "Update exist ip addr Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Add new ip addr Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device ip addr", + "parameters": [ + { + "$ref": "#/parameters/sapool" + }, + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/device-addr" + } + ], + "responses": { + "200": { + "description": "delete ip addr from device Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/netlink": { + "get": { + "tags": [ + "device" + ], + "summary": "ip link show dev ${name}", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "ip link set ${name} up", + "parameters": [ + { + "$ref": "#/parameters/device-name" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "ip link set ${name} down", + "parameters": [ + { + "$ref": "#/parameters/device-name" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/netlink/addr": { + "get": { + "tags": [ + "device" + ], + "summary": "display special linux net device addr detail", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "set ip cird to linux net device", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/device-addr" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete ip cird fron linux net device", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/device-addr" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/nic": { + "get": { + "tags": [ + "device" + ], + "summary": "dpip link show ${nic-name} -s -v", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/verbose" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/NicDeviceSpecList" + } + }, + "500": { + "description": "Failure", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "dpip link set ${nic-name} [forward2kni,link,promisc,tc-ingress,tc-egress] [on/up,off/down]", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/forward2kni" + }, + { + "$ref": "#/parameters/link" + }, + { + "$ref": "#/parameters/promisc" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failure", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/route": { + "get": { + "tags": [ + "device" + ], + "summary": "display special net device route", + "parameters": [ + { + "$ref": "#/parameters/stats" + }, + { + "$ref": "#/parameters/device-name" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device route", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/route-config" + } + ], + "responses": { + "200": { + "description": "Update exist route Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Add new route Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device route", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/route-config" + } + ], + "responses": { + "200": { + "description": "delete route Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/vlan": { + "get": { + "tags": [ + "device" + ], + "summary": "display all net device list", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device ", + "parameters": [ + { + "$ref": "#/parameters/device-name" + }, + { + "$ref": "#/parameters/vlan-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device", + "parameters": [ + { + "$ref": "#/parameters/device-name" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/vs": { + "get": { + "tags": [ + "virtualserver" + ], + "summary": "display all vip:port:proto and rsip:port list", + "parameters": [ + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/VirtualServerList" + } + } + } + } + }, + "/vs/{VipPort}": { + "get": { + "tags": [ + "virtualserver" + ], + "summary": "get a specific virtual server", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/VirtualServerList" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "create or update virtual server", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/vs-config" + } + ], + "responses": { + "200": { + "description": "Updated", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/allow": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of ip from white list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update a fully white ip list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of ip form white list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/deny": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of ip from black list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update a fully black ip list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of ip form black list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/acl-config" + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/laddr": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/LocalAddressExpandList" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/laddr-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/laddr-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/rs": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/stats" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of real server to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/rss-config" + }, + { + "$ref": "#/parameters/healthcheck" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update fully real server list to vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/rss-config" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of real server from vip:port:proto", + "parameters": [ + { + "$ref": "#/parameters/service-id" + }, + { + "$ref": "#/parameters/rss-config" + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + } + }, + "definitions": { + "AclAddrList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/CertAuthSpec" + } + } + } + }, + "AddrRange": { + "type": "object", + "properties": { + "End": { + "type": "string" + }, + "Start": { + "type": "string" + } + } + }, + "CertAuthSpec": { + "properties": { + "addr": { + "type": "string" + } + } + }, + "DestCheckSpec": { + "type": "string", + "enum": [ + "passive", + "tcp", + "udp", + "ping" + ] + }, + "Error": { + "type": "string" + }, + "InetAddrSpec": { + "properties": { + "addr": { + "type": "string" + }, + "broadcast": { + "type": "string" + }, + "scope": { + "type": "string" + } + } + }, + "LocalAddressExpandList": { + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/LocalAddressSpecExpand" + } + } + } + }, + "LocalAddressSpecExpand": { + "type": "object", + "properties": { + "addr": { + "type": "string" + }, + "af": { + "type": "integer", + "format": "uint32" + }, + "conns": { + "type": "integer", + "format": "uint32" + }, + "device": { + "type": "string" + }, + "portConflict": { + "type": "integer", + "format": "uint64" + } + } + }, + "LocalAddressSpecTiny": { + "properties": { + "addr": { + "type": "string" + }, + "device": { + "type": "string" + } + } + }, + "LocalAddressTinyList": { + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + } + } + }, + "MatchSpec": { + "type": "object", + "properties": { + "Dest": { + "$ref": "#/definitions/AddrRange" + }, + "InIfName": { + "type": "string" + }, + "OutIfName": { + "type": "string" + }, + "Src": { + "$ref": "#/definitions/AddrRange" + } + } + }, + "NicDeviceDetail": { + "type": "object", + "properties": { + "Flags": { + "type": "integer", + "format": "uint16" + }, + "ID": { + "type": "integer", + "format": "uint16" + }, + "MTU": { + "type": "integer", + "format": "uint16" + }, + "addr": { + "type": "string" + }, + "autoneg": { + "type": "string", + "enum": [ + "fixed-nego", + "auto-nego" + ] + }, + "duplex": { + "type": "string", + "enum": [ + "half-duplex", + "full-duplex" + ] + }, + "nRxQ": { + "type": "integer", + "format": "uint8" + }, + "nTxQ": { + "type": "integer", + "format": "uint8" + }, + "name": { + "type": "string" + }, + "socketID": { + "type": "integer", + "format": "uint8" + }, + "speed": { + "type": "integer", + "format": "uint32" + }, + "status": { + "type": "string", + "enum": [ + "UP", + "DOWN" + ] + } + } + }, + "NicDeviceQueueData": { + "type": "integer", + "format": "uint64" + }, + "NicDeviceSpec": { + "type": "object", + "properties": { + "detail": { + "$ref": "#/definitions/NicDeviceDetail" + }, + "stats": { + "$ref": "#/definitions/NicDeviceStats" + } + } + }, + "NicDeviceSpecList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceSpec" + } + } + } + }, + "NicDeviceStats": { + "type": "object", + "properties": { + "bufAvail": { + "type": "integer", + "format": "uint32" + }, + "bufInuse": { + "type": "integer", + "format": "uint32" + }, + "errorBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "id": { + "type": "integer", + "format": "uint16" + }, + "inBytes": { + "type": "integer", + "format": "uint64" + }, + "inBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "inErrors": { + "type": "integer", + "format": "uint64" + }, + "inMissed": { + "type": "integer", + "format": "uint64" + }, + "inPkts": { + "type": "integer", + "format": "uint64" + }, + "inPktsQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "outBytes": { + "type": "integer", + "format": "uint64" + }, + "outBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "outErrors": { + "type": "integer", + "format": "uint64" + }, + "outPkts": { + "type": "integer", + "format": "uint64" + }, + "outPktsQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "rxNoMbuf": { + "type": "integer", + "format": "uint64" + } + } + }, + "RealServerExpandList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/RealServerSpecExpand" + } + } + } + }, + "RealServerSpecExpand": { + "type": "object", + "properties": { + "Spec": { + "$ref": "#/definitions/RealServerSpecTiny" + }, + "Stats": { + "$ref": "#/definitions/ServerStats" + } + } + }, + "RealServerSpecTiny": { + "type": "object", + "properties": { + "inhibited": { + "type": "boolean", + "default": false + }, + "ip": { + "type": "string" + }, + "mode": { + "type": "string", + "enum": [ + "FNAT", + "SNAT", + "DR", + "TUNNEL", + "NAT" + ] + }, + "overloaded": { + "type": "boolean", + "default": false + }, + "port": { + "type": "integer", + "format": "uint16", + "x-omitempty": false + }, + "weight": { + "type": "integer", + "format": "uint16", + "x-omitempty": false + } + } + }, + "RealServerTinyList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/RealServerSpecTiny" + } + } + } + }, + "RouteSpec": { + "properties": { + "device": { + "type": "string" + }, + "dst": { + "type": "string" + }, + "gateway": { + "type": "string" + }, + "metric": { + "type": "integer", + "format": "uint32" + }, + "mtu": { + "type": "integer", + "format": "uint32" + }, + "prefixSrc": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "src": { + "type": "string" + } + } + }, + "ServerStats": { + "type": "object", + "properties": { + "Conns": { + "type": "integer", + "format": "uint64" + }, + "Cps": { + "type": "integer", + "format": "uint32" + }, + "InBps": { + "type": "integer", + "format": "uint32" + }, + "InBytes": { + "type": "integer", + "format": "uint64" + }, + "InPkts": { + "type": "integer", + "format": "uint64" + }, + "InPps": { + "type": "integer", + "format": "uint32" + }, + "OutBps": { + "type": "integer", + "format": "uint32" + }, + "OutBytes": { + "type": "integer", + "format": "uint64" + }, + "OutPkts": { + "type": "integer", + "format": "uint64" + }, + "OutPps": { + "type": "integer", + "format": "uint32" + } + } + }, + "Status": { + "description": "Status of an individual component", + "type": "object", + "properties": { + "msg": { + "description": "Human readable status/error/warning message", + "type": "string" + }, + "state": { + "description": "State the component is in", + "type": "string", + "enum": [ + "Ok", + "Warning", + "Failure", + "Disabled" + ] + } + } + }, + "VirtualServerList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/VirtualServerSpecExpand" + } + } + } + }, + "VirtualServerSpecExpand": { + "type": "object", + "properties": { + "Addr": { + "type": "string" + }, + "Af": { + "type": "integer", + "format": "uint32" + }, + "Bps": { + "type": "integer", + "format": "uint32" + }, + "ConnTimeout": { + "type": "integer", + "format": "uint32" + }, + "DestCheck": { + "type": "array", + "items": { + "$ref": "#/definitions/DestCheckSpec" + } + }, + "ExpireQuiescent": { + "type": "string", + "enum": [ + "true", + "false" + ] + }, + "Flags": { + "type": "string" + }, + "Fwmark": { + "type": "integer", + "format": "uint32" + }, + "LimitProportion": { + "type": "integer", + "format": "uint32" + }, + "Match": { + "$ref": "#/definitions/MatchSpec" + }, + "Netmask": { + "type": "integer", + "format": "uint32" + }, + "Port": { + "type": "integer", + "format": "uint16" + }, + "Proto": { + "type": "integer", + "format": "uint16" + }, + "RSs": { + "$ref": "#/definitions/RealServerExpandList" + }, + "SchedName": { + "type": "string", + "enum": [ + "rr", + "wrr", + "wlc", + "connhash" + ] + }, + "Stats": { + "$ref": "#/definitions/ServerStats" + }, + "SyncProxy": { + "type": "string", + "enum": [ + "true", + "false" + ] + }, + "Timeout": { + "type": "integer", + "format": "uint32" + } + } + }, + "VirtualServerSpecTiny": { + "type": "object", + "properties": { + "Bps": { + "type": "integer", + "format": "uint32" + }, + "ConnTimeout": { + "type": "integer", + "format": "uint32" + }, + "ExpireQuiescent": { + "type": "boolean", + "default": false + }, + "Fwmark": { + "type": "integer", + "format": "uint32" + }, + "LimitProportion": { + "type": "integer", + "format": "uint32" + }, + "Match": { + "$ref": "#/definitions/MatchSpec" + }, + "SchedName": { + "type": "string", + "enum": [ + "rr", + "wrr", + "wlc", + "connhash" + ] + }, + "SyncProxy": { + "type": "boolean", + "default": false + }, + "Timeout": { + "type": "integer", + "format": "uint32" + } + } + }, + "VlanSpec": { + "properties": { + "device": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + }, + "parameters": { + "acl-config": { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + }, + "device-addr": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + }, + "device-name": { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + "forward2kni": { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "forward2Kni", + "in": "query" + }, + "healthcheck": { + "type": "boolean", + "default": false, + "name": "healthcheck", + "in": "query" + }, + "laddr-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + }, + "link": { + "enum": [ + "unset", + "up", + "down" + ], + "type": "string", + "default": "unset", + "name": "link", + "in": "query" + }, + "promisc": { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "promisc", + "in": "query" + }, + "realserver-id": { + "type": "string", + "name": "RipPort", + "in": "path", + "required": true + }, + "route-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RouteSpec" + } + }, + "rs-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerSpecTiny" + } + }, + "rss-config": { + "name": "rss", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerTinyList" + } + }, + "sapool": { + "type": "boolean", + "default": false, + "name": "sapool", + "in": "query" + }, + "service-id": { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + "stats": { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + }, + "verbose": { + "type": "boolean", + "default": false, + "name": "verbose", + "in": "query" + }, + "vlan-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VlanSpec" + } + }, + "vs-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VirtualServerSpecTiny" + } + } + }, + "tags": [ + { + "description": "virtualserver", + "name": "virtualserver" + }, + { + "description": "route", + "name": "route" + }, + { + "description": "laddr", + "name": "laddr" + }, + { + "description": "tunnel", + "name": "tunnel" + }, + { + "description": "inet addr", + "name": "inetaddr" + }, + { + "description": "white list", + "name": "white_list" + }, + { + "description": "black list", + "name": "black_list" + }, + { + "description": "arp", + "name": "arp" + } + ] +}`)) + FlatSwaggerJSON = json.RawMessage([]byte(`{ + "schemes": [ + "http" + ], + "swagger": "2.0", + "info": { + "description": "dpvs agent api", + "title": "dpvs agent", + "version": "1.0.0" + }, + "host": "petstore.swagger.io", + "basePath": "/v2", + "paths": { + "/device": { + "get": { + "tags": [ + "device" + ], + "summary": "display all net device list", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/addr": { + "get": { + "tags": [ + "device" + ], + "summary": "display special net device ip addr", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "name": "verbose", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device ip addr", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "sapool", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + } + ], + "responses": { + "200": { + "description": "Update exist ip addr Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Add new ip addr Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device ip addr", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "sapool", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + } + ], + "responses": { + "200": { + "description": "delete ip addr from device Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/netlink": { + "get": { + "tags": [ + "device" + ], + "summary": "ip link show dev ${name}", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "ip link set ${name} up", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "ip link set ${name} down", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/netlink/addr": { + "get": { + "tags": [ + "device" + ], + "summary": "display special linux net device addr detail", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "set ip cird to linux net device", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete ip cird fron linux net device", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/nic": { + "get": { + "tags": [ + "device" + ], + "summary": "dpip link show ${nic-name} -s -v", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "verbose", + "in": "query" + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/NicDeviceSpecList" + } + }, + "500": { + "description": "Failure", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "dpip link set ${nic-name} [forward2kni,link,promisc,tc-ingress,tc-egress] [on/up,off/down]", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "forward2Kni", + "in": "query" + }, + { + "enum": [ + "unset", + "up", + "down" + ], + "type": "string", + "default": "unset", + "name": "link", + "in": "query" + }, + { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "promisc", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failure", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/route": { + "get": { + "tags": [ + "device" + ], + "summary": "display special net device route", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + }, + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device route", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RouteSpec" + } + } + ], + "responses": { + "200": { + "description": "Update exist route Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Add new route Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device route", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RouteSpec" + } + } + ], + "responses": { + "200": { + "description": "delete route Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/device/{name}/vlan": { + "get": { + "tags": [ + "device" + ], + "summary": "display all net device list", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Not Found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "device" + ], + "summary": "add/update special net device ", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VlanSpec" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + }, + "delete": { + "tags": [ + "device" + ], + "summary": "delete special net device", + "parameters": [ + { + "type": "string", + "name": "name", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Failed", + "schema": { + "type": "string" + } + } + } + } + }, + "/vs": { + "get": { + "tags": [ + "virtualserver" + ], + "summary": "display all vip:port:proto and rsip:port list", + "parameters": [ + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/VirtualServerList" + } + } + } + } + }, + "/vs/{VipPort}": { + "get": { + "tags": [ + "virtualserver" + ], + "summary": "get a specific virtual server", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/VirtualServerList" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "create or update virtual server", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VirtualServerSpecTiny" + } + } + ], + "responses": { + "200": { + "description": "Updated", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/allow": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of ip from white list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update a fully white ip list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of ip form white list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/deny": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of ip from black list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update a fully black ip list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of ip form black list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/laddr": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "$ref": "#/definitions/LocalAddressExpandList" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Error while creating virtual server", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + }, + "/vs/{VipPort}/rs": { + "get": { + "tags": [ + "virtualserver" + ], + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + } + } + }, + "put": { + "tags": [ + "virtualserver" + ], + "summary": "Add a set of real server to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "rss", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerTinyList" + } + }, + { + "type": "boolean", + "default": false, + "name": "healthcheck", + "in": "query" + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "post": { + "tags": [ + "virtualserver" + ], + "summary": "Update fully real server list to vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "rss", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerTinyList" + } + } + ], + "responses": { + "200": { + "description": "Success", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + }, + "delete": { + "tags": [ + "virtualserver" + ], + "summary": "Delete a set of real server from vip:port:proto", + "parameters": [ + { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + { + "name": "rss", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerTinyList" + } + } + ], + "responses": { + "200": { + "description": "Success" + }, + "404": { + "description": "Service not found", + "schema": { + "type": "string" + } + }, + "460": { + "description": "Invalid frontend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidFrontend" + }, + "461": { + "description": "Invalid backend in service configuration", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "InvalidBackend" + }, + "500": { + "description": "Service deletion failed", + "schema": { + "$ref": "#/definitions/Error" + }, + "x-go-name": "Failure" + } + } + } + } + }, + "definitions": { + "AclAddrList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/CertAuthSpec" + } + } + } + }, + "AddrRange": { + "type": "object", + "properties": { + "End": { + "type": "string" + }, + "Start": { + "type": "string" + } + } + }, + "CertAuthSpec": { + "properties": { + "addr": { + "type": "string" + } + } + }, + "DestCheckSpec": { + "type": "string", + "enum": [ + "passive", + "tcp", + "udp", + "ping" + ] + }, + "Error": { + "type": "string" + }, + "InetAddrSpec": { + "properties": { + "addr": { + "type": "string" + }, + "broadcast": { + "type": "string" + }, + "scope": { + "type": "string" + } + } + }, + "LocalAddressExpandList": { + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/LocalAddressSpecExpand" + } + } + } + }, + "LocalAddressSpecExpand": { + "type": "object", + "properties": { + "addr": { + "type": "string" + }, + "af": { + "type": "integer", + "format": "uint32" + }, + "conns": { + "type": "integer", + "format": "uint32" + }, + "device": { + "type": "string" + }, + "portConflict": { + "type": "integer", + "format": "uint64" + } + } + }, + "LocalAddressSpecTiny": { + "properties": { + "addr": { + "type": "string" + }, + "device": { + "type": "string" + } + } + }, + "LocalAddressTinyList": { + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + } + } + }, + "MatchSpec": { + "type": "object", + "properties": { + "Dest": { + "$ref": "#/definitions/AddrRange" + }, + "InIfName": { + "type": "string" + }, + "OutIfName": { + "type": "string" + }, + "Src": { + "$ref": "#/definitions/AddrRange" + } + } + }, + "NicDeviceDetail": { + "type": "object", + "properties": { + "Flags": { + "type": "integer", + "format": "uint16" + }, + "ID": { + "type": "integer", + "format": "uint16" + }, + "MTU": { + "type": "integer", + "format": "uint16" + }, + "addr": { + "type": "string" + }, + "autoneg": { + "type": "string", + "enum": [ + "fixed-nego", + "auto-nego" + ] + }, + "duplex": { + "type": "string", + "enum": [ + "half-duplex", + "full-duplex" + ] + }, + "nRxQ": { + "type": "integer", + "format": "uint8" + }, + "nTxQ": { + "type": "integer", + "format": "uint8" + }, + "name": { + "type": "string" + }, + "socketID": { + "type": "integer", + "format": "uint8" + }, + "speed": { + "type": "integer", + "format": "uint32" + }, + "status": { + "type": "string", + "enum": [ + "UP", + "DOWN" + ] + } + } + }, + "NicDeviceQueueData": { + "type": "integer", + "format": "uint64" + }, + "NicDeviceSpec": { + "type": "object", + "properties": { + "detail": { + "$ref": "#/definitions/NicDeviceDetail" + }, + "stats": { + "$ref": "#/definitions/NicDeviceStats" + } + } + }, + "NicDeviceSpecList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceSpec" + } + } + } + }, + "NicDeviceStats": { + "type": "object", + "properties": { + "bufAvail": { + "type": "integer", + "format": "uint32" + }, + "bufInuse": { + "type": "integer", + "format": "uint32" + }, + "errorBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "id": { + "type": "integer", + "format": "uint16" + }, + "inBytes": { + "type": "integer", + "format": "uint64" + }, + "inBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "inErrors": { + "type": "integer", + "format": "uint64" + }, + "inMissed": { + "type": "integer", + "format": "uint64" + }, + "inPkts": { + "type": "integer", + "format": "uint64" + }, + "inPktsQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "outBytes": { + "type": "integer", + "format": "uint64" + }, + "outBytesQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "outErrors": { + "type": "integer", + "format": "uint64" + }, + "outPkts": { + "type": "integer", + "format": "uint64" + }, + "outPktsQ": { + "type": "array", + "items": { + "$ref": "#/definitions/NicDeviceQueueData" + } + }, + "rxNoMbuf": { + "type": "integer", + "format": "uint64" + } + } + }, + "RealServerExpandList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/RealServerSpecExpand" + } + } + } + }, + "RealServerSpecExpand": { + "type": "object", + "properties": { + "Spec": { + "$ref": "#/definitions/RealServerSpecTiny" + }, + "Stats": { + "$ref": "#/definitions/ServerStats" + } + } + }, + "RealServerSpecTiny": { + "type": "object", + "properties": { + "inhibited": { + "type": "boolean", + "default": false + }, + "ip": { + "type": "string" + }, + "mode": { + "type": "string", + "enum": [ + "FNAT", + "SNAT", + "DR", + "TUNNEL", + "NAT" + ] + }, + "overloaded": { + "type": "boolean", + "default": false + }, + "port": { + "type": "integer", + "format": "uint16", + "x-omitempty": false + }, + "weight": { + "type": "integer", + "format": "uint16", + "x-omitempty": false + } + } + }, + "RealServerTinyList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/RealServerSpecTiny" + } + } + } + }, + "RouteSpec": { + "properties": { + "device": { + "type": "string" + }, + "dst": { + "type": "string" + }, + "gateway": { + "type": "string" + }, + "metric": { + "type": "integer", + "format": "uint32" + }, + "mtu": { + "type": "integer", + "format": "uint32" + }, + "prefixSrc": { + "type": "string" + }, + "scope": { + "type": "string" + }, + "src": { + "type": "string" + } + } + }, + "ServerStats": { + "type": "object", + "properties": { + "Conns": { + "type": "integer", + "format": "uint64" + }, + "Cps": { + "type": "integer", + "format": "uint32" + }, + "InBps": { + "type": "integer", + "format": "uint32" + }, + "InBytes": { + "type": "integer", + "format": "uint64" + }, + "InPkts": { + "type": "integer", + "format": "uint64" + }, + "InPps": { + "type": "integer", + "format": "uint32" + }, + "OutBps": { + "type": "integer", + "format": "uint32" + }, + "OutBytes": { + "type": "integer", + "format": "uint64" + }, + "OutPkts": { + "type": "integer", + "format": "uint64" + }, + "OutPps": { + "type": "integer", + "format": "uint32" + } + } + }, + "Status": { + "description": "Status of an individual component", + "type": "object", + "properties": { + "msg": { + "description": "Human readable status/error/warning message", + "type": "string" + }, + "state": { + "description": "State the component is in", + "type": "string", + "enum": [ + "Ok", + "Warning", + "Failure", + "Disabled" + ] + } + } + }, + "VirtualServerList": { + "type": "object", + "properties": { + "Items": { + "type": "array", + "items": { + "$ref": "#/definitions/VirtualServerSpecExpand" + } + } + } + }, + "VirtualServerSpecExpand": { + "type": "object", + "properties": { + "Addr": { + "type": "string" + }, + "Af": { + "type": "integer", + "format": "uint32" + }, + "Bps": { + "type": "integer", + "format": "uint32" + }, + "ConnTimeout": { + "type": "integer", + "format": "uint32" + }, + "DestCheck": { + "type": "array", + "items": { + "$ref": "#/definitions/DestCheckSpec" + } + }, + "ExpireQuiescent": { + "type": "string", + "enum": [ + "true", + "false" + ] + }, + "Flags": { + "type": "string" + }, + "Fwmark": { + "type": "integer", + "format": "uint32" + }, + "LimitProportion": { + "type": "integer", + "format": "uint32" + }, + "Match": { + "$ref": "#/definitions/MatchSpec" + }, + "Netmask": { + "type": "integer", + "format": "uint32" + }, + "Port": { + "type": "integer", + "format": "uint16" + }, + "Proto": { + "type": "integer", + "format": "uint16" + }, + "RSs": { + "$ref": "#/definitions/RealServerExpandList" + }, + "SchedName": { + "type": "string", + "enum": [ + "rr", + "wrr", + "wlc", + "connhash" + ] + }, + "Stats": { + "$ref": "#/definitions/ServerStats" + }, + "SyncProxy": { + "type": "string", + "enum": [ + "true", + "false" + ] + }, + "Timeout": { + "type": "integer", + "format": "uint32" + } + } + }, + "VirtualServerSpecTiny": { + "type": "object", + "properties": { + "Bps": { + "type": "integer", + "format": "uint32" + }, + "ConnTimeout": { + "type": "integer", + "format": "uint32" + }, + "ExpireQuiescent": { + "type": "boolean", + "default": false + }, + "Fwmark": { + "type": "integer", + "format": "uint32" + }, + "LimitProportion": { + "type": "integer", + "format": "uint32" + }, + "Match": { + "$ref": "#/definitions/MatchSpec" + }, + "SchedName": { + "type": "string", + "enum": [ + "rr", + "wrr", + "wlc", + "connhash" + ] + }, + "SyncProxy": { + "type": "boolean", + "default": false + }, + "Timeout": { + "type": "integer", + "format": "uint32" + } + } + }, + "VlanSpec": { + "properties": { + "device": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + } + }, + "parameters": { + "acl-config": { + "name": "acl", + "in": "body", + "schema": { + "$ref": "#/definitions/AclAddrList" + } + }, + "device-addr": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/InetAddrSpec" + } + }, + "device-name": { + "type": "string", + "name": "name", + "in": "path", + "required": true + }, + "forward2kni": { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "forward2Kni", + "in": "query" + }, + "healthcheck": { + "type": "boolean", + "default": false, + "name": "healthcheck", + "in": "query" + }, + "laddr-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/LocalAddressSpecTiny" + } + }, + "link": { + "enum": [ + "unset", + "up", + "down" + ], + "type": "string", + "default": "unset", + "name": "link", + "in": "query" + }, + "promisc": { + "enum": [ + "unset", + "on", + "off" + ], + "type": "string", + "default": "unset", + "name": "promisc", + "in": "query" + }, + "realserver-id": { + "type": "string", + "name": "RipPort", + "in": "path", + "required": true + }, + "route-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RouteSpec" + } + }, + "rs-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerSpecTiny" + } + }, + "rss-config": { + "name": "rss", + "in": "body", + "schema": { + "$ref": "#/definitions/RealServerTinyList" + } + }, + "sapool": { + "type": "boolean", + "default": false, + "name": "sapool", + "in": "query" + }, + "service-id": { + "type": "string", + "name": "VipPort", + "in": "path", + "required": true + }, + "stats": { + "type": "boolean", + "default": false, + "name": "stats", + "in": "query" + }, + "verbose": { + "type": "boolean", + "default": false, + "name": "verbose", + "in": "query" + }, + "vlan-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VlanSpec" + } + }, + "vs-config": { + "name": "spec", + "in": "body", + "schema": { + "$ref": "#/definitions/VirtualServerSpecTiny" + } + } + }, + "tags": [ + { + "description": "virtualserver", + "name": "virtualserver" + }, + { + "description": "route", + "name": "route" + }, + { + "description": "laddr", + "name": "laddr" + }, + { + "description": "tunnel", + "name": "tunnel" + }, + { + "description": "inet addr", + "name": "inetaddr" + }, + { + "description": "white list", + "name": "white_list" + }, + { + "description": "black list", + "name": "black_list" + }, + { + "description": "arp", + "name": "arp" + } + ] +}`)) +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr.go new file mode 100644 index 000000000..ecb1bab59 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteDeviceNameAddrHandlerFunc turns a function with the right signature into a delete device name addr handler +type DeleteDeviceNameAddrHandlerFunc func(DeleteDeviceNameAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteDeviceNameAddrHandlerFunc) Handle(params DeleteDeviceNameAddrParams) middleware.Responder { + return fn(params) +} + +// DeleteDeviceNameAddrHandler interface for that can handle valid delete device name addr params +type DeleteDeviceNameAddrHandler interface { + Handle(DeleteDeviceNameAddrParams) middleware.Responder +} + +// NewDeleteDeviceNameAddr creates a new http.Handler for the delete device name addr operation +func NewDeleteDeviceNameAddr(ctx *middleware.Context, handler DeleteDeviceNameAddrHandler) *DeleteDeviceNameAddr { + return &DeleteDeviceNameAddr{Context: ctx, Handler: handler} +} + +/* + DeleteDeviceNameAddr swagger:route DELETE /device/{name}/addr device deleteDeviceNameAddr + +delete special net device ip addr +*/ +type DeleteDeviceNameAddr struct { + Context *middleware.Context + Handler DeleteDeviceNameAddrHandler +} + +func (o *DeleteDeviceNameAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteDeviceNameAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_parameters.go new file mode 100644 index 000000000..c4134b592 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_parameters.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteDeviceNameAddrParams creates a new DeleteDeviceNameAddrParams object +// with the default values initialized. +func NewDeleteDeviceNameAddrParams() DeleteDeviceNameAddrParams { + + var ( + // initialize parameters with default values + + sapoolDefault = bool(false) + ) + + return DeleteDeviceNameAddrParams{ + Sapool: &sapoolDefault, + } +} + +// DeleteDeviceNameAddrParams contains all the bound params for the delete device name addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteDeviceNameAddr +type DeleteDeviceNameAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Sapool *bool + /* + In: body + */ + Spec *models.InetAddrSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteDeviceNameAddrParams() beforehand. +func (o *DeleteDeviceNameAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qSapool, qhkSapool, _ := qs.GetOK("sapool") + if err := o.bindSapool(qSapool, qhkSapool, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.InetAddrSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *DeleteDeviceNameAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindSapool binds and validates parameter Sapool from query. +func (o *DeleteDeviceNameAddrParams) bindSapool(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewDeleteDeviceNameAddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("sapool", "query", "bool", raw) + } + o.Sapool = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_responses.go new file mode 100644 index 000000000..82afd7bb0 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// DeleteDeviceNameAddrOKCode is the HTTP code returned for type DeleteDeviceNameAddrOK +const DeleteDeviceNameAddrOKCode int = 200 + +/* +DeleteDeviceNameAddrOK delete ip addr from device Success + +swagger:response deleteDeviceNameAddrOK +*/ +type DeleteDeviceNameAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameAddrOK creates DeleteDeviceNameAddrOK with default headers values +func NewDeleteDeviceNameAddrOK() *DeleteDeviceNameAddrOK { + + return &DeleteDeviceNameAddrOK{} +} + +// WithPayload adds the payload to the delete device name addr o k response +func (o *DeleteDeviceNameAddrOK) WithPayload(payload string) *DeleteDeviceNameAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name addr o k response +func (o *DeleteDeviceNameAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteDeviceNameAddrInternalServerErrorCode is the HTTP code returned for type DeleteDeviceNameAddrInternalServerError +const DeleteDeviceNameAddrInternalServerErrorCode int = 500 + +/* +DeleteDeviceNameAddrInternalServerError Failed + +swagger:response deleteDeviceNameAddrInternalServerError +*/ +type DeleteDeviceNameAddrInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameAddrInternalServerError creates DeleteDeviceNameAddrInternalServerError with default headers values +func NewDeleteDeviceNameAddrInternalServerError() *DeleteDeviceNameAddrInternalServerError { + + return &DeleteDeviceNameAddrInternalServerError{} +} + +// WithPayload adds the payload to the delete device name addr internal server error response +func (o *DeleteDeviceNameAddrInternalServerError) WithPayload(payload string) *DeleteDeviceNameAddrInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name addr internal server error response +func (o *DeleteDeviceNameAddrInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameAddrInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_urlbuilder.go new file mode 100644 index 000000000..e58276264 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_addr_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// DeleteDeviceNameAddrURL generates an URL for the delete device name addr operation +type DeleteDeviceNameAddrURL struct { + Name string + + Sapool *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameAddrURL) WithBasePath(bp string) *DeleteDeviceNameAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteDeviceNameAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on DeleteDeviceNameAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var sapoolQ string + if o.Sapool != nil { + sapoolQ = swag.FormatBool(*o.Sapool) + } + if sapoolQ != "" { + qs.Set("sapool", sapoolQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteDeviceNameAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteDeviceNameAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteDeviceNameAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteDeviceNameAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteDeviceNameAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteDeviceNameAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink.go new file mode 100644 index 000000000..5429f3a10 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteDeviceNameNetlinkHandlerFunc turns a function with the right signature into a delete device name netlink handler +type DeleteDeviceNameNetlinkHandlerFunc func(DeleteDeviceNameNetlinkParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteDeviceNameNetlinkHandlerFunc) Handle(params DeleteDeviceNameNetlinkParams) middleware.Responder { + return fn(params) +} + +// DeleteDeviceNameNetlinkHandler interface for that can handle valid delete device name netlink params +type DeleteDeviceNameNetlinkHandler interface { + Handle(DeleteDeviceNameNetlinkParams) middleware.Responder +} + +// NewDeleteDeviceNameNetlink creates a new http.Handler for the delete device name netlink operation +func NewDeleteDeviceNameNetlink(ctx *middleware.Context, handler DeleteDeviceNameNetlinkHandler) *DeleteDeviceNameNetlink { + return &DeleteDeviceNameNetlink{Context: ctx, Handler: handler} +} + +/* + DeleteDeviceNameNetlink swagger:route DELETE /device/{name}/netlink device deleteDeviceNameNetlink + +ip link set ${name} down +*/ +type DeleteDeviceNameNetlink struct { + Context *middleware.Context + Handler DeleteDeviceNameNetlinkHandler +} + +func (o *DeleteDeviceNameNetlink) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteDeviceNameNetlinkParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr.go new file mode 100644 index 000000000..63cb56c24 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteDeviceNameNetlinkAddrHandlerFunc turns a function with the right signature into a delete device name netlink addr handler +type DeleteDeviceNameNetlinkAddrHandlerFunc func(DeleteDeviceNameNetlinkAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteDeviceNameNetlinkAddrHandlerFunc) Handle(params DeleteDeviceNameNetlinkAddrParams) middleware.Responder { + return fn(params) +} + +// DeleteDeviceNameNetlinkAddrHandler interface for that can handle valid delete device name netlink addr params +type DeleteDeviceNameNetlinkAddrHandler interface { + Handle(DeleteDeviceNameNetlinkAddrParams) middleware.Responder +} + +// NewDeleteDeviceNameNetlinkAddr creates a new http.Handler for the delete device name netlink addr operation +func NewDeleteDeviceNameNetlinkAddr(ctx *middleware.Context, handler DeleteDeviceNameNetlinkAddrHandler) *DeleteDeviceNameNetlinkAddr { + return &DeleteDeviceNameNetlinkAddr{Context: ctx, Handler: handler} +} + +/* + DeleteDeviceNameNetlinkAddr swagger:route DELETE /device/{name}/netlink/addr device deleteDeviceNameNetlinkAddr + +delete ip cird fron linux net device +*/ +type DeleteDeviceNameNetlinkAddr struct { + Context *middleware.Context + Handler DeleteDeviceNameNetlinkAddrHandler +} + +func (o *DeleteDeviceNameNetlinkAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteDeviceNameNetlinkAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_parameters.go new file mode 100644 index 000000000..9727f0252 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteDeviceNameNetlinkAddrParams creates a new DeleteDeviceNameNetlinkAddrParams object +// +// There are no default values defined in the spec. +func NewDeleteDeviceNameNetlinkAddrParams() DeleteDeviceNameNetlinkAddrParams { + + return DeleteDeviceNameNetlinkAddrParams{} +} + +// DeleteDeviceNameNetlinkAddrParams contains all the bound params for the delete device name netlink addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteDeviceNameNetlinkAddr +type DeleteDeviceNameNetlinkAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: body + */ + Spec *models.InetAddrSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteDeviceNameNetlinkAddrParams() beforehand. +func (o *DeleteDeviceNameNetlinkAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.InetAddrSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *DeleteDeviceNameNetlinkAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_responses.go new file mode 100644 index 000000000..25d71dc7d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// DeleteDeviceNameNetlinkAddrOKCode is the HTTP code returned for type DeleteDeviceNameNetlinkAddrOK +const DeleteDeviceNameNetlinkAddrOKCode int = 200 + +/* +DeleteDeviceNameNetlinkAddrOK Success + +swagger:response deleteDeviceNameNetlinkAddrOK +*/ +type DeleteDeviceNameNetlinkAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameNetlinkAddrOK creates DeleteDeviceNameNetlinkAddrOK with default headers values +func NewDeleteDeviceNameNetlinkAddrOK() *DeleteDeviceNameNetlinkAddrOK { + + return &DeleteDeviceNameNetlinkAddrOK{} +} + +// WithPayload adds the payload to the delete device name netlink addr o k response +func (o *DeleteDeviceNameNetlinkAddrOK) WithPayload(payload string) *DeleteDeviceNameNetlinkAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name netlink addr o k response +func (o *DeleteDeviceNameNetlinkAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameNetlinkAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteDeviceNameNetlinkAddrInternalServerErrorCode is the HTTP code returned for type DeleteDeviceNameNetlinkAddrInternalServerError +const DeleteDeviceNameNetlinkAddrInternalServerErrorCode int = 500 + +/* +DeleteDeviceNameNetlinkAddrInternalServerError Not Found + +swagger:response deleteDeviceNameNetlinkAddrInternalServerError +*/ +type DeleteDeviceNameNetlinkAddrInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameNetlinkAddrInternalServerError creates DeleteDeviceNameNetlinkAddrInternalServerError with default headers values +func NewDeleteDeviceNameNetlinkAddrInternalServerError() *DeleteDeviceNameNetlinkAddrInternalServerError { + + return &DeleteDeviceNameNetlinkAddrInternalServerError{} +} + +// WithPayload adds the payload to the delete device name netlink addr internal server error response +func (o *DeleteDeviceNameNetlinkAddrInternalServerError) WithPayload(payload string) *DeleteDeviceNameNetlinkAddrInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name netlink addr internal server error response +func (o *DeleteDeviceNameNetlinkAddrInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameNetlinkAddrInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_urlbuilder.go new file mode 100644 index 000000000..581dbc5f3 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_addr_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteDeviceNameNetlinkAddrURL generates an URL for the delete device name netlink addr operation +type DeleteDeviceNameNetlinkAddrURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameNetlinkAddrURL) WithBasePath(bp string) *DeleteDeviceNameNetlinkAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameNetlinkAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteDeviceNameNetlinkAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on DeleteDeviceNameNetlinkAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteDeviceNameNetlinkAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteDeviceNameNetlinkAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteDeviceNameNetlinkAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteDeviceNameNetlinkAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteDeviceNameNetlinkAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteDeviceNameNetlinkAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_parameters.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_parameters.go new file mode 100644 index 000000000..8dd329583 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewDeleteDeviceNameNetlinkParams creates a new DeleteDeviceNameNetlinkParams object +// +// There are no default values defined in the spec. +func NewDeleteDeviceNameNetlinkParams() DeleteDeviceNameNetlinkParams { + + return DeleteDeviceNameNetlinkParams{} +} + +// DeleteDeviceNameNetlinkParams contains all the bound params for the delete device name netlink operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteDeviceNameNetlink +type DeleteDeviceNameNetlinkParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteDeviceNameNetlinkParams() beforehand. +func (o *DeleteDeviceNameNetlinkParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *DeleteDeviceNameNetlinkParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_responses.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_responses.go new file mode 100644 index 000000000..fd82c62e1 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// DeleteDeviceNameNetlinkOKCode is the HTTP code returned for type DeleteDeviceNameNetlinkOK +const DeleteDeviceNameNetlinkOKCode int = 200 + +/* +DeleteDeviceNameNetlinkOK Success + +swagger:response deleteDeviceNameNetlinkOK +*/ +type DeleteDeviceNameNetlinkOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameNetlinkOK creates DeleteDeviceNameNetlinkOK with default headers values +func NewDeleteDeviceNameNetlinkOK() *DeleteDeviceNameNetlinkOK { + + return &DeleteDeviceNameNetlinkOK{} +} + +// WithPayload adds the payload to the delete device name netlink o k response +func (o *DeleteDeviceNameNetlinkOK) WithPayload(payload string) *DeleteDeviceNameNetlinkOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name netlink o k response +func (o *DeleteDeviceNameNetlinkOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameNetlinkOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteDeviceNameNetlinkInternalServerErrorCode is the HTTP code returned for type DeleteDeviceNameNetlinkInternalServerError +const DeleteDeviceNameNetlinkInternalServerErrorCode int = 500 + +/* +DeleteDeviceNameNetlinkInternalServerError Not Found + +swagger:response deleteDeviceNameNetlinkInternalServerError +*/ +type DeleteDeviceNameNetlinkInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameNetlinkInternalServerError creates DeleteDeviceNameNetlinkInternalServerError with default headers values +func NewDeleteDeviceNameNetlinkInternalServerError() *DeleteDeviceNameNetlinkInternalServerError { + + return &DeleteDeviceNameNetlinkInternalServerError{} +} + +// WithPayload adds the payload to the delete device name netlink internal server error response +func (o *DeleteDeviceNameNetlinkInternalServerError) WithPayload(payload string) *DeleteDeviceNameNetlinkInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name netlink internal server error response +func (o *DeleteDeviceNameNetlinkInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameNetlinkInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_urlbuilder.go new file mode 100644 index 000000000..460186582 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_netlink_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteDeviceNameNetlinkURL generates an URL for the delete device name netlink operation +type DeleteDeviceNameNetlinkURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameNetlinkURL) WithBasePath(bp string) *DeleteDeviceNameNetlinkURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameNetlinkURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteDeviceNameNetlinkURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on DeleteDeviceNameNetlinkURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteDeviceNameNetlinkURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteDeviceNameNetlinkURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteDeviceNameNetlinkURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteDeviceNameNetlinkURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteDeviceNameNetlinkURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteDeviceNameNetlinkURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_route.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route.go new file mode 100644 index 000000000..8cce8d372 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteDeviceNameRouteHandlerFunc turns a function with the right signature into a delete device name route handler +type DeleteDeviceNameRouteHandlerFunc func(DeleteDeviceNameRouteParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteDeviceNameRouteHandlerFunc) Handle(params DeleteDeviceNameRouteParams) middleware.Responder { + return fn(params) +} + +// DeleteDeviceNameRouteHandler interface for that can handle valid delete device name route params +type DeleteDeviceNameRouteHandler interface { + Handle(DeleteDeviceNameRouteParams) middleware.Responder +} + +// NewDeleteDeviceNameRoute creates a new http.Handler for the delete device name route operation +func NewDeleteDeviceNameRoute(ctx *middleware.Context, handler DeleteDeviceNameRouteHandler) *DeleteDeviceNameRoute { + return &DeleteDeviceNameRoute{Context: ctx, Handler: handler} +} + +/* + DeleteDeviceNameRoute swagger:route DELETE /device/{name}/route device deleteDeviceNameRoute + +delete special net device route +*/ +type DeleteDeviceNameRoute struct { + Context *middleware.Context + Handler DeleteDeviceNameRouteHandler +} + +func (o *DeleteDeviceNameRoute) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteDeviceNameRouteParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_parameters.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_parameters.go new file mode 100644 index 000000000..47b47fba7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteDeviceNameRouteParams creates a new DeleteDeviceNameRouteParams object +// +// There are no default values defined in the spec. +func NewDeleteDeviceNameRouteParams() DeleteDeviceNameRouteParams { + + return DeleteDeviceNameRouteParams{} +} + +// DeleteDeviceNameRouteParams contains all the bound params for the delete device name route operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteDeviceNameRoute +type DeleteDeviceNameRouteParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: body + */ + Spec *models.RouteSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteDeviceNameRouteParams() beforehand. +func (o *DeleteDeviceNameRouteParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.RouteSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *DeleteDeviceNameRouteParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_responses.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_responses.go new file mode 100644 index 000000000..c9146f0fe --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// DeleteDeviceNameRouteOKCode is the HTTP code returned for type DeleteDeviceNameRouteOK +const DeleteDeviceNameRouteOKCode int = 200 + +/* +DeleteDeviceNameRouteOK delete route Success + +swagger:response deleteDeviceNameRouteOK +*/ +type DeleteDeviceNameRouteOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameRouteOK creates DeleteDeviceNameRouteOK with default headers values +func NewDeleteDeviceNameRouteOK() *DeleteDeviceNameRouteOK { + + return &DeleteDeviceNameRouteOK{} +} + +// WithPayload adds the payload to the delete device name route o k response +func (o *DeleteDeviceNameRouteOK) WithPayload(payload string) *DeleteDeviceNameRouteOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name route o k response +func (o *DeleteDeviceNameRouteOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameRouteOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteDeviceNameRouteInternalServerErrorCode is the HTTP code returned for type DeleteDeviceNameRouteInternalServerError +const DeleteDeviceNameRouteInternalServerErrorCode int = 500 + +/* +DeleteDeviceNameRouteInternalServerError Failed + +swagger:response deleteDeviceNameRouteInternalServerError +*/ +type DeleteDeviceNameRouteInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameRouteInternalServerError creates DeleteDeviceNameRouteInternalServerError with default headers values +func NewDeleteDeviceNameRouteInternalServerError() *DeleteDeviceNameRouteInternalServerError { + + return &DeleteDeviceNameRouteInternalServerError{} +} + +// WithPayload adds the payload to the delete device name route internal server error response +func (o *DeleteDeviceNameRouteInternalServerError) WithPayload(payload string) *DeleteDeviceNameRouteInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name route internal server error response +func (o *DeleteDeviceNameRouteInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameRouteInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_urlbuilder.go new file mode 100644 index 000000000..8be3d0374 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_route_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteDeviceNameRouteURL generates an URL for the delete device name route operation +type DeleteDeviceNameRouteURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameRouteURL) WithBasePath(bp string) *DeleteDeviceNameRouteURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameRouteURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteDeviceNameRouteURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/route" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on DeleteDeviceNameRouteURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteDeviceNameRouteURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteDeviceNameRouteURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteDeviceNameRouteURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteDeviceNameRouteURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteDeviceNameRouteURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteDeviceNameRouteURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan.go new file mode 100644 index 000000000..88d8a8feb --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteDeviceNameVlanHandlerFunc turns a function with the right signature into a delete device name vlan handler +type DeleteDeviceNameVlanHandlerFunc func(DeleteDeviceNameVlanParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteDeviceNameVlanHandlerFunc) Handle(params DeleteDeviceNameVlanParams) middleware.Responder { + return fn(params) +} + +// DeleteDeviceNameVlanHandler interface for that can handle valid delete device name vlan params +type DeleteDeviceNameVlanHandler interface { + Handle(DeleteDeviceNameVlanParams) middleware.Responder +} + +// NewDeleteDeviceNameVlan creates a new http.Handler for the delete device name vlan operation +func NewDeleteDeviceNameVlan(ctx *middleware.Context, handler DeleteDeviceNameVlanHandler) *DeleteDeviceNameVlan { + return &DeleteDeviceNameVlan{Context: ctx, Handler: handler} +} + +/* + DeleteDeviceNameVlan swagger:route DELETE /device/{name}/vlan device deleteDeviceNameVlan + +delete special net device +*/ +type DeleteDeviceNameVlan struct { + Context *middleware.Context + Handler DeleteDeviceNameVlanHandler +} + +func (o *DeleteDeviceNameVlan) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteDeviceNameVlanParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_parameters.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_parameters.go new file mode 100644 index 000000000..ab157fa5a --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewDeleteDeviceNameVlanParams creates a new DeleteDeviceNameVlanParams object +// +// There are no default values defined in the spec. +func NewDeleteDeviceNameVlanParams() DeleteDeviceNameVlanParams { + + return DeleteDeviceNameVlanParams{} +} + +// DeleteDeviceNameVlanParams contains all the bound params for the delete device name vlan operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteDeviceNameVlan +type DeleteDeviceNameVlanParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteDeviceNameVlanParams() beforehand. +func (o *DeleteDeviceNameVlanParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *DeleteDeviceNameVlanParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_responses.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_responses.go new file mode 100644 index 000000000..f6a934a11 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// DeleteDeviceNameVlanOKCode is the HTTP code returned for type DeleteDeviceNameVlanOK +const DeleteDeviceNameVlanOKCode int = 200 + +/* +DeleteDeviceNameVlanOK Success + +swagger:response deleteDeviceNameVlanOK +*/ +type DeleteDeviceNameVlanOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameVlanOK creates DeleteDeviceNameVlanOK with default headers values +func NewDeleteDeviceNameVlanOK() *DeleteDeviceNameVlanOK { + + return &DeleteDeviceNameVlanOK{} +} + +// WithPayload adds the payload to the delete device name vlan o k response +func (o *DeleteDeviceNameVlanOK) WithPayload(payload string) *DeleteDeviceNameVlanOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name vlan o k response +func (o *DeleteDeviceNameVlanOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameVlanOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteDeviceNameVlanInternalServerErrorCode is the HTTP code returned for type DeleteDeviceNameVlanInternalServerError +const DeleteDeviceNameVlanInternalServerErrorCode int = 500 + +/* +DeleteDeviceNameVlanInternalServerError Failed + +swagger:response deleteDeviceNameVlanInternalServerError +*/ +type DeleteDeviceNameVlanInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteDeviceNameVlanInternalServerError creates DeleteDeviceNameVlanInternalServerError with default headers values +func NewDeleteDeviceNameVlanInternalServerError() *DeleteDeviceNameVlanInternalServerError { + + return &DeleteDeviceNameVlanInternalServerError{} +} + +// WithPayload adds the payload to the delete device name vlan internal server error response +func (o *DeleteDeviceNameVlanInternalServerError) WithPayload(payload string) *DeleteDeviceNameVlanInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete device name vlan internal server error response +func (o *DeleteDeviceNameVlanInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteDeviceNameVlanInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_urlbuilder.go new file mode 100644 index 000000000..e0e5ef6cf --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/delete_device_name_vlan_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteDeviceNameVlanURL generates an URL for the delete device name vlan operation +type DeleteDeviceNameVlanURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameVlanURL) WithBasePath(bp string) *DeleteDeviceNameVlanURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteDeviceNameVlanURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteDeviceNameVlanURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/vlan" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on DeleteDeviceNameVlanURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteDeviceNameVlanURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteDeviceNameVlanURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteDeviceNameVlanURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteDeviceNameVlanURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteDeviceNameVlanURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteDeviceNameVlanURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device.go b/tools/dpvs-agent/restapi/operations/device/get_device.go new file mode 100644 index 000000000..f9f968395 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceHandlerFunc turns a function with the right signature into a get device handler +type GetDeviceHandlerFunc func(GetDeviceParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceHandlerFunc) Handle(params GetDeviceParams) middleware.Responder { + return fn(params) +} + +// GetDeviceHandler interface for that can handle valid get device params +type GetDeviceHandler interface { + Handle(GetDeviceParams) middleware.Responder +} + +// NewGetDevice creates a new http.Handler for the get device operation +func NewGetDevice(ctx *middleware.Context, handler GetDeviceHandler) *GetDevice { + return &GetDevice{Context: ctx, Handler: handler} +} + +/* + GetDevice swagger:route GET /device device getDevice + +display all net device list +*/ +type GetDevice struct { + Context *middleware.Context + Handler GetDeviceHandler +} + +func (o *GetDevice) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_addr.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr.go new file mode 100644 index 000000000..0c159713c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameAddrHandlerFunc turns a function with the right signature into a get device name addr handler +type GetDeviceNameAddrHandlerFunc func(GetDeviceNameAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameAddrHandlerFunc) Handle(params GetDeviceNameAddrParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameAddrHandler interface for that can handle valid get device name addr params +type GetDeviceNameAddrHandler interface { + Handle(GetDeviceNameAddrParams) middleware.Responder +} + +// NewGetDeviceNameAddr creates a new http.Handler for the get device name addr operation +func NewGetDeviceNameAddr(ctx *middleware.Context, handler GetDeviceNameAddrHandler) *GetDeviceNameAddr { + return &GetDeviceNameAddr{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameAddr swagger:route GET /device/{name}/addr device getDeviceNameAddr + +display special net device ip addr +*/ +type GetDeviceNameAddr struct { + Context *middleware.Context + Handler GetDeviceNameAddrHandler +} + +func (o *GetDeviceNameAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_parameters.go new file mode 100644 index 000000000..cc1620fa7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_parameters.go @@ -0,0 +1,153 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameAddrParams creates a new GetDeviceNameAddrParams object +// with the default values initialized. +func NewGetDeviceNameAddrParams() GetDeviceNameAddrParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + verboseDefault = bool(false) + ) + + return GetDeviceNameAddrParams{ + Stats: &statsDefault, + + Verbose: &verboseDefault, + } +} + +// GetDeviceNameAddrParams contains all the bound params for the get device name addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameAddr +type GetDeviceNameAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool + /* + In: query + Default: false + */ + Verbose *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameAddrParams() beforehand. +func (o *GetDeviceNameAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + + qVerbose, qhkVerbose, _ := qs.GetOK("verbose") + if err := o.bindVerbose(qVerbose, qhkVerbose, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameAddrParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameAddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} + +// bindVerbose binds and validates parameter Verbose from query. +func (o *GetDeviceNameAddrParams) bindVerbose(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameAddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("verbose", "query", "bool", raw) + } + o.Verbose = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_responses.go new file mode 100644 index 000000000..e2ff4ac14 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceNameAddrOKCode is the HTTP code returned for type GetDeviceNameAddrOK +const GetDeviceNameAddrOKCode int = 200 + +/* +GetDeviceNameAddrOK Success + +swagger:response getDeviceNameAddrOK +*/ +type GetDeviceNameAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameAddrOK creates GetDeviceNameAddrOK with default headers values +func NewGetDeviceNameAddrOK() *GetDeviceNameAddrOK { + + return &GetDeviceNameAddrOK{} +} + +// WithPayload adds the payload to the get device name addr o k response +func (o *GetDeviceNameAddrOK) WithPayload(payload string) *GetDeviceNameAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name addr o k response +func (o *GetDeviceNameAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetDeviceNameAddrNotFoundCode is the HTTP code returned for type GetDeviceNameAddrNotFound +const GetDeviceNameAddrNotFoundCode int = 404 + +/* +GetDeviceNameAddrNotFound Not Found + +swagger:response getDeviceNameAddrNotFound +*/ +type GetDeviceNameAddrNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameAddrNotFound creates GetDeviceNameAddrNotFound with default headers values +func NewGetDeviceNameAddrNotFound() *GetDeviceNameAddrNotFound { + + return &GetDeviceNameAddrNotFound{} +} + +// WithPayload adds the payload to the get device name addr not found response +func (o *GetDeviceNameAddrNotFound) WithPayload(payload string) *GetDeviceNameAddrNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name addr not found response +func (o *GetDeviceNameAddrNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameAddrNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_urlbuilder.go new file mode 100644 index 000000000..a4c2cd9db --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_addr_urlbuilder.go @@ -0,0 +1,124 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameAddrURL generates an URL for the get device name addr operation +type GetDeviceNameAddrURL struct { + Name string + + Stats *bool + Verbose *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameAddrURL) WithBasePath(bp string) *GetDeviceNameAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + var verboseQ string + if o.Verbose != nil { + verboseQ = swag.FormatBool(*o.Verbose) + } + if verboseQ != "" { + qs.Set("verbose", verboseQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink.go new file mode 100644 index 000000000..04f4f4ce7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameNetlinkHandlerFunc turns a function with the right signature into a get device name netlink handler +type GetDeviceNameNetlinkHandlerFunc func(GetDeviceNameNetlinkParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameNetlinkHandlerFunc) Handle(params GetDeviceNameNetlinkParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameNetlinkHandler interface for that can handle valid get device name netlink params +type GetDeviceNameNetlinkHandler interface { + Handle(GetDeviceNameNetlinkParams) middleware.Responder +} + +// NewGetDeviceNameNetlink creates a new http.Handler for the get device name netlink operation +func NewGetDeviceNameNetlink(ctx *middleware.Context, handler GetDeviceNameNetlinkHandler) *GetDeviceNameNetlink { + return &GetDeviceNameNetlink{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameNetlink swagger:route GET /device/{name}/netlink device getDeviceNameNetlink + +ip link show dev ${name} +*/ +type GetDeviceNameNetlink struct { + Context *middleware.Context + Handler GetDeviceNameNetlinkHandler +} + +func (o *GetDeviceNameNetlink) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameNetlinkParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr.go new file mode 100644 index 000000000..d9670c047 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameNetlinkAddrHandlerFunc turns a function with the right signature into a get device name netlink addr handler +type GetDeviceNameNetlinkAddrHandlerFunc func(GetDeviceNameNetlinkAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameNetlinkAddrHandlerFunc) Handle(params GetDeviceNameNetlinkAddrParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameNetlinkAddrHandler interface for that can handle valid get device name netlink addr params +type GetDeviceNameNetlinkAddrHandler interface { + Handle(GetDeviceNameNetlinkAddrParams) middleware.Responder +} + +// NewGetDeviceNameNetlinkAddr creates a new http.Handler for the get device name netlink addr operation +func NewGetDeviceNameNetlinkAddr(ctx *middleware.Context, handler GetDeviceNameNetlinkAddrHandler) *GetDeviceNameNetlinkAddr { + return &GetDeviceNameNetlinkAddr{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameNetlinkAddr swagger:route GET /device/{name}/netlink/addr device getDeviceNameNetlinkAddr + +display special linux net device addr detail +*/ +type GetDeviceNameNetlinkAddr struct { + Context *middleware.Context + Handler GetDeviceNameNetlinkAddrHandler +} + +func (o *GetDeviceNameNetlinkAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameNetlinkAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_parameters.go new file mode 100644 index 000000000..ff3ffbf49 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameNetlinkAddrParams creates a new GetDeviceNameNetlinkAddrParams object +// with the default values initialized. +func NewGetDeviceNameNetlinkAddrParams() GetDeviceNameNetlinkAddrParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetDeviceNameNetlinkAddrParams{ + Stats: &statsDefault, + } +} + +// GetDeviceNameNetlinkAddrParams contains all the bound params for the get device name netlink addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameNetlinkAddr +type GetDeviceNameNetlinkAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameNetlinkAddrParams() beforehand. +func (o *GetDeviceNameNetlinkAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameNetlinkAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameNetlinkAddrParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameNetlinkAddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_responses.go new file mode 100644 index 000000000..ee54be55b --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceNameNetlinkAddrOKCode is the HTTP code returned for type GetDeviceNameNetlinkAddrOK +const GetDeviceNameNetlinkAddrOKCode int = 200 + +/* +GetDeviceNameNetlinkAddrOK Success + +swagger:response getDeviceNameNetlinkAddrOK +*/ +type GetDeviceNameNetlinkAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameNetlinkAddrOK creates GetDeviceNameNetlinkAddrOK with default headers values +func NewGetDeviceNameNetlinkAddrOK() *GetDeviceNameNetlinkAddrOK { + + return &GetDeviceNameNetlinkAddrOK{} +} + +// WithPayload adds the payload to the get device name netlink addr o k response +func (o *GetDeviceNameNetlinkAddrOK) WithPayload(payload string) *GetDeviceNameNetlinkAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name netlink addr o k response +func (o *GetDeviceNameNetlinkAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNetlinkAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetDeviceNameNetlinkAddrNotFoundCode is the HTTP code returned for type GetDeviceNameNetlinkAddrNotFound +const GetDeviceNameNetlinkAddrNotFoundCode int = 404 + +/* +GetDeviceNameNetlinkAddrNotFound Not Found + +swagger:response getDeviceNameNetlinkAddrNotFound +*/ +type GetDeviceNameNetlinkAddrNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameNetlinkAddrNotFound creates GetDeviceNameNetlinkAddrNotFound with default headers values +func NewGetDeviceNameNetlinkAddrNotFound() *GetDeviceNameNetlinkAddrNotFound { + + return &GetDeviceNameNetlinkAddrNotFound{} +} + +// WithPayload adds the payload to the get device name netlink addr not found response +func (o *GetDeviceNameNetlinkAddrNotFound) WithPayload(payload string) *GetDeviceNameNetlinkAddrNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name netlink addr not found response +func (o *GetDeviceNameNetlinkAddrNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNetlinkAddrNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_urlbuilder.go new file mode 100644 index 000000000..463da03fe --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_addr_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameNetlinkAddrURL generates an URL for the get device name netlink addr operation +type GetDeviceNameNetlinkAddrURL struct { + Name string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNetlinkAddrURL) WithBasePath(bp string) *GetDeviceNameNetlinkAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNetlinkAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameNetlinkAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameNetlinkAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameNetlinkAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameNetlinkAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameNetlinkAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameNetlinkAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameNetlinkAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameNetlinkAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_parameters.go new file mode 100644 index 000000000..99f198265 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameNetlinkParams creates a new GetDeviceNameNetlinkParams object +// with the default values initialized. +func NewGetDeviceNameNetlinkParams() GetDeviceNameNetlinkParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetDeviceNameNetlinkParams{ + Stats: &statsDefault, + } +} + +// GetDeviceNameNetlinkParams contains all the bound params for the get device name netlink operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameNetlink +type GetDeviceNameNetlinkParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameNetlinkParams() beforehand. +func (o *GetDeviceNameNetlinkParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameNetlinkParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameNetlinkParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameNetlinkParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_responses.go new file mode 100644 index 000000000..865e01439 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceNameNetlinkOKCode is the HTTP code returned for type GetDeviceNameNetlinkOK +const GetDeviceNameNetlinkOKCode int = 200 + +/* +GetDeviceNameNetlinkOK Success + +swagger:response getDeviceNameNetlinkOK +*/ +type GetDeviceNameNetlinkOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameNetlinkOK creates GetDeviceNameNetlinkOK with default headers values +func NewGetDeviceNameNetlinkOK() *GetDeviceNameNetlinkOK { + + return &GetDeviceNameNetlinkOK{} +} + +// WithPayload adds the payload to the get device name netlink o k response +func (o *GetDeviceNameNetlinkOK) WithPayload(payload string) *GetDeviceNameNetlinkOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name netlink o k response +func (o *GetDeviceNameNetlinkOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNetlinkOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetDeviceNameNetlinkNotFoundCode is the HTTP code returned for type GetDeviceNameNetlinkNotFound +const GetDeviceNameNetlinkNotFoundCode int = 404 + +/* +GetDeviceNameNetlinkNotFound Not Found + +swagger:response getDeviceNameNetlinkNotFound +*/ +type GetDeviceNameNetlinkNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameNetlinkNotFound creates GetDeviceNameNetlinkNotFound with default headers values +func NewGetDeviceNameNetlinkNotFound() *GetDeviceNameNetlinkNotFound { + + return &GetDeviceNameNetlinkNotFound{} +} + +// WithPayload adds the payload to the get device name netlink not found response +func (o *GetDeviceNameNetlinkNotFound) WithPayload(payload string) *GetDeviceNameNetlinkNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name netlink not found response +func (o *GetDeviceNameNetlinkNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNetlinkNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_urlbuilder.go new file mode 100644 index 000000000..2f9847cdc --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_netlink_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameNetlinkURL generates an URL for the get device name netlink operation +type GetDeviceNameNetlinkURL struct { + Name string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNetlinkURL) WithBasePath(bp string) *GetDeviceNameNetlinkURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNetlinkURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameNetlinkURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameNetlinkURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameNetlinkURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameNetlinkURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameNetlinkURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameNetlinkURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameNetlinkURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameNetlinkURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_nic.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic.go new file mode 100644 index 000000000..1f58cbd38 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameNicHandlerFunc turns a function with the right signature into a get device name nic handler +type GetDeviceNameNicHandlerFunc func(GetDeviceNameNicParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameNicHandlerFunc) Handle(params GetDeviceNameNicParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameNicHandler interface for that can handle valid get device name nic params +type GetDeviceNameNicHandler interface { + Handle(GetDeviceNameNicParams) middleware.Responder +} + +// NewGetDeviceNameNic creates a new http.Handler for the get device name nic operation +func NewGetDeviceNameNic(ctx *middleware.Context, handler GetDeviceNameNicHandler) *GetDeviceNameNic { + return &GetDeviceNameNic{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameNic swagger:route GET /device/{name}/nic device getDeviceNameNic + +dpip link show ${nic-name} -s -v +*/ +type GetDeviceNameNic struct { + Context *middleware.Context + Handler GetDeviceNameNicHandler +} + +func (o *GetDeviceNameNic) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameNicParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_parameters.go new file mode 100644 index 000000000..d09091d52 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_parameters.go @@ -0,0 +1,153 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameNicParams creates a new GetDeviceNameNicParams object +// with the default values initialized. +func NewGetDeviceNameNicParams() GetDeviceNameNicParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + verboseDefault = bool(false) + ) + + return GetDeviceNameNicParams{ + Stats: &statsDefault, + + Verbose: &verboseDefault, + } +} + +// GetDeviceNameNicParams contains all the bound params for the get device name nic operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameNic +type GetDeviceNameNicParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool + /* + In: query + Default: false + */ + Verbose *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameNicParams() beforehand. +func (o *GetDeviceNameNicParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + + qVerbose, qhkVerbose, _ := qs.GetOK("verbose") + if err := o.bindVerbose(qVerbose, qhkVerbose, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameNicParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameNicParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameNicParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} + +// bindVerbose binds and validates parameter Verbose from query. +func (o *GetDeviceNameNicParams) bindVerbose(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameNicParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("verbose", "query", "bool", raw) + } + o.Verbose = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_responses.go new file mode 100644 index 000000000..b55984b92 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_responses.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// GetDeviceNameNicOKCode is the HTTP code returned for type GetDeviceNameNicOK +const GetDeviceNameNicOKCode int = 200 + +/* +GetDeviceNameNicOK Success + +swagger:response getDeviceNameNicOK +*/ +type GetDeviceNameNicOK struct { + + /* + In: Body + */ + Payload *models.NicDeviceSpecList `json:"body,omitempty"` +} + +// NewGetDeviceNameNicOK creates GetDeviceNameNicOK with default headers values +func NewGetDeviceNameNicOK() *GetDeviceNameNicOK { + + return &GetDeviceNameNicOK{} +} + +// WithPayload adds the payload to the get device name nic o k response +func (o *GetDeviceNameNicOK) WithPayload(payload *models.NicDeviceSpecList) *GetDeviceNameNicOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name nic o k response +func (o *GetDeviceNameNicOK) SetPayload(payload *models.NicDeviceSpecList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNicOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetDeviceNameNicInternalServerErrorCode is the HTTP code returned for type GetDeviceNameNicInternalServerError +const GetDeviceNameNicInternalServerErrorCode int = 500 + +/* +GetDeviceNameNicInternalServerError Failure + +swagger:response getDeviceNameNicInternalServerError +*/ +type GetDeviceNameNicInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameNicInternalServerError creates GetDeviceNameNicInternalServerError with default headers values +func NewGetDeviceNameNicInternalServerError() *GetDeviceNameNicInternalServerError { + + return &GetDeviceNameNicInternalServerError{} +} + +// WithPayload adds the payload to the get device name nic internal server error response +func (o *GetDeviceNameNicInternalServerError) WithPayload(payload string) *GetDeviceNameNicInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name nic internal server error response +func (o *GetDeviceNameNicInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameNicInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_urlbuilder.go new file mode 100644 index 000000000..9d1b99104 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_nic_urlbuilder.go @@ -0,0 +1,124 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameNicURL generates an URL for the get device name nic operation +type GetDeviceNameNicURL struct { + Name string + + Stats *bool + Verbose *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNicURL) WithBasePath(bp string) *GetDeviceNameNicURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameNicURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameNicURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/nic" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameNicURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + var verboseQ string + if o.Verbose != nil { + verboseQ = swag.FormatBool(*o.Verbose) + } + if verboseQ != "" { + qs.Set("verbose", verboseQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameNicURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameNicURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameNicURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameNicURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameNicURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameNicURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_route.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_route.go new file mode 100644 index 000000000..fe7625fc1 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_route.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameRouteHandlerFunc turns a function with the right signature into a get device name route handler +type GetDeviceNameRouteHandlerFunc func(GetDeviceNameRouteParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameRouteHandlerFunc) Handle(params GetDeviceNameRouteParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameRouteHandler interface for that can handle valid get device name route params +type GetDeviceNameRouteHandler interface { + Handle(GetDeviceNameRouteParams) middleware.Responder +} + +// NewGetDeviceNameRoute creates a new http.Handler for the get device name route operation +func NewGetDeviceNameRoute(ctx *middleware.Context, handler GetDeviceNameRouteHandler) *GetDeviceNameRoute { + return &GetDeviceNameRoute{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameRoute swagger:route GET /device/{name}/route device getDeviceNameRoute + +display special net device route +*/ +type GetDeviceNameRoute struct { + Context *middleware.Context + Handler GetDeviceNameRouteHandler +} + +func (o *GetDeviceNameRoute) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameRouteParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_route_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_parameters.go new file mode 100644 index 000000000..00ab725c6 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameRouteParams creates a new GetDeviceNameRouteParams object +// with the default values initialized. +func NewGetDeviceNameRouteParams() GetDeviceNameRouteParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetDeviceNameRouteParams{ + Stats: &statsDefault, + } +} + +// GetDeviceNameRouteParams contains all the bound params for the get device name route operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameRoute +type GetDeviceNameRouteParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameRouteParams() beforehand. +func (o *GetDeviceNameRouteParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameRouteParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameRouteParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameRouteParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_route_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_responses.go new file mode 100644 index 000000000..d66415808 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceNameRouteOKCode is the HTTP code returned for type GetDeviceNameRouteOK +const GetDeviceNameRouteOKCode int = 200 + +/* +GetDeviceNameRouteOK Success + +swagger:response getDeviceNameRouteOK +*/ +type GetDeviceNameRouteOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameRouteOK creates GetDeviceNameRouteOK with default headers values +func NewGetDeviceNameRouteOK() *GetDeviceNameRouteOK { + + return &GetDeviceNameRouteOK{} +} + +// WithPayload adds the payload to the get device name route o k response +func (o *GetDeviceNameRouteOK) WithPayload(payload string) *GetDeviceNameRouteOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name route o k response +func (o *GetDeviceNameRouteOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameRouteOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetDeviceNameRouteNotFoundCode is the HTTP code returned for type GetDeviceNameRouteNotFound +const GetDeviceNameRouteNotFoundCode int = 404 + +/* +GetDeviceNameRouteNotFound Not Found + +swagger:response getDeviceNameRouteNotFound +*/ +type GetDeviceNameRouteNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameRouteNotFound creates GetDeviceNameRouteNotFound with default headers values +func NewGetDeviceNameRouteNotFound() *GetDeviceNameRouteNotFound { + + return &GetDeviceNameRouteNotFound{} +} + +// WithPayload adds the payload to the get device name route not found response +func (o *GetDeviceNameRouteNotFound) WithPayload(payload string) *GetDeviceNameRouteNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name route not found response +func (o *GetDeviceNameRouteNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameRouteNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_route_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_urlbuilder.go new file mode 100644 index 000000000..167d1f25a --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_route_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameRouteURL generates an URL for the get device name route operation +type GetDeviceNameRouteURL struct { + Name string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameRouteURL) WithBasePath(bp string) *GetDeviceNameRouteURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameRouteURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameRouteURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/route" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameRouteURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameRouteURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameRouteURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameRouteURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameRouteURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameRouteURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameRouteURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan.go new file mode 100644 index 000000000..78539a3f5 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetDeviceNameVlanHandlerFunc turns a function with the right signature into a get device name vlan handler +type GetDeviceNameVlanHandlerFunc func(GetDeviceNameVlanParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetDeviceNameVlanHandlerFunc) Handle(params GetDeviceNameVlanParams) middleware.Responder { + return fn(params) +} + +// GetDeviceNameVlanHandler interface for that can handle valid get device name vlan params +type GetDeviceNameVlanHandler interface { + Handle(GetDeviceNameVlanParams) middleware.Responder +} + +// NewGetDeviceNameVlan creates a new http.Handler for the get device name vlan operation +func NewGetDeviceNameVlan(ctx *middleware.Context, handler GetDeviceNameVlanHandler) *GetDeviceNameVlan { + return &GetDeviceNameVlan{Context: ctx, Handler: handler} +} + +/* + GetDeviceNameVlan swagger:route GET /device/{name}/vlan device getDeviceNameVlan + +display all net device list +*/ +type GetDeviceNameVlan struct { + Context *middleware.Context + Handler GetDeviceNameVlanHandler +} + +func (o *GetDeviceNameVlan) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetDeviceNameVlanParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_parameters.go new file mode 100644 index 000000000..1188161c8 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceNameVlanParams creates a new GetDeviceNameVlanParams object +// with the default values initialized. +func NewGetDeviceNameVlanParams() GetDeviceNameVlanParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetDeviceNameVlanParams{ + Stats: &statsDefault, + } +} + +// GetDeviceNameVlanParams contains all the bound params for the get device name vlan operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDeviceNameVlan +type GetDeviceNameVlanParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceNameVlanParams() beforehand. +func (o *GetDeviceNameVlanParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *GetDeviceNameVlanParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceNameVlanParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceNameVlanParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_responses.go new file mode 100644 index 000000000..d3bf35e47 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceNameVlanOKCode is the HTTP code returned for type GetDeviceNameVlanOK +const GetDeviceNameVlanOKCode int = 200 + +/* +GetDeviceNameVlanOK Success + +swagger:response getDeviceNameVlanOK +*/ +type GetDeviceNameVlanOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameVlanOK creates GetDeviceNameVlanOK with default headers values +func NewGetDeviceNameVlanOK() *GetDeviceNameVlanOK { + + return &GetDeviceNameVlanOK{} +} + +// WithPayload adds the payload to the get device name vlan o k response +func (o *GetDeviceNameVlanOK) WithPayload(payload string) *GetDeviceNameVlanOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name vlan o k response +func (o *GetDeviceNameVlanOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameVlanOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetDeviceNameVlanNotFoundCode is the HTTP code returned for type GetDeviceNameVlanNotFound +const GetDeviceNameVlanNotFoundCode int = 404 + +/* +GetDeviceNameVlanNotFound Not Found + +swagger:response getDeviceNameVlanNotFound +*/ +type GetDeviceNameVlanNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceNameVlanNotFound creates GetDeviceNameVlanNotFound with default headers values +func NewGetDeviceNameVlanNotFound() *GetDeviceNameVlanNotFound { + + return &GetDeviceNameVlanNotFound{} +} + +// WithPayload adds the payload to the get device name vlan not found response +func (o *GetDeviceNameVlanNotFound) WithPayload(payload string) *GetDeviceNameVlanNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device name vlan not found response +func (o *GetDeviceNameVlanNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceNameVlanNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_urlbuilder.go new file mode 100644 index 000000000..7044acbc9 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_name_vlan_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetDeviceNameVlanURL generates an URL for the get device name vlan operation +type GetDeviceNameVlanURL struct { + Name string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameVlanURL) WithBasePath(bp string) *GetDeviceNameVlanURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceNameVlanURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceNameVlanURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/vlan" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on GetDeviceNameVlanURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceNameVlanURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceNameVlanURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceNameVlanURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceNameVlanURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceNameVlanURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceNameVlanURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_parameters.go b/tools/dpvs-agent/restapi/operations/device/get_device_parameters.go new file mode 100644 index 000000000..59c367e91 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_parameters.go @@ -0,0 +1,92 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetDeviceParams creates a new GetDeviceParams object +// with the default values initialized. +func NewGetDeviceParams() GetDeviceParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetDeviceParams{ + Stats: &statsDefault, + } +} + +// GetDeviceParams contains all the bound params for the get device operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetDevice +type GetDeviceParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetDeviceParams() beforehand. +func (o *GetDeviceParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetDeviceParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetDeviceParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_responses.go b/tools/dpvs-agent/restapi/operations/device/get_device_responses.go new file mode 100644 index 000000000..c9b51cc5e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_responses.go @@ -0,0 +1,55 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetDeviceOKCode is the HTTP code returned for type GetDeviceOK +const GetDeviceOKCode int = 200 + +/* +GetDeviceOK Success + +swagger:response getDeviceOK +*/ +type GetDeviceOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetDeviceOK creates GetDeviceOK with default headers values +func NewGetDeviceOK() *GetDeviceOK { + + return &GetDeviceOK{} +} + +// WithPayload adds the payload to the get device o k response +func (o *GetDeviceOK) WithPayload(payload string) *GetDeviceOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get device o k response +func (o *GetDeviceOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetDeviceOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/get_device_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/get_device_urlbuilder.go new file mode 100644 index 000000000..87d5f1eab --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/get_device_urlbuilder.go @@ -0,0 +1,105 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + + "github.com/go-openapi/swag" +) + +// GetDeviceURL generates an URL for the get device operation +type GetDeviceURL struct { + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceURL) WithBasePath(bp string) *GetDeviceURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetDeviceURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetDeviceURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetDeviceURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetDeviceURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetDeviceURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetDeviceURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetDeviceURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetDeviceURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_addr.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr.go new file mode 100644 index 000000000..2d46e6c55 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameAddrHandlerFunc turns a function with the right signature into a put device name addr handler +type PutDeviceNameAddrHandlerFunc func(PutDeviceNameAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameAddrHandlerFunc) Handle(params PutDeviceNameAddrParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameAddrHandler interface for that can handle valid put device name addr params +type PutDeviceNameAddrHandler interface { + Handle(PutDeviceNameAddrParams) middleware.Responder +} + +// NewPutDeviceNameAddr creates a new http.Handler for the put device name addr operation +func NewPutDeviceNameAddr(ctx *middleware.Context, handler PutDeviceNameAddrHandler) *PutDeviceNameAddr { + return &PutDeviceNameAddr{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameAddr swagger:route PUT /device/{name}/addr device putDeviceNameAddr + +add/update special net device ip addr +*/ +type PutDeviceNameAddr struct { + Context *middleware.Context + Handler PutDeviceNameAddrHandler +} + +func (o *PutDeviceNameAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_parameters.go new file mode 100644 index 000000000..07bc411bb --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_parameters.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutDeviceNameAddrParams creates a new PutDeviceNameAddrParams object +// with the default values initialized. +func NewPutDeviceNameAddrParams() PutDeviceNameAddrParams { + + var ( + // initialize parameters with default values + + sapoolDefault = bool(false) + ) + + return PutDeviceNameAddrParams{ + Sapool: &sapoolDefault, + } +} + +// PutDeviceNameAddrParams contains all the bound params for the put device name addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameAddr +type PutDeviceNameAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: false + */ + Sapool *bool + /* + In: body + */ + Spec *models.InetAddrSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameAddrParams() beforehand. +func (o *PutDeviceNameAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qSapool, qhkSapool, _ := qs.GetOK("sapool") + if err := o.bindSapool(qSapool, qhkSapool, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.InetAddrSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindSapool binds and validates parameter Sapool from query. +func (o *PutDeviceNameAddrParams) bindSapool(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewPutDeviceNameAddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("sapool", "query", "bool", raw) + } + o.Sapool = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_responses.go new file mode 100644 index 000000000..417f1d91d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_responses.go @@ -0,0 +1,141 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameAddrOKCode is the HTTP code returned for type PutDeviceNameAddrOK +const PutDeviceNameAddrOKCode int = 200 + +/* +PutDeviceNameAddrOK Update exist ip addr Success + +swagger:response putDeviceNameAddrOK +*/ +type PutDeviceNameAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameAddrOK creates PutDeviceNameAddrOK with default headers values +func NewPutDeviceNameAddrOK() *PutDeviceNameAddrOK { + + return &PutDeviceNameAddrOK{} +} + +// WithPayload adds the payload to the put device name addr o k response +func (o *PutDeviceNameAddrOK) WithPayload(payload string) *PutDeviceNameAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name addr o k response +func (o *PutDeviceNameAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameAddrCreatedCode is the HTTP code returned for type PutDeviceNameAddrCreated +const PutDeviceNameAddrCreatedCode int = 201 + +/* +PutDeviceNameAddrCreated Add new ip addr Success + +swagger:response putDeviceNameAddrCreated +*/ +type PutDeviceNameAddrCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameAddrCreated creates PutDeviceNameAddrCreated with default headers values +func NewPutDeviceNameAddrCreated() *PutDeviceNameAddrCreated { + + return &PutDeviceNameAddrCreated{} +} + +// WithPayload adds the payload to the put device name addr created response +func (o *PutDeviceNameAddrCreated) WithPayload(payload string) *PutDeviceNameAddrCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name addr created response +func (o *PutDeviceNameAddrCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameAddrCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameAddrInternalServerErrorCode is the HTTP code returned for type PutDeviceNameAddrInternalServerError +const PutDeviceNameAddrInternalServerErrorCode int = 500 + +/* +PutDeviceNameAddrInternalServerError Failed + +swagger:response putDeviceNameAddrInternalServerError +*/ +type PutDeviceNameAddrInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameAddrInternalServerError creates PutDeviceNameAddrInternalServerError with default headers values +func NewPutDeviceNameAddrInternalServerError() *PutDeviceNameAddrInternalServerError { + + return &PutDeviceNameAddrInternalServerError{} +} + +// WithPayload adds the payload to the put device name addr internal server error response +func (o *PutDeviceNameAddrInternalServerError) WithPayload(payload string) *PutDeviceNameAddrInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name addr internal server error response +func (o *PutDeviceNameAddrInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameAddrInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_urlbuilder.go new file mode 100644 index 000000000..a136e39c6 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_addr_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// PutDeviceNameAddrURL generates an URL for the put device name addr operation +type PutDeviceNameAddrURL struct { + Name string + + Sapool *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameAddrURL) WithBasePath(bp string) *PutDeviceNameAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var sapoolQ string + if o.Sapool != nil { + sapoolQ = swag.FormatBool(*o.Sapool) + } + if sapoolQ != "" { + qs.Set("sapool", sapoolQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink.go new file mode 100644 index 000000000..41ba0fcd6 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameNetlinkHandlerFunc turns a function with the right signature into a put device name netlink handler +type PutDeviceNameNetlinkHandlerFunc func(PutDeviceNameNetlinkParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameNetlinkHandlerFunc) Handle(params PutDeviceNameNetlinkParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameNetlinkHandler interface for that can handle valid put device name netlink params +type PutDeviceNameNetlinkHandler interface { + Handle(PutDeviceNameNetlinkParams) middleware.Responder +} + +// NewPutDeviceNameNetlink creates a new http.Handler for the put device name netlink operation +func NewPutDeviceNameNetlink(ctx *middleware.Context, handler PutDeviceNameNetlinkHandler) *PutDeviceNameNetlink { + return &PutDeviceNameNetlink{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameNetlink swagger:route PUT /device/{name}/netlink device putDeviceNameNetlink + +ip link set ${name} up +*/ +type PutDeviceNameNetlink struct { + Context *middleware.Context + Handler PutDeviceNameNetlinkHandler +} + +func (o *PutDeviceNameNetlink) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameNetlinkParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr.go new file mode 100644 index 000000000..b08ea86b7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameNetlinkAddrHandlerFunc turns a function with the right signature into a put device name netlink addr handler +type PutDeviceNameNetlinkAddrHandlerFunc func(PutDeviceNameNetlinkAddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameNetlinkAddrHandlerFunc) Handle(params PutDeviceNameNetlinkAddrParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameNetlinkAddrHandler interface for that can handle valid put device name netlink addr params +type PutDeviceNameNetlinkAddrHandler interface { + Handle(PutDeviceNameNetlinkAddrParams) middleware.Responder +} + +// NewPutDeviceNameNetlinkAddr creates a new http.Handler for the put device name netlink addr operation +func NewPutDeviceNameNetlinkAddr(ctx *middleware.Context, handler PutDeviceNameNetlinkAddrHandler) *PutDeviceNameNetlinkAddr { + return &PutDeviceNameNetlinkAddr{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameNetlinkAddr swagger:route PUT /device/{name}/netlink/addr device putDeviceNameNetlinkAddr + +set ip cird to linux net device +*/ +type PutDeviceNameNetlinkAddr struct { + Context *middleware.Context + Handler PutDeviceNameNetlinkAddrHandler +} + +func (o *PutDeviceNameNetlinkAddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameNetlinkAddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_parameters.go new file mode 100644 index 000000000..7fcd77b11 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutDeviceNameNetlinkAddrParams creates a new PutDeviceNameNetlinkAddrParams object +// +// There are no default values defined in the spec. +func NewPutDeviceNameNetlinkAddrParams() PutDeviceNameNetlinkAddrParams { + + return PutDeviceNameNetlinkAddrParams{} +} + +// PutDeviceNameNetlinkAddrParams contains all the bound params for the put device name netlink addr operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameNetlinkAddr +type PutDeviceNameNetlinkAddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: body + */ + Spec *models.InetAddrSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameNetlinkAddrParams() beforehand. +func (o *PutDeviceNameNetlinkAddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.InetAddrSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameNetlinkAddrParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_responses.go new file mode 100644 index 000000000..b0287d36b --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameNetlinkAddrOKCode is the HTTP code returned for type PutDeviceNameNetlinkAddrOK +const PutDeviceNameNetlinkAddrOKCode int = 200 + +/* +PutDeviceNameNetlinkAddrOK Success + +swagger:response putDeviceNameNetlinkAddrOK +*/ +type PutDeviceNameNetlinkAddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNetlinkAddrOK creates PutDeviceNameNetlinkAddrOK with default headers values +func NewPutDeviceNameNetlinkAddrOK() *PutDeviceNameNetlinkAddrOK { + + return &PutDeviceNameNetlinkAddrOK{} +} + +// WithPayload adds the payload to the put device name netlink addr o k response +func (o *PutDeviceNameNetlinkAddrOK) WithPayload(payload string) *PutDeviceNameNetlinkAddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name netlink addr o k response +func (o *PutDeviceNameNetlinkAddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNetlinkAddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameNetlinkAddrInternalServerErrorCode is the HTTP code returned for type PutDeviceNameNetlinkAddrInternalServerError +const PutDeviceNameNetlinkAddrInternalServerErrorCode int = 500 + +/* +PutDeviceNameNetlinkAddrInternalServerError Not Found + +swagger:response putDeviceNameNetlinkAddrInternalServerError +*/ +type PutDeviceNameNetlinkAddrInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNetlinkAddrInternalServerError creates PutDeviceNameNetlinkAddrInternalServerError with default headers values +func NewPutDeviceNameNetlinkAddrInternalServerError() *PutDeviceNameNetlinkAddrInternalServerError { + + return &PutDeviceNameNetlinkAddrInternalServerError{} +} + +// WithPayload adds the payload to the put device name netlink addr internal server error response +func (o *PutDeviceNameNetlinkAddrInternalServerError) WithPayload(payload string) *PutDeviceNameNetlinkAddrInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name netlink addr internal server error response +func (o *PutDeviceNameNetlinkAddrInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNetlinkAddrInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_urlbuilder.go new file mode 100644 index 000000000..ef47a83b2 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_addr_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutDeviceNameNetlinkAddrURL generates an URL for the put device name netlink addr operation +type PutDeviceNameNetlinkAddrURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNetlinkAddrURL) WithBasePath(bp string) *PutDeviceNameNetlinkAddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNetlinkAddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameNetlinkAddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink/addr" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameNetlinkAddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameNetlinkAddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameNetlinkAddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameNetlinkAddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameNetlinkAddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameNetlinkAddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameNetlinkAddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_parameters.go new file mode 100644 index 000000000..d8d9e20f1 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewPutDeviceNameNetlinkParams creates a new PutDeviceNameNetlinkParams object +// +// There are no default values defined in the spec. +func NewPutDeviceNameNetlinkParams() PutDeviceNameNetlinkParams { + + return PutDeviceNameNetlinkParams{} +} + +// PutDeviceNameNetlinkParams contains all the bound params for the put device name netlink operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameNetlink +type PutDeviceNameNetlinkParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameNetlinkParams() beforehand. +func (o *PutDeviceNameNetlinkParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameNetlinkParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_responses.go new file mode 100644 index 000000000..ba2a6d07f --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameNetlinkOKCode is the HTTP code returned for type PutDeviceNameNetlinkOK +const PutDeviceNameNetlinkOKCode int = 200 + +/* +PutDeviceNameNetlinkOK Success + +swagger:response putDeviceNameNetlinkOK +*/ +type PutDeviceNameNetlinkOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNetlinkOK creates PutDeviceNameNetlinkOK with default headers values +func NewPutDeviceNameNetlinkOK() *PutDeviceNameNetlinkOK { + + return &PutDeviceNameNetlinkOK{} +} + +// WithPayload adds the payload to the put device name netlink o k response +func (o *PutDeviceNameNetlinkOK) WithPayload(payload string) *PutDeviceNameNetlinkOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name netlink o k response +func (o *PutDeviceNameNetlinkOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNetlinkOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameNetlinkInternalServerErrorCode is the HTTP code returned for type PutDeviceNameNetlinkInternalServerError +const PutDeviceNameNetlinkInternalServerErrorCode int = 500 + +/* +PutDeviceNameNetlinkInternalServerError Not Found + +swagger:response putDeviceNameNetlinkInternalServerError +*/ +type PutDeviceNameNetlinkInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNetlinkInternalServerError creates PutDeviceNameNetlinkInternalServerError with default headers values +func NewPutDeviceNameNetlinkInternalServerError() *PutDeviceNameNetlinkInternalServerError { + + return &PutDeviceNameNetlinkInternalServerError{} +} + +// WithPayload adds the payload to the put device name netlink internal server error response +func (o *PutDeviceNameNetlinkInternalServerError) WithPayload(payload string) *PutDeviceNameNetlinkInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name netlink internal server error response +func (o *PutDeviceNameNetlinkInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNetlinkInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_urlbuilder.go new file mode 100644 index 000000000..1b636026c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_netlink_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutDeviceNameNetlinkURL generates an URL for the put device name netlink operation +type PutDeviceNameNetlinkURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNetlinkURL) WithBasePath(bp string) *PutDeviceNameNetlinkURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNetlinkURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameNetlinkURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/netlink" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameNetlinkURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameNetlinkURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameNetlinkURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameNetlinkURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameNetlinkURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameNetlinkURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameNetlinkURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic.go new file mode 100644 index 000000000..4bf05efd7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameNicHandlerFunc turns a function with the right signature into a put device name nic handler +type PutDeviceNameNicHandlerFunc func(PutDeviceNameNicParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameNicHandlerFunc) Handle(params PutDeviceNameNicParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameNicHandler interface for that can handle valid put device name nic params +type PutDeviceNameNicHandler interface { + Handle(PutDeviceNameNicParams) middleware.Responder +} + +// NewPutDeviceNameNic creates a new http.Handler for the put device name nic operation +func NewPutDeviceNameNic(ctx *middleware.Context, handler PutDeviceNameNicHandler) *PutDeviceNameNic { + return &PutDeviceNameNic{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameNic swagger:route PUT /device/{name}/nic device putDeviceNameNic + +dpip link set ${nic-name} [forward2kni,link,promisc,tc-ingress,tc-egress] [on/up,off/down] +*/ +type PutDeviceNameNic struct { + Context *middleware.Context + Handler PutDeviceNameNicHandler +} + +func (o *PutDeviceNameNic) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameNicParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go new file mode 100644 index 000000000..a8cd915e3 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_parameters.go @@ -0,0 +1,218 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" +) + +// NewPutDeviceNameNicParams creates a new PutDeviceNameNicParams object +// with the default values initialized. +func NewPutDeviceNameNicParams() PutDeviceNameNicParams { + + var ( + // initialize parameters with default values + + forward2KniDefault = string("unset") + linkDefault = string("unset") + + promiscDefault = string("unset") + ) + + return PutDeviceNameNicParams{ + Forward2Kni: &forward2KniDefault, + + Link: &linkDefault, + + Promisc: &promiscDefault, + } +} + +// PutDeviceNameNicParams contains all the bound params for the put device name nic operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameNic +type PutDeviceNameNicParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + In: query + Default: "unset" + */ + Forward2Kni *string + /* + In: query + Default: "unset" + */ + Link *string + /* + Required: true + In: path + */ + Name string + /* + In: query + Default: "unset" + */ + Promisc *string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameNicParams() beforehand. +func (o *PutDeviceNameNicParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qForward2Kni, qhkForward2Kni, _ := qs.GetOK("forward2Kni") + if err := o.bindForward2Kni(qForward2Kni, qhkForward2Kni, route.Formats); err != nil { + res = append(res, err) + } + + qLink, qhkLink, _ := qs.GetOK("link") + if err := o.bindLink(qLink, qhkLink, route.Formats); err != nil { + res = append(res, err) + } + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + qPromisc, qhkPromisc, _ := qs.GetOK("promisc") + if err := o.bindPromisc(qPromisc, qhkPromisc, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindForward2Kni binds and validates parameter Forward2Kni from query. +func (o *PutDeviceNameNicParams) bindForward2Kni(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewPutDeviceNameNicParams() + return nil + } + o.Forward2Kni = &raw + + if err := o.validateForward2Kni(formats); err != nil { + return err + } + + return nil +} + +// validateForward2Kni carries on validations for parameter Forward2Kni +func (o *PutDeviceNameNicParams) validateForward2Kni(formats strfmt.Registry) error { + + if err := validate.EnumCase("forward2Kni", "query", *o.Forward2Kni, []interface{}{"unset", "on", "off"}, true); err != nil { + return err + } + + return nil +} + +// bindLink binds and validates parameter Link from query. +func (o *PutDeviceNameNicParams) bindLink(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewPutDeviceNameNicParams() + return nil + } + o.Link = &raw + + if err := o.validateLink(formats); err != nil { + return err + } + + return nil +} + +// validateLink carries on validations for parameter Link +func (o *PutDeviceNameNicParams) validateLink(formats strfmt.Registry) error { + + if err := validate.EnumCase("link", "query", *o.Link, []interface{}{"unset", "up", "down"}, true); err != nil { + return err + } + + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameNicParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} + +// bindPromisc binds and validates parameter Promisc from query. +func (o *PutDeviceNameNicParams) bindPromisc(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewPutDeviceNameNicParams() + return nil + } + o.Promisc = &raw + + if err := o.validatePromisc(formats); err != nil { + return err + } + + return nil +} + +// validatePromisc carries on validations for parameter Promisc +func (o *PutDeviceNameNicParams) validatePromisc(formats strfmt.Registry) error { + + if err := validate.EnumCase("promisc", "query", *o.Promisc, []interface{}{"unset", "on", "off"}, true); err != nil { + return err + } + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_responses.go new file mode 100644 index 000000000..2ca881446 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameNicOKCode is the HTTP code returned for type PutDeviceNameNicOK +const PutDeviceNameNicOKCode int = 200 + +/* +PutDeviceNameNicOK Success + +swagger:response putDeviceNameNicOK +*/ +type PutDeviceNameNicOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNicOK creates PutDeviceNameNicOK with default headers values +func NewPutDeviceNameNicOK() *PutDeviceNameNicOK { + + return &PutDeviceNameNicOK{} +} + +// WithPayload adds the payload to the put device name nic o k response +func (o *PutDeviceNameNicOK) WithPayload(payload string) *PutDeviceNameNicOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name nic o k response +func (o *PutDeviceNameNicOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNicOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameNicInternalServerErrorCode is the HTTP code returned for type PutDeviceNameNicInternalServerError +const PutDeviceNameNicInternalServerErrorCode int = 500 + +/* +PutDeviceNameNicInternalServerError Failure + +swagger:response putDeviceNameNicInternalServerError +*/ +type PutDeviceNameNicInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameNicInternalServerError creates PutDeviceNameNicInternalServerError with default headers values +func NewPutDeviceNameNicInternalServerError() *PutDeviceNameNicInternalServerError { + + return &PutDeviceNameNicInternalServerError{} +} + +// WithPayload adds the payload to the put device name nic internal server error response +func (o *PutDeviceNameNicInternalServerError) WithPayload(payload string) *PutDeviceNameNicInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name nic internal server error response +func (o *PutDeviceNameNicInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameNicInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_urlbuilder.go new file mode 100644 index 000000000..865956941 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_nic_urlbuilder.go @@ -0,0 +1,131 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutDeviceNameNicURL generates an URL for the put device name nic operation +type PutDeviceNameNicURL struct { + Name string + + Forward2Kni *string + Link *string + Promisc *string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNicURL) WithBasePath(bp string) *PutDeviceNameNicURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameNicURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameNicURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/nic" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameNicURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var forward2KniQ string + if o.Forward2Kni != nil { + forward2KniQ = *o.Forward2Kni + } + if forward2KniQ != "" { + qs.Set("forward2Kni", forward2KniQ) + } + + var linkQ string + if o.Link != nil { + linkQ = *o.Link + } + if linkQ != "" { + qs.Set("link", linkQ) + } + + var promiscQ string + if o.Promisc != nil { + promiscQ = *o.Promisc + } + if promiscQ != "" { + qs.Set("promisc", promiscQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameNicURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameNicURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameNicURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameNicURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameNicURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameNicURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_route.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_route.go new file mode 100644 index 000000000..e5b7940c5 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_route.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameRouteHandlerFunc turns a function with the right signature into a put device name route handler +type PutDeviceNameRouteHandlerFunc func(PutDeviceNameRouteParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameRouteHandlerFunc) Handle(params PutDeviceNameRouteParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameRouteHandler interface for that can handle valid put device name route params +type PutDeviceNameRouteHandler interface { + Handle(PutDeviceNameRouteParams) middleware.Responder +} + +// NewPutDeviceNameRoute creates a new http.Handler for the put device name route operation +func NewPutDeviceNameRoute(ctx *middleware.Context, handler PutDeviceNameRouteHandler) *PutDeviceNameRoute { + return &PutDeviceNameRoute{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameRoute swagger:route PUT /device/{name}/route device putDeviceNameRoute + +add/update special net device route +*/ +type PutDeviceNameRoute struct { + Context *middleware.Context + Handler PutDeviceNameRouteHandler +} + +func (o *PutDeviceNameRoute) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameRouteParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_route_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_parameters.go new file mode 100644 index 000000000..29831e533 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutDeviceNameRouteParams creates a new PutDeviceNameRouteParams object +// +// There are no default values defined in the spec. +func NewPutDeviceNameRouteParams() PutDeviceNameRouteParams { + + return PutDeviceNameRouteParams{} +} + +// PutDeviceNameRouteParams contains all the bound params for the put device name route operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameRoute +type PutDeviceNameRouteParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: body + */ + Spec *models.RouteSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameRouteParams() beforehand. +func (o *PutDeviceNameRouteParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.RouteSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameRouteParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_route_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_responses.go new file mode 100644 index 000000000..87f0b47ed --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_responses.go @@ -0,0 +1,141 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameRouteOKCode is the HTTP code returned for type PutDeviceNameRouteOK +const PutDeviceNameRouteOKCode int = 200 + +/* +PutDeviceNameRouteOK Update exist route Success + +swagger:response putDeviceNameRouteOK +*/ +type PutDeviceNameRouteOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameRouteOK creates PutDeviceNameRouteOK with default headers values +func NewPutDeviceNameRouteOK() *PutDeviceNameRouteOK { + + return &PutDeviceNameRouteOK{} +} + +// WithPayload adds the payload to the put device name route o k response +func (o *PutDeviceNameRouteOK) WithPayload(payload string) *PutDeviceNameRouteOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name route o k response +func (o *PutDeviceNameRouteOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameRouteOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameRouteCreatedCode is the HTTP code returned for type PutDeviceNameRouteCreated +const PutDeviceNameRouteCreatedCode int = 201 + +/* +PutDeviceNameRouteCreated Add new route Success + +swagger:response putDeviceNameRouteCreated +*/ +type PutDeviceNameRouteCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameRouteCreated creates PutDeviceNameRouteCreated with default headers values +func NewPutDeviceNameRouteCreated() *PutDeviceNameRouteCreated { + + return &PutDeviceNameRouteCreated{} +} + +// WithPayload adds the payload to the put device name route created response +func (o *PutDeviceNameRouteCreated) WithPayload(payload string) *PutDeviceNameRouteCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name route created response +func (o *PutDeviceNameRouteCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameRouteCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameRouteInternalServerErrorCode is the HTTP code returned for type PutDeviceNameRouteInternalServerError +const PutDeviceNameRouteInternalServerErrorCode int = 500 + +/* +PutDeviceNameRouteInternalServerError Failed + +swagger:response putDeviceNameRouteInternalServerError +*/ +type PutDeviceNameRouteInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameRouteInternalServerError creates PutDeviceNameRouteInternalServerError with default headers values +func NewPutDeviceNameRouteInternalServerError() *PutDeviceNameRouteInternalServerError { + + return &PutDeviceNameRouteInternalServerError{} +} + +// WithPayload adds the payload to the put device name route internal server error response +func (o *PutDeviceNameRouteInternalServerError) WithPayload(payload string) *PutDeviceNameRouteInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name route internal server error response +func (o *PutDeviceNameRouteInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameRouteInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_route_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_urlbuilder.go new file mode 100644 index 000000000..3776a3036 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_route_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutDeviceNameRouteURL generates an URL for the put device name route operation +type PutDeviceNameRouteURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameRouteURL) WithBasePath(bp string) *PutDeviceNameRouteURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameRouteURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameRouteURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/route" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameRouteURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameRouteURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameRouteURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameRouteURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameRouteURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameRouteURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameRouteURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan.go new file mode 100644 index 000000000..dd519e482 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutDeviceNameVlanHandlerFunc turns a function with the right signature into a put device name vlan handler +type PutDeviceNameVlanHandlerFunc func(PutDeviceNameVlanParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutDeviceNameVlanHandlerFunc) Handle(params PutDeviceNameVlanParams) middleware.Responder { + return fn(params) +} + +// PutDeviceNameVlanHandler interface for that can handle valid put device name vlan params +type PutDeviceNameVlanHandler interface { + Handle(PutDeviceNameVlanParams) middleware.Responder +} + +// NewPutDeviceNameVlan creates a new http.Handler for the put device name vlan operation +func NewPutDeviceNameVlan(ctx *middleware.Context, handler PutDeviceNameVlanHandler) *PutDeviceNameVlan { + return &PutDeviceNameVlan{Context: ctx, Handler: handler} +} + +/* + PutDeviceNameVlan swagger:route PUT /device/{name}/vlan device putDeviceNameVlan + +add/update special net device +*/ +type PutDeviceNameVlan struct { + Context *middleware.Context + Handler PutDeviceNameVlanHandler +} + +func (o *PutDeviceNameVlan) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutDeviceNameVlanParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_parameters.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_parameters.go new file mode 100644 index 000000000..63c5965c5 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutDeviceNameVlanParams creates a new PutDeviceNameVlanParams object +// +// There are no default values defined in the spec. +func NewPutDeviceNameVlanParams() PutDeviceNameVlanParams { + + return PutDeviceNameVlanParams{} +} + +// PutDeviceNameVlanParams contains all the bound params for the put device name vlan operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutDeviceNameVlan +type PutDeviceNameVlanParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + Name string + /* + In: body + */ + Spec *models.VlanSpec +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutDeviceNameVlanParams() beforehand. +func (o *PutDeviceNameVlanParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rName, rhkName, _ := route.Params.GetOK("name") + if err := o.bindName(rName, rhkName, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.VlanSpec + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindName binds and validates parameter Name from path. +func (o *PutDeviceNameVlanParams) bindName(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.Name = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_responses.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_responses.go new file mode 100644 index 000000000..241b8ef3d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// PutDeviceNameVlanOKCode is the HTTP code returned for type PutDeviceNameVlanOK +const PutDeviceNameVlanOKCode int = 200 + +/* +PutDeviceNameVlanOK Success + +swagger:response putDeviceNameVlanOK +*/ +type PutDeviceNameVlanOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameVlanOK creates PutDeviceNameVlanOK with default headers values +func NewPutDeviceNameVlanOK() *PutDeviceNameVlanOK { + + return &PutDeviceNameVlanOK{} +} + +// WithPayload adds the payload to the put device name vlan o k response +func (o *PutDeviceNameVlanOK) WithPayload(payload string) *PutDeviceNameVlanOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name vlan o k response +func (o *PutDeviceNameVlanOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameVlanOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutDeviceNameVlanInternalServerErrorCode is the HTTP code returned for type PutDeviceNameVlanInternalServerError +const PutDeviceNameVlanInternalServerErrorCode int = 500 + +/* +PutDeviceNameVlanInternalServerError Failed + +swagger:response putDeviceNameVlanInternalServerError +*/ +type PutDeviceNameVlanInternalServerError struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutDeviceNameVlanInternalServerError creates PutDeviceNameVlanInternalServerError with default headers values +func NewPutDeviceNameVlanInternalServerError() *PutDeviceNameVlanInternalServerError { + + return &PutDeviceNameVlanInternalServerError{} +} + +// WithPayload adds the payload to the put device name vlan internal server error response +func (o *PutDeviceNameVlanInternalServerError) WithPayload(payload string) *PutDeviceNameVlanInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put device name vlan internal server error response +func (o *PutDeviceNameVlanInternalServerError) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutDeviceNameVlanInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_urlbuilder.go b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_urlbuilder.go new file mode 100644 index 000000000..2892d676c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/device/put_device_name_vlan_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package device + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutDeviceNameVlanURL generates an URL for the put device name vlan operation +type PutDeviceNameVlanURL struct { + Name string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameVlanURL) WithBasePath(bp string) *PutDeviceNameVlanURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutDeviceNameVlanURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutDeviceNameVlanURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/device/{name}/vlan" + + name := o.Name + if name != "" { + _path = strings.Replace(_path, "{name}", name, -1) + } else { + return nil, errors.New("name is required on PutDeviceNameVlanURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutDeviceNameVlanURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutDeviceNameVlanURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutDeviceNameVlanURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutDeviceNameVlanURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutDeviceNameVlanURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutDeviceNameVlanURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/dpvs_agent_api.go b/tools/dpvs-agent/restapi/operations/dpvs_agent_api.go new file mode 100644 index 000000000..5421e4aa7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/dpvs_agent_api.go @@ -0,0 +1,736 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package operations + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "fmt" + "net/http" + "strings" + + "github.com/go-openapi/errors" + "github.com/go-openapi/loads" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/runtime/security" + "github.com/go-openapi/spec" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + + "github.com/dpvs-agent/restapi/operations/device" + "github.com/dpvs-agent/restapi/operations/virtualserver" +) + +// NewDpvsAgentAPI creates a new DpvsAgent instance +func NewDpvsAgentAPI(spec *loads.Document) *DpvsAgentAPI { + return &DpvsAgentAPI{ + handlers: make(map[string]map[string]http.Handler), + formats: strfmt.Default, + defaultConsumes: "application/json", + defaultProduces: "application/json", + customConsumers: make(map[string]runtime.Consumer), + customProducers: make(map[string]runtime.Producer), + PreServerShutdown: func() {}, + ServerShutdown: func() {}, + spec: spec, + useSwaggerUI: false, + ServeError: errors.ServeError, + BasicAuthenticator: security.BasicAuth, + APIKeyAuthenticator: security.APIKeyAuth, + BearerAuthenticator: security.BearerAuth, + + JSONConsumer: runtime.JSONConsumer(), + + JSONProducer: runtime.JSONProducer(), + + DeviceDeleteDeviceNameAddrHandler: device.DeleteDeviceNameAddrHandlerFunc(func(params device.DeleteDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameAddr has not yet been implemented") + }), + DeviceDeleteDeviceNameNetlinkHandler: device.DeleteDeviceNameNetlinkHandlerFunc(func(params device.DeleteDeviceNameNetlinkParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameNetlink has not yet been implemented") + }), + DeviceDeleteDeviceNameNetlinkAddrHandler: device.DeleteDeviceNameNetlinkAddrHandlerFunc(func(params device.DeleteDeviceNameNetlinkAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameNetlinkAddr has not yet been implemented") + }), + DeviceDeleteDeviceNameRouteHandler: device.DeleteDeviceNameRouteHandlerFunc(func(params device.DeleteDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameRoute has not yet been implemented") + }), + DeviceDeleteDeviceNameVlanHandler: device.DeleteDeviceNameVlanHandlerFunc(func(params device.DeleteDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.DeleteDeviceNameVlan has not yet been implemented") + }), + VirtualserverDeleteVsVipPortHandler: virtualserver.DeleteVsVipPortHandlerFunc(func(params virtualserver.DeleteVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPort has not yet been implemented") + }), + VirtualserverDeleteVsVipPortAllowHandler: virtualserver.DeleteVsVipPortAllowHandlerFunc(func(params virtualserver.DeleteVsVipPortAllowParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortAllow has not yet been implemented") + }), + VirtualserverDeleteVsVipPortDenyHandler: virtualserver.DeleteVsVipPortDenyHandlerFunc(func(params virtualserver.DeleteVsVipPortDenyParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortDeny has not yet been implemented") + }), + VirtualserverDeleteVsVipPortLaddrHandler: virtualserver.DeleteVsVipPortLaddrHandlerFunc(func(params virtualserver.DeleteVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortLaddr has not yet been implemented") + }), + VirtualserverDeleteVsVipPortRsHandler: virtualserver.DeleteVsVipPortRsHandlerFunc(func(params virtualserver.DeleteVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.DeleteVsVipPortRs has not yet been implemented") + }), + DeviceGetDeviceHandler: device.GetDeviceHandlerFunc(func(params device.GetDeviceParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDevice has not yet been implemented") + }), + DeviceGetDeviceNameAddrHandler: device.GetDeviceNameAddrHandlerFunc(func(params device.GetDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameAddr has not yet been implemented") + }), + DeviceGetDeviceNameNetlinkHandler: device.GetDeviceNameNetlinkHandlerFunc(func(params device.GetDeviceNameNetlinkParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameNetlink has not yet been implemented") + }), + DeviceGetDeviceNameNetlinkAddrHandler: device.GetDeviceNameNetlinkAddrHandlerFunc(func(params device.GetDeviceNameNetlinkAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameNetlinkAddr has not yet been implemented") + }), + DeviceGetDeviceNameNicHandler: device.GetDeviceNameNicHandlerFunc(func(params device.GetDeviceNameNicParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameNic has not yet been implemented") + }), + DeviceGetDeviceNameRouteHandler: device.GetDeviceNameRouteHandlerFunc(func(params device.GetDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameRoute has not yet been implemented") + }), + DeviceGetDeviceNameVlanHandler: device.GetDeviceNameVlanHandlerFunc(func(params device.GetDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.GetDeviceNameVlan has not yet been implemented") + }), + VirtualserverGetVsHandler: virtualserver.GetVsHandlerFunc(func(params virtualserver.GetVsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVs has not yet been implemented") + }), + VirtualserverGetVsVipPortHandler: virtualserver.GetVsVipPortHandlerFunc(func(params virtualserver.GetVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPort has not yet been implemented") + }), + VirtualserverGetVsVipPortAllowHandler: virtualserver.GetVsVipPortAllowHandlerFunc(func(params virtualserver.GetVsVipPortAllowParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortAllow has not yet been implemented") + }), + VirtualserverGetVsVipPortDenyHandler: virtualserver.GetVsVipPortDenyHandlerFunc(func(params virtualserver.GetVsVipPortDenyParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortDeny has not yet been implemented") + }), + VirtualserverGetVsVipPortLaddrHandler: virtualserver.GetVsVipPortLaddrHandlerFunc(func(params virtualserver.GetVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortLaddr has not yet been implemented") + }), + VirtualserverGetVsVipPortRsHandler: virtualserver.GetVsVipPortRsHandlerFunc(func(params virtualserver.GetVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.GetVsVipPortRs has not yet been implemented") + }), + VirtualserverPostVsVipPortAllowHandler: virtualserver.PostVsVipPortAllowHandlerFunc(func(params virtualserver.PostVsVipPortAllowParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PostVsVipPortAllow has not yet been implemented") + }), + VirtualserverPostVsVipPortDenyHandler: virtualserver.PostVsVipPortDenyHandlerFunc(func(params virtualserver.PostVsVipPortDenyParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PostVsVipPortDeny has not yet been implemented") + }), + VirtualserverPostVsVipPortRsHandler: virtualserver.PostVsVipPortRsHandlerFunc(func(params virtualserver.PostVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PostVsVipPortRs has not yet been implemented") + }), + DevicePutDeviceNameAddrHandler: device.PutDeviceNameAddrHandlerFunc(func(params device.PutDeviceNameAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameAddr has not yet been implemented") + }), + DevicePutDeviceNameNetlinkHandler: device.PutDeviceNameNetlinkHandlerFunc(func(params device.PutDeviceNameNetlinkParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameNetlink has not yet been implemented") + }), + DevicePutDeviceNameNetlinkAddrHandler: device.PutDeviceNameNetlinkAddrHandlerFunc(func(params device.PutDeviceNameNetlinkAddrParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameNetlinkAddr has not yet been implemented") + }), + DevicePutDeviceNameNicHandler: device.PutDeviceNameNicHandlerFunc(func(params device.PutDeviceNameNicParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameNic has not yet been implemented") + }), + DevicePutDeviceNameRouteHandler: device.PutDeviceNameRouteHandlerFunc(func(params device.PutDeviceNameRouteParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameRoute has not yet been implemented") + }), + DevicePutDeviceNameVlanHandler: device.PutDeviceNameVlanHandlerFunc(func(params device.PutDeviceNameVlanParams) middleware.Responder { + return middleware.NotImplemented("operation device.PutDeviceNameVlan has not yet been implemented") + }), + VirtualserverPutVsVipPortHandler: virtualserver.PutVsVipPortHandlerFunc(func(params virtualserver.PutVsVipPortParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPort has not yet been implemented") + }), + VirtualserverPutVsVipPortAllowHandler: virtualserver.PutVsVipPortAllowHandlerFunc(func(params virtualserver.PutVsVipPortAllowParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortAllow has not yet been implemented") + }), + VirtualserverPutVsVipPortDenyHandler: virtualserver.PutVsVipPortDenyHandlerFunc(func(params virtualserver.PutVsVipPortDenyParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortDeny has not yet been implemented") + }), + VirtualserverPutVsVipPortLaddrHandler: virtualserver.PutVsVipPortLaddrHandlerFunc(func(params virtualserver.PutVsVipPortLaddrParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortLaddr has not yet been implemented") + }), + VirtualserverPutVsVipPortRsHandler: virtualserver.PutVsVipPortRsHandlerFunc(func(params virtualserver.PutVsVipPortRsParams) middleware.Responder { + return middleware.NotImplemented("operation virtualserver.PutVsVipPortRs has not yet been implemented") + }), + } +} + +/*DpvsAgentAPI dpvs agent api */ +type DpvsAgentAPI struct { + spec *loads.Document + context *middleware.Context + handlers map[string]map[string]http.Handler + formats strfmt.Registry + customConsumers map[string]runtime.Consumer + customProducers map[string]runtime.Producer + defaultConsumes string + defaultProduces string + Middleware func(middleware.Builder) http.Handler + useSwaggerUI bool + + // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator + + // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator + + // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function. + // It has a default implementation in the security package, however you can replace it for your particular usage. + BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator + + // JSONConsumer registers a consumer for the following mime types: + // - application/json + JSONConsumer runtime.Consumer + + // JSONProducer registers a producer for the following mime types: + // - application/json + JSONProducer runtime.Producer + + // DeviceDeleteDeviceNameAddrHandler sets the operation handler for the delete device name addr operation + DeviceDeleteDeviceNameAddrHandler device.DeleteDeviceNameAddrHandler + // DeviceDeleteDeviceNameNetlinkHandler sets the operation handler for the delete device name netlink operation + DeviceDeleteDeviceNameNetlinkHandler device.DeleteDeviceNameNetlinkHandler + // DeviceDeleteDeviceNameNetlinkAddrHandler sets the operation handler for the delete device name netlink addr operation + DeviceDeleteDeviceNameNetlinkAddrHandler device.DeleteDeviceNameNetlinkAddrHandler + // DeviceDeleteDeviceNameRouteHandler sets the operation handler for the delete device name route operation + DeviceDeleteDeviceNameRouteHandler device.DeleteDeviceNameRouteHandler + // DeviceDeleteDeviceNameVlanHandler sets the operation handler for the delete device name vlan operation + DeviceDeleteDeviceNameVlanHandler device.DeleteDeviceNameVlanHandler + // VirtualserverDeleteVsVipPortHandler sets the operation handler for the delete vs vip port operation + VirtualserverDeleteVsVipPortHandler virtualserver.DeleteVsVipPortHandler + // VirtualserverDeleteVsVipPortAllowHandler sets the operation handler for the delete vs vip port allow operation + VirtualserverDeleteVsVipPortAllowHandler virtualserver.DeleteVsVipPortAllowHandler + // VirtualserverDeleteVsVipPortDenyHandler sets the operation handler for the delete vs vip port deny operation + VirtualserverDeleteVsVipPortDenyHandler virtualserver.DeleteVsVipPortDenyHandler + // VirtualserverDeleteVsVipPortLaddrHandler sets the operation handler for the delete vs vip port laddr operation + VirtualserverDeleteVsVipPortLaddrHandler virtualserver.DeleteVsVipPortLaddrHandler + // VirtualserverDeleteVsVipPortRsHandler sets the operation handler for the delete vs vip port rs operation + VirtualserverDeleteVsVipPortRsHandler virtualserver.DeleteVsVipPortRsHandler + // DeviceGetDeviceHandler sets the operation handler for the get device operation + DeviceGetDeviceHandler device.GetDeviceHandler + // DeviceGetDeviceNameAddrHandler sets the operation handler for the get device name addr operation + DeviceGetDeviceNameAddrHandler device.GetDeviceNameAddrHandler + // DeviceGetDeviceNameNetlinkHandler sets the operation handler for the get device name netlink operation + DeviceGetDeviceNameNetlinkHandler device.GetDeviceNameNetlinkHandler + // DeviceGetDeviceNameNetlinkAddrHandler sets the operation handler for the get device name netlink addr operation + DeviceGetDeviceNameNetlinkAddrHandler device.GetDeviceNameNetlinkAddrHandler + // DeviceGetDeviceNameNicHandler sets the operation handler for the get device name nic operation + DeviceGetDeviceNameNicHandler device.GetDeviceNameNicHandler + // DeviceGetDeviceNameRouteHandler sets the operation handler for the get device name route operation + DeviceGetDeviceNameRouteHandler device.GetDeviceNameRouteHandler + // DeviceGetDeviceNameVlanHandler sets the operation handler for the get device name vlan operation + DeviceGetDeviceNameVlanHandler device.GetDeviceNameVlanHandler + // VirtualserverGetVsHandler sets the operation handler for the get vs operation + VirtualserverGetVsHandler virtualserver.GetVsHandler + // VirtualserverGetVsVipPortHandler sets the operation handler for the get vs vip port operation + VirtualserverGetVsVipPortHandler virtualserver.GetVsVipPortHandler + // VirtualserverGetVsVipPortAllowHandler sets the operation handler for the get vs vip port allow operation + VirtualserverGetVsVipPortAllowHandler virtualserver.GetVsVipPortAllowHandler + // VirtualserverGetVsVipPortDenyHandler sets the operation handler for the get vs vip port deny operation + VirtualserverGetVsVipPortDenyHandler virtualserver.GetVsVipPortDenyHandler + // VirtualserverGetVsVipPortLaddrHandler sets the operation handler for the get vs vip port laddr operation + VirtualserverGetVsVipPortLaddrHandler virtualserver.GetVsVipPortLaddrHandler + // VirtualserverGetVsVipPortRsHandler sets the operation handler for the get vs vip port rs operation + VirtualserverGetVsVipPortRsHandler virtualserver.GetVsVipPortRsHandler + // VirtualserverPostVsVipPortAllowHandler sets the operation handler for the post vs vip port allow operation + VirtualserverPostVsVipPortAllowHandler virtualserver.PostVsVipPortAllowHandler + // VirtualserverPostVsVipPortDenyHandler sets the operation handler for the post vs vip port deny operation + VirtualserverPostVsVipPortDenyHandler virtualserver.PostVsVipPortDenyHandler + // VirtualserverPostVsVipPortRsHandler sets the operation handler for the post vs vip port rs operation + VirtualserverPostVsVipPortRsHandler virtualserver.PostVsVipPortRsHandler + // DevicePutDeviceNameAddrHandler sets the operation handler for the put device name addr operation + DevicePutDeviceNameAddrHandler device.PutDeviceNameAddrHandler + // DevicePutDeviceNameNetlinkHandler sets the operation handler for the put device name netlink operation + DevicePutDeviceNameNetlinkHandler device.PutDeviceNameNetlinkHandler + // DevicePutDeviceNameNetlinkAddrHandler sets the operation handler for the put device name netlink addr operation + DevicePutDeviceNameNetlinkAddrHandler device.PutDeviceNameNetlinkAddrHandler + // DevicePutDeviceNameNicHandler sets the operation handler for the put device name nic operation + DevicePutDeviceNameNicHandler device.PutDeviceNameNicHandler + // DevicePutDeviceNameRouteHandler sets the operation handler for the put device name route operation + DevicePutDeviceNameRouteHandler device.PutDeviceNameRouteHandler + // DevicePutDeviceNameVlanHandler sets the operation handler for the put device name vlan operation + DevicePutDeviceNameVlanHandler device.PutDeviceNameVlanHandler + // VirtualserverPutVsVipPortHandler sets the operation handler for the put vs vip port operation + VirtualserverPutVsVipPortHandler virtualserver.PutVsVipPortHandler + // VirtualserverPutVsVipPortAllowHandler sets the operation handler for the put vs vip port allow operation + VirtualserverPutVsVipPortAllowHandler virtualserver.PutVsVipPortAllowHandler + // VirtualserverPutVsVipPortDenyHandler sets the operation handler for the put vs vip port deny operation + VirtualserverPutVsVipPortDenyHandler virtualserver.PutVsVipPortDenyHandler + // VirtualserverPutVsVipPortLaddrHandler sets the operation handler for the put vs vip port laddr operation + VirtualserverPutVsVipPortLaddrHandler virtualserver.PutVsVipPortLaddrHandler + // VirtualserverPutVsVipPortRsHandler sets the operation handler for the put vs vip port rs operation + VirtualserverPutVsVipPortRsHandler virtualserver.PutVsVipPortRsHandler + + // ServeError is called when an error is received, there is a default handler + // but you can set your own with this + ServeError func(http.ResponseWriter, *http.Request, error) + + // PreServerShutdown is called before the HTTP(S) server is shutdown + // This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic + PreServerShutdown func() + + // ServerShutdown is called when the HTTP(S) server is shut down and done + // handling all active connections and does not accept connections any more + ServerShutdown func() + + // Custom command line argument groups with their descriptions + CommandLineOptionsGroups []swag.CommandLineOptionsGroup + + // User defined logger function. + Logger func(string, ...interface{}) +} + +// UseRedoc for documentation at /docs +func (o *DpvsAgentAPI) UseRedoc() { + o.useSwaggerUI = false +} + +// UseSwaggerUI for documentation at /docs +func (o *DpvsAgentAPI) UseSwaggerUI() { + o.useSwaggerUI = true +} + +// SetDefaultProduces sets the default produces media type +func (o *DpvsAgentAPI) SetDefaultProduces(mediaType string) { + o.defaultProduces = mediaType +} + +// SetDefaultConsumes returns the default consumes media type +func (o *DpvsAgentAPI) SetDefaultConsumes(mediaType string) { + o.defaultConsumes = mediaType +} + +// SetSpec sets a spec that will be served for the clients. +func (o *DpvsAgentAPI) SetSpec(spec *loads.Document) { + o.spec = spec +} + +// DefaultProduces returns the default produces media type +func (o *DpvsAgentAPI) DefaultProduces() string { + return o.defaultProduces +} + +// DefaultConsumes returns the default consumes media type +func (o *DpvsAgentAPI) DefaultConsumes() string { + return o.defaultConsumes +} + +// Formats returns the registered string formats +func (o *DpvsAgentAPI) Formats() strfmt.Registry { + return o.formats +} + +// RegisterFormat registers a custom format validator +func (o *DpvsAgentAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) { + o.formats.Add(name, format, validator) +} + +// Validate validates the registrations in the DpvsAgentAPI +func (o *DpvsAgentAPI) Validate() error { + var unregistered []string + + if o.JSONConsumer == nil { + unregistered = append(unregistered, "JSONConsumer") + } + + if o.JSONProducer == nil { + unregistered = append(unregistered, "JSONProducer") + } + + if o.DeviceDeleteDeviceNameAddrHandler == nil { + unregistered = append(unregistered, "device.DeleteDeviceNameAddrHandler") + } + if o.DeviceDeleteDeviceNameNetlinkHandler == nil { + unregistered = append(unregistered, "device.DeleteDeviceNameNetlinkHandler") + } + if o.DeviceDeleteDeviceNameNetlinkAddrHandler == nil { + unregistered = append(unregistered, "device.DeleteDeviceNameNetlinkAddrHandler") + } + if o.DeviceDeleteDeviceNameRouteHandler == nil { + unregistered = append(unregistered, "device.DeleteDeviceNameRouteHandler") + } + if o.DeviceDeleteDeviceNameVlanHandler == nil { + unregistered = append(unregistered, "device.DeleteDeviceNameVlanHandler") + } + if o.VirtualserverDeleteVsVipPortHandler == nil { + unregistered = append(unregistered, "virtualserver.DeleteVsVipPortHandler") + } + if o.VirtualserverDeleteVsVipPortAllowHandler == nil { + unregistered = append(unregistered, "virtualserver.DeleteVsVipPortAllowHandler") + } + if o.VirtualserverDeleteVsVipPortDenyHandler == nil { + unregistered = append(unregistered, "virtualserver.DeleteVsVipPortDenyHandler") + } + if o.VirtualserverDeleteVsVipPortLaddrHandler == nil { + unregistered = append(unregistered, "virtualserver.DeleteVsVipPortLaddrHandler") + } + if o.VirtualserverDeleteVsVipPortRsHandler == nil { + unregistered = append(unregistered, "virtualserver.DeleteVsVipPortRsHandler") + } + if o.DeviceGetDeviceHandler == nil { + unregistered = append(unregistered, "device.GetDeviceHandler") + } + if o.DeviceGetDeviceNameAddrHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameAddrHandler") + } + if o.DeviceGetDeviceNameNetlinkHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameNetlinkHandler") + } + if o.DeviceGetDeviceNameNetlinkAddrHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameNetlinkAddrHandler") + } + if o.DeviceGetDeviceNameNicHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameNicHandler") + } + if o.DeviceGetDeviceNameRouteHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameRouteHandler") + } + if o.DeviceGetDeviceNameVlanHandler == nil { + unregistered = append(unregistered, "device.GetDeviceNameVlanHandler") + } + if o.VirtualserverGetVsHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsHandler") + } + if o.VirtualserverGetVsVipPortHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsVipPortHandler") + } + if o.VirtualserverGetVsVipPortAllowHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsVipPortAllowHandler") + } + if o.VirtualserverGetVsVipPortDenyHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsVipPortDenyHandler") + } + if o.VirtualserverGetVsVipPortLaddrHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsVipPortLaddrHandler") + } + if o.VirtualserverGetVsVipPortRsHandler == nil { + unregistered = append(unregistered, "virtualserver.GetVsVipPortRsHandler") + } + if o.VirtualserverPostVsVipPortAllowHandler == nil { + unregistered = append(unregistered, "virtualserver.PostVsVipPortAllowHandler") + } + if o.VirtualserverPostVsVipPortDenyHandler == nil { + unregistered = append(unregistered, "virtualserver.PostVsVipPortDenyHandler") + } + if o.VirtualserverPostVsVipPortRsHandler == nil { + unregistered = append(unregistered, "virtualserver.PostVsVipPortRsHandler") + } + if o.DevicePutDeviceNameAddrHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameAddrHandler") + } + if o.DevicePutDeviceNameNetlinkHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameNetlinkHandler") + } + if o.DevicePutDeviceNameNetlinkAddrHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameNetlinkAddrHandler") + } + if o.DevicePutDeviceNameNicHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameNicHandler") + } + if o.DevicePutDeviceNameRouteHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameRouteHandler") + } + if o.DevicePutDeviceNameVlanHandler == nil { + unregistered = append(unregistered, "device.PutDeviceNameVlanHandler") + } + if o.VirtualserverPutVsVipPortHandler == nil { + unregistered = append(unregistered, "virtualserver.PutVsVipPortHandler") + } + if o.VirtualserverPutVsVipPortAllowHandler == nil { + unregistered = append(unregistered, "virtualserver.PutVsVipPortAllowHandler") + } + if o.VirtualserverPutVsVipPortDenyHandler == nil { + unregistered = append(unregistered, "virtualserver.PutVsVipPortDenyHandler") + } + if o.VirtualserverPutVsVipPortLaddrHandler == nil { + unregistered = append(unregistered, "virtualserver.PutVsVipPortLaddrHandler") + } + if o.VirtualserverPutVsVipPortRsHandler == nil { + unregistered = append(unregistered, "virtualserver.PutVsVipPortRsHandler") + } + + if len(unregistered) > 0 { + return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", ")) + } + + return nil +} + +// ServeErrorFor gets a error handler for a given operation id +func (o *DpvsAgentAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) { + return o.ServeError +} + +// AuthenticatorsFor gets the authenticators for the specified security schemes +func (o *DpvsAgentAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator { + return nil +} + +// Authorizer returns the registered authorizer +func (o *DpvsAgentAPI) Authorizer() runtime.Authorizer { + return nil +} + +// ConsumersFor gets the consumers for the specified media types. +// MIME type parameters are ignored here. +func (o *DpvsAgentAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer { + result := make(map[string]runtime.Consumer, len(mediaTypes)) + for _, mt := range mediaTypes { + switch mt { + case "application/json": + result["application/json"] = o.JSONConsumer + } + + if c, ok := o.customConsumers[mt]; ok { + result[mt] = c + } + } + return result +} + +// ProducersFor gets the producers for the specified media types. +// MIME type parameters are ignored here. +func (o *DpvsAgentAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer { + result := make(map[string]runtime.Producer, len(mediaTypes)) + for _, mt := range mediaTypes { + switch mt { + case "application/json": + result["application/json"] = o.JSONProducer + } + + if p, ok := o.customProducers[mt]; ok { + result[mt] = p + } + } + return result +} + +// HandlerFor gets a http.Handler for the provided operation method and path +func (o *DpvsAgentAPI) HandlerFor(method, path string) (http.Handler, bool) { + if o.handlers == nil { + return nil, false + } + um := strings.ToUpper(method) + if _, ok := o.handlers[um]; !ok { + return nil, false + } + if path == "/" { + path = "" + } + h, ok := o.handlers[um][path] + return h, ok +} + +// Context returns the middleware context for the dpvs agent API +func (o *DpvsAgentAPI) Context() *middleware.Context { + if o.context == nil { + o.context = middleware.NewRoutableContext(o.spec, o, nil) + } + + return o.context +} + +func (o *DpvsAgentAPI) initHandlerCache() { + o.Context() // don't care about the result, just that the initialization happened + if o.handlers == nil { + o.handlers = make(map[string]map[string]http.Handler) + } + + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/device/{name}/addr"] = device.NewDeleteDeviceNameAddr(o.context, o.DeviceDeleteDeviceNameAddrHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/device/{name}/netlink"] = device.NewDeleteDeviceNameNetlink(o.context, o.DeviceDeleteDeviceNameNetlinkHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/device/{name}/netlink/addr"] = device.NewDeleteDeviceNameNetlinkAddr(o.context, o.DeviceDeleteDeviceNameNetlinkAddrHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/device/{name}/route"] = device.NewDeleteDeviceNameRoute(o.context, o.DeviceDeleteDeviceNameRouteHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/device/{name}/vlan"] = device.NewDeleteDeviceNameVlan(o.context, o.DeviceDeleteDeviceNameVlanHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/vs/{VipPort}"] = virtualserver.NewDeleteVsVipPort(o.context, o.VirtualserverDeleteVsVipPortHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/vs/{VipPort}/allow"] = virtualserver.NewDeleteVsVipPortAllow(o.context, o.VirtualserverDeleteVsVipPortAllowHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/vs/{VipPort}/deny"] = virtualserver.NewDeleteVsVipPortDeny(o.context, o.VirtualserverDeleteVsVipPortDenyHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/vs/{VipPort}/laddr"] = virtualserver.NewDeleteVsVipPortLaddr(o.context, o.VirtualserverDeleteVsVipPortLaddrHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } + o.handlers["DELETE"]["/vs/{VipPort}/rs"] = virtualserver.NewDeleteVsVipPortRs(o.context, o.VirtualserverDeleteVsVipPortRsHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device"] = device.NewGetDevice(o.context, o.DeviceGetDeviceHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/addr"] = device.NewGetDeviceNameAddr(o.context, o.DeviceGetDeviceNameAddrHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/netlink"] = device.NewGetDeviceNameNetlink(o.context, o.DeviceGetDeviceNameNetlinkHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/netlink/addr"] = device.NewGetDeviceNameNetlinkAddr(o.context, o.DeviceGetDeviceNameNetlinkAddrHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/nic"] = device.NewGetDeviceNameNic(o.context, o.DeviceGetDeviceNameNicHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/route"] = device.NewGetDeviceNameRoute(o.context, o.DeviceGetDeviceNameRouteHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/device/{name}/vlan"] = device.NewGetDeviceNameVlan(o.context, o.DeviceGetDeviceNameVlanHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs"] = virtualserver.NewGetVs(o.context, o.VirtualserverGetVsHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs/{VipPort}"] = virtualserver.NewGetVsVipPort(o.context, o.VirtualserverGetVsVipPortHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs/{VipPort}/allow"] = virtualserver.NewGetVsVipPortAllow(o.context, o.VirtualserverGetVsVipPortAllowHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs/{VipPort}/deny"] = virtualserver.NewGetVsVipPortDeny(o.context, o.VirtualserverGetVsVipPortDenyHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs/{VipPort}/laddr"] = virtualserver.NewGetVsVipPortLaddr(o.context, o.VirtualserverGetVsVipPortLaddrHandler) + if o.handlers["GET"] == nil { + o.handlers["GET"] = make(map[string]http.Handler) + } + o.handlers["GET"]["/vs/{VipPort}/rs"] = virtualserver.NewGetVsVipPortRs(o.context, o.VirtualserverGetVsVipPortRsHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/vs/{VipPort}/allow"] = virtualserver.NewPostVsVipPortAllow(o.context, o.VirtualserverPostVsVipPortAllowHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/vs/{VipPort}/deny"] = virtualserver.NewPostVsVipPortDeny(o.context, o.VirtualserverPostVsVipPortDenyHandler) + if o.handlers["POST"] == nil { + o.handlers["POST"] = make(map[string]http.Handler) + } + o.handlers["POST"]["/vs/{VipPort}/rs"] = virtualserver.NewPostVsVipPortRs(o.context, o.VirtualserverPostVsVipPortRsHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/addr"] = device.NewPutDeviceNameAddr(o.context, o.DevicePutDeviceNameAddrHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/netlink"] = device.NewPutDeviceNameNetlink(o.context, o.DevicePutDeviceNameNetlinkHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/netlink/addr"] = device.NewPutDeviceNameNetlinkAddr(o.context, o.DevicePutDeviceNameNetlinkAddrHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/nic"] = device.NewPutDeviceNameNic(o.context, o.DevicePutDeviceNameNicHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/route"] = device.NewPutDeviceNameRoute(o.context, o.DevicePutDeviceNameRouteHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/device/{name}/vlan"] = device.NewPutDeviceNameVlan(o.context, o.DevicePutDeviceNameVlanHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/vs/{VipPort}"] = virtualserver.NewPutVsVipPort(o.context, o.VirtualserverPutVsVipPortHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/vs/{VipPort}/allow"] = virtualserver.NewPutVsVipPortAllow(o.context, o.VirtualserverPutVsVipPortAllowHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/vs/{VipPort}/deny"] = virtualserver.NewPutVsVipPortDeny(o.context, o.VirtualserverPutVsVipPortDenyHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/vs/{VipPort}/laddr"] = virtualserver.NewPutVsVipPortLaddr(o.context, o.VirtualserverPutVsVipPortLaddrHandler) + if o.handlers["PUT"] == nil { + o.handlers["PUT"] = make(map[string]http.Handler) + } + o.handlers["PUT"]["/vs/{VipPort}/rs"] = virtualserver.NewPutVsVipPortRs(o.context, o.VirtualserverPutVsVipPortRsHandler) +} + +// Serve creates a http handler to serve the API over HTTP +// can be used directly in http.ListenAndServe(":8000", api.Serve(nil)) +func (o *DpvsAgentAPI) Serve(builder middleware.Builder) http.Handler { + o.Init() + + if o.Middleware != nil { + return o.Middleware(builder) + } + if o.useSwaggerUI { + return o.context.APIHandlerSwaggerUI(builder) + } + return o.context.APIHandler(builder) +} + +// Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit +func (o *DpvsAgentAPI) Init() { + if len(o.handlers) == 0 { + o.initHandlerCache() + } +} + +// RegisterConsumer allows you to add (or override) a consumer for a media type. +func (o *DpvsAgentAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) { + o.customConsumers[mediaType] = consumer +} + +// RegisterProducer allows you to add (or override) a producer for a media type. +func (o *DpvsAgentAPI) RegisterProducer(mediaType string, producer runtime.Producer) { + o.customProducers[mediaType] = producer +} + +// AddMiddlewareFor adds a http middleware to existing handler +func (o *DpvsAgentAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) { + um := strings.ToUpper(method) + if path == "/" { + path = "" + } + o.Init() + if h, ok := o.handlers[um][path]; ok { + o.handlers[method][path] = builder(h) + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port.go new file mode 100644 index 000000000..14d8bbebd --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteVsVipPortHandlerFunc turns a function with the right signature into a delete vs vip port handler +type DeleteVsVipPortHandlerFunc func(DeleteVsVipPortParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteVsVipPortHandlerFunc) Handle(params DeleteVsVipPortParams) middleware.Responder { + return fn(params) +} + +// DeleteVsVipPortHandler interface for that can handle valid delete vs vip port params +type DeleteVsVipPortHandler interface { + Handle(DeleteVsVipPortParams) middleware.Responder +} + +// NewDeleteVsVipPort creates a new http.Handler for the delete vs vip port operation +func NewDeleteVsVipPort(ctx *middleware.Context, handler DeleteVsVipPortHandler) *DeleteVsVipPort { + return &DeleteVsVipPort{Context: ctx, Handler: handler} +} + +/* + DeleteVsVipPort swagger:route DELETE /vs/{VipPort} virtualserver deleteVsVipPort + +Delete a vip:port:proto +*/ +type DeleteVsVipPort struct { + Context *middleware.Context + Handler DeleteVsVipPortHandler +} + +func (o *DeleteVsVipPort) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteVsVipPortParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow.go new file mode 100644 index 000000000..1aee746da --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteVsVipPortAllowHandlerFunc turns a function with the right signature into a delete vs vip port allow handler +type DeleteVsVipPortAllowHandlerFunc func(DeleteVsVipPortAllowParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteVsVipPortAllowHandlerFunc) Handle(params DeleteVsVipPortAllowParams) middleware.Responder { + return fn(params) +} + +// DeleteVsVipPortAllowHandler interface for that can handle valid delete vs vip port allow params +type DeleteVsVipPortAllowHandler interface { + Handle(DeleteVsVipPortAllowParams) middleware.Responder +} + +// NewDeleteVsVipPortAllow creates a new http.Handler for the delete vs vip port allow operation +func NewDeleteVsVipPortAllow(ctx *middleware.Context, handler DeleteVsVipPortAllowHandler) *DeleteVsVipPortAllow { + return &DeleteVsVipPortAllow{Context: ctx, Handler: handler} +} + +/* + DeleteVsVipPortAllow swagger:route DELETE /vs/{VipPort}/allow virtualserver deleteVsVipPortAllow + +Delete a set of ip form white list to vip:port:proto +*/ +type DeleteVsVipPortAllow struct { + Context *middleware.Context + Handler DeleteVsVipPortAllowHandler +} + +func (o *DeleteVsVipPortAllow) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteVsVipPortAllowParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_parameters.go new file mode 100644 index 000000000..532017c51 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteVsVipPortAllowParams creates a new DeleteVsVipPortAllowParams object +// +// There are no default values defined in the spec. +func NewDeleteVsVipPortAllowParams() DeleteVsVipPortAllowParams { + + return DeleteVsVipPortAllowParams{} +} + +// DeleteVsVipPortAllowParams contains all the bound params for the delete vs vip port allow operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteVsVipPortAllow +type DeleteVsVipPortAllowParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteVsVipPortAllowParams() beforehand. +func (o *DeleteVsVipPortAllowParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *DeleteVsVipPortAllowParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_responses.go new file mode 100644 index 000000000..03337c63d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_responses.go @@ -0,0 +1,211 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// DeleteVsVipPortAllowOKCode is the HTTP code returned for type DeleteVsVipPortAllowOK +const DeleteVsVipPortAllowOKCode int = 200 + +/* +DeleteVsVipPortAllowOK Success + +swagger:response deleteVsVipPortAllowOK +*/ +type DeleteVsVipPortAllowOK struct { +} + +// NewDeleteVsVipPortAllowOK creates DeleteVsVipPortAllowOK with default headers values +func NewDeleteVsVipPortAllowOK() *DeleteVsVipPortAllowOK { + + return &DeleteVsVipPortAllowOK{} +} + +// WriteResponse to the client +func (o *DeleteVsVipPortAllowOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(200) +} + +// DeleteVsVipPortAllowNotFoundCode is the HTTP code returned for type DeleteVsVipPortAllowNotFound +const DeleteVsVipPortAllowNotFoundCode int = 404 + +/* +DeleteVsVipPortAllowNotFound Service not found + +swagger:response deleteVsVipPortAllowNotFound +*/ +type DeleteVsVipPortAllowNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortAllowNotFound creates DeleteVsVipPortAllowNotFound with default headers values +func NewDeleteVsVipPortAllowNotFound() *DeleteVsVipPortAllowNotFound { + + return &DeleteVsVipPortAllowNotFound{} +} + +// WithPayload adds the payload to the delete vs vip port allow not found response +func (o *DeleteVsVipPortAllowNotFound) WithPayload(payload string) *DeleteVsVipPortAllowNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port allow not found response +func (o *DeleteVsVipPortAllowNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortAllowNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortAllowInvalidFrontendCode is the HTTP code returned for type DeleteVsVipPortAllowInvalidFrontend +const DeleteVsVipPortAllowInvalidFrontendCode int = 460 + +/* +DeleteVsVipPortAllowInvalidFrontend Invalid frontend in service configuration + +swagger:response deleteVsVipPortAllowInvalidFrontend +*/ +type DeleteVsVipPortAllowInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortAllowInvalidFrontend creates DeleteVsVipPortAllowInvalidFrontend with default headers values +func NewDeleteVsVipPortAllowInvalidFrontend() *DeleteVsVipPortAllowInvalidFrontend { + + return &DeleteVsVipPortAllowInvalidFrontend{} +} + +// WithPayload adds the payload to the delete vs vip port allow invalid frontend response +func (o *DeleteVsVipPortAllowInvalidFrontend) WithPayload(payload models.Error) *DeleteVsVipPortAllowInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port allow invalid frontend response +func (o *DeleteVsVipPortAllowInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortAllowInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortAllowInvalidBackendCode is the HTTP code returned for type DeleteVsVipPortAllowInvalidBackend +const DeleteVsVipPortAllowInvalidBackendCode int = 461 + +/* +DeleteVsVipPortAllowInvalidBackend Invalid backend in service configuration + +swagger:response deleteVsVipPortAllowInvalidBackend +*/ +type DeleteVsVipPortAllowInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortAllowInvalidBackend creates DeleteVsVipPortAllowInvalidBackend with default headers values +func NewDeleteVsVipPortAllowInvalidBackend() *DeleteVsVipPortAllowInvalidBackend { + + return &DeleteVsVipPortAllowInvalidBackend{} +} + +// WithPayload adds the payload to the delete vs vip port allow invalid backend response +func (o *DeleteVsVipPortAllowInvalidBackend) WithPayload(payload models.Error) *DeleteVsVipPortAllowInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port allow invalid backend response +func (o *DeleteVsVipPortAllowInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortAllowInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortAllowFailureCode is the HTTP code returned for type DeleteVsVipPortAllowFailure +const DeleteVsVipPortAllowFailureCode int = 500 + +/* +DeleteVsVipPortAllowFailure Service deletion failed + +swagger:response deleteVsVipPortAllowFailure +*/ +type DeleteVsVipPortAllowFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortAllowFailure creates DeleteVsVipPortAllowFailure with default headers values +func NewDeleteVsVipPortAllowFailure() *DeleteVsVipPortAllowFailure { + + return &DeleteVsVipPortAllowFailure{} +} + +// WithPayload adds the payload to the delete vs vip port allow failure response +func (o *DeleteVsVipPortAllowFailure) WithPayload(payload models.Error) *DeleteVsVipPortAllowFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port allow failure response +func (o *DeleteVsVipPortAllowFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortAllowFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_urlbuilder.go new file mode 100644 index 000000000..bb48d3228 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_allow_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteVsVipPortAllowURL generates an URL for the delete vs vip port allow operation +type DeleteVsVipPortAllowURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortAllowURL) WithBasePath(bp string) *DeleteVsVipPortAllowURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortAllowURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteVsVipPortAllowURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/allow" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on DeleteVsVipPortAllowURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteVsVipPortAllowURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteVsVipPortAllowURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteVsVipPortAllowURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteVsVipPortAllowURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteVsVipPortAllowURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteVsVipPortAllowURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny.go new file mode 100644 index 000000000..93c81f5b4 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteVsVipPortDenyHandlerFunc turns a function with the right signature into a delete vs vip port deny handler +type DeleteVsVipPortDenyHandlerFunc func(DeleteVsVipPortDenyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteVsVipPortDenyHandlerFunc) Handle(params DeleteVsVipPortDenyParams) middleware.Responder { + return fn(params) +} + +// DeleteVsVipPortDenyHandler interface for that can handle valid delete vs vip port deny params +type DeleteVsVipPortDenyHandler interface { + Handle(DeleteVsVipPortDenyParams) middleware.Responder +} + +// NewDeleteVsVipPortDeny creates a new http.Handler for the delete vs vip port deny operation +func NewDeleteVsVipPortDeny(ctx *middleware.Context, handler DeleteVsVipPortDenyHandler) *DeleteVsVipPortDeny { + return &DeleteVsVipPortDeny{Context: ctx, Handler: handler} +} + +/* + DeleteVsVipPortDeny swagger:route DELETE /vs/{VipPort}/deny virtualserver deleteVsVipPortDeny + +Delete a set of ip form black list to vip:port:proto +*/ +type DeleteVsVipPortDeny struct { + Context *middleware.Context + Handler DeleteVsVipPortDenyHandler +} + +func (o *DeleteVsVipPortDeny) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteVsVipPortDenyParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_parameters.go new file mode 100644 index 000000000..b01bc07e9 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteVsVipPortDenyParams creates a new DeleteVsVipPortDenyParams object +// +// There are no default values defined in the spec. +func NewDeleteVsVipPortDenyParams() DeleteVsVipPortDenyParams { + + return DeleteVsVipPortDenyParams{} +} + +// DeleteVsVipPortDenyParams contains all the bound params for the delete vs vip port deny operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteVsVipPortDeny +type DeleteVsVipPortDenyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteVsVipPortDenyParams() beforehand. +func (o *DeleteVsVipPortDenyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *DeleteVsVipPortDenyParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_responses.go new file mode 100644 index 000000000..05c87233f --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_responses.go @@ -0,0 +1,211 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// DeleteVsVipPortDenyOKCode is the HTTP code returned for type DeleteVsVipPortDenyOK +const DeleteVsVipPortDenyOKCode int = 200 + +/* +DeleteVsVipPortDenyOK Success + +swagger:response deleteVsVipPortDenyOK +*/ +type DeleteVsVipPortDenyOK struct { +} + +// NewDeleteVsVipPortDenyOK creates DeleteVsVipPortDenyOK with default headers values +func NewDeleteVsVipPortDenyOK() *DeleteVsVipPortDenyOK { + + return &DeleteVsVipPortDenyOK{} +} + +// WriteResponse to the client +func (o *DeleteVsVipPortDenyOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(200) +} + +// DeleteVsVipPortDenyNotFoundCode is the HTTP code returned for type DeleteVsVipPortDenyNotFound +const DeleteVsVipPortDenyNotFoundCode int = 404 + +/* +DeleteVsVipPortDenyNotFound Service not found + +swagger:response deleteVsVipPortDenyNotFound +*/ +type DeleteVsVipPortDenyNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortDenyNotFound creates DeleteVsVipPortDenyNotFound with default headers values +func NewDeleteVsVipPortDenyNotFound() *DeleteVsVipPortDenyNotFound { + + return &DeleteVsVipPortDenyNotFound{} +} + +// WithPayload adds the payload to the delete vs vip port deny not found response +func (o *DeleteVsVipPortDenyNotFound) WithPayload(payload string) *DeleteVsVipPortDenyNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port deny not found response +func (o *DeleteVsVipPortDenyNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortDenyNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortDenyInvalidFrontendCode is the HTTP code returned for type DeleteVsVipPortDenyInvalidFrontend +const DeleteVsVipPortDenyInvalidFrontendCode int = 460 + +/* +DeleteVsVipPortDenyInvalidFrontend Invalid frontend in service configuration + +swagger:response deleteVsVipPortDenyInvalidFrontend +*/ +type DeleteVsVipPortDenyInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortDenyInvalidFrontend creates DeleteVsVipPortDenyInvalidFrontend with default headers values +func NewDeleteVsVipPortDenyInvalidFrontend() *DeleteVsVipPortDenyInvalidFrontend { + + return &DeleteVsVipPortDenyInvalidFrontend{} +} + +// WithPayload adds the payload to the delete vs vip port deny invalid frontend response +func (o *DeleteVsVipPortDenyInvalidFrontend) WithPayload(payload models.Error) *DeleteVsVipPortDenyInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port deny invalid frontend response +func (o *DeleteVsVipPortDenyInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortDenyInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortDenyInvalidBackendCode is the HTTP code returned for type DeleteVsVipPortDenyInvalidBackend +const DeleteVsVipPortDenyInvalidBackendCode int = 461 + +/* +DeleteVsVipPortDenyInvalidBackend Invalid backend in service configuration + +swagger:response deleteVsVipPortDenyInvalidBackend +*/ +type DeleteVsVipPortDenyInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortDenyInvalidBackend creates DeleteVsVipPortDenyInvalidBackend with default headers values +func NewDeleteVsVipPortDenyInvalidBackend() *DeleteVsVipPortDenyInvalidBackend { + + return &DeleteVsVipPortDenyInvalidBackend{} +} + +// WithPayload adds the payload to the delete vs vip port deny invalid backend response +func (o *DeleteVsVipPortDenyInvalidBackend) WithPayload(payload models.Error) *DeleteVsVipPortDenyInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port deny invalid backend response +func (o *DeleteVsVipPortDenyInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortDenyInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortDenyFailureCode is the HTTP code returned for type DeleteVsVipPortDenyFailure +const DeleteVsVipPortDenyFailureCode int = 500 + +/* +DeleteVsVipPortDenyFailure Service deletion failed + +swagger:response deleteVsVipPortDenyFailure +*/ +type DeleteVsVipPortDenyFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortDenyFailure creates DeleteVsVipPortDenyFailure with default headers values +func NewDeleteVsVipPortDenyFailure() *DeleteVsVipPortDenyFailure { + + return &DeleteVsVipPortDenyFailure{} +} + +// WithPayload adds the payload to the delete vs vip port deny failure response +func (o *DeleteVsVipPortDenyFailure) WithPayload(payload models.Error) *DeleteVsVipPortDenyFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port deny failure response +func (o *DeleteVsVipPortDenyFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortDenyFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_urlbuilder.go new file mode 100644 index 000000000..3254ab8a7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_deny_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteVsVipPortDenyURL generates an URL for the delete vs vip port deny operation +type DeleteVsVipPortDenyURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortDenyURL) WithBasePath(bp string) *DeleteVsVipPortDenyURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortDenyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteVsVipPortDenyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/deny" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on DeleteVsVipPortDenyURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteVsVipPortDenyURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteVsVipPortDenyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteVsVipPortDenyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteVsVipPortDenyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteVsVipPortDenyURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteVsVipPortDenyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr.go new file mode 100644 index 000000000..d29b0e7c4 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteVsVipPortLaddrHandlerFunc turns a function with the right signature into a delete vs vip port laddr handler +type DeleteVsVipPortLaddrHandlerFunc func(DeleteVsVipPortLaddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteVsVipPortLaddrHandlerFunc) Handle(params DeleteVsVipPortLaddrParams) middleware.Responder { + return fn(params) +} + +// DeleteVsVipPortLaddrHandler interface for that can handle valid delete vs vip port laddr params +type DeleteVsVipPortLaddrHandler interface { + Handle(DeleteVsVipPortLaddrParams) middleware.Responder +} + +// NewDeleteVsVipPortLaddr creates a new http.Handler for the delete vs vip port laddr operation +func NewDeleteVsVipPortLaddr(ctx *middleware.Context, handler DeleteVsVipPortLaddrHandler) *DeleteVsVipPortLaddr { + return &DeleteVsVipPortLaddr{Context: ctx, Handler: handler} +} + +/* + DeleteVsVipPortLaddr swagger:route DELETE /vs/{VipPort}/laddr virtualserver deleteVsVipPortLaddr + +DeleteVsVipPortLaddr delete vs vip port laddr API +*/ +type DeleteVsVipPortLaddr struct { + Context *middleware.Context + Handler DeleteVsVipPortLaddrHandler +} + +func (o *DeleteVsVipPortLaddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteVsVipPortLaddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_parameters.go new file mode 100644 index 000000000..33498eedc --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteVsVipPortLaddrParams creates a new DeleteVsVipPortLaddrParams object +// +// There are no default values defined in the spec. +func NewDeleteVsVipPortLaddrParams() DeleteVsVipPortLaddrParams { + + return DeleteVsVipPortLaddrParams{} +} + +// DeleteVsVipPortLaddrParams contains all the bound params for the delete vs vip port laddr operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteVsVipPortLaddr +type DeleteVsVipPortLaddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + Spec *models.LocalAddressSpecTiny +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteVsVipPortLaddrParams() beforehand. +func (o *DeleteVsVipPortLaddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.LocalAddressSpecTiny + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *DeleteVsVipPortLaddrParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_responses.go new file mode 100644 index 000000000..7b474dc5a --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_responses.go @@ -0,0 +1,186 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// DeleteVsVipPortLaddrOKCode is the HTTP code returned for type DeleteVsVipPortLaddrOK +const DeleteVsVipPortLaddrOKCode int = 200 + +/* +DeleteVsVipPortLaddrOK Success + +swagger:response deleteVsVipPortLaddrOK +*/ +type DeleteVsVipPortLaddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortLaddrOK creates DeleteVsVipPortLaddrOK with default headers values +func NewDeleteVsVipPortLaddrOK() *DeleteVsVipPortLaddrOK { + + return &DeleteVsVipPortLaddrOK{} +} + +// WithPayload adds the payload to the delete vs vip port laddr o k response +func (o *DeleteVsVipPortLaddrOK) WithPayload(payload string) *DeleteVsVipPortLaddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port laddr o k response +func (o *DeleteVsVipPortLaddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortLaddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortLaddrInvalidFrontendCode is the HTTP code returned for type DeleteVsVipPortLaddrInvalidFrontend +const DeleteVsVipPortLaddrInvalidFrontendCode int = 460 + +/* +DeleteVsVipPortLaddrInvalidFrontend Invalid frontend in service configuration + +swagger:response deleteVsVipPortLaddrInvalidFrontend +*/ +type DeleteVsVipPortLaddrInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortLaddrInvalidFrontend creates DeleteVsVipPortLaddrInvalidFrontend with default headers values +func NewDeleteVsVipPortLaddrInvalidFrontend() *DeleteVsVipPortLaddrInvalidFrontend { + + return &DeleteVsVipPortLaddrInvalidFrontend{} +} + +// WithPayload adds the payload to the delete vs vip port laddr invalid frontend response +func (o *DeleteVsVipPortLaddrInvalidFrontend) WithPayload(payload models.Error) *DeleteVsVipPortLaddrInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port laddr invalid frontend response +func (o *DeleteVsVipPortLaddrInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortLaddrInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortLaddrInvalidBackendCode is the HTTP code returned for type DeleteVsVipPortLaddrInvalidBackend +const DeleteVsVipPortLaddrInvalidBackendCode int = 461 + +/* +DeleteVsVipPortLaddrInvalidBackend Invalid backend in service configuration + +swagger:response deleteVsVipPortLaddrInvalidBackend +*/ +type DeleteVsVipPortLaddrInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortLaddrInvalidBackend creates DeleteVsVipPortLaddrInvalidBackend with default headers values +func NewDeleteVsVipPortLaddrInvalidBackend() *DeleteVsVipPortLaddrInvalidBackend { + + return &DeleteVsVipPortLaddrInvalidBackend{} +} + +// WithPayload adds the payload to the delete vs vip port laddr invalid backend response +func (o *DeleteVsVipPortLaddrInvalidBackend) WithPayload(payload models.Error) *DeleteVsVipPortLaddrInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port laddr invalid backend response +func (o *DeleteVsVipPortLaddrInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortLaddrInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortLaddrFailureCode is the HTTP code returned for type DeleteVsVipPortLaddrFailure +const DeleteVsVipPortLaddrFailureCode int = 500 + +/* +DeleteVsVipPortLaddrFailure Error while creating virtual server + +swagger:response deleteVsVipPortLaddrFailure +*/ +type DeleteVsVipPortLaddrFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortLaddrFailure creates DeleteVsVipPortLaddrFailure with default headers values +func NewDeleteVsVipPortLaddrFailure() *DeleteVsVipPortLaddrFailure { + + return &DeleteVsVipPortLaddrFailure{} +} + +// WithPayload adds the payload to the delete vs vip port laddr failure response +func (o *DeleteVsVipPortLaddrFailure) WithPayload(payload models.Error) *DeleteVsVipPortLaddrFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port laddr failure response +func (o *DeleteVsVipPortLaddrFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortLaddrFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_urlbuilder.go new file mode 100644 index 000000000..4926a3d0c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_laddr_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteVsVipPortLaddrURL generates an URL for the delete vs vip port laddr operation +type DeleteVsVipPortLaddrURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortLaddrURL) WithBasePath(bp string) *DeleteVsVipPortLaddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortLaddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteVsVipPortLaddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/laddr" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on DeleteVsVipPortLaddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteVsVipPortLaddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteVsVipPortLaddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteVsVipPortLaddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteVsVipPortLaddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteVsVipPortLaddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteVsVipPortLaddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_parameters.go new file mode 100644 index 000000000..d8e528348 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewDeleteVsVipPortParams creates a new DeleteVsVipPortParams object +// +// There are no default values defined in the spec. +func NewDeleteVsVipPortParams() DeleteVsVipPortParams { + + return DeleteVsVipPortParams{} +} + +// DeleteVsVipPortParams contains all the bound params for the delete vs vip port operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteVsVipPort +type DeleteVsVipPortParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteVsVipPortParams() beforehand. +func (o *DeleteVsVipPortParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *DeleteVsVipPortParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_responses.go new file mode 100644 index 000000000..f423fd023 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_responses.go @@ -0,0 +1,143 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// DeleteVsVipPortOKCode is the HTTP code returned for type DeleteVsVipPortOK +const DeleteVsVipPortOKCode int = 200 + +/* +DeleteVsVipPortOK Success + +swagger:response deleteVsVipPortOK +*/ +type DeleteVsVipPortOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortOK creates DeleteVsVipPortOK with default headers values +func NewDeleteVsVipPortOK() *DeleteVsVipPortOK { + + return &DeleteVsVipPortOK{} +} + +// WithPayload adds the payload to the delete vs vip port o k response +func (o *DeleteVsVipPortOK) WithPayload(payload string) *DeleteVsVipPortOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port o k response +func (o *DeleteVsVipPortOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortNotFoundCode is the HTTP code returned for type DeleteVsVipPortNotFound +const DeleteVsVipPortNotFoundCode int = 404 + +/* +DeleteVsVipPortNotFound Service not found + +swagger:response deleteVsVipPortNotFound +*/ +type DeleteVsVipPortNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortNotFound creates DeleteVsVipPortNotFound with default headers values +func NewDeleteVsVipPortNotFound() *DeleteVsVipPortNotFound { + + return &DeleteVsVipPortNotFound{} +} + +// WithPayload adds the payload to the delete vs vip port not found response +func (o *DeleteVsVipPortNotFound) WithPayload(payload string) *DeleteVsVipPortNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port not found response +func (o *DeleteVsVipPortNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortFailureCode is the HTTP code returned for type DeleteVsVipPortFailure +const DeleteVsVipPortFailureCode int = 500 + +/* +DeleteVsVipPortFailure Service deletion failed + +swagger:response deleteVsVipPortFailure +*/ +type DeleteVsVipPortFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortFailure creates DeleteVsVipPortFailure with default headers values +func NewDeleteVsVipPortFailure() *DeleteVsVipPortFailure { + + return &DeleteVsVipPortFailure{} +} + +// WithPayload adds the payload to the delete vs vip port failure response +func (o *DeleteVsVipPortFailure) WithPayload(payload models.Error) *DeleteVsVipPortFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port failure response +func (o *DeleteVsVipPortFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs.go new file mode 100644 index 000000000..1598ebfbf --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteVsVipPortRsHandlerFunc turns a function with the right signature into a delete vs vip port rs handler +type DeleteVsVipPortRsHandlerFunc func(DeleteVsVipPortRsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteVsVipPortRsHandlerFunc) Handle(params DeleteVsVipPortRsParams) middleware.Responder { + return fn(params) +} + +// DeleteVsVipPortRsHandler interface for that can handle valid delete vs vip port rs params +type DeleteVsVipPortRsHandler interface { + Handle(DeleteVsVipPortRsParams) middleware.Responder +} + +// NewDeleteVsVipPortRs creates a new http.Handler for the delete vs vip port rs operation +func NewDeleteVsVipPortRs(ctx *middleware.Context, handler DeleteVsVipPortRsHandler) *DeleteVsVipPortRs { + return &DeleteVsVipPortRs{Context: ctx, Handler: handler} +} + +/* + DeleteVsVipPortRs swagger:route DELETE /vs/{VipPort}/rs virtualserver deleteVsVipPortRs + +Delete a set of real server from vip:port:proto +*/ +type DeleteVsVipPortRs struct { + Context *middleware.Context + Handler DeleteVsVipPortRsHandler +} + +func (o *DeleteVsVipPortRs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteVsVipPortRsParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_parameters.go new file mode 100644 index 000000000..f643ff30e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewDeleteVsVipPortRsParams creates a new DeleteVsVipPortRsParams object +// +// There are no default values defined in the spec. +func NewDeleteVsVipPortRsParams() DeleteVsVipPortRsParams { + + return DeleteVsVipPortRsParams{} +} + +// DeleteVsVipPortRsParams contains all the bound params for the delete vs vip port rs operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteVsVipPortRs +type DeleteVsVipPortRsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + Rss *models.RealServerTinyList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewDeleteVsVipPortRsParams() beforehand. +func (o *DeleteVsVipPortRsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.RealServerTinyList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("rss", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Rss = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *DeleteVsVipPortRsParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_responses.go new file mode 100644 index 000000000..e51843937 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_responses.go @@ -0,0 +1,211 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// DeleteVsVipPortRsOKCode is the HTTP code returned for type DeleteVsVipPortRsOK +const DeleteVsVipPortRsOKCode int = 200 + +/* +DeleteVsVipPortRsOK Success + +swagger:response deleteVsVipPortRsOK +*/ +type DeleteVsVipPortRsOK struct { +} + +// NewDeleteVsVipPortRsOK creates DeleteVsVipPortRsOK with default headers values +func NewDeleteVsVipPortRsOK() *DeleteVsVipPortRsOK { + + return &DeleteVsVipPortRsOK{} +} + +// WriteResponse to the client +func (o *DeleteVsVipPortRsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(200) +} + +// DeleteVsVipPortRsNotFoundCode is the HTTP code returned for type DeleteVsVipPortRsNotFound +const DeleteVsVipPortRsNotFoundCode int = 404 + +/* +DeleteVsVipPortRsNotFound Service not found + +swagger:response deleteVsVipPortRsNotFound +*/ +type DeleteVsVipPortRsNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewDeleteVsVipPortRsNotFound creates DeleteVsVipPortRsNotFound with default headers values +func NewDeleteVsVipPortRsNotFound() *DeleteVsVipPortRsNotFound { + + return &DeleteVsVipPortRsNotFound{} +} + +// WithPayload adds the payload to the delete vs vip port rs not found response +func (o *DeleteVsVipPortRsNotFound) WithPayload(payload string) *DeleteVsVipPortRsNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port rs not found response +func (o *DeleteVsVipPortRsNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortRsNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortRsInvalidFrontendCode is the HTTP code returned for type DeleteVsVipPortRsInvalidFrontend +const DeleteVsVipPortRsInvalidFrontendCode int = 460 + +/* +DeleteVsVipPortRsInvalidFrontend Invalid frontend in service configuration + +swagger:response deleteVsVipPortRsInvalidFrontend +*/ +type DeleteVsVipPortRsInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortRsInvalidFrontend creates DeleteVsVipPortRsInvalidFrontend with default headers values +func NewDeleteVsVipPortRsInvalidFrontend() *DeleteVsVipPortRsInvalidFrontend { + + return &DeleteVsVipPortRsInvalidFrontend{} +} + +// WithPayload adds the payload to the delete vs vip port rs invalid frontend response +func (o *DeleteVsVipPortRsInvalidFrontend) WithPayload(payload models.Error) *DeleteVsVipPortRsInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port rs invalid frontend response +func (o *DeleteVsVipPortRsInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortRsInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortRsInvalidBackendCode is the HTTP code returned for type DeleteVsVipPortRsInvalidBackend +const DeleteVsVipPortRsInvalidBackendCode int = 461 + +/* +DeleteVsVipPortRsInvalidBackend Invalid backend in service configuration + +swagger:response deleteVsVipPortRsInvalidBackend +*/ +type DeleteVsVipPortRsInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortRsInvalidBackend creates DeleteVsVipPortRsInvalidBackend with default headers values +func NewDeleteVsVipPortRsInvalidBackend() *DeleteVsVipPortRsInvalidBackend { + + return &DeleteVsVipPortRsInvalidBackend{} +} + +// WithPayload adds the payload to the delete vs vip port rs invalid backend response +func (o *DeleteVsVipPortRsInvalidBackend) WithPayload(payload models.Error) *DeleteVsVipPortRsInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port rs invalid backend response +func (o *DeleteVsVipPortRsInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortRsInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// DeleteVsVipPortRsFailureCode is the HTTP code returned for type DeleteVsVipPortRsFailure +const DeleteVsVipPortRsFailureCode int = 500 + +/* +DeleteVsVipPortRsFailure Service deletion failed + +swagger:response deleteVsVipPortRsFailure +*/ +type DeleteVsVipPortRsFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewDeleteVsVipPortRsFailure creates DeleteVsVipPortRsFailure with default headers values +func NewDeleteVsVipPortRsFailure() *DeleteVsVipPortRsFailure { + + return &DeleteVsVipPortRsFailure{} +} + +// WithPayload adds the payload to the delete vs vip port rs failure response +func (o *DeleteVsVipPortRsFailure) WithPayload(payload models.Error) *DeleteVsVipPortRsFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete vs vip port rs failure response +func (o *DeleteVsVipPortRsFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteVsVipPortRsFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_urlbuilder.go new file mode 100644 index 000000000..074cd0068 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_rs_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteVsVipPortRsURL generates an URL for the delete vs vip port rs operation +type DeleteVsVipPortRsURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortRsURL) WithBasePath(bp string) *DeleteVsVipPortRsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortRsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteVsVipPortRsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/rs" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on DeleteVsVipPortRsURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteVsVipPortRsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteVsVipPortRsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteVsVipPortRsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteVsVipPortRsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteVsVipPortRsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteVsVipPortRsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_urlbuilder.go new file mode 100644 index 000000000..44d932d71 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/delete_vs_vip_port_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// DeleteVsVipPortURL generates an URL for the delete vs vip port operation +type DeleteVsVipPortURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortURL) WithBasePath(bp string) *DeleteVsVipPortURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *DeleteVsVipPortURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteVsVipPortURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on DeleteVsVipPortURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *DeleteVsVipPortURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *DeleteVsVipPortURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteVsVipPortURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteVsVipPortURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteVsVipPortURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *DeleteVsVipPortURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs.go new file mode 100644 index 000000000..1e82546f7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsHandlerFunc turns a function with the right signature into a get vs handler +type GetVsHandlerFunc func(GetVsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsHandlerFunc) Handle(params GetVsParams) middleware.Responder { + return fn(params) +} + +// GetVsHandler interface for that can handle valid get vs params +type GetVsHandler interface { + Handle(GetVsParams) middleware.Responder +} + +// NewGetVs creates a new http.Handler for the get vs operation +func NewGetVs(ctx *middleware.Context, handler GetVsHandler) *GetVs { + return &GetVs{Context: ctx, Handler: handler} +} + +/* + GetVs swagger:route GET /vs virtualserver getVs + +display all vip:port:proto and rsip:port list +*/ +type GetVs struct { + Context *middleware.Context + Handler GetVsHandler +} + +func (o *GetVs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_parameters.go new file mode 100644 index 000000000..ac28ba465 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_parameters.go @@ -0,0 +1,92 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetVsParams creates a new GetVsParams object +// with the default values initialized. +func NewGetVsParams() GetVsParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetVsParams{ + Stats: &statsDefault, + } +} + +// GetVsParams contains all the bound params for the get vs operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVs +type GetVsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsParams() beforehand. +func (o *GetVsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetVsParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetVsParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_responses.go new file mode 100644 index 000000000..c67eec7a7 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_responses.go @@ -0,0 +1,59 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// GetVsOKCode is the HTTP code returned for type GetVsOK +const GetVsOKCode int = 200 + +/* +GetVsOK Success + +swagger:response getVsOK +*/ +type GetVsOK struct { + + /* + In: Body + */ + Payload *models.VirtualServerList `json:"body,omitempty"` +} + +// NewGetVsOK creates GetVsOK with default headers values +func NewGetVsOK() *GetVsOK { + + return &GetVsOK{} +} + +// WithPayload adds the payload to the get vs o k response +func (o *GetVsOK) WithPayload(payload *models.VirtualServerList) *GetVsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs o k response +func (o *GetVsOK) SetPayload(payload *models.VirtualServerList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_urlbuilder.go new file mode 100644 index 000000000..917308dcf --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_urlbuilder.go @@ -0,0 +1,105 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + + "github.com/go-openapi/swag" +) + +// GetVsURL generates an URL for the get vs operation +type GetVsURL struct { + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsURL) WithBasePath(bp string) *GetVsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port.go new file mode 100644 index 000000000..f7e02c0d4 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsVipPortHandlerFunc turns a function with the right signature into a get vs vip port handler +type GetVsVipPortHandlerFunc func(GetVsVipPortParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsVipPortHandlerFunc) Handle(params GetVsVipPortParams) middleware.Responder { + return fn(params) +} + +// GetVsVipPortHandler interface for that can handle valid get vs vip port params +type GetVsVipPortHandler interface { + Handle(GetVsVipPortParams) middleware.Responder +} + +// NewGetVsVipPort creates a new http.Handler for the get vs vip port operation +func NewGetVsVipPort(ctx *middleware.Context, handler GetVsVipPortHandler) *GetVsVipPort { + return &GetVsVipPort{Context: ctx, Handler: handler} +} + +/* + GetVsVipPort swagger:route GET /vs/{VipPort} virtualserver getVsVipPort + +get a specific virtual server +*/ +type GetVsVipPort struct { + Context *middleware.Context + Handler GetVsVipPortHandler +} + +func (o *GetVsVipPort) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsVipPortParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow.go new file mode 100644 index 000000000..267a01e25 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsVipPortAllowHandlerFunc turns a function with the right signature into a get vs vip port allow handler +type GetVsVipPortAllowHandlerFunc func(GetVsVipPortAllowParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsVipPortAllowHandlerFunc) Handle(params GetVsVipPortAllowParams) middleware.Responder { + return fn(params) +} + +// GetVsVipPortAllowHandler interface for that can handle valid get vs vip port allow params +type GetVsVipPortAllowHandler interface { + Handle(GetVsVipPortAllowParams) middleware.Responder +} + +// NewGetVsVipPortAllow creates a new http.Handler for the get vs vip port allow operation +func NewGetVsVipPortAllow(ctx *middleware.Context, handler GetVsVipPortAllowHandler) *GetVsVipPortAllow { + return &GetVsVipPortAllow{Context: ctx, Handler: handler} +} + +/* + GetVsVipPortAllow swagger:route GET /vs/{VipPort}/allow virtualserver getVsVipPortAllow + +GetVsVipPortAllow get vs vip port allow API +*/ +type GetVsVipPortAllow struct { + Context *middleware.Context + Handler GetVsVipPortAllowHandler +} + +func (o *GetVsVipPortAllow) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsVipPortAllowParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_parameters.go new file mode 100644 index 000000000..df1e98ae2 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewGetVsVipPortAllowParams creates a new GetVsVipPortAllowParams object +// +// There are no default values defined in the spec. +func NewGetVsVipPortAllowParams() GetVsVipPortAllowParams { + + return GetVsVipPortAllowParams{} +} + +// GetVsVipPortAllowParams contains all the bound params for the get vs vip port allow operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVsVipPortAllow +type GetVsVipPortAllowParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsVipPortAllowParams() beforehand. +func (o *GetVsVipPortAllowParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *GetVsVipPortAllowParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_responses.go new file mode 100644 index 000000000..21f2eb892 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetVsVipPortAllowOKCode is the HTTP code returned for type GetVsVipPortAllowOK +const GetVsVipPortAllowOKCode int = 200 + +/* +GetVsVipPortAllowOK Success + +swagger:response getVsVipPortAllowOK +*/ +type GetVsVipPortAllowOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortAllowOK creates GetVsVipPortAllowOK with default headers values +func NewGetVsVipPortAllowOK() *GetVsVipPortAllowOK { + + return &GetVsVipPortAllowOK{} +} + +// WithPayload adds the payload to the get vs vip port allow o k response +func (o *GetVsVipPortAllowOK) WithPayload(payload string) *GetVsVipPortAllowOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port allow o k response +func (o *GetVsVipPortAllowOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortAllowOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetVsVipPortAllowNotFoundCode is the HTTP code returned for type GetVsVipPortAllowNotFound +const GetVsVipPortAllowNotFoundCode int = 404 + +/* +GetVsVipPortAllowNotFound Service not found + +swagger:response getVsVipPortAllowNotFound +*/ +type GetVsVipPortAllowNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortAllowNotFound creates GetVsVipPortAllowNotFound with default headers values +func NewGetVsVipPortAllowNotFound() *GetVsVipPortAllowNotFound { + + return &GetVsVipPortAllowNotFound{} +} + +// WithPayload adds the payload to the get vs vip port allow not found response +func (o *GetVsVipPortAllowNotFound) WithPayload(payload string) *GetVsVipPortAllowNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port allow not found response +func (o *GetVsVipPortAllowNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortAllowNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_urlbuilder.go new file mode 100644 index 000000000..9f00c3d27 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_allow_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// GetVsVipPortAllowURL generates an URL for the get vs vip port allow operation +type GetVsVipPortAllowURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortAllowURL) WithBasePath(bp string) *GetVsVipPortAllowURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortAllowURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsVipPortAllowURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/allow" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on GetVsVipPortAllowURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsVipPortAllowURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsVipPortAllowURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsVipPortAllowURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsVipPortAllowURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsVipPortAllowURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsVipPortAllowURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny.go new file mode 100644 index 000000000..92631c107 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsVipPortDenyHandlerFunc turns a function with the right signature into a get vs vip port deny handler +type GetVsVipPortDenyHandlerFunc func(GetVsVipPortDenyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsVipPortDenyHandlerFunc) Handle(params GetVsVipPortDenyParams) middleware.Responder { + return fn(params) +} + +// GetVsVipPortDenyHandler interface for that can handle valid get vs vip port deny params +type GetVsVipPortDenyHandler interface { + Handle(GetVsVipPortDenyParams) middleware.Responder +} + +// NewGetVsVipPortDeny creates a new http.Handler for the get vs vip port deny operation +func NewGetVsVipPortDeny(ctx *middleware.Context, handler GetVsVipPortDenyHandler) *GetVsVipPortDeny { + return &GetVsVipPortDeny{Context: ctx, Handler: handler} +} + +/* + GetVsVipPortDeny swagger:route GET /vs/{VipPort}/deny virtualserver getVsVipPortDeny + +GetVsVipPortDeny get vs vip port deny API +*/ +type GetVsVipPortDeny struct { + Context *middleware.Context + Handler GetVsVipPortDenyHandler +} + +func (o *GetVsVipPortDeny) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsVipPortDenyParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_parameters.go new file mode 100644 index 000000000..3e8046c1e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_parameters.go @@ -0,0 +1,71 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" +) + +// NewGetVsVipPortDenyParams creates a new GetVsVipPortDenyParams object +// +// There are no default values defined in the spec. +func NewGetVsVipPortDenyParams() GetVsVipPortDenyParams { + + return GetVsVipPortDenyParams{} +} + +// GetVsVipPortDenyParams contains all the bound params for the get vs vip port deny operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVsVipPortDeny +type GetVsVipPortDenyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsVipPortDenyParams() beforehand. +func (o *GetVsVipPortDenyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *GetVsVipPortDenyParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_responses.go new file mode 100644 index 000000000..38dca5634 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetVsVipPortDenyOKCode is the HTTP code returned for type GetVsVipPortDenyOK +const GetVsVipPortDenyOKCode int = 200 + +/* +GetVsVipPortDenyOK Success + +swagger:response getVsVipPortDenyOK +*/ +type GetVsVipPortDenyOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortDenyOK creates GetVsVipPortDenyOK with default headers values +func NewGetVsVipPortDenyOK() *GetVsVipPortDenyOK { + + return &GetVsVipPortDenyOK{} +} + +// WithPayload adds the payload to the get vs vip port deny o k response +func (o *GetVsVipPortDenyOK) WithPayload(payload string) *GetVsVipPortDenyOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port deny o k response +func (o *GetVsVipPortDenyOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortDenyOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetVsVipPortDenyNotFoundCode is the HTTP code returned for type GetVsVipPortDenyNotFound +const GetVsVipPortDenyNotFoundCode int = 404 + +/* +GetVsVipPortDenyNotFound Service not found + +swagger:response getVsVipPortDenyNotFound +*/ +type GetVsVipPortDenyNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortDenyNotFound creates GetVsVipPortDenyNotFound with default headers values +func NewGetVsVipPortDenyNotFound() *GetVsVipPortDenyNotFound { + + return &GetVsVipPortDenyNotFound{} +} + +// WithPayload adds the payload to the get vs vip port deny not found response +func (o *GetVsVipPortDenyNotFound) WithPayload(payload string) *GetVsVipPortDenyNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port deny not found response +func (o *GetVsVipPortDenyNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortDenyNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_urlbuilder.go new file mode 100644 index 000000000..4cbbbbc4e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_deny_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// GetVsVipPortDenyURL generates an URL for the get vs vip port deny operation +type GetVsVipPortDenyURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortDenyURL) WithBasePath(bp string) *GetVsVipPortDenyURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortDenyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsVipPortDenyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/deny" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on GetVsVipPortDenyURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsVipPortDenyURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsVipPortDenyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsVipPortDenyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsVipPortDenyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsVipPortDenyURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsVipPortDenyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr.go new file mode 100644 index 000000000..32e70086c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsVipPortLaddrHandlerFunc turns a function with the right signature into a get vs vip port laddr handler +type GetVsVipPortLaddrHandlerFunc func(GetVsVipPortLaddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsVipPortLaddrHandlerFunc) Handle(params GetVsVipPortLaddrParams) middleware.Responder { + return fn(params) +} + +// GetVsVipPortLaddrHandler interface for that can handle valid get vs vip port laddr params +type GetVsVipPortLaddrHandler interface { + Handle(GetVsVipPortLaddrParams) middleware.Responder +} + +// NewGetVsVipPortLaddr creates a new http.Handler for the get vs vip port laddr operation +func NewGetVsVipPortLaddr(ctx *middleware.Context, handler GetVsVipPortLaddrHandler) *GetVsVipPortLaddr { + return &GetVsVipPortLaddr{Context: ctx, Handler: handler} +} + +/* + GetVsVipPortLaddr swagger:route GET /vs/{VipPort}/laddr virtualserver getVsVipPortLaddr + +GetVsVipPortLaddr get vs vip port laddr API +*/ +type GetVsVipPortLaddr struct { + Context *middleware.Context + Handler GetVsVipPortLaddrHandler +} + +func (o *GetVsVipPortLaddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsVipPortLaddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_parameters.go new file mode 100644 index 000000000..0fb9cf281 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetVsVipPortLaddrParams creates a new GetVsVipPortLaddrParams object +// with the default values initialized. +func NewGetVsVipPortLaddrParams() GetVsVipPortLaddrParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetVsVipPortLaddrParams{ + Stats: &statsDefault, + } +} + +// GetVsVipPortLaddrParams contains all the bound params for the get vs vip port laddr operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVsVipPortLaddr +type GetVsVipPortLaddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsVipPortLaddrParams() beforehand. +func (o *GetVsVipPortLaddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *GetVsVipPortLaddrParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetVsVipPortLaddrParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetVsVipPortLaddrParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_responses.go new file mode 100644 index 000000000..5ba73eeb0 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_responses.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// GetVsVipPortLaddrOKCode is the HTTP code returned for type GetVsVipPortLaddrOK +const GetVsVipPortLaddrOKCode int = 200 + +/* +GetVsVipPortLaddrOK Success + +swagger:response getVsVipPortLaddrOK +*/ +type GetVsVipPortLaddrOK struct { + + /* + In: Body + */ + Payload *models.LocalAddressExpandList `json:"body,omitempty"` +} + +// NewGetVsVipPortLaddrOK creates GetVsVipPortLaddrOK with default headers values +func NewGetVsVipPortLaddrOK() *GetVsVipPortLaddrOK { + + return &GetVsVipPortLaddrOK{} +} + +// WithPayload adds the payload to the get vs vip port laddr o k response +func (o *GetVsVipPortLaddrOK) WithPayload(payload *models.LocalAddressExpandList) *GetVsVipPortLaddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port laddr o k response +func (o *GetVsVipPortLaddrOK) SetPayload(payload *models.LocalAddressExpandList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortLaddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetVsVipPortLaddrNotFoundCode is the HTTP code returned for type GetVsVipPortLaddrNotFound +const GetVsVipPortLaddrNotFoundCode int = 404 + +/* +GetVsVipPortLaddrNotFound Service not found + +swagger:response getVsVipPortLaddrNotFound +*/ +type GetVsVipPortLaddrNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortLaddrNotFound creates GetVsVipPortLaddrNotFound with default headers values +func NewGetVsVipPortLaddrNotFound() *GetVsVipPortLaddrNotFound { + + return &GetVsVipPortLaddrNotFound{} +} + +// WithPayload adds the payload to the get vs vip port laddr not found response +func (o *GetVsVipPortLaddrNotFound) WithPayload(payload string) *GetVsVipPortLaddrNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port laddr not found response +func (o *GetVsVipPortLaddrNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortLaddrNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_urlbuilder.go new file mode 100644 index 000000000..053283e75 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_laddr_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetVsVipPortLaddrURL generates an URL for the get vs vip port laddr operation +type GetVsVipPortLaddrURL struct { + VipPort string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortLaddrURL) WithBasePath(bp string) *GetVsVipPortLaddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortLaddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsVipPortLaddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/laddr" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on GetVsVipPortLaddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsVipPortLaddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsVipPortLaddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsVipPortLaddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsVipPortLaddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsVipPortLaddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsVipPortLaddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_parameters.go new file mode 100644 index 000000000..a917c108a --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetVsVipPortParams creates a new GetVsVipPortParams object +// with the default values initialized. +func NewGetVsVipPortParams() GetVsVipPortParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetVsVipPortParams{ + Stats: &statsDefault, + } +} + +// GetVsVipPortParams contains all the bound params for the get vs vip port operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVsVipPort +type GetVsVipPortParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsVipPortParams() beforehand. +func (o *GetVsVipPortParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *GetVsVipPortParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetVsVipPortParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetVsVipPortParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_responses.go new file mode 100644 index 000000000..83d209125 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_responses.go @@ -0,0 +1,102 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// GetVsVipPortOKCode is the HTTP code returned for type GetVsVipPortOK +const GetVsVipPortOKCode int = 200 + +/* +GetVsVipPortOK Success + +swagger:response getVsVipPortOK +*/ +type GetVsVipPortOK struct { + + /* + In: Body + */ + Payload *models.VirtualServerList `json:"body,omitempty"` +} + +// NewGetVsVipPortOK creates GetVsVipPortOK with default headers values +func NewGetVsVipPortOK() *GetVsVipPortOK { + + return &GetVsVipPortOK{} +} + +// WithPayload adds the payload to the get vs vip port o k response +func (o *GetVsVipPortOK) WithPayload(payload *models.VirtualServerList) *GetVsVipPortOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port o k response +func (o *GetVsVipPortOK) SetPayload(payload *models.VirtualServerList) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// GetVsVipPortNotFoundCode is the HTTP code returned for type GetVsVipPortNotFound +const GetVsVipPortNotFoundCode int = 404 + +/* +GetVsVipPortNotFound Service not found + +swagger:response getVsVipPortNotFound +*/ +type GetVsVipPortNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortNotFound creates GetVsVipPortNotFound with default headers values +func NewGetVsVipPortNotFound() *GetVsVipPortNotFound { + + return &GetVsVipPortNotFound{} +} + +// WithPayload adds the payload to the get vs vip port not found response +func (o *GetVsVipPortNotFound) WithPayload(payload string) *GetVsVipPortNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port not found response +func (o *GetVsVipPortNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs.go new file mode 100644 index 000000000..05692a9ba --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// GetVsVipPortRsHandlerFunc turns a function with the right signature into a get vs vip port rs handler +type GetVsVipPortRsHandlerFunc func(GetVsVipPortRsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn GetVsVipPortRsHandlerFunc) Handle(params GetVsVipPortRsParams) middleware.Responder { + return fn(params) +} + +// GetVsVipPortRsHandler interface for that can handle valid get vs vip port rs params +type GetVsVipPortRsHandler interface { + Handle(GetVsVipPortRsParams) middleware.Responder +} + +// NewGetVsVipPortRs creates a new http.Handler for the get vs vip port rs operation +func NewGetVsVipPortRs(ctx *middleware.Context, handler GetVsVipPortRsHandler) *GetVsVipPortRs { + return &GetVsVipPortRs{Context: ctx, Handler: handler} +} + +/* + GetVsVipPortRs swagger:route GET /vs/{VipPort}/rs virtualserver getVsVipPortRs + +GetVsVipPortRs get vs vip port rs API +*/ +type GetVsVipPortRs struct { + Context *middleware.Context + Handler GetVsVipPortRsHandler +} + +func (o *GetVsVipPortRs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewGetVsVipPortRsParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_parameters.go new file mode 100644 index 000000000..422d711e1 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_parameters.go @@ -0,0 +1,116 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// NewGetVsVipPortRsParams creates a new GetVsVipPortRsParams object +// with the default values initialized. +func NewGetVsVipPortRsParams() GetVsVipPortRsParams { + + var ( + // initialize parameters with default values + + statsDefault = bool(false) + ) + + return GetVsVipPortRsParams{ + Stats: &statsDefault, + } +} + +// GetVsVipPortRsParams contains all the bound params for the get vs vip port rs operation +// typically these are obtained from a http.Request +// +// swagger:parameters GetVsVipPortRs +type GetVsVipPortRsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: query + Default: false + */ + Stats *bool +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewGetVsVipPortRsParams() beforehand. +func (o *GetVsVipPortRsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + qStats, qhkStats, _ := qs.GetOK("stats") + if err := o.bindStats(qStats, qhkStats, route.Formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *GetVsVipPortRsParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} + +// bindStats binds and validates parameter Stats from query. +func (o *GetVsVipPortRsParams) bindStats(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewGetVsVipPortRsParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("stats", "query", "bool", raw) + } + o.Stats = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_responses.go new file mode 100644 index 000000000..54df068a5 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_responses.go @@ -0,0 +1,98 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" +) + +// GetVsVipPortRsOKCode is the HTTP code returned for type GetVsVipPortRsOK +const GetVsVipPortRsOKCode int = 200 + +/* +GetVsVipPortRsOK Success + +swagger:response getVsVipPortRsOK +*/ +type GetVsVipPortRsOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortRsOK creates GetVsVipPortRsOK with default headers values +func NewGetVsVipPortRsOK() *GetVsVipPortRsOK { + + return &GetVsVipPortRsOK{} +} + +// WithPayload adds the payload to the get vs vip port rs o k response +func (o *GetVsVipPortRsOK) WithPayload(payload string) *GetVsVipPortRsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port rs o k response +func (o *GetVsVipPortRsOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortRsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// GetVsVipPortRsNotFoundCode is the HTTP code returned for type GetVsVipPortRsNotFound +const GetVsVipPortRsNotFoundCode int = 404 + +/* +GetVsVipPortRsNotFound Service not found + +swagger:response getVsVipPortRsNotFound +*/ +type GetVsVipPortRsNotFound struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewGetVsVipPortRsNotFound creates GetVsVipPortRsNotFound with default headers values +func NewGetVsVipPortRsNotFound() *GetVsVipPortRsNotFound { + + return &GetVsVipPortRsNotFound{} +} + +// WithPayload adds the payload to the get vs vip port rs not found response +func (o *GetVsVipPortRsNotFound) WithPayload(payload string) *GetVsVipPortRsNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the get vs vip port rs not found response +func (o *GetVsVipPortRsNotFound) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *GetVsVipPortRsNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_urlbuilder.go new file mode 100644 index 000000000..f97a471ed --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_rs_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetVsVipPortRsURL generates an URL for the get vs vip port rs operation +type GetVsVipPortRsURL struct { + VipPort string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortRsURL) WithBasePath(bp string) *GetVsVipPortRsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortRsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsVipPortRsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/rs" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on GetVsVipPortRsURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsVipPortRsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsVipPortRsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsVipPortRsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsVipPortRsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsVipPortRsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsVipPortRsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_urlbuilder.go new file mode 100644 index 000000000..699572745 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/get_vs_vip_port_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// GetVsVipPortURL generates an URL for the get vs vip port operation +type GetVsVipPortURL struct { + VipPort string + + Stats *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortURL) WithBasePath(bp string) *GetVsVipPortURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *GetVsVipPortURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *GetVsVipPortURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on GetVsVipPortURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var statsQ string + if o.Stats != nil { + statsQ = swag.FormatBool(*o.Stats) + } + if statsQ != "" { + qs.Set("stats", statsQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *GetVsVipPortURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *GetVsVipPortURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *GetVsVipPortURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on GetVsVipPortURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on GetVsVipPortURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *GetVsVipPortURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow.go new file mode 100644 index 000000000..d5d55cb5e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostVsVipPortAllowHandlerFunc turns a function with the right signature into a post vs vip port allow handler +type PostVsVipPortAllowHandlerFunc func(PostVsVipPortAllowParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostVsVipPortAllowHandlerFunc) Handle(params PostVsVipPortAllowParams) middleware.Responder { + return fn(params) +} + +// PostVsVipPortAllowHandler interface for that can handle valid post vs vip port allow params +type PostVsVipPortAllowHandler interface { + Handle(PostVsVipPortAllowParams) middleware.Responder +} + +// NewPostVsVipPortAllow creates a new http.Handler for the post vs vip port allow operation +func NewPostVsVipPortAllow(ctx *middleware.Context, handler PostVsVipPortAllowHandler) *PostVsVipPortAllow { + return &PostVsVipPortAllow{Context: ctx, Handler: handler} +} + +/* + PostVsVipPortAllow swagger:route POST /vs/{VipPort}/allow virtualserver postVsVipPortAllow + +Update a fully white ip list to vip:port:proto +*/ +type PostVsVipPortAllow struct { + Context *middleware.Context + Handler PostVsVipPortAllowHandler +} + +func (o *PostVsVipPortAllow) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostVsVipPortAllowParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_parameters.go new file mode 100644 index 000000000..6b2511250 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPostVsVipPortAllowParams creates a new PostVsVipPortAllowParams object +// +// There are no default values defined in the spec. +func NewPostVsVipPortAllowParams() PostVsVipPortAllowParams { + + return PostVsVipPortAllowParams{} +} + +// PostVsVipPortAllowParams contains all the bound params for the post vs vip port allow operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostVsVipPortAllow +type PostVsVipPortAllowParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostVsVipPortAllowParams() beforehand. +func (o *PostVsVipPortAllowParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PostVsVipPortAllowParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_responses.go new file mode 100644 index 000000000..b1d15b9c8 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PostVsVipPortAllowOKCode is the HTTP code returned for type PostVsVipPortAllowOK +const PostVsVipPortAllowOKCode int = 200 + +/* +PostVsVipPortAllowOK Success + +swagger:response postVsVipPortAllowOK +*/ +type PostVsVipPortAllowOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortAllowOK creates PostVsVipPortAllowOK with default headers values +func NewPostVsVipPortAllowOK() *PostVsVipPortAllowOK { + + return &PostVsVipPortAllowOK{} +} + +// WithPayload adds the payload to the post vs vip port allow o k response +func (o *PostVsVipPortAllowOK) WithPayload(payload string) *PostVsVipPortAllowOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port allow o k response +func (o *PostVsVipPortAllowOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortAllowOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortAllowCreatedCode is the HTTP code returned for type PostVsVipPortAllowCreated +const PostVsVipPortAllowCreatedCode int = 201 + +/* +PostVsVipPortAllowCreated Created + +swagger:response postVsVipPortAllowCreated +*/ +type PostVsVipPortAllowCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortAllowCreated creates PostVsVipPortAllowCreated with default headers values +func NewPostVsVipPortAllowCreated() *PostVsVipPortAllowCreated { + + return &PostVsVipPortAllowCreated{} +} + +// WithPayload adds the payload to the post vs vip port allow created response +func (o *PostVsVipPortAllowCreated) WithPayload(payload string) *PostVsVipPortAllowCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port allow created response +func (o *PostVsVipPortAllowCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortAllowCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortAllowInvalidFrontendCode is the HTTP code returned for type PostVsVipPortAllowInvalidFrontend +const PostVsVipPortAllowInvalidFrontendCode int = 460 + +/* +PostVsVipPortAllowInvalidFrontend Invalid frontend in service configuration + +swagger:response postVsVipPortAllowInvalidFrontend +*/ +type PostVsVipPortAllowInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortAllowInvalidFrontend creates PostVsVipPortAllowInvalidFrontend with default headers values +func NewPostVsVipPortAllowInvalidFrontend() *PostVsVipPortAllowInvalidFrontend { + + return &PostVsVipPortAllowInvalidFrontend{} +} + +// WithPayload adds the payload to the post vs vip port allow invalid frontend response +func (o *PostVsVipPortAllowInvalidFrontend) WithPayload(payload models.Error) *PostVsVipPortAllowInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port allow invalid frontend response +func (o *PostVsVipPortAllowInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortAllowInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortAllowInvalidBackendCode is the HTTP code returned for type PostVsVipPortAllowInvalidBackend +const PostVsVipPortAllowInvalidBackendCode int = 461 + +/* +PostVsVipPortAllowInvalidBackend Invalid backend in service configuration + +swagger:response postVsVipPortAllowInvalidBackend +*/ +type PostVsVipPortAllowInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortAllowInvalidBackend creates PostVsVipPortAllowInvalidBackend with default headers values +func NewPostVsVipPortAllowInvalidBackend() *PostVsVipPortAllowInvalidBackend { + + return &PostVsVipPortAllowInvalidBackend{} +} + +// WithPayload adds the payload to the post vs vip port allow invalid backend response +func (o *PostVsVipPortAllowInvalidBackend) WithPayload(payload models.Error) *PostVsVipPortAllowInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port allow invalid backend response +func (o *PostVsVipPortAllowInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortAllowInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortAllowFailureCode is the HTTP code returned for type PostVsVipPortAllowFailure +const PostVsVipPortAllowFailureCode int = 500 + +/* +PostVsVipPortAllowFailure Service deletion failed + +swagger:response postVsVipPortAllowFailure +*/ +type PostVsVipPortAllowFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortAllowFailure creates PostVsVipPortAllowFailure with default headers values +func NewPostVsVipPortAllowFailure() *PostVsVipPortAllowFailure { + + return &PostVsVipPortAllowFailure{} +} + +// WithPayload adds the payload to the post vs vip port allow failure response +func (o *PostVsVipPortAllowFailure) WithPayload(payload models.Error) *PostVsVipPortAllowFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port allow failure response +func (o *PostVsVipPortAllowFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortAllowFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_urlbuilder.go new file mode 100644 index 000000000..c7edb0b96 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_allow_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PostVsVipPortAllowURL generates an URL for the post vs vip port allow operation +type PostVsVipPortAllowURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortAllowURL) WithBasePath(bp string) *PostVsVipPortAllowURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortAllowURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostVsVipPortAllowURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/allow" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PostVsVipPortAllowURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostVsVipPortAllowURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostVsVipPortAllowURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostVsVipPortAllowURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostVsVipPortAllowURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostVsVipPortAllowURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostVsVipPortAllowURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny.go new file mode 100644 index 000000000..d19eee50e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostVsVipPortDenyHandlerFunc turns a function with the right signature into a post vs vip port deny handler +type PostVsVipPortDenyHandlerFunc func(PostVsVipPortDenyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostVsVipPortDenyHandlerFunc) Handle(params PostVsVipPortDenyParams) middleware.Responder { + return fn(params) +} + +// PostVsVipPortDenyHandler interface for that can handle valid post vs vip port deny params +type PostVsVipPortDenyHandler interface { + Handle(PostVsVipPortDenyParams) middleware.Responder +} + +// NewPostVsVipPortDeny creates a new http.Handler for the post vs vip port deny operation +func NewPostVsVipPortDeny(ctx *middleware.Context, handler PostVsVipPortDenyHandler) *PostVsVipPortDeny { + return &PostVsVipPortDeny{Context: ctx, Handler: handler} +} + +/* + PostVsVipPortDeny swagger:route POST /vs/{VipPort}/deny virtualserver postVsVipPortDeny + +Update a fully black ip list to vip:port:proto +*/ +type PostVsVipPortDeny struct { + Context *middleware.Context + Handler PostVsVipPortDenyHandler +} + +func (o *PostVsVipPortDeny) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostVsVipPortDenyParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_parameters.go new file mode 100644 index 000000000..56f735df3 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPostVsVipPortDenyParams creates a new PostVsVipPortDenyParams object +// +// There are no default values defined in the spec. +func NewPostVsVipPortDenyParams() PostVsVipPortDenyParams { + + return PostVsVipPortDenyParams{} +} + +// PostVsVipPortDenyParams contains all the bound params for the post vs vip port deny operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostVsVipPortDeny +type PostVsVipPortDenyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostVsVipPortDenyParams() beforehand. +func (o *PostVsVipPortDenyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PostVsVipPortDenyParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_responses.go new file mode 100644 index 000000000..8e813626d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PostVsVipPortDenyOKCode is the HTTP code returned for type PostVsVipPortDenyOK +const PostVsVipPortDenyOKCode int = 200 + +/* +PostVsVipPortDenyOK Success + +swagger:response postVsVipPortDenyOK +*/ +type PostVsVipPortDenyOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortDenyOK creates PostVsVipPortDenyOK with default headers values +func NewPostVsVipPortDenyOK() *PostVsVipPortDenyOK { + + return &PostVsVipPortDenyOK{} +} + +// WithPayload adds the payload to the post vs vip port deny o k response +func (o *PostVsVipPortDenyOK) WithPayload(payload string) *PostVsVipPortDenyOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port deny o k response +func (o *PostVsVipPortDenyOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortDenyOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortDenyCreatedCode is the HTTP code returned for type PostVsVipPortDenyCreated +const PostVsVipPortDenyCreatedCode int = 201 + +/* +PostVsVipPortDenyCreated Created + +swagger:response postVsVipPortDenyCreated +*/ +type PostVsVipPortDenyCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortDenyCreated creates PostVsVipPortDenyCreated with default headers values +func NewPostVsVipPortDenyCreated() *PostVsVipPortDenyCreated { + + return &PostVsVipPortDenyCreated{} +} + +// WithPayload adds the payload to the post vs vip port deny created response +func (o *PostVsVipPortDenyCreated) WithPayload(payload string) *PostVsVipPortDenyCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port deny created response +func (o *PostVsVipPortDenyCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortDenyCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortDenyInvalidFrontendCode is the HTTP code returned for type PostVsVipPortDenyInvalidFrontend +const PostVsVipPortDenyInvalidFrontendCode int = 460 + +/* +PostVsVipPortDenyInvalidFrontend Invalid frontend in service configuration + +swagger:response postVsVipPortDenyInvalidFrontend +*/ +type PostVsVipPortDenyInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortDenyInvalidFrontend creates PostVsVipPortDenyInvalidFrontend with default headers values +func NewPostVsVipPortDenyInvalidFrontend() *PostVsVipPortDenyInvalidFrontend { + + return &PostVsVipPortDenyInvalidFrontend{} +} + +// WithPayload adds the payload to the post vs vip port deny invalid frontend response +func (o *PostVsVipPortDenyInvalidFrontend) WithPayload(payload models.Error) *PostVsVipPortDenyInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port deny invalid frontend response +func (o *PostVsVipPortDenyInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortDenyInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortDenyInvalidBackendCode is the HTTP code returned for type PostVsVipPortDenyInvalidBackend +const PostVsVipPortDenyInvalidBackendCode int = 461 + +/* +PostVsVipPortDenyInvalidBackend Invalid backend in service configuration + +swagger:response postVsVipPortDenyInvalidBackend +*/ +type PostVsVipPortDenyInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortDenyInvalidBackend creates PostVsVipPortDenyInvalidBackend with default headers values +func NewPostVsVipPortDenyInvalidBackend() *PostVsVipPortDenyInvalidBackend { + + return &PostVsVipPortDenyInvalidBackend{} +} + +// WithPayload adds the payload to the post vs vip port deny invalid backend response +func (o *PostVsVipPortDenyInvalidBackend) WithPayload(payload models.Error) *PostVsVipPortDenyInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port deny invalid backend response +func (o *PostVsVipPortDenyInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortDenyInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortDenyFailureCode is the HTTP code returned for type PostVsVipPortDenyFailure +const PostVsVipPortDenyFailureCode int = 500 + +/* +PostVsVipPortDenyFailure Service deletion failed + +swagger:response postVsVipPortDenyFailure +*/ +type PostVsVipPortDenyFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortDenyFailure creates PostVsVipPortDenyFailure with default headers values +func NewPostVsVipPortDenyFailure() *PostVsVipPortDenyFailure { + + return &PostVsVipPortDenyFailure{} +} + +// WithPayload adds the payload to the post vs vip port deny failure response +func (o *PostVsVipPortDenyFailure) WithPayload(payload models.Error) *PostVsVipPortDenyFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port deny failure response +func (o *PostVsVipPortDenyFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortDenyFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_urlbuilder.go new file mode 100644 index 000000000..b63560b1d --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_deny_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PostVsVipPortDenyURL generates an URL for the post vs vip port deny operation +type PostVsVipPortDenyURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortDenyURL) WithBasePath(bp string) *PostVsVipPortDenyURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortDenyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostVsVipPortDenyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/deny" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PostVsVipPortDenyURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostVsVipPortDenyURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostVsVipPortDenyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostVsVipPortDenyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostVsVipPortDenyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostVsVipPortDenyURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostVsVipPortDenyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs.go new file mode 100644 index 000000000..26ff3ea34 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PostVsVipPortRsHandlerFunc turns a function with the right signature into a post vs vip port rs handler +type PostVsVipPortRsHandlerFunc func(PostVsVipPortRsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PostVsVipPortRsHandlerFunc) Handle(params PostVsVipPortRsParams) middleware.Responder { + return fn(params) +} + +// PostVsVipPortRsHandler interface for that can handle valid post vs vip port rs params +type PostVsVipPortRsHandler interface { + Handle(PostVsVipPortRsParams) middleware.Responder +} + +// NewPostVsVipPortRs creates a new http.Handler for the post vs vip port rs operation +func NewPostVsVipPortRs(ctx *middleware.Context, handler PostVsVipPortRsHandler) *PostVsVipPortRs { + return &PostVsVipPortRs{Context: ctx, Handler: handler} +} + +/* + PostVsVipPortRs swagger:route POST /vs/{VipPort}/rs virtualserver postVsVipPortRs + +Update fully real server list to vip:port:proto +*/ +type PostVsVipPortRs struct { + Context *middleware.Context + Handler PostVsVipPortRsHandler +} + +func (o *PostVsVipPortRs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPostVsVipPortRsParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_parameters.go new file mode 100644 index 000000000..948a9f38b --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPostVsVipPortRsParams creates a new PostVsVipPortRsParams object +// +// There are no default values defined in the spec. +func NewPostVsVipPortRsParams() PostVsVipPortRsParams { + + return PostVsVipPortRsParams{} +} + +// PostVsVipPortRsParams contains all the bound params for the post vs vip port rs operation +// typically these are obtained from a http.Request +// +// swagger:parameters PostVsVipPortRs +type PostVsVipPortRsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + Rss *models.RealServerTinyList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPostVsVipPortRsParams() beforehand. +func (o *PostVsVipPortRsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.RealServerTinyList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("rss", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Rss = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PostVsVipPortRsParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_responses.go new file mode 100644 index 000000000..fd154d53e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PostVsVipPortRsOKCode is the HTTP code returned for type PostVsVipPortRsOK +const PostVsVipPortRsOKCode int = 200 + +/* +PostVsVipPortRsOK Success + +swagger:response postVsVipPortRsOK +*/ +type PostVsVipPortRsOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortRsOK creates PostVsVipPortRsOK with default headers values +func NewPostVsVipPortRsOK() *PostVsVipPortRsOK { + + return &PostVsVipPortRsOK{} +} + +// WithPayload adds the payload to the post vs vip port rs o k response +func (o *PostVsVipPortRsOK) WithPayload(payload string) *PostVsVipPortRsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port rs o k response +func (o *PostVsVipPortRsOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortRsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortRsCreatedCode is the HTTP code returned for type PostVsVipPortRsCreated +const PostVsVipPortRsCreatedCode int = 201 + +/* +PostVsVipPortRsCreated Created + +swagger:response postVsVipPortRsCreated +*/ +type PostVsVipPortRsCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPostVsVipPortRsCreated creates PostVsVipPortRsCreated with default headers values +func NewPostVsVipPortRsCreated() *PostVsVipPortRsCreated { + + return &PostVsVipPortRsCreated{} +} + +// WithPayload adds the payload to the post vs vip port rs created response +func (o *PostVsVipPortRsCreated) WithPayload(payload string) *PostVsVipPortRsCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port rs created response +func (o *PostVsVipPortRsCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortRsCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortRsInvalidFrontendCode is the HTTP code returned for type PostVsVipPortRsInvalidFrontend +const PostVsVipPortRsInvalidFrontendCode int = 460 + +/* +PostVsVipPortRsInvalidFrontend Invalid frontend in service configuration + +swagger:response postVsVipPortRsInvalidFrontend +*/ +type PostVsVipPortRsInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortRsInvalidFrontend creates PostVsVipPortRsInvalidFrontend with default headers values +func NewPostVsVipPortRsInvalidFrontend() *PostVsVipPortRsInvalidFrontend { + + return &PostVsVipPortRsInvalidFrontend{} +} + +// WithPayload adds the payload to the post vs vip port rs invalid frontend response +func (o *PostVsVipPortRsInvalidFrontend) WithPayload(payload models.Error) *PostVsVipPortRsInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port rs invalid frontend response +func (o *PostVsVipPortRsInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortRsInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortRsInvalidBackendCode is the HTTP code returned for type PostVsVipPortRsInvalidBackend +const PostVsVipPortRsInvalidBackendCode int = 461 + +/* +PostVsVipPortRsInvalidBackend Invalid backend in service configuration + +swagger:response postVsVipPortRsInvalidBackend +*/ +type PostVsVipPortRsInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortRsInvalidBackend creates PostVsVipPortRsInvalidBackend with default headers values +func NewPostVsVipPortRsInvalidBackend() *PostVsVipPortRsInvalidBackend { + + return &PostVsVipPortRsInvalidBackend{} +} + +// WithPayload adds the payload to the post vs vip port rs invalid backend response +func (o *PostVsVipPortRsInvalidBackend) WithPayload(payload models.Error) *PostVsVipPortRsInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port rs invalid backend response +func (o *PostVsVipPortRsInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortRsInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PostVsVipPortRsFailureCode is the HTTP code returned for type PostVsVipPortRsFailure +const PostVsVipPortRsFailureCode int = 500 + +/* +PostVsVipPortRsFailure Service deletion failed + +swagger:response postVsVipPortRsFailure +*/ +type PostVsVipPortRsFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPostVsVipPortRsFailure creates PostVsVipPortRsFailure with default headers values +func NewPostVsVipPortRsFailure() *PostVsVipPortRsFailure { + + return &PostVsVipPortRsFailure{} +} + +// WithPayload adds the payload to the post vs vip port rs failure response +func (o *PostVsVipPortRsFailure) WithPayload(payload models.Error) *PostVsVipPortRsFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the post vs vip port rs failure response +func (o *PostVsVipPortRsFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PostVsVipPortRsFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_urlbuilder.go new file mode 100644 index 000000000..1c7f7b01e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/post_vs_vip_port_rs_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PostVsVipPortRsURL generates an URL for the post vs vip port rs operation +type PostVsVipPortRsURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortRsURL) WithBasePath(bp string) *PostVsVipPortRsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PostVsVipPortRsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PostVsVipPortRsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/rs" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PostVsVipPortRsURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PostVsVipPortRsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PostVsVipPortRsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PostVsVipPortRsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PostVsVipPortRsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PostVsVipPortRsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PostVsVipPortRsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port.go new file mode 100644 index 000000000..78b20e404 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutVsVipPortHandlerFunc turns a function with the right signature into a put vs vip port handler +type PutVsVipPortHandlerFunc func(PutVsVipPortParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutVsVipPortHandlerFunc) Handle(params PutVsVipPortParams) middleware.Responder { + return fn(params) +} + +// PutVsVipPortHandler interface for that can handle valid put vs vip port params +type PutVsVipPortHandler interface { + Handle(PutVsVipPortParams) middleware.Responder +} + +// NewPutVsVipPort creates a new http.Handler for the put vs vip port operation +func NewPutVsVipPort(ctx *middleware.Context, handler PutVsVipPortHandler) *PutVsVipPort { + return &PutVsVipPort{Context: ctx, Handler: handler} +} + +/* + PutVsVipPort swagger:route PUT /vs/{VipPort} virtualserver putVsVipPort + +create or update virtual server +*/ +type PutVsVipPort struct { + Context *middleware.Context + Handler PutVsVipPortHandler +} + +func (o *PutVsVipPort) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutVsVipPortParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow.go new file mode 100644 index 000000000..d3fa4b93c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutVsVipPortAllowHandlerFunc turns a function with the right signature into a put vs vip port allow handler +type PutVsVipPortAllowHandlerFunc func(PutVsVipPortAllowParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutVsVipPortAllowHandlerFunc) Handle(params PutVsVipPortAllowParams) middleware.Responder { + return fn(params) +} + +// PutVsVipPortAllowHandler interface for that can handle valid put vs vip port allow params +type PutVsVipPortAllowHandler interface { + Handle(PutVsVipPortAllowParams) middleware.Responder +} + +// NewPutVsVipPortAllow creates a new http.Handler for the put vs vip port allow operation +func NewPutVsVipPortAllow(ctx *middleware.Context, handler PutVsVipPortAllowHandler) *PutVsVipPortAllow { + return &PutVsVipPortAllow{Context: ctx, Handler: handler} +} + +/* + PutVsVipPortAllow swagger:route PUT /vs/{VipPort}/allow virtualserver putVsVipPortAllow + +Add a set of ip from white list to vip:port:proto +*/ +type PutVsVipPortAllow struct { + Context *middleware.Context + Handler PutVsVipPortAllowHandler +} + +func (o *PutVsVipPortAllow) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutVsVipPortAllowParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_parameters.go new file mode 100644 index 000000000..dfb8da2e2 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutVsVipPortAllowParams creates a new PutVsVipPortAllowParams object +// +// There are no default values defined in the spec. +func NewPutVsVipPortAllowParams() PutVsVipPortAllowParams { + + return PutVsVipPortAllowParams{} +} + +// PutVsVipPortAllowParams contains all the bound params for the put vs vip port allow operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutVsVipPortAllow +type PutVsVipPortAllowParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutVsVipPortAllowParams() beforehand. +func (o *PutVsVipPortAllowParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PutVsVipPortAllowParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_responses.go new file mode 100644 index 000000000..38d69cf91 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PutVsVipPortAllowOKCode is the HTTP code returned for type PutVsVipPortAllowOK +const PutVsVipPortAllowOKCode int = 200 + +/* +PutVsVipPortAllowOK Success + +swagger:response putVsVipPortAllowOK +*/ +type PutVsVipPortAllowOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortAllowOK creates PutVsVipPortAllowOK with default headers values +func NewPutVsVipPortAllowOK() *PutVsVipPortAllowOK { + + return &PutVsVipPortAllowOK{} +} + +// WithPayload adds the payload to the put vs vip port allow o k response +func (o *PutVsVipPortAllowOK) WithPayload(payload string) *PutVsVipPortAllowOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port allow o k response +func (o *PutVsVipPortAllowOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortAllowOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortAllowCreatedCode is the HTTP code returned for type PutVsVipPortAllowCreated +const PutVsVipPortAllowCreatedCode int = 201 + +/* +PutVsVipPortAllowCreated Created + +swagger:response putVsVipPortAllowCreated +*/ +type PutVsVipPortAllowCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortAllowCreated creates PutVsVipPortAllowCreated with default headers values +func NewPutVsVipPortAllowCreated() *PutVsVipPortAllowCreated { + + return &PutVsVipPortAllowCreated{} +} + +// WithPayload adds the payload to the put vs vip port allow created response +func (o *PutVsVipPortAllowCreated) WithPayload(payload string) *PutVsVipPortAllowCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port allow created response +func (o *PutVsVipPortAllowCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortAllowCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortAllowInvalidFrontendCode is the HTTP code returned for type PutVsVipPortAllowInvalidFrontend +const PutVsVipPortAllowInvalidFrontendCode int = 460 + +/* +PutVsVipPortAllowInvalidFrontend Invalid frontend in service configuration + +swagger:response putVsVipPortAllowInvalidFrontend +*/ +type PutVsVipPortAllowInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortAllowInvalidFrontend creates PutVsVipPortAllowInvalidFrontend with default headers values +func NewPutVsVipPortAllowInvalidFrontend() *PutVsVipPortAllowInvalidFrontend { + + return &PutVsVipPortAllowInvalidFrontend{} +} + +// WithPayload adds the payload to the put vs vip port allow invalid frontend response +func (o *PutVsVipPortAllowInvalidFrontend) WithPayload(payload models.Error) *PutVsVipPortAllowInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port allow invalid frontend response +func (o *PutVsVipPortAllowInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortAllowInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortAllowInvalidBackendCode is the HTTP code returned for type PutVsVipPortAllowInvalidBackend +const PutVsVipPortAllowInvalidBackendCode int = 461 + +/* +PutVsVipPortAllowInvalidBackend Invalid backend in service configuration + +swagger:response putVsVipPortAllowInvalidBackend +*/ +type PutVsVipPortAllowInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortAllowInvalidBackend creates PutVsVipPortAllowInvalidBackend with default headers values +func NewPutVsVipPortAllowInvalidBackend() *PutVsVipPortAllowInvalidBackend { + + return &PutVsVipPortAllowInvalidBackend{} +} + +// WithPayload adds the payload to the put vs vip port allow invalid backend response +func (o *PutVsVipPortAllowInvalidBackend) WithPayload(payload models.Error) *PutVsVipPortAllowInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port allow invalid backend response +func (o *PutVsVipPortAllowInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortAllowInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortAllowFailureCode is the HTTP code returned for type PutVsVipPortAllowFailure +const PutVsVipPortAllowFailureCode int = 500 + +/* +PutVsVipPortAllowFailure Service deletion failed + +swagger:response putVsVipPortAllowFailure +*/ +type PutVsVipPortAllowFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortAllowFailure creates PutVsVipPortAllowFailure with default headers values +func NewPutVsVipPortAllowFailure() *PutVsVipPortAllowFailure { + + return &PutVsVipPortAllowFailure{} +} + +// WithPayload adds the payload to the put vs vip port allow failure response +func (o *PutVsVipPortAllowFailure) WithPayload(payload models.Error) *PutVsVipPortAllowFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port allow failure response +func (o *PutVsVipPortAllowFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortAllowFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_urlbuilder.go new file mode 100644 index 000000000..ba8719936 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_allow_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutVsVipPortAllowURL generates an URL for the put vs vip port allow operation +type PutVsVipPortAllowURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortAllowURL) WithBasePath(bp string) *PutVsVipPortAllowURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortAllowURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutVsVipPortAllowURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/allow" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PutVsVipPortAllowURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutVsVipPortAllowURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutVsVipPortAllowURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutVsVipPortAllowURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutVsVipPortAllowURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutVsVipPortAllowURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutVsVipPortAllowURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny.go new file mode 100644 index 000000000..180e1242b --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutVsVipPortDenyHandlerFunc turns a function with the right signature into a put vs vip port deny handler +type PutVsVipPortDenyHandlerFunc func(PutVsVipPortDenyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutVsVipPortDenyHandlerFunc) Handle(params PutVsVipPortDenyParams) middleware.Responder { + return fn(params) +} + +// PutVsVipPortDenyHandler interface for that can handle valid put vs vip port deny params +type PutVsVipPortDenyHandler interface { + Handle(PutVsVipPortDenyParams) middleware.Responder +} + +// NewPutVsVipPortDeny creates a new http.Handler for the put vs vip port deny operation +func NewPutVsVipPortDeny(ctx *middleware.Context, handler PutVsVipPortDenyHandler) *PutVsVipPortDeny { + return &PutVsVipPortDeny{Context: ctx, Handler: handler} +} + +/* + PutVsVipPortDeny swagger:route PUT /vs/{VipPort}/deny virtualserver putVsVipPortDeny + +Add a set of ip from black list to vip:port:proto +*/ +type PutVsVipPortDeny struct { + Context *middleware.Context + Handler PutVsVipPortDenyHandler +} + +func (o *PutVsVipPortDeny) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutVsVipPortDenyParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_parameters.go new file mode 100644 index 000000000..6d28ff26e --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutVsVipPortDenyParams creates a new PutVsVipPortDenyParams object +// +// There are no default values defined in the spec. +func NewPutVsVipPortDenyParams() PutVsVipPortDenyParams { + + return PutVsVipPortDenyParams{} +} + +// PutVsVipPortDenyParams contains all the bound params for the put vs vip port deny operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutVsVipPortDeny +type PutVsVipPortDenyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + ACL *models.ACLAddrList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutVsVipPortDenyParams() beforehand. +func (o *PutVsVipPortDenyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.ACLAddrList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("acl", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.ACL = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PutVsVipPortDenyParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_responses.go new file mode 100644 index 000000000..aae11334f --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PutVsVipPortDenyOKCode is the HTTP code returned for type PutVsVipPortDenyOK +const PutVsVipPortDenyOKCode int = 200 + +/* +PutVsVipPortDenyOK Success + +swagger:response putVsVipPortDenyOK +*/ +type PutVsVipPortDenyOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortDenyOK creates PutVsVipPortDenyOK with default headers values +func NewPutVsVipPortDenyOK() *PutVsVipPortDenyOK { + + return &PutVsVipPortDenyOK{} +} + +// WithPayload adds the payload to the put vs vip port deny o k response +func (o *PutVsVipPortDenyOK) WithPayload(payload string) *PutVsVipPortDenyOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port deny o k response +func (o *PutVsVipPortDenyOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortDenyOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortDenyCreatedCode is the HTTP code returned for type PutVsVipPortDenyCreated +const PutVsVipPortDenyCreatedCode int = 201 + +/* +PutVsVipPortDenyCreated Created + +swagger:response putVsVipPortDenyCreated +*/ +type PutVsVipPortDenyCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortDenyCreated creates PutVsVipPortDenyCreated with default headers values +func NewPutVsVipPortDenyCreated() *PutVsVipPortDenyCreated { + + return &PutVsVipPortDenyCreated{} +} + +// WithPayload adds the payload to the put vs vip port deny created response +func (o *PutVsVipPortDenyCreated) WithPayload(payload string) *PutVsVipPortDenyCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port deny created response +func (o *PutVsVipPortDenyCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortDenyCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortDenyInvalidFrontendCode is the HTTP code returned for type PutVsVipPortDenyInvalidFrontend +const PutVsVipPortDenyInvalidFrontendCode int = 460 + +/* +PutVsVipPortDenyInvalidFrontend Invalid frontend in service configuration + +swagger:response putVsVipPortDenyInvalidFrontend +*/ +type PutVsVipPortDenyInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortDenyInvalidFrontend creates PutVsVipPortDenyInvalidFrontend with default headers values +func NewPutVsVipPortDenyInvalidFrontend() *PutVsVipPortDenyInvalidFrontend { + + return &PutVsVipPortDenyInvalidFrontend{} +} + +// WithPayload adds the payload to the put vs vip port deny invalid frontend response +func (o *PutVsVipPortDenyInvalidFrontend) WithPayload(payload models.Error) *PutVsVipPortDenyInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port deny invalid frontend response +func (o *PutVsVipPortDenyInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortDenyInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortDenyInvalidBackendCode is the HTTP code returned for type PutVsVipPortDenyInvalidBackend +const PutVsVipPortDenyInvalidBackendCode int = 461 + +/* +PutVsVipPortDenyInvalidBackend Invalid backend in service configuration + +swagger:response putVsVipPortDenyInvalidBackend +*/ +type PutVsVipPortDenyInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortDenyInvalidBackend creates PutVsVipPortDenyInvalidBackend with default headers values +func NewPutVsVipPortDenyInvalidBackend() *PutVsVipPortDenyInvalidBackend { + + return &PutVsVipPortDenyInvalidBackend{} +} + +// WithPayload adds the payload to the put vs vip port deny invalid backend response +func (o *PutVsVipPortDenyInvalidBackend) WithPayload(payload models.Error) *PutVsVipPortDenyInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port deny invalid backend response +func (o *PutVsVipPortDenyInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortDenyInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortDenyFailureCode is the HTTP code returned for type PutVsVipPortDenyFailure +const PutVsVipPortDenyFailureCode int = 500 + +/* +PutVsVipPortDenyFailure Service deletion failed + +swagger:response putVsVipPortDenyFailure +*/ +type PutVsVipPortDenyFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortDenyFailure creates PutVsVipPortDenyFailure with default headers values +func NewPutVsVipPortDenyFailure() *PutVsVipPortDenyFailure { + + return &PutVsVipPortDenyFailure{} +} + +// WithPayload adds the payload to the put vs vip port deny failure response +func (o *PutVsVipPortDenyFailure) WithPayload(payload models.Error) *PutVsVipPortDenyFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port deny failure response +func (o *PutVsVipPortDenyFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortDenyFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_urlbuilder.go new file mode 100644 index 000000000..48450185b --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_deny_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutVsVipPortDenyURL generates an URL for the put vs vip port deny operation +type PutVsVipPortDenyURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortDenyURL) WithBasePath(bp string) *PutVsVipPortDenyURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortDenyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutVsVipPortDenyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/deny" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PutVsVipPortDenyURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutVsVipPortDenyURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutVsVipPortDenyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutVsVipPortDenyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutVsVipPortDenyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutVsVipPortDenyURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutVsVipPortDenyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr.go new file mode 100644 index 000000000..a75db0dc4 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutVsVipPortLaddrHandlerFunc turns a function with the right signature into a put vs vip port laddr handler +type PutVsVipPortLaddrHandlerFunc func(PutVsVipPortLaddrParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutVsVipPortLaddrHandlerFunc) Handle(params PutVsVipPortLaddrParams) middleware.Responder { + return fn(params) +} + +// PutVsVipPortLaddrHandler interface for that can handle valid put vs vip port laddr params +type PutVsVipPortLaddrHandler interface { + Handle(PutVsVipPortLaddrParams) middleware.Responder +} + +// NewPutVsVipPortLaddr creates a new http.Handler for the put vs vip port laddr operation +func NewPutVsVipPortLaddr(ctx *middleware.Context, handler PutVsVipPortLaddrHandler) *PutVsVipPortLaddr { + return &PutVsVipPortLaddr{Context: ctx, Handler: handler} +} + +/* + PutVsVipPortLaddr swagger:route PUT /vs/{VipPort}/laddr virtualserver putVsVipPortLaddr + +PutVsVipPortLaddr put vs vip port laddr API +*/ +type PutVsVipPortLaddr struct { + Context *middleware.Context + Handler PutVsVipPortLaddrHandler +} + +func (o *PutVsVipPortLaddr) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutVsVipPortLaddrParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_parameters.go new file mode 100644 index 000000000..94c97a03a --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutVsVipPortLaddrParams creates a new PutVsVipPortLaddrParams object +// +// There are no default values defined in the spec. +func NewPutVsVipPortLaddrParams() PutVsVipPortLaddrParams { + + return PutVsVipPortLaddrParams{} +} + +// PutVsVipPortLaddrParams contains all the bound params for the put vs vip port laddr operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutVsVipPortLaddr +type PutVsVipPortLaddrParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + Spec *models.LocalAddressSpecTiny +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutVsVipPortLaddrParams() beforehand. +func (o *PutVsVipPortLaddrParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.LocalAddressSpecTiny + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PutVsVipPortLaddrParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_responses.go new file mode 100644 index 000000000..9d4f6bc00 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PutVsVipPortLaddrOKCode is the HTTP code returned for type PutVsVipPortLaddrOK +const PutVsVipPortLaddrOKCode int = 200 + +/* +PutVsVipPortLaddrOK Success + +swagger:response putVsVipPortLaddrOK +*/ +type PutVsVipPortLaddrOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortLaddrOK creates PutVsVipPortLaddrOK with default headers values +func NewPutVsVipPortLaddrOK() *PutVsVipPortLaddrOK { + + return &PutVsVipPortLaddrOK{} +} + +// WithPayload adds the payload to the put vs vip port laddr o k response +func (o *PutVsVipPortLaddrOK) WithPayload(payload string) *PutVsVipPortLaddrOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port laddr o k response +func (o *PutVsVipPortLaddrOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortLaddrOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortLaddrCreatedCode is the HTTP code returned for type PutVsVipPortLaddrCreated +const PutVsVipPortLaddrCreatedCode int = 201 + +/* +PutVsVipPortLaddrCreated Created + +swagger:response putVsVipPortLaddrCreated +*/ +type PutVsVipPortLaddrCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortLaddrCreated creates PutVsVipPortLaddrCreated with default headers values +func NewPutVsVipPortLaddrCreated() *PutVsVipPortLaddrCreated { + + return &PutVsVipPortLaddrCreated{} +} + +// WithPayload adds the payload to the put vs vip port laddr created response +func (o *PutVsVipPortLaddrCreated) WithPayload(payload string) *PutVsVipPortLaddrCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port laddr created response +func (o *PutVsVipPortLaddrCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortLaddrCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortLaddrInvalidFrontendCode is the HTTP code returned for type PutVsVipPortLaddrInvalidFrontend +const PutVsVipPortLaddrInvalidFrontendCode int = 460 + +/* +PutVsVipPortLaddrInvalidFrontend Invalid frontend in service configuration + +swagger:response putVsVipPortLaddrInvalidFrontend +*/ +type PutVsVipPortLaddrInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortLaddrInvalidFrontend creates PutVsVipPortLaddrInvalidFrontend with default headers values +func NewPutVsVipPortLaddrInvalidFrontend() *PutVsVipPortLaddrInvalidFrontend { + + return &PutVsVipPortLaddrInvalidFrontend{} +} + +// WithPayload adds the payload to the put vs vip port laddr invalid frontend response +func (o *PutVsVipPortLaddrInvalidFrontend) WithPayload(payload models.Error) *PutVsVipPortLaddrInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port laddr invalid frontend response +func (o *PutVsVipPortLaddrInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortLaddrInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortLaddrInvalidBackendCode is the HTTP code returned for type PutVsVipPortLaddrInvalidBackend +const PutVsVipPortLaddrInvalidBackendCode int = 461 + +/* +PutVsVipPortLaddrInvalidBackend Invalid backend in service configuration + +swagger:response putVsVipPortLaddrInvalidBackend +*/ +type PutVsVipPortLaddrInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortLaddrInvalidBackend creates PutVsVipPortLaddrInvalidBackend with default headers values +func NewPutVsVipPortLaddrInvalidBackend() *PutVsVipPortLaddrInvalidBackend { + + return &PutVsVipPortLaddrInvalidBackend{} +} + +// WithPayload adds the payload to the put vs vip port laddr invalid backend response +func (o *PutVsVipPortLaddrInvalidBackend) WithPayload(payload models.Error) *PutVsVipPortLaddrInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port laddr invalid backend response +func (o *PutVsVipPortLaddrInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortLaddrInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortLaddrFailureCode is the HTTP code returned for type PutVsVipPortLaddrFailure +const PutVsVipPortLaddrFailureCode int = 500 + +/* +PutVsVipPortLaddrFailure Error while creating virtual server + +swagger:response putVsVipPortLaddrFailure +*/ +type PutVsVipPortLaddrFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortLaddrFailure creates PutVsVipPortLaddrFailure with default headers values +func NewPutVsVipPortLaddrFailure() *PutVsVipPortLaddrFailure { + + return &PutVsVipPortLaddrFailure{} +} + +// WithPayload adds the payload to the put vs vip port laddr failure response +func (o *PutVsVipPortLaddrFailure) WithPayload(payload models.Error) *PutVsVipPortLaddrFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port laddr failure response +func (o *PutVsVipPortLaddrFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortLaddrFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_urlbuilder.go new file mode 100644 index 000000000..c0dc2d7d5 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_laddr_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutVsVipPortLaddrURL generates an URL for the put vs vip port laddr operation +type PutVsVipPortLaddrURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortLaddrURL) WithBasePath(bp string) *PutVsVipPortLaddrURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortLaddrURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutVsVipPortLaddrURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/laddr" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PutVsVipPortLaddrURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutVsVipPortLaddrURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutVsVipPortLaddrURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutVsVipPortLaddrURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutVsVipPortLaddrURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutVsVipPortLaddrURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutVsVipPortLaddrURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_parameters.go new file mode 100644 index 000000000..8dc0c2030 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_parameters.go @@ -0,0 +1,101 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutVsVipPortParams creates a new PutVsVipPortParams object +// +// There are no default values defined in the spec. +func NewPutVsVipPortParams() PutVsVipPortParams { + + return PutVsVipPortParams{} +} + +// PutVsVipPortParams contains all the bound params for the put vs vip port operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutVsVipPort +type PutVsVipPortParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: body + */ + Spec *models.VirtualServerSpecTiny +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutVsVipPortParams() beforehand. +func (o *PutVsVipPortParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.VirtualServerSpecTiny + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("spec", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Spec = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PutVsVipPortParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_responses.go new file mode 100644 index 000000000..19946ac56 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PutVsVipPortOKCode is the HTTP code returned for type PutVsVipPortOK +const PutVsVipPortOKCode int = 200 + +/* +PutVsVipPortOK Updated + +swagger:response putVsVipPortOK +*/ +type PutVsVipPortOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortOK creates PutVsVipPortOK with default headers values +func NewPutVsVipPortOK() *PutVsVipPortOK { + + return &PutVsVipPortOK{} +} + +// WithPayload adds the payload to the put vs vip port o k response +func (o *PutVsVipPortOK) WithPayload(payload string) *PutVsVipPortOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port o k response +func (o *PutVsVipPortOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortCreatedCode is the HTTP code returned for type PutVsVipPortCreated +const PutVsVipPortCreatedCode int = 201 + +/* +PutVsVipPortCreated Created + +swagger:response putVsVipPortCreated +*/ +type PutVsVipPortCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortCreated creates PutVsVipPortCreated with default headers values +func NewPutVsVipPortCreated() *PutVsVipPortCreated { + + return &PutVsVipPortCreated{} +} + +// WithPayload adds the payload to the put vs vip port created response +func (o *PutVsVipPortCreated) WithPayload(payload string) *PutVsVipPortCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port created response +func (o *PutVsVipPortCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortInvalidFrontendCode is the HTTP code returned for type PutVsVipPortInvalidFrontend +const PutVsVipPortInvalidFrontendCode int = 460 + +/* +PutVsVipPortInvalidFrontend Invalid frontend in service configuration + +swagger:response putVsVipPortInvalidFrontend +*/ +type PutVsVipPortInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortInvalidFrontend creates PutVsVipPortInvalidFrontend with default headers values +func NewPutVsVipPortInvalidFrontend() *PutVsVipPortInvalidFrontend { + + return &PutVsVipPortInvalidFrontend{} +} + +// WithPayload adds the payload to the put vs vip port invalid frontend response +func (o *PutVsVipPortInvalidFrontend) WithPayload(payload models.Error) *PutVsVipPortInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port invalid frontend response +func (o *PutVsVipPortInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortInvalidBackendCode is the HTTP code returned for type PutVsVipPortInvalidBackend +const PutVsVipPortInvalidBackendCode int = 461 + +/* +PutVsVipPortInvalidBackend Invalid backend in service configuration + +swagger:response putVsVipPortInvalidBackend +*/ +type PutVsVipPortInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortInvalidBackend creates PutVsVipPortInvalidBackend with default headers values +func NewPutVsVipPortInvalidBackend() *PutVsVipPortInvalidBackend { + + return &PutVsVipPortInvalidBackend{} +} + +// WithPayload adds the payload to the put vs vip port invalid backend response +func (o *PutVsVipPortInvalidBackend) WithPayload(payload models.Error) *PutVsVipPortInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port invalid backend response +func (o *PutVsVipPortInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortFailureCode is the HTTP code returned for type PutVsVipPortFailure +const PutVsVipPortFailureCode int = 500 + +/* +PutVsVipPortFailure Error while creating virtual server + +swagger:response putVsVipPortFailure +*/ +type PutVsVipPortFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortFailure creates PutVsVipPortFailure with default headers values +func NewPutVsVipPortFailure() *PutVsVipPortFailure { + + return &PutVsVipPortFailure{} +} + +// WithPayload adds the payload to the put vs vip port failure response +func (o *PutVsVipPortFailure) WithPayload(payload models.Error) *PutVsVipPortFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port failure response +func (o *PutVsVipPortFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs.go new file mode 100644 index 000000000..475833200 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs.go @@ -0,0 +1,56 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// PutVsVipPortRsHandlerFunc turns a function with the right signature into a put vs vip port rs handler +type PutVsVipPortRsHandlerFunc func(PutVsVipPortRsParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn PutVsVipPortRsHandlerFunc) Handle(params PutVsVipPortRsParams) middleware.Responder { + return fn(params) +} + +// PutVsVipPortRsHandler interface for that can handle valid put vs vip port rs params +type PutVsVipPortRsHandler interface { + Handle(PutVsVipPortRsParams) middleware.Responder +} + +// NewPutVsVipPortRs creates a new http.Handler for the put vs vip port rs operation +func NewPutVsVipPortRs(ctx *middleware.Context, handler PutVsVipPortRsHandler) *PutVsVipPortRs { + return &PutVsVipPortRs{Context: ctx, Handler: handler} +} + +/* + PutVsVipPortRs swagger:route PUT /vs/{VipPort}/rs virtualserver putVsVipPortRs + +Add a set of real server to vip:port:proto +*/ +type PutVsVipPortRs struct { + Context *middleware.Context + Handler PutVsVipPortRsHandler +} + +func (o *PutVsVipPortRs) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewPutVsVipPortRsParams() + if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params + o.Context.Respond(rw, r, route.Produces, route, err) + return + } + + res := o.Handler.Handle(Params) // actually handle the request + o.Context.Respond(rw, r, route.Produces, route, res) + +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_parameters.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_parameters.go new file mode 100644 index 000000000..0e36def24 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_parameters.go @@ -0,0 +1,145 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" + + "github.com/dpvs-agent/models" +) + +// NewPutVsVipPortRsParams creates a new PutVsVipPortRsParams object +// with the default values initialized. +func NewPutVsVipPortRsParams() PutVsVipPortRsParams { + + var ( + // initialize parameters with default values + + healthcheckDefault = bool(false) + ) + + return PutVsVipPortRsParams{ + Healthcheck: &healthcheckDefault, + } +} + +// PutVsVipPortRsParams contains all the bound params for the put vs vip port rs operation +// typically these are obtained from a http.Request +// +// swagger:parameters PutVsVipPortRs +type PutVsVipPortRsParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /* + Required: true + In: path + */ + VipPort string + /* + In: query + Default: false + */ + Healthcheck *bool + /* + In: body + */ + Rss *models.RealServerTinyList +} + +// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface +// for simple values it will use straight method calls. +// +// To ensure default values, the struct must have been initialized with NewPutVsVipPortRsParams() beforehand. +func (o *PutVsVipPortRsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + qs := runtime.Values(r.URL.Query()) + + rVipPort, rhkVipPort, _ := route.Params.GetOK("VipPort") + if err := o.bindVipPort(rVipPort, rhkVipPort, route.Formats); err != nil { + res = append(res, err) + } + + qHealthcheck, qhkHealthcheck, _ := qs.GetOK("healthcheck") + if err := o.bindHealthcheck(qHealthcheck, qhkHealthcheck, route.Formats); err != nil { + res = append(res, err) + } + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.RealServerTinyList + if err := route.Consumer.Consume(r.Body, &body); err != nil { + res = append(res, errors.NewParseError("rss", "body", "", err)) + } else { + // validate body object + if err := body.Validate(route.Formats); err != nil { + res = append(res, err) + } + + ctx := validate.WithOperationRequest(r.Context()) + if err := body.ContextValidate(ctx, route.Formats); err != nil { + res = append(res, err) + } + + if len(res) == 0 { + o.Rss = &body + } + } + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +// bindVipPort binds and validates parameter VipPort from path. +func (o *PutVsVipPortRsParams) bindVipPort(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: true + // Parameter is provided by construction from the route + o.VipPort = raw + + return nil +} + +// bindHealthcheck binds and validates parameter Healthcheck from query. +func (o *PutVsVipPortRsParams) bindHealthcheck(rawData []string, hasKey bool, formats strfmt.Registry) error { + var raw string + if len(rawData) > 0 { + raw = rawData[len(rawData)-1] + } + + // Required: false + // AllowEmptyValue: false + + if raw == "" { // empty values pass all other validations + // Default values have been previously initialized by NewPutVsVipPortRsParams() + return nil + } + + value, err := swag.ConvertBool(raw) + if err != nil { + return errors.InvalidType("healthcheck", "query", "bool", raw) + } + o.Healthcheck = &value + + return nil +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_responses.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_responses.go new file mode 100644 index 000000000..8dd6b9737 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_responses.go @@ -0,0 +1,229 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/dpvs-agent/models" +) + +// PutVsVipPortRsOKCode is the HTTP code returned for type PutVsVipPortRsOK +const PutVsVipPortRsOKCode int = 200 + +/* +PutVsVipPortRsOK Success + +swagger:response putVsVipPortRsOK +*/ +type PutVsVipPortRsOK struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortRsOK creates PutVsVipPortRsOK with default headers values +func NewPutVsVipPortRsOK() *PutVsVipPortRsOK { + + return &PutVsVipPortRsOK{} +} + +// WithPayload adds the payload to the put vs vip port rs o k response +func (o *PutVsVipPortRsOK) WithPayload(payload string) *PutVsVipPortRsOK { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port rs o k response +func (o *PutVsVipPortRsOK) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortRsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(200) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortRsCreatedCode is the HTTP code returned for type PutVsVipPortRsCreated +const PutVsVipPortRsCreatedCode int = 201 + +/* +PutVsVipPortRsCreated Created + +swagger:response putVsVipPortRsCreated +*/ +type PutVsVipPortRsCreated struct { + + /* + In: Body + */ + Payload string `json:"body,omitempty"` +} + +// NewPutVsVipPortRsCreated creates PutVsVipPortRsCreated with default headers values +func NewPutVsVipPortRsCreated() *PutVsVipPortRsCreated { + + return &PutVsVipPortRsCreated{} +} + +// WithPayload adds the payload to the put vs vip port rs created response +func (o *PutVsVipPortRsCreated) WithPayload(payload string) *PutVsVipPortRsCreated { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port rs created response +func (o *PutVsVipPortRsCreated) SetPayload(payload string) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortRsCreated) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(201) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortRsInvalidFrontendCode is the HTTP code returned for type PutVsVipPortRsInvalidFrontend +const PutVsVipPortRsInvalidFrontendCode int = 460 + +/* +PutVsVipPortRsInvalidFrontend Invalid frontend in service configuration + +swagger:response putVsVipPortRsInvalidFrontend +*/ +type PutVsVipPortRsInvalidFrontend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortRsInvalidFrontend creates PutVsVipPortRsInvalidFrontend with default headers values +func NewPutVsVipPortRsInvalidFrontend() *PutVsVipPortRsInvalidFrontend { + + return &PutVsVipPortRsInvalidFrontend{} +} + +// WithPayload adds the payload to the put vs vip port rs invalid frontend response +func (o *PutVsVipPortRsInvalidFrontend) WithPayload(payload models.Error) *PutVsVipPortRsInvalidFrontend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port rs invalid frontend response +func (o *PutVsVipPortRsInvalidFrontend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortRsInvalidFrontend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(460) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortRsInvalidBackendCode is the HTTP code returned for type PutVsVipPortRsInvalidBackend +const PutVsVipPortRsInvalidBackendCode int = 461 + +/* +PutVsVipPortRsInvalidBackend Invalid backend in service configuration + +swagger:response putVsVipPortRsInvalidBackend +*/ +type PutVsVipPortRsInvalidBackend struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortRsInvalidBackend creates PutVsVipPortRsInvalidBackend with default headers values +func NewPutVsVipPortRsInvalidBackend() *PutVsVipPortRsInvalidBackend { + + return &PutVsVipPortRsInvalidBackend{} +} + +// WithPayload adds the payload to the put vs vip port rs invalid backend response +func (o *PutVsVipPortRsInvalidBackend) WithPayload(payload models.Error) *PutVsVipPortRsInvalidBackend { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port rs invalid backend response +func (o *PutVsVipPortRsInvalidBackend) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortRsInvalidBackend) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(461) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} + +// PutVsVipPortRsFailureCode is the HTTP code returned for type PutVsVipPortRsFailure +const PutVsVipPortRsFailureCode int = 500 + +/* +PutVsVipPortRsFailure Service deletion failed + +swagger:response putVsVipPortRsFailure +*/ +type PutVsVipPortRsFailure struct { + + /* + In: Body + */ + Payload models.Error `json:"body,omitempty"` +} + +// NewPutVsVipPortRsFailure creates PutVsVipPortRsFailure with default headers values +func NewPutVsVipPortRsFailure() *PutVsVipPortRsFailure { + + return &PutVsVipPortRsFailure{} +} + +// WithPayload adds the payload to the put vs vip port rs failure response +func (o *PutVsVipPortRsFailure) WithPayload(payload models.Error) *PutVsVipPortRsFailure { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the put vs vip port rs failure response +func (o *PutVsVipPortRsFailure) SetPayload(payload models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *PutVsVipPortRsFailure) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_urlbuilder.go new file mode 100644 index 000000000..d906fae36 --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_rs_urlbuilder.go @@ -0,0 +1,115 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" + + "github.com/go-openapi/swag" +) + +// PutVsVipPortRsURL generates an URL for the put vs vip port rs operation +type PutVsVipPortRsURL struct { + VipPort string + + Healthcheck *bool + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortRsURL) WithBasePath(bp string) *PutVsVipPortRsURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortRsURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutVsVipPortRsURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}/rs" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PutVsVipPortRsURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + qs := make(url.Values) + + var healthcheckQ string + if o.Healthcheck != nil { + healthcheckQ = swag.FormatBool(*o.Healthcheck) + } + if healthcheckQ != "" { + qs.Set("healthcheck", healthcheckQ) + } + + _result.RawQuery = qs.Encode() + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutVsVipPortRsURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutVsVipPortRsURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutVsVipPortRsURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutVsVipPortRsURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutVsVipPortRsURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutVsVipPortRsURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_urlbuilder.go b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_urlbuilder.go new file mode 100644 index 000000000..01adfb16c --- /dev/null +++ b/tools/dpvs-agent/restapi/operations/virtualserver/put_vs_vip_port_urlbuilder.go @@ -0,0 +1,99 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package virtualserver + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" + "strings" +) + +// PutVsVipPortURL generates an URL for the put vs vip port operation +type PutVsVipPortURL struct { + VipPort string + + _basePath string + // avoid unkeyed usage + _ struct{} +} + +// WithBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortURL) WithBasePath(bp string) *PutVsVipPortURL { + o.SetBasePath(bp) + return o +} + +// SetBasePath sets the base path for this url builder, only required when it's different from the +// base path specified in the swagger spec. +// When the value of the base path is an empty string +func (o *PutVsVipPortURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *PutVsVipPortURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/vs/{VipPort}" + + vipPort := o.VipPort + if vipPort != "" { + _path = strings.Replace(_path, "{VipPort}", vipPort, -1) + } else { + return nil, errors.New("vipPort is required on PutVsVipPortURL") + } + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/v2" + } + _result.Path = golangswaggerpaths.Join(_basePath, _path) + + return &_result, nil +} + +// Must is a helper function to panic when the url builder returns an error +func (o *PutVsVipPortURL) Must(u *url.URL, err error) *url.URL { + if err != nil { + panic(err) + } + if u == nil { + panic("url can't be nil") + } + return u +} + +// String returns the string representation of the path with query string +func (o *PutVsVipPortURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *PutVsVipPortURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on PutVsVipPortURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on PutVsVipPortURL") + } + + base, err := o.Build() + if err != nil { + return nil, err + } + + base.Scheme = scheme + base.Host = host + return base, nil +} + +// StringFull returns the string representation of a complete url +func (o *PutVsVipPortURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/tools/dpvs-agent/restapi/server.go b/tools/dpvs-agent/restapi/server.go new file mode 100644 index 000000000..2c8225403 --- /dev/null +++ b/tools/dpvs-agent/restapi/server.go @@ -0,0 +1,507 @@ +// Code generated by go-swagger; DO NOT EDIT. + +package restapi + +import ( + "context" + "crypto/tls" + "crypto/x509" + "errors" + "fmt" + "log" + "net" + "net/http" + "os" + "os/signal" + "strconv" + "sync" + "sync/atomic" + "syscall" + "time" + + "github.com/go-openapi/runtime/flagext" + "github.com/go-openapi/swag" + flags "github.com/jessevdk/go-flags" + "golang.org/x/net/netutil" + + "github.com/dpvs-agent/restapi/operations" +) + +const ( + schemeHTTP = "http" + schemeHTTPS = "https" + schemeUnix = "unix" +) + +var defaultSchemes []string + +func init() { + defaultSchemes = []string{ + schemeHTTP, + } +} + +// NewServer creates a new api dpvs agent server but does not configure it +func NewServer(api *operations.DpvsAgentAPI) *Server { + s := new(Server) + + s.shutdown = make(chan struct{}) + s.api = api + s.interrupt = make(chan os.Signal, 1) + return s +} + +// ConfigureAPI configures the API and handlers. +func (s *Server) ConfigureAPI() { + if s.api != nil { + s.handler = configureAPI(s.api) + } +} + +// ConfigureFlags configures the additional flags defined by the handlers. Needs to be called before the parser.Parse +func (s *Server) ConfigureFlags() { + if s.api != nil { + configureFlags(s.api) + } +} + +// Server for the dpvs agent API +type Server struct { + EnabledListeners []string `long:"scheme" description:"the listeners to enable, this can be repeated and defaults to the schemes in the swagger spec"` + CleanupTimeout time.Duration `long:"cleanup-timeout" description:"grace period for which to wait before killing idle connections" default:"10s"` + GracefulTimeout time.Duration `long:"graceful-timeout" description:"grace period for which to wait before shutting down the server" default:"15s"` + MaxHeaderSize flagext.ByteSize `long:"max-header-size" description:"controls the maximum number of bytes the server will read parsing the request header's keys and values, including the request line. It does not limit the size of the request body." default:"1MiB"` + + SocketPath flags.Filename `long:"socket-path" description:"the unix socket to listen on" default:"/var/run/dpvs-agent.sock"` + domainSocketL net.Listener + + Host string `long:"host" description:"the IP to listen on" default:"localhost" env:"HOST"` + Port int `long:"port" description:"the port to listen on for insecure connections, defaults to a random value" env:"PORT"` + ListenLimit int `long:"listen-limit" description:"limit the number of outstanding requests"` + KeepAlive time.Duration `long:"keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)" default:"3m"` + ReadTimeout time.Duration `long:"read-timeout" description:"maximum duration before timing out read of the request" default:"30s"` + WriteTimeout time.Duration `long:"write-timeout" description:"maximum duration before timing out write of the response" default:"60s"` + httpServerL net.Listener + + TLSHost string `long:"tls-host" description:"the IP to listen on for tls, when not specified it's the same as --host" env:"TLS_HOST"` + TLSPort int `long:"tls-port" description:"the port to listen on for secure connections, defaults to a random value" env:"TLS_PORT"` + TLSCertificate flags.Filename `long:"tls-certificate" description:"the certificate to use for secure connections" env:"TLS_CERTIFICATE"` + TLSCertificateKey flags.Filename `long:"tls-key" description:"the private key to use for secure connections" env:"TLS_PRIVATE_KEY"` + TLSCACertificate flags.Filename `long:"tls-ca" description:"the certificate authority file to be used with mutual tls auth" env:"TLS_CA_CERTIFICATE"` + TLSListenLimit int `long:"tls-listen-limit" description:"limit the number of outstanding requests"` + TLSKeepAlive time.Duration `long:"tls-keep-alive" description:"sets the TCP keep-alive timeouts on accepted connections. It prunes dead TCP connections ( e.g. closing laptop mid-download)"` + TLSReadTimeout time.Duration `long:"tls-read-timeout" description:"maximum duration before timing out read of the request"` + TLSWriteTimeout time.Duration `long:"tls-write-timeout" description:"maximum duration before timing out write of the response"` + httpsServerL net.Listener + + api *operations.DpvsAgentAPI + handler http.Handler + hasListeners bool + shutdown chan struct{} + shuttingDown int32 + interrupted bool + interrupt chan os.Signal +} + +// Logf logs message either via defined user logger or via system one if no user logger is defined. +func (s *Server) Logf(f string, args ...interface{}) { + if s.api != nil && s.api.Logger != nil { + s.api.Logger(f, args...) + } else { + log.Printf(f, args...) + } +} + +// Fatalf logs message either via defined user logger or via system one if no user logger is defined. +// Exits with non-zero status after printing +func (s *Server) Fatalf(f string, args ...interface{}) { + if s.api != nil && s.api.Logger != nil { + s.api.Logger(f, args...) + os.Exit(1) + } else { + log.Fatalf(f, args...) + } +} + +// SetAPI configures the server with the specified API. Needs to be called before Serve +func (s *Server) SetAPI(api *operations.DpvsAgentAPI) { + if api == nil { + s.api = nil + s.handler = nil + return + } + + s.api = api + s.handler = configureAPI(api) +} + +func (s *Server) hasScheme(scheme string) bool { + schemes := s.EnabledListeners + if len(schemes) == 0 { + schemes = defaultSchemes + } + + for _, v := range schemes { + if v == scheme { + return true + } + } + return false +} + +// Serve the api +func (s *Server) Serve() (err error) { + if !s.hasListeners { + if err = s.Listen(); err != nil { + return err + } + } + + // set default handler, if none is set + if s.handler == nil { + if s.api == nil { + return errors.New("can't create the default handler, as no api is set") + } + + s.SetHandler(s.api.Serve(nil)) + } + + wg := new(sync.WaitGroup) + once := new(sync.Once) + signalNotify(s.interrupt) + go handleInterrupt(once, s) + + servers := []*http.Server{} + + if s.hasScheme(schemeUnix) { + domainSocket := new(http.Server) + domainSocket.MaxHeaderBytes = int(s.MaxHeaderSize) + domainSocket.Handler = s.handler + if int64(s.CleanupTimeout) > 0 { + domainSocket.IdleTimeout = s.CleanupTimeout + } + + configureServer(domainSocket, "unix", string(s.SocketPath)) + + servers = append(servers, domainSocket) + wg.Add(1) + s.Logf("Serving dpvs agent at unix://%s", s.SocketPath) + go func(l net.Listener) { + defer wg.Done() + if err := domainSocket.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving dpvs agent at unix://%s", s.SocketPath) + }(s.domainSocketL) + } + + if s.hasScheme(schemeHTTP) { + httpServer := new(http.Server) + httpServer.MaxHeaderBytes = int(s.MaxHeaderSize) + httpServer.ReadTimeout = s.ReadTimeout + httpServer.WriteTimeout = s.WriteTimeout + httpServer.SetKeepAlivesEnabled(int64(s.KeepAlive) > 0) + if s.ListenLimit > 0 { + s.httpServerL = netutil.LimitListener(s.httpServerL, s.ListenLimit) + } + + if int64(s.CleanupTimeout) > 0 { + httpServer.IdleTimeout = s.CleanupTimeout + } + + httpServer.Handler = s.handler + + configureServer(httpServer, "http", s.httpServerL.Addr().String()) + + servers = append(servers, httpServer) + wg.Add(1) + s.Logf("Serving dpvs agent at http://%s", s.httpServerL.Addr()) + go func(l net.Listener) { + defer wg.Done() + if err := httpServer.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving dpvs agent at http://%s", l.Addr()) + }(s.httpServerL) + } + + if s.hasScheme(schemeHTTPS) { + httpsServer := new(http.Server) + httpsServer.MaxHeaderBytes = int(s.MaxHeaderSize) + httpsServer.ReadTimeout = s.TLSReadTimeout + httpsServer.WriteTimeout = s.TLSWriteTimeout + httpsServer.SetKeepAlivesEnabled(int64(s.TLSKeepAlive) > 0) + if s.TLSListenLimit > 0 { + s.httpsServerL = netutil.LimitListener(s.httpsServerL, s.TLSListenLimit) + } + if int64(s.CleanupTimeout) > 0 { + httpsServer.IdleTimeout = s.CleanupTimeout + } + httpsServer.Handler = s.handler + + // Inspired by https://blog.bracebin.com/achieving-perfect-ssl-labs-score-with-go + httpsServer.TLSConfig = &tls.Config{ + // Causes servers to use Go's default ciphersuite preferences, + // which are tuned to avoid attacks. Does nothing on clients. + PreferServerCipherSuites: true, + // Only use curves which have assembly implementations + // https://github.com/golang/go/tree/master/src/crypto/elliptic + CurvePreferences: []tls.CurveID{tls.CurveP256}, + // Use modern tls mode https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility + NextProtos: []string{"h2", "http/1.1"}, + // https://www.owasp.org/index.php/Transport_Layer_Protection_Cheat_Sheet#Rule_-_Only_Support_Strong_Protocols + MinVersion: tls.VersionTLS12, + // These ciphersuites support Forward Secrecy: https://en.wikipedia.org/wiki/Forward_secrecy + CipherSuites: []uint16{ + tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, + tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, + }, + } + + // build standard config from server options + if s.TLSCertificate != "" && s.TLSCertificateKey != "" { + httpsServer.TLSConfig.Certificates = make([]tls.Certificate, 1) + httpsServer.TLSConfig.Certificates[0], err = tls.LoadX509KeyPair(string(s.TLSCertificate), string(s.TLSCertificateKey)) + if err != nil { + return err + } + } + + if s.TLSCACertificate != "" { + // include specified CA certificate + caCert, caCertErr := os.ReadFile(string(s.TLSCACertificate)) + if caCertErr != nil { + return caCertErr + } + caCertPool := x509.NewCertPool() + ok := caCertPool.AppendCertsFromPEM(caCert) + if !ok { + return fmt.Errorf("cannot parse CA certificate") + } + httpsServer.TLSConfig.ClientCAs = caCertPool + httpsServer.TLSConfig.ClientAuth = tls.RequireAndVerifyClientCert + } + + // call custom TLS configurator + configureTLS(httpsServer.TLSConfig) + + if len(httpsServer.TLSConfig.Certificates) == 0 && httpsServer.TLSConfig.GetCertificate == nil { + // after standard and custom config are passed, this ends up with no certificate + if s.TLSCertificate == "" { + if s.TLSCertificateKey == "" { + s.Fatalf("the required flags `--tls-certificate` and `--tls-key` were not specified") + } + s.Fatalf("the required flag `--tls-certificate` was not specified") + } + if s.TLSCertificateKey == "" { + s.Fatalf("the required flag `--tls-key` was not specified") + } + // this happens with a wrong custom TLS configurator + s.Fatalf("no certificate was configured for TLS") + } + + configureServer(httpsServer, "https", s.httpsServerL.Addr().String()) + + servers = append(servers, httpsServer) + wg.Add(1) + s.Logf("Serving dpvs agent at https://%s", s.httpsServerL.Addr()) + go func(l net.Listener) { + defer wg.Done() + if err := httpsServer.Serve(l); err != nil && err != http.ErrServerClosed { + s.Fatalf("%v", err) + } + s.Logf("Stopped serving dpvs agent at https://%s", l.Addr()) + }(tls.NewListener(s.httpsServerL, httpsServer.TLSConfig)) + } + + wg.Add(1) + go s.handleShutdown(wg, &servers) + + wg.Wait() + return nil +} + +// Listen creates the listeners for the server +func (s *Server) Listen() error { + if s.hasListeners { // already done this + return nil + } + + if s.hasScheme(schemeHTTPS) { + // Use http host if https host wasn't defined + if s.TLSHost == "" { + s.TLSHost = s.Host + } + // Use http listen limit if https listen limit wasn't defined + if s.TLSListenLimit == 0 { + s.TLSListenLimit = s.ListenLimit + } + // Use http tcp keep alive if https tcp keep alive wasn't defined + if int64(s.TLSKeepAlive) == 0 { + s.TLSKeepAlive = s.KeepAlive + } + // Use http read timeout if https read timeout wasn't defined + if int64(s.TLSReadTimeout) == 0 { + s.TLSReadTimeout = s.ReadTimeout + } + // Use http write timeout if https write timeout wasn't defined + if int64(s.TLSWriteTimeout) == 0 { + s.TLSWriteTimeout = s.WriteTimeout + } + } + + if s.hasScheme(schemeUnix) { + domSockListener, err := net.Listen("unix", string(s.SocketPath)) + if err != nil { + return err + } + s.domainSocketL = domSockListener + } + + if s.hasScheme(schemeHTTP) { + listener, err := net.Listen("tcp", net.JoinHostPort(s.Host, strconv.Itoa(s.Port))) + if err != nil { + return err + } + + h, p, err := swag.SplitHostPort(listener.Addr().String()) + if err != nil { + return err + } + s.Host = h + s.Port = p + s.httpServerL = listener + } + + if s.hasScheme(schemeHTTPS) { + tlsListener, err := net.Listen("tcp", net.JoinHostPort(s.TLSHost, strconv.Itoa(s.TLSPort))) + if err != nil { + return err + } + + sh, sp, err := swag.SplitHostPort(tlsListener.Addr().String()) + if err != nil { + return err + } + s.TLSHost = sh + s.TLSPort = sp + s.httpsServerL = tlsListener + } + + s.hasListeners = true + return nil +} + +// Shutdown server and clean up resources +func (s *Server) Shutdown() error { + if atomic.CompareAndSwapInt32(&s.shuttingDown, 0, 1) { + close(s.shutdown) + } + return nil +} + +func (s *Server) handleShutdown(wg *sync.WaitGroup, serversPtr *[]*http.Server) { + // wg.Done must occur last, after s.api.ServerShutdown() + // (to preserve old behaviour) + defer wg.Done() + + <-s.shutdown + + servers := *serversPtr + + ctx, cancel := context.WithTimeout(context.TODO(), s.GracefulTimeout) + defer cancel() + + // first execute the pre-shutdown hook + s.api.PreServerShutdown() + + shutdownChan := make(chan bool) + for i := range servers { + server := servers[i] + go func() { + var success bool + defer func() { + shutdownChan <- success + }() + if err := server.Shutdown(ctx); err != nil { + // Error from closing listeners, or context timeout: + s.Logf("HTTP server Shutdown: %v", err) + } else { + success = true + } + }() + } + + // Wait until all listeners have successfully shut down before calling ServerShutdown + success := true + for range servers { + success = success && <-shutdownChan + } + if success { + s.api.ServerShutdown() + } +} + +// GetHandler returns a handler useful for testing +func (s *Server) GetHandler() http.Handler { + return s.handler +} + +// SetHandler allows for setting a http handler on this server +func (s *Server) SetHandler(handler http.Handler) { + s.handler = handler +} + +// UnixListener returns the domain socket listener +func (s *Server) UnixListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.domainSocketL, nil +} + +// HTTPListener returns the http listener +func (s *Server) HTTPListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.httpServerL, nil +} + +// TLSListener returns the https listener +func (s *Server) TLSListener() (net.Listener, error) { + if !s.hasListeners { + if err := s.Listen(); err != nil { + return nil, err + } + } + return s.httpsServerL, nil +} + +func handleInterrupt(once *sync.Once, s *Server) { + once.Do(func() { + for range s.interrupt { + if s.interrupted { + s.Logf("Server already shutting down") + continue + } + s.interrupted = true + s.Logf("Shutting down... ") + if err := s.Shutdown(); err != nil { + s.Logf("HTTP server Shutdown: %v", err) + } + } + }) +} + +func signalNotify(interrupt chan<- os.Signal) { + signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) +}