Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR - Introduced a managed flag for LB rules for saving #10

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/create/create_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

type CreateEndPointOptions struct {
Host string
Name string
Name string
ProbeType string
ProbeReq string
ProbeResp string
Expand Down Expand Up @@ -84,7 +84,7 @@ ex) loxicmd create endpoint 32.32.32.1 --name=32.32.32.1_http_8080 --probetype=h
return
}
}

if o.ProbeType == "ping" && o.ProbePort != 0 {
fmt.Printf("probeport should be 0 for '%s' probes\n", o.ProbeType)
return
Expand Down
8 changes: 4 additions & 4 deletions cmd/create/create_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type CreateLoadBalancerOptions struct {
Mark uint16
SCTP []string
Endpoints []string
SecIPs []string
SecIPs []string
Select string
}

Expand Down Expand Up @@ -202,13 +202,13 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2
lbModel.Endpoints = append(lbModel.Endpoints, ep)
}

for _, sip:= range o.SecIPs {
for _, sip := range o.SecIPs {
sp := api.LoadBalancerSecIp{
SecondaryIP: sip,
}
lbModel.SecondaryIPs = append(lbModel.SecondaryIPs, sp)
}

resp, err := LoadbalancerAPICall(restOptions, lbModel)
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
Expand Down Expand Up @@ -320,4 +320,4 @@ func LoadbalancerAPICall(restOptions *api.RESTOptions, lbModel api.LoadBalancerM
}

return client.LoadBalancer().Create(ctx, lbModel)
}
}
34 changes: 17 additions & 17 deletions cmd/delete/delete_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,26 @@ package delete
import (
"context"
"fmt"
"loxicmd/pkg/api"
"net"
"net/http"
"os"
"time"
"strconv"
"loxicmd/pkg/api"
"time"

"github.com/spf13/cobra"
)

type DeleteEndPoint struct {
Host string
Name string
ProbeType string
ProbePort int
Host string
Name string
ProbeType string
ProbePort int
}

func NewDeleteEndPointCmd(restOptions *api.RESTOptions) *cobra.Command {
o := DeleteEndPoint{}

var deleteEndPointCmd = &cobra.Command{
Use: "endpoint IP [--name=<id>] [--probetype=<probetype>] [--probeport=<port>]",
Short: "Delete a LB EndPoint from monitoring",
Expand Down Expand Up @@ -88,22 +88,22 @@ ex) loxicmd delete endpoint 31.31.31.31 --name=31.31.31.31_http_8080 --probetype
return
}

/* subResources := []string{
"epipaddress", o.Host,
"name", o.Name,
"probetype", o.ProbeType,
"probeport", strconv.Itoa(o.ProbePort),
}
resp, err := client.EndPoint().SubResources(subResources).Delete(ctx)
*/
/* subResources := []string{
"epipaddress", o.Host,
"name", o.Name,
"probetype", o.ProbeType,
"probeport", strconv.Itoa(o.ProbePort),
}
resp, err := client.EndPoint().SubResources(subResources).Delete(ctx)
*/
subResources := []string{
"epipaddress", o.Host,
}

qmap := map[string]string{}
qmap["name"] = o.Name
qmap["probe_type"] = o.ProbeType
qmap["probe_port"] = strconv.Itoa(o.ProbePort)
qmap["probe_port"] = strconv.Itoa(o.ProbePort)

resp, err := client.EndPoint().SubResources(subResources).Query(qmap).Delete(ctx)

Expand All @@ -123,4 +123,4 @@ ex) loxicmd delete endpoint 31.31.31.31 --name=31.31.31.31_http_8080 --probetype
deleteEndPointCmd.Flags().StringVar(&o.ProbeType, "probetype", "ping", "Probe-type:ping,http,https,udp,tcp,sctp,none")
deleteEndPointCmd.Flags().IntVar(&o.ProbePort, "probeport", 0, "If probe is http,https,tcp,udp,sctp one can specify custom l4port to use")
return deleteEndPointCmd
}
}
22 changes: 21 additions & 1 deletion cmd/get/get_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ func LoadbalancerAPICall(restOptions *api.RESTOptions) (*http.Response, error) {
}

func Lbdump(restOptions *api.RESTOptions, path string) (string, error) {
lbresp := api.LbRuleModGet{}
dresp := api.LbRuleModGet{}
// File Open
fileP := []string{"lbconfig_", ".txt"}
t := time.Now()
Expand Down Expand Up @@ -218,8 +220,26 @@ func Lbdump(restOptions *api.RESTOptions, path string) (string, error) {
if err != nil {
fmt.Printf("Error: Failed to read HTTP response: (%s)\n", err.Error())
}

if err := json.Unmarshal(resultByte, &lbresp); err != nil {
fmt.Printf("Error: Failed to unmarshal HTTP response: (%s)\n", err.Error())
return "", err
}

for _, lbrule := range lbresp.LbRules {
if !lbrule.Service.Managed {
dresp.LbRules = append(dresp.LbRules, lbrule)
}
}

dumpBytes, err := json.Marshal(dresp)
if err != nil {
fmt.Printf("Error: Failed to marshal dump LB rules (%s)\n", err.Error())
return "", err
}

// Write
_, err = f.Write(resultByte)
_, err = f.Write(dumpBytes)
if err != nil {
fmt.Println("File write error")
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/api/loadBalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type LbRuleModGet struct {
}

type LoadBalancerModel struct {
Service LoadBalancerService `json:"serviceArguments" yaml:"serviceArguments"`
SecondaryIPs []LoadBalancerSecIp `json:"secondaryIPs" yaml:"secondaryIPs"`
Endpoints []LoadBalancerEndpoint `json:"endpoints" yaml:"endpoints"`
Service LoadBalancerService `json:"serviceArguments" yaml:"serviceArguments"`
SecondaryIPs []LoadBalancerSecIp `json:"secondaryIPs" yaml:"secondaryIPs"`
Endpoints []LoadBalancerEndpoint `json:"endpoints" yaml:"endpoints"`
}

type LoadBalancerService struct {
Expand All @@ -46,6 +46,7 @@ type LoadBalancerService struct {
Monitor bool `json:"Monitor" yaml:"Monitor"`
Timeout uint32 `json:"inactiveTimeOut" yaml:"inactiveTimeOut"`
Block uint16 `json:"block" yaml:"block"`
Managed bool `json:"managed,omitempty" yaml:"managed"`
}

type LoadBalancerEndpoint struct {
Expand Down