From 2d4501d3eade8064dd30218d5285e3a0172c9af3 Mon Sep 17 00:00:00 2001 From: inho Date: Thu, 27 Jun 2024 17:29:29 +0900 Subject: [PATCH 1/2] Add path flag to loxicmd save to non default /etc/loxilb directory #706 --- api/loxinlp/nlp.go | 44 +++++++++++++++++++++++++++++--------------- options/options.go | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/api/loxinlp/nlp.go b/api/loxinlp/nlp.go index 7fa9c7a45..4bdce6cf9 100644 --- a/api/loxinlp/nlp.go +++ b/api/loxinlp/nlp.go @@ -30,6 +30,7 @@ import ( "time" cmn "github.com/loxilb-io/loxilb/common" + opt "github.com/loxilb-io/loxilb/options" tk "github.com/loxilb-io/loxilib" nlp "github.com/vishvananda/netlink" "golang.org/x/sys/unix" @@ -105,7 +106,8 @@ func iSBlackListedIntf(name string, masterIdx int) bool { } func applyAllConfig(name string) bool { - command := "loxicmd apply --per-intf " + name + " -c /etc/loxilb/ipconfig/" + + command := "loxicmd apply --per-intf " + name + " -c " + opt.Opts.ConfigPath + "/ipconfig/" cmd := exec.Command("bash", "-c", command) output, err := cmd.Output() if err != nil { @@ -120,7 +122,8 @@ func applyLoadBalancerConfig() bool { var resp struct { Attr []cmn.LbRuleMod `json:"lbAttr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/lbconfig.txt") + dpath := opt.Opts.ConfigPath + "/lbconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -141,7 +144,8 @@ func applySessionConfig() bool { var resp struct { Attr []cmn.SessionMod `json:"sessionAttr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/sessionconfig.txt") + dpath := opt.Opts.ConfigPath + "/sessionconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -162,7 +166,8 @@ func applyUlClConfig() bool { var resp struct { Attr []cmn.SessionUlClMod `json:"ulclAttr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/sessionulclconfig.txt") + dpath := opt.Opts.ConfigPath + "/sessionulclconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -183,7 +188,8 @@ func applyFWConfig() bool { var resp struct { Attr []cmn.FwRuleMod `json:"fwAttr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/FWconfig.txt") + dpath := opt.Opts.ConfigPath + "/FWconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -204,7 +210,8 @@ func applyEPConfig() bool { var resp struct { Attr []cmn.EndPointMod `json:"Attr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/EPconfig.txt") + dpath := opt.Opts.ConfigPath + "/EPconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -225,7 +232,8 @@ func ApplyBFDConfig() bool { var resp struct { Attr []cmn.BFDMod `json:"Attr"` } - byteBuf, err := os.ReadFile("/etc/loxilb/BFDconfig.txt") + dpath := opt.Opts.ConfigPath + "/BFDconfig.txt" + byteBuf, err := os.ReadFile(dpath) if err != nil { fmt.Println(err.Error()) return false @@ -244,7 +252,7 @@ func ApplyBFDConfig() bool { func applyRoutes(name string) { tk.LogIt(tk.LogDebug, "[NLP] Applying Route Config for %s \n", name) - command := "loxicmd apply --per-intf " + name + " -r -c /etc/loxilb/ipconfig/" + command := "loxicmd apply --per-intf " + name + " -r -c " + opt.Opts.ConfigPath + "/ipconfig/" cmd := exec.Command("bash", "-c", command) output, err := cmd.Output() if err != nil { @@ -257,7 +265,9 @@ func applyRoutes(name string) { func applyConfigMap(name string, state bool, add bool) { var configApplied bool var needRouteApply bool - if _, err := os.Stat("/etc/loxilb/ipconfig/"); errors.Is(err, os.ErrNotExist) { + dpath := opt.Opts.ConfigPath + "/ipconfig/" + + if _, err := os.Stat(dpath); errors.Is(err, os.ErrNotExist) { return } if add { @@ -1200,7 +1210,7 @@ func AddRoute(route nlp.Route) int { return ret } -func AddRouteNoHook(DestinationIPNet, gateway string) int { +func AddRouteNoHook(DestinationIPNet, gateway, proto string) int { var ret int var route nlp.Route _, Ipnet, err := net.ParseCIDR(DestinationIPNet) @@ -1210,6 +1220,10 @@ func AddRouteNoHook(DestinationIPNet, gateway string) int { Gw := net.ParseIP(gateway) route.Dst = Ipnet route.Gw = Gw + + if proto == "static" { + route.Protocol = 4 // 4 means Proto Static. + } err = nlp.RouteAdd(&route) if err != nil { return -1 @@ -1577,7 +1591,7 @@ func LbSessionGet(done bool) int { if done { - if _, err := os.Stat("/etc/loxilb/EPconfig.txt"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(opt.Opts.ConfigPath + "/EPconfig.txt"); errors.Is(err, os.ErrNotExist) { if err != nil { tk.LogIt(tk.LogInfo, "[NLP] No EndPoint config file : %s \n", err.Error()) } @@ -1586,7 +1600,7 @@ func LbSessionGet(done bool) int { } tk.LogIt(tk.LogInfo, "[NLP] EndPoint done\n") - if _, err := os.Stat("/etc/loxilb/lbconfig.txt"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(opt.Opts.ConfigPath + "/lbconfig.txt"); errors.Is(err, os.ErrNotExist) { if err != nil { tk.LogIt(tk.LogInfo, "[NLP] No load balancer config file : %s \n", err.Error()) } @@ -1595,7 +1609,7 @@ func LbSessionGet(done bool) int { } tk.LogIt(tk.LogInfo, "[NLP] LoadBalancer done\n") - if _, err := os.Stat("/etc/loxilb/sessionconfig.txt"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(opt.Opts.ConfigPath + "/sessionconfig.txt"); errors.Is(err, os.ErrNotExist) { if err != nil { tk.LogIt(tk.LogInfo, "[NLP] No Session config file : %s \n", err.Error()) } @@ -1604,7 +1618,7 @@ func LbSessionGet(done bool) int { } tk.LogIt(tk.LogInfo, "[NLP] Session done\n") - if _, err := os.Stat("/etc/loxilb/sessionulclconfig.txt"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(opt.Opts.ConfigPath + "/sessionulclconfig.txt"); errors.Is(err, os.ErrNotExist) { if err != nil { tk.LogIt(tk.LogInfo, "[NLP] No UlCl config file : %s \n", err.Error()) } @@ -1613,7 +1627,7 @@ func LbSessionGet(done bool) int { } tk.LogIt(tk.LogInfo, "[NLP] Session UlCl done\n") - if _, err := os.Stat("/etc/loxilb/FWconfig.txt"); errors.Is(err, os.ErrNotExist) { + if _, err := os.Stat(opt.Opts.ConfigPath + "/FWconfig.txt"); errors.Is(err, os.ErrNotExist) { if err != nil { tk.LogIt(tk.LogInfo, "[NLP] No Firewall config file : %s \n", err.Error()) } diff --git a/options/options.go b/options/options.go index c96d8bd52..a0633ee8c 100644 --- a/options/options.go +++ b/options/options.go @@ -34,4 +34,5 @@ var Opts struct { FallBack bool `long:"fallback" description:"Fallback to system default networking(experimental)"` LocalSockPolicy bool `long:"localsockpolicy" description:"support local socket policies (experimental)"` SockMapSupport bool `long:"sockmapsupport" description:"Support sockmap based L4 proxying (experimental)"` + ConfigPath string `long:"config-path" description:"Config file path" default:"/etc/loxilb/"` } From 275861162ba2a06118e8437b4f50b362de75accf Mon Sep 17 00:00:00 2001 From: inho Date: Thu, 27 Jun 2024 17:33:57 +0900 Subject: [PATCH 2/2] Add static route API, appling policy API --- api/models/route_entry.go | 3 + api/restapi/configure_loxilb_rest_api.go | 3 +- api/restapi/embedded_spec.go | 132 +++++++ api/restapi/handler/gobgp.go | 31 +- api/restapi/handler/route.go | 2 +- .../delete_config_bgp_policy_apply.go | 58 +++ ...lete_config_bgp_policy_apply_parameters.go | 84 +++++ ...elete_config_bgp_policy_apply_responses.go | 354 ++++++++++++++++++ ...lete_config_bgp_policy_apply_urlbuilder.go | 87 +++++ api/restapi/operations/loxilb_rest_api_api.go | 12 + api/swagger.yml | 45 ++- common/common.go | 1 + pkg/loxinet/apiclient.go | 13 +- pkg/loxinet/gobgpclient.go | 4 +- 14 files changed, 816 insertions(+), 13 deletions(-) create mode 100644 api/restapi/operations/delete_config_bgp_policy_apply.go create mode 100644 api/restapi/operations/delete_config_bgp_policy_apply_parameters.go create mode 100644 api/restapi/operations/delete_config_bgp_policy_apply_responses.go create mode 100644 api/restapi/operations/delete_config_bgp_policy_apply_urlbuilder.go diff --git a/api/models/route_entry.go b/api/models/route_entry.go index 16697bf37..b1cc525a4 100644 --- a/api/models/route_entry.go +++ b/api/models/route_entry.go @@ -22,6 +22,9 @@ type RouteEntry struct { // IP address for nexthop Gateway string `json:"gateway,omitempty"` + + // Protocol type of the route like "static" + Protocol string `json:"protocol,omitempty"` } // Validate validates this route entry diff --git a/api/restapi/configure_loxilb_rest_api.go b/api/restapi/configure_loxilb_rest_api.go index 3b4c9d205..df3fd8730 100644 --- a/api/restapi/configure_loxilb_rest_api.go +++ b/api/restapi/configure_loxilb_rest_api.go @@ -176,8 +176,9 @@ func configureAPI(api *operations.LoxilbRestAPIAPI) http.Handler { // BGP Policy Apply api.PostConfigBgpPolicyApplyHandler = operations.PostConfigBgpPolicyApplyHandlerFunc(handler.ConfigPostBGPPolicyApply) - api.PreServerShutdown = func() {} + api.DeleteConfigBgpPolicyApplyHandler = operations.DeleteConfigBgpPolicyApplyHandlerFunc(handler.ConfigDeleteBGPPolicyApply) + api.PreServerShutdown = func() {} api.ServerShutdown = func() {} return setupGlobalMiddleware(api.Serve(setupMiddlewares)) diff --git a/api/restapi/embedded_spec.go b/api/restapi/embedded_spec.go index fc7362b54..605848d59 100644 --- a/api/restapi/embedded_spec.go +++ b/api/restapi/embedded_spec.go @@ -535,6 +535,68 @@ func init() { } } } + }, + "delete": { + "description": "Delete BGP Policy in neighbor. It don't need \"routeAction\" in the attr body", + "summary": "Delete BGP Policy in neighbor", + "parameters": [ + { + "description": "Attributes of bgp neighbor", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPApplyPolicyToNeighborMod" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. Neigh already exists", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } } }, "/config/bgp/policy/definedsets/{defineset_type}": { @@ -5330,6 +5392,10 @@ func init() { "gateway": { "description": "IP address for nexthop", "type": "string" + }, + "protocol": { + "description": "Protocol type of the route like \"static\"", + "type": "string" } } }, @@ -6056,6 +6122,68 @@ func init() { } } } + }, + "delete": { + "description": "Delete BGP Policy in neighbor. It don't need \"routeAction\" in the attr body", + "summary": "Delete BGP Policy in neighbor", + "parameters": [ + { + "description": "Attributes of bgp neighbor", + "name": "attr", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/BGPApplyPolicyToNeighborMod" + } + } + ], + "responses": { + "204": { + "description": "OK" + }, + "400": { + "description": "Malformed arguments for API call", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "401": { + "description": "Invalid authentication credentials", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "403": { + "description": "Capacity insufficient", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "404": { + "description": "Resource not found", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "409": { + "description": "Resource Conflict. Neigh already exists", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "500": { + "description": "Internal service error", + "schema": { + "$ref": "#/definitions/Error" + } + }, + "503": { + "description": "Maintanence mode", + "schema": { + "$ref": "#/definitions/Error" + } + } + } } }, "/config/bgp/policy/definedsets/{defineset_type}": { @@ -11652,6 +11780,10 @@ func init() { "gateway": { "description": "IP address for nexthop", "type": "string" + }, + "protocol": { + "description": "Protocol type of the route like \"static\"", + "type": "string" } } }, diff --git a/api/restapi/handler/gobgp.go b/api/restapi/handler/gobgp.go index f093eaa6d..47bfc65f3 100644 --- a/api/restapi/handler/gobgp.go +++ b/api/restapi/handler/gobgp.go @@ -119,7 +119,7 @@ func ConfigPostBGPGlobal(params operations.PostConfigBgpGlobalParams) middleware } func ConfigPostBGPPolicyDefinedsets(params operations.PostConfigBgpPolicyDefinedsetsDefinesetTypeParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Policy Prefix %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy DefinedSet %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpPolicyDefinedSet cmn.GoBGPPolicyDefinedSetMod // name @@ -148,7 +148,7 @@ func ConfigPostBGPPolicyDefinedsets(params operations.PostConfigBgpPolicyDefined } func ConfigDeleteBGPPolicyDefinedsets(params operations.DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Policy %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy DefinedSet %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpPolicyConfig cmn.GoBGPPolicyDefinedSetMod bgpPolicyConfig.Name = params.TypeName @@ -164,7 +164,7 @@ func ConfigDeleteBGPPolicyDefinedsets(params operations.DeleteConfigBgpPolicyDef } func ConfigGetBGPPolicyDefinedSetGet(params operations.GetConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP DefinedSet %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) res, err := ApiHooks.NetGoBGPPolicyDefinedSetGet(params.TypeName, params.DefinesetType) if err != nil { tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) @@ -194,7 +194,7 @@ func ConfigGetBGPPolicyDefinedSetGet(params operations.GetConfigBgpPolicyDefined } func ConfigPostBGPPolicyDefinitions(params operations.PostConfigBgpPolicyDefinitionsParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Policy Prefix %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy Definitions %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpPolicyConfig cmn.GoBGPPolicyDefinitionsMod // name @@ -286,7 +286,7 @@ func ConfigPostBGPPolicyDefinitions(params operations.PostConfigBgpPolicyDefinit } func ConfigDeleteBGPPolicyDefinitions(params operations.DeleteConfigBgpPolicyDefinitionsPolicyNameParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Policy %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy Definitions %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpPolicyConfig cmn.GoBGPPolicyDefinitionsMod // name @@ -302,7 +302,7 @@ func ConfigDeleteBGPPolicyDefinitions(params operations.DeleteConfigBgpPolicyDef } func ConfigGetBGPPolicyDefinitions(params operations.GetConfigBgpPolicyDefinitionsAllParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy Definitions %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) res, err := ApiHooks.NetGoBGPPolicyDefinitionsGet() if err != nil { tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) @@ -400,7 +400,7 @@ func ConfigGetBGPPolicyDefinitions(params operations.GetConfigBgpPolicyDefinitio } func ConfigPostBGPPolicyApply(params operations.PostConfigBgpPolicyApplyParams) middleware.Responder { - tk.LogIt(tk.LogDebug, "[API] BGP Policy Prefix %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + tk.LogIt(tk.LogDebug, "[API] BGP Policy Apply %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) var bgpPolicyConfig cmn.GoBGPPolicyApply bgpPolicyConfig.NeighIPAddress = params.Attr.IPAddress @@ -415,3 +415,20 @@ func ConfigPostBGPPolicyApply(params operations.PostConfigBgpPolicyApplyParams) } return &ResultResponse{Result: "Success"} } + +func ConfigDeleteBGPPolicyApply(params operations.DeleteConfigBgpPolicyApplyParams) middleware.Responder { + tk.LogIt(tk.LogDebug, "[API] BGP Policy Apply %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) + var bgpPolicyConfig cmn.GoBGPPolicyApply + + bgpPolicyConfig.NeighIPAddress = params.Attr.IPAddress + bgpPolicyConfig.PolicyType = params.Attr.PolicyType + bgpPolicyConfig.Polices = params.Attr.Policies + bgpPolicyConfig.RouteAction = "" // No need RouteAction for delete + tk.LogIt(tk.LogDebug, "[API] GoBGP bgpPolicyConfig : %v\n", bgpPolicyConfig) + _, err := ApiHooks.NetGoBGPPolicyApplyDel(&bgpPolicyConfig) + if err != nil { + tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", err) + return &ResultResponse{Result: err.Error()} + } + return &ResultResponse{Result: "Success"} +} diff --git a/api/restapi/handler/route.go b/api/restapi/handler/route.go index 3b304ea56..c911bfe7f 100644 --- a/api/restapi/handler/route.go +++ b/api/restapi/handler/route.go @@ -28,7 +28,7 @@ import ( func ConfigPostRoute(params operations.PostConfigRouteParams) middleware.Responder { tk.LogIt(tk.LogDebug, "[API] Route %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL) - ret := loxinlp.AddRouteNoHook(params.Attr.DestinationIPNet, params.Attr.Gateway) + ret := loxinlp.AddRouteNoHook(params.Attr.DestinationIPNet, params.Attr.Gateway, params.Attr.Protocol) if ret != 0 { tk.LogIt(tk.LogDebug, "[API] Error occur : %v\n", ret) return &ResultResponse{Result: "fail"} diff --git a/api/restapi/operations/delete_config_bgp_policy_apply.go b/api/restapi/operations/delete_config_bgp_policy_apply.go new file mode 100644 index 000000000..d3160708b --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_policy_apply.go @@ -0,0 +1,58 @@ +// 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 generate command + +import ( + "net/http" + + "github.com/go-openapi/runtime/middleware" +) + +// DeleteConfigBgpPolicyApplyHandlerFunc turns a function with the right signature into a delete config bgp policy apply handler +type DeleteConfigBgpPolicyApplyHandlerFunc func(DeleteConfigBgpPolicyApplyParams) middleware.Responder + +// Handle executing the request and returning a response +func (fn DeleteConfigBgpPolicyApplyHandlerFunc) Handle(params DeleteConfigBgpPolicyApplyParams) middleware.Responder { + return fn(params) +} + +// DeleteConfigBgpPolicyApplyHandler interface for that can handle valid delete config bgp policy apply params +type DeleteConfigBgpPolicyApplyHandler interface { + Handle(DeleteConfigBgpPolicyApplyParams) middleware.Responder +} + +// NewDeleteConfigBgpPolicyApply creates a new http.Handler for the delete config bgp policy apply operation +func NewDeleteConfigBgpPolicyApply(ctx *middleware.Context, handler DeleteConfigBgpPolicyApplyHandler) *DeleteConfigBgpPolicyApply { + return &DeleteConfigBgpPolicyApply{Context: ctx, Handler: handler} +} + +/* + DeleteConfigBgpPolicyApply swagger:route DELETE /config/bgp/policy/apply deleteConfigBgpPolicyApply + +# Delete BGP Policy in neighbor + +Delete BGP Policy in neighbor. It don't need "routeAction" in the attr body +*/ +type DeleteConfigBgpPolicyApply struct { + Context *middleware.Context + Handler DeleteConfigBgpPolicyApplyHandler +} + +func (o *DeleteConfigBgpPolicyApply) ServeHTTP(rw http.ResponseWriter, r *http.Request) { + route, rCtx, _ := o.Context.RouteInfo(r) + if rCtx != nil { + *r = *rCtx + } + var Params = NewDeleteConfigBgpPolicyApplyParams() + 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/api/restapi/operations/delete_config_bgp_policy_apply_parameters.go b/api/restapi/operations/delete_config_bgp_policy_apply_parameters.go new file mode 100644 index 000000000..33dda3ab2 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_policy_apply_parameters.go @@ -0,0 +1,84 @@ +// 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 ( + "io" + "net/http" + + "github.com/go-openapi/errors" + "github.com/go-openapi/runtime" + "github.com/go-openapi/runtime/middleware" + "github.com/go-openapi/validate" + + "github.com/loxilb-io/loxilb/api/models" +) + +// NewDeleteConfigBgpPolicyApplyParams creates a new DeleteConfigBgpPolicyApplyParams object +// +// There are no default values defined in the spec. +func NewDeleteConfigBgpPolicyApplyParams() DeleteConfigBgpPolicyApplyParams { + + return DeleteConfigBgpPolicyApplyParams{} +} + +// DeleteConfigBgpPolicyApplyParams contains all the bound params for the delete config bgp policy apply operation +// typically these are obtained from a http.Request +// +// swagger:parameters DeleteConfigBgpPolicyApply +type DeleteConfigBgpPolicyApplyParams struct { + + // HTTP Request Object + HTTPRequest *http.Request `json:"-"` + + /*Attributes of bgp neighbor + Required: true + In: body + */ + Attr *models.BGPApplyPolicyToNeighborMod +} + +// 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 NewDeleteConfigBgpPolicyApplyParams() beforehand. +func (o *DeleteConfigBgpPolicyApplyParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { + var res []error + + o.HTTPRequest = r + + if runtime.HasBody(r) { + defer r.Body.Close() + var body models.BGPApplyPolicyToNeighborMod + if err := route.Consumer.Consume(r.Body, &body); err != nil { + if err == io.EOF { + res = append(res, errors.Required("attr", "body", "")) + } else { + res = append(res, errors.NewParseError("attr", "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.Attr = &body + } + } + } else { + res = append(res, errors.Required("attr", "body", "")) + } + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} diff --git a/api/restapi/operations/delete_config_bgp_policy_apply_responses.go b/api/restapi/operations/delete_config_bgp_policy_apply_responses.go new file mode 100644 index 000000000..42066df67 --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_policy_apply_responses.go @@ -0,0 +1,354 @@ +// 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 ( + "net/http" + + "github.com/go-openapi/runtime" + + "github.com/loxilb-io/loxilb/api/models" +) + +// DeleteConfigBgpPolicyApplyNoContentCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyNoContent +const DeleteConfigBgpPolicyApplyNoContentCode int = 204 + +/* +DeleteConfigBgpPolicyApplyNoContent OK + +swagger:response deleteConfigBgpPolicyApplyNoContent +*/ +type DeleteConfigBgpPolicyApplyNoContent struct { +} + +// NewDeleteConfigBgpPolicyApplyNoContent creates DeleteConfigBgpPolicyApplyNoContent with default headers values +func NewDeleteConfigBgpPolicyApplyNoContent() *DeleteConfigBgpPolicyApplyNoContent { + + return &DeleteConfigBgpPolicyApplyNoContent{} +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyNoContent) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(204) +} + +// DeleteConfigBgpPolicyApplyBadRequestCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyBadRequest +const DeleteConfigBgpPolicyApplyBadRequestCode int = 400 + +/* +DeleteConfigBgpPolicyApplyBadRequest Malformed arguments for API call + +swagger:response deleteConfigBgpPolicyApplyBadRequest +*/ +type DeleteConfigBgpPolicyApplyBadRequest struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyBadRequest creates DeleteConfigBgpPolicyApplyBadRequest with default headers values +func NewDeleteConfigBgpPolicyApplyBadRequest() *DeleteConfigBgpPolicyApplyBadRequest { + + return &DeleteConfigBgpPolicyApplyBadRequest{} +} + +// WithPayload adds the payload to the delete config bgp policy apply bad request response +func (o *DeleteConfigBgpPolicyApplyBadRequest) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyBadRequest { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply bad request response +func (o *DeleteConfigBgpPolicyApplyBadRequest) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyBadRequest) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(400) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyUnauthorizedCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyUnauthorized +const DeleteConfigBgpPolicyApplyUnauthorizedCode int = 401 + +/* +DeleteConfigBgpPolicyApplyUnauthorized Invalid authentication credentials + +swagger:response deleteConfigBgpPolicyApplyUnauthorized +*/ +type DeleteConfigBgpPolicyApplyUnauthorized struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyUnauthorized creates DeleteConfigBgpPolicyApplyUnauthorized with default headers values +func NewDeleteConfigBgpPolicyApplyUnauthorized() *DeleteConfigBgpPolicyApplyUnauthorized { + + return &DeleteConfigBgpPolicyApplyUnauthorized{} +} + +// WithPayload adds the payload to the delete config bgp policy apply unauthorized response +func (o *DeleteConfigBgpPolicyApplyUnauthorized) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyUnauthorized { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply unauthorized response +func (o *DeleteConfigBgpPolicyApplyUnauthorized) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyUnauthorized) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(401) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyForbiddenCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyForbidden +const DeleteConfigBgpPolicyApplyForbiddenCode int = 403 + +/* +DeleteConfigBgpPolicyApplyForbidden Capacity insufficient + +swagger:response deleteConfigBgpPolicyApplyForbidden +*/ +type DeleteConfigBgpPolicyApplyForbidden struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyForbidden creates DeleteConfigBgpPolicyApplyForbidden with default headers values +func NewDeleteConfigBgpPolicyApplyForbidden() *DeleteConfigBgpPolicyApplyForbidden { + + return &DeleteConfigBgpPolicyApplyForbidden{} +} + +// WithPayload adds the payload to the delete config bgp policy apply forbidden response +func (o *DeleteConfigBgpPolicyApplyForbidden) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyForbidden { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply forbidden response +func (o *DeleteConfigBgpPolicyApplyForbidden) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyForbidden) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(403) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyNotFoundCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyNotFound +const DeleteConfigBgpPolicyApplyNotFoundCode int = 404 + +/* +DeleteConfigBgpPolicyApplyNotFound Resource not found + +swagger:response deleteConfigBgpPolicyApplyNotFound +*/ +type DeleteConfigBgpPolicyApplyNotFound struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyNotFound creates DeleteConfigBgpPolicyApplyNotFound with default headers values +func NewDeleteConfigBgpPolicyApplyNotFound() *DeleteConfigBgpPolicyApplyNotFound { + + return &DeleteConfigBgpPolicyApplyNotFound{} +} + +// WithPayload adds the payload to the delete config bgp policy apply not found response +func (o *DeleteConfigBgpPolicyApplyNotFound) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyNotFound { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply not found response +func (o *DeleteConfigBgpPolicyApplyNotFound) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(404) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyConflictCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyConflict +const DeleteConfigBgpPolicyApplyConflictCode int = 409 + +/* +DeleteConfigBgpPolicyApplyConflict Resource Conflict. Neigh already exists + +swagger:response deleteConfigBgpPolicyApplyConflict +*/ +type DeleteConfigBgpPolicyApplyConflict struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyConflict creates DeleteConfigBgpPolicyApplyConflict with default headers values +func NewDeleteConfigBgpPolicyApplyConflict() *DeleteConfigBgpPolicyApplyConflict { + + return &DeleteConfigBgpPolicyApplyConflict{} +} + +// WithPayload adds the payload to the delete config bgp policy apply conflict response +func (o *DeleteConfigBgpPolicyApplyConflict) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyConflict { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply conflict response +func (o *DeleteConfigBgpPolicyApplyConflict) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(409) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyInternalServerErrorCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyInternalServerError +const DeleteConfigBgpPolicyApplyInternalServerErrorCode int = 500 + +/* +DeleteConfigBgpPolicyApplyInternalServerError Internal service error + +swagger:response deleteConfigBgpPolicyApplyInternalServerError +*/ +type DeleteConfigBgpPolicyApplyInternalServerError struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyInternalServerError creates DeleteConfigBgpPolicyApplyInternalServerError with default headers values +func NewDeleteConfigBgpPolicyApplyInternalServerError() *DeleteConfigBgpPolicyApplyInternalServerError { + + return &DeleteConfigBgpPolicyApplyInternalServerError{} +} + +// WithPayload adds the payload to the delete config bgp policy apply internal server error response +func (o *DeleteConfigBgpPolicyApplyInternalServerError) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyInternalServerError { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply internal server error response +func (o *DeleteConfigBgpPolicyApplyInternalServerError) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyInternalServerError) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(500) + if o.Payload != nil { + payload := o.Payload + if err := producer.Produce(rw, payload); err != nil { + panic(err) // let the recovery middleware deal with this + } + } +} + +// DeleteConfigBgpPolicyApplyServiceUnavailableCode is the HTTP code returned for type DeleteConfigBgpPolicyApplyServiceUnavailable +const DeleteConfigBgpPolicyApplyServiceUnavailableCode int = 503 + +/* +DeleteConfigBgpPolicyApplyServiceUnavailable Maintanence mode + +swagger:response deleteConfigBgpPolicyApplyServiceUnavailable +*/ +type DeleteConfigBgpPolicyApplyServiceUnavailable struct { + + /* + In: Body + */ + Payload *models.Error `json:"body,omitempty"` +} + +// NewDeleteConfigBgpPolicyApplyServiceUnavailable creates DeleteConfigBgpPolicyApplyServiceUnavailable with default headers values +func NewDeleteConfigBgpPolicyApplyServiceUnavailable() *DeleteConfigBgpPolicyApplyServiceUnavailable { + + return &DeleteConfigBgpPolicyApplyServiceUnavailable{} +} + +// WithPayload adds the payload to the delete config bgp policy apply service unavailable response +func (o *DeleteConfigBgpPolicyApplyServiceUnavailable) WithPayload(payload *models.Error) *DeleteConfigBgpPolicyApplyServiceUnavailable { + o.Payload = payload + return o +} + +// SetPayload sets the payload to the delete config bgp policy apply service unavailable response +func (o *DeleteConfigBgpPolicyApplyServiceUnavailable) SetPayload(payload *models.Error) { + o.Payload = payload +} + +// WriteResponse to the client +func (o *DeleteConfigBgpPolicyApplyServiceUnavailable) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.WriteHeader(503) + 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/api/restapi/operations/delete_config_bgp_policy_apply_urlbuilder.go b/api/restapi/operations/delete_config_bgp_policy_apply_urlbuilder.go new file mode 100644 index 000000000..05631825e --- /dev/null +++ b/api/restapi/operations/delete_config_bgp_policy_apply_urlbuilder.go @@ -0,0 +1,87 @@ +// 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 generate command + +import ( + "errors" + "net/url" + golangswaggerpaths "path" +) + +// DeleteConfigBgpPolicyApplyURL generates an URL for the delete config bgp policy apply operation +type DeleteConfigBgpPolicyApplyURL struct { + _basePath string +} + +// 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 *DeleteConfigBgpPolicyApplyURL) WithBasePath(bp string) *DeleteConfigBgpPolicyApplyURL { + 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 *DeleteConfigBgpPolicyApplyURL) SetBasePath(bp string) { + o._basePath = bp +} + +// Build a url path and query string +func (o *DeleteConfigBgpPolicyApplyURL) Build() (*url.URL, error) { + var _result url.URL + + var _path = "/config/bgp/policy/apply" + + _basePath := o._basePath + if _basePath == "" { + _basePath = "/netlox/v1" + } + _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 *DeleteConfigBgpPolicyApplyURL) 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 *DeleteConfigBgpPolicyApplyURL) String() string { + return o.Must(o.Build()).String() +} + +// BuildFull builds a full url with scheme, host, path and query string +func (o *DeleteConfigBgpPolicyApplyURL) BuildFull(scheme, host string) (*url.URL, error) { + if scheme == "" { + return nil, errors.New("scheme is required for a full url on DeleteConfigBgpPolicyApplyURL") + } + if host == "" { + return nil, errors.New("host is required for a full url on DeleteConfigBgpPolicyApplyURL") + } + + 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 *DeleteConfigBgpPolicyApplyURL) StringFull(scheme, host string) string { + return o.Must(o.BuildFull(scheme, host)).String() +} diff --git a/api/restapi/operations/loxilb_rest_api_api.go b/api/restapi/operations/loxilb_rest_api_api.go index ff406d36a..088e42435 100644 --- a/api/restapi/operations/loxilb_rest_api_api.go +++ b/api/restapi/operations/loxilb_rest_api_api.go @@ -48,6 +48,9 @@ func NewLoxilbRestAPIAPI(spec *loads.Document) *LoxilbRestAPIAPI { DeleteConfigBgpNeighIPAddressHandler: DeleteConfigBgpNeighIPAddressHandlerFunc(func(params DeleteConfigBgpNeighIPAddressParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigBgpNeighIPAddress has not yet been implemented") }), + DeleteConfigBgpPolicyApplyHandler: DeleteConfigBgpPolicyApplyHandlerFunc(func(params DeleteConfigBgpPolicyApplyParams) middleware.Responder { + return middleware.NotImplemented("operation DeleteConfigBgpPolicyApply has not yet been implemented") + }), DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler: DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandlerFunc(func(params DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameParams) middleware.Responder { return middleware.NotImplemented("operation DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeName has not yet been implemented") }), @@ -289,6 +292,8 @@ type LoxilbRestAPIAPI struct { DeleteConfigBfdRemoteIPRemoteIPHandler DeleteConfigBfdRemoteIPRemoteIPHandler // DeleteConfigBgpNeighIPAddressHandler sets the operation handler for the delete config bgp neigh IP address operation DeleteConfigBgpNeighIPAddressHandler DeleteConfigBgpNeighIPAddressHandler + // DeleteConfigBgpPolicyApplyHandler sets the operation handler for the delete config bgp policy apply operation + DeleteConfigBgpPolicyApplyHandler DeleteConfigBgpPolicyApplyHandler // DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler sets the operation handler for the delete config bgp policy definedsets defineset type type name operation DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler // DeleteConfigBgpPolicyDefinitionsPolicyNameHandler sets the operation handler for the delete config bgp policy definitions policy name operation @@ -506,6 +511,9 @@ func (o *LoxilbRestAPIAPI) Validate() error { if o.DeleteConfigBgpNeighIPAddressHandler == nil { unregistered = append(unregistered, "DeleteConfigBgpNeighIPAddressHandler") } + if o.DeleteConfigBgpPolicyApplyHandler == nil { + unregistered = append(unregistered, "DeleteConfigBgpPolicyApplyHandler") + } if o.DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler == nil { unregistered = append(unregistered, "DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler") } @@ -806,6 +814,10 @@ func (o *LoxilbRestAPIAPI) initHandlerCache() { if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) } + o.handlers["DELETE"]["/config/bgp/policy/apply"] = NewDeleteConfigBgpPolicyApply(o.context, o.DeleteConfigBgpPolicyApplyHandler) + if o.handlers["DELETE"] == nil { + o.handlers["DELETE"] = make(map[string]http.Handler) + } o.handlers["DELETE"]["/config/bgp/policy/definedsets/{defineset_type}/{type_name}"] = NewDeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeName(o.context, o.DeleteConfigBgpPolicyDefinedsetsDefinesetTypeTypeNameHandler) if o.handlers["DELETE"] == nil { o.handlers["DELETE"] = make(map[string]http.Handler) diff --git a/api/swagger.yml b/api/swagger.yml index 91c6dd7a2..d7ec5fbf7 100644 --- a/api/swagger.yml +++ b/api/swagger.yml @@ -2581,7 +2581,47 @@ paths: description: Maintanence mode schema: $ref: '#/definitions/Error' - + delete: + summary: Delete BGP Policy in neighbor + description: Delete BGP Policy in neighbor. It don't need "routeAction" in the attr body + parameters: + - name: attr + in: body + required: true + description: Attributes of bgp neighbor + schema: + $ref: '#/definitions/BGPApplyPolicyToNeighborMod' + responses: + '204': + description: OK + '400': + description: Malformed arguments for API call + schema: + $ref: '#/definitions/Error' + '401': + description: Invalid authentication credentials + schema: + $ref: '#/definitions/Error' + '403': + description: Capacity insufficient + schema: + $ref: '#/definitions/Error' + '404': + description: Resource not found + schema: + $ref: '#/definitions/Error' + '409': + description: Resource Conflict. Neigh already exists + schema: + $ref: '#/definitions/Error' + '500': + description: Internal service error + schema: + $ref: '#/definitions/Error' + '503': + description: Maintanence mode + schema: + $ref: '#/definitions/Error' '/config/bgp/global': post: @@ -2894,6 +2934,9 @@ definitions: gateway: type: string description: IP address for nexthop + protocol: + type: string + description: Protocol type of the route like "static" RouteGetEntry: type: object diff --git a/common/common.go b/common/common.go index 229ee0de2..6f049b004 100644 --- a/common/common.go +++ b/common/common.go @@ -1027,6 +1027,7 @@ type NetHookInterface interface { NetGoBGPPolicyApplyAdd(nm *GoBGPPolicyApply) (int, error) + NetGoBGPPolicyApplyDel(nm *GoBGPPolicyApply) (int, error) NetGoBGPGCAdd(gc *GoBGPGlobalConfig) (int, error) NetBFDGet() ([]BFDMod, error) NetBFDAdd(bm *BFDMod) (int, error) diff --git a/pkg/loxinet/apiclient.go b/pkg/loxinet/apiclient.go index 4f79c57e1..3941d7d15 100644 --- a/pkg/loxinet/apiclient.go +++ b/pkg/loxinet/apiclient.go @@ -754,7 +754,7 @@ func (na *NetAPIStruct) NetGoBGPPolicyDefinitionDel(param *cmn.GoBGPPolicyDefini } -// NetGoBGPPolicyNeighAdd - Add bgp neigh to gobgp +// NetGoBGPPolicyApplyAdd - Add bgp neigh to gobgp func (na *NetAPIStruct) NetGoBGPPolicyApplyAdd(param *cmn.GoBGPPolicyApply) (int, error) { if mh.bgp != nil { return mh.bgp.BGPApplyPolicyToNeighbor("add", param.NeighIPAddress, param.PolicyType, param.Polices, param.RouteAction) @@ -763,3 +763,14 @@ func (na *NetAPIStruct) NetGoBGPPolicyApplyAdd(param *cmn.GoBGPPolicyApply) (int return 0, errors.New("loxilb BGP mode is disabled") } + + +// NetGoBGPPolicyApplyDel - Del bgp neigh to gobgp +func (na *NetAPIStruct) NetGoBGPPolicyApplyDel(param *cmn.GoBGPPolicyApply) (int, error) { + if mh.bgp != nil { + return mh.bgp.BGPApplyPolicyToNeighbor("del", param.NeighIPAddress, param.PolicyType, param.Polices, param.RouteAction) + } + tk.LogIt(tk.LogDebug, "loxilb BGP mode is disabled \n") + return 0, errors.New("loxilb BGP mode is disabled") + +} diff --git a/pkg/loxinet/gobgpclient.go b/pkg/loxinet/gobgpclient.go index 798456bd5..ca75d40ad 100644 --- a/pkg/loxinet/gobgpclient.go +++ b/pkg/loxinet/gobgpclient.go @@ -1316,7 +1316,7 @@ func (gbh *GoBgpH) AddPolicyDefinedSets(df cmn.GoBGPPolicyDefinedSetMod) (int, e DefinedType = api.DefinedType_EXT_COMMUNITY case "LargeCommunity", "largecommunity", "largeCommunity", "Largecommunity": DefinedType = api.DefinedType_LARGE_COMMUNITY - case "AsPath", "asPath", "ASPath": + case "AsPath", "asPath", "ASPath", "aspath": DefinedType = api.DefinedType_AS_PATH } Prefixes, err := gbh.MakePrefixDefinedSet(df.PrefixList) @@ -1351,7 +1351,7 @@ func (gbh *GoBgpH) DelPolicyDefinedSets(Name string, DefinedTypeString string) ( DefinedType = api.DefinedType_EXT_COMMUNITY case "LargeCommunity", "largecommunity", "largeCommunity", "Largecommunity": DefinedType = api.DefinedType_LARGE_COMMUNITY - case "AsPath", "asPath", "ASPath": + case "AsPath", "asPath", "ASPath", "aspath": DefinedType = api.DefinedType_AS_PATH } // Make DefinedSet