From e7b5c9aacc0902e73229730861afcc37a0f2e683 Mon Sep 17 00:00:00 2001 From: Ali Bazlamit Date: Thu, 26 Jul 2018 12:33:58 +0200 Subject: [PATCH] Firewall improvements --- README.md | 13 +++++------ baremetal_server_test.go | 2 +- firewallpolicies.go | 11 +++++---- firewallpolicies_test.go | 13 ++++++----- servers.go | 48 +++++++++++++++++++++------------------- servers_test.go | 32 --------------------------- 6 files changed, 46 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 0718e14..62e4207 100644 --- a/README.md +++ b/README.md @@ -577,8 +577,8 @@ request := oneandone.FirewallPolicyRequest { Rules: []oneandone.FirewallPolicyRule { { Protocol: protocol, - PortFrom: oneandone.Int2Pointer(port_from), - PortTo: oneandone.Int2Pointer(port_to), + Port: "80", + Action: "allow", SourceIp: source_ip, }, }, @@ -639,14 +639,13 @@ Passing an empty string in `fp_new_name` or `fp_new_description` skips updating fp_rules := []oneandone.FirewallPolicyRule { { Protocol: protocol1, - PortFrom: oneandone.Int2Pointer(port_from1), - PortTo: oneandone.Int2Pointer(port_to1), + Port: "80", SourceIp: source_ip, }, { Protocol: protocol2, - PortFrom: oneandone.Int2Pointer(port_from2), - PortTo: oneandone.Int2Pointer(port_to2), + Port: "4000-5000", + Action: "allow", }, } @@ -2398,7 +2397,7 @@ func (api *API) GetVPNConfigFile(vpn_id string) (string, error) ``` ```Go -func (api *API) ListBaremetalModels(args ...interface{}) ([]BaremetalModel, error) +func (api *API) ListBaremetalModels() ([]BaremetalModel, error) ``` ```Go diff --git a/baremetal_server_test.go b/baremetal_server_test.go index 3cf8c3a..cb32078 100644 --- a/baremetal_server_test.go +++ b/baremetal_server_test.go @@ -62,7 +62,7 @@ func create_baremetal_test_server(power_on bool) (string, *Server, error) { sap := get_baremetal_appliance(hdd_size) baremetal_ser_app_id = sap.Id //mp := get_default_mon_policy() - baremetalModels, err := api.ListBaremetalModels(1, 1, "", "BMC_L", "") + baremetalModels, err := api.ListBaremetalModels() baremetalModel = baremetalModels[0] baremetalModelId := baremetalModels[0].Id diff --git a/firewallpolicies.go b/firewallpolicies.go index 6d9f9a1..949e2b1 100644 --- a/firewallpolicies.go +++ b/firewallpolicies.go @@ -17,10 +17,13 @@ type FirewallPolicy struct { type FirewallPolicyRule struct { idField - Protocol string `json:"protocol,omitempty"` - PortFrom *int `json:"port_from,omitempty"` - PortTo *int `json:"port_to,omitempty"` - SourceIp string `json:"source,omitempty"` + Protocol string `json:"protocol,omitempty"` + PortFrom *int `json:"port_from,omitempty"` + PortTo *int `json:"port_to,omitempty"` + Port string `json:"port,omitempty"` + Action string `json:"action,omitempty"` + Description string `json:"description,omitempty"` + SourceIp string `json:"source,omitempty"` } type FirewallPolicyRequest struct { diff --git a/firewallpolicies_test.go b/firewallpolicies_test.go index 677dc86..162ea1a 100644 --- a/firewallpolicies_test.go +++ b/firewallpolicies_test.go @@ -28,8 +28,9 @@ func create_firewall_policy() *FirewallPolicy { Rules: []FirewallPolicyRule{ { Protocol: "UDP", - PortFrom: Int2Pointer(161), - PortTo: Int2Pointer(162), + Port:"161", + Action: "allow", + Description:"test rules", }, }, } @@ -264,14 +265,14 @@ func TestAddFirewallPolicyRules(t *testing.T) { rules := []FirewallPolicyRule{ { Protocol: "TCP", - PortFrom: Int2Pointer(4567), - PortTo: Int2Pointer(4567), + Port:"4567", + Action:"allow", SourceIp: "0.0.0.0", }, { Protocol: "TCP/UDP", - PortFrom: Int2Pointer(143), - PortTo: Int2Pointer(143), + Port:"143", + Action:"allow", }, { Protocol: "GRE", // PortFrom & PortTo are optional for GRE, ICMP and IPSEC protocols. diff --git a/servers.go b/servers.go index 8186586..89de110 100644 --- a/servers.go +++ b/servers.go @@ -11,22 +11,22 @@ type Server struct { ApiPtr Identity descField - CreationDate string `json:"creation_date,omitempty"` - FirstPassword string `json:"first_password,omitempty"` - ServerType string `json:"server_type,omitempty"` - Ipv6Range string `json:"ipv6_range,omitempty"` - Hostname string `json:"hostname,omitempty"` - Datacenter *Datacenter `json:"datacenter,omitempty"` - Status *Status `json:"status,omitempty"` - Hardware *Hardware `json:"hardware,omitempty"` - Image *Identity `json:"image,omitempty"` - Dvd *Identity `json:"dvd,omitempty"` - MonPolicy *Identity `json:"monitoring_policy,omitempty"` - Snapshot *ServerSnapshot `json:"snapshot,omitempty"` - Ips []ServerIp `json:"ips,omitempty"` - PrivateNets []Identity `json:"private_networks,omitempty"` - Alerts *ServerAlerts `json:"-"` - AlertsRaw *json.RawMessage `json:"alerts,omitempty"` + CreationDate string `json:"creation_date,omitempty"` + FirstPassword string `json:"first_password,omitempty"` + ServerType string `json:"server_type,omitempty"` + Ipv6Range string `json:"ipv6_range,omitempty"` + Hostname string `json:"hostname,omitempty"` + Datacenter *Datacenter `json:"datacenter,omitempty"` + Status *Status `json:"status,omitempty"` + Hardware *Hardware `json:"hardware,omitempty"` + Image *Identity `json:"image,omitempty"` + Dvd *Identity `json:"dvd,omitempty"` + MonPolicy *Identity `json:"monitoring_policy,omitempty"` + Snapshot *ServerSnapshot `json:"snapshot,omitempty"` + Ips []ServerIp `json:"ips,omitempty"` + PrivateNets []ServerPrivateNetwork `json:"private_networks,omitempty"` + Alerts *ServerAlerts `json:"-"` + AlertsRaw *json.RawMessage `json:"alerts,omitempty"` } type Hardware struct { @@ -43,6 +43,11 @@ type ServerHdds struct { Hdds []Hdd `json:"hdds,omitempty"` } +type ServerPrivateNetwork struct { + Identity + ServerPrivateIp string `json:"server_ip,omitempty"` +} + type Hdd struct { idField Size int `json:"size,omitempty"` @@ -146,7 +151,7 @@ type BaremetalHardware struct { CoresPerProcessor int `json:"cores_per_processor"` Ram float32 `json:"ram"` Unit string `json:"unit,omitempty"` - Hdds Hdd `json:"hdds,omitempty"` + Hdds []Hdd `json:"hdds,omitempty"` ApiPtr } @@ -817,13 +822,10 @@ func (api *API) CloneServer(server_id string, new_name string, datacenter_id str } // GET /servers/baremetal_models -func (api *API) ListBaremetalModels(args ...interface{}) ([]BaremetalModel, error) { - url, err := processQueryParams(createUrl(api, serverPathSegment, baremetalSegment), args...) - if err != nil { - return nil, err - } +func (api *API) ListBaremetalModels() ([]BaremetalModel, error) { + url := createUrl(api, serverPathSegment, baremetalSegment) res := []BaremetalModel{} - err = api.Client.Get(url, &res, http.StatusOK) + err := api.Client.Get(url, &res, http.StatusOK) if err != nil { return nil, err } diff --git a/servers_test.go b/servers_test.go index 572c5ec..5c91956 100644 --- a/servers_test.go +++ b/servers_test.go @@ -301,41 +301,9 @@ func TestListBaremetalModel(t *testing.T) { baremetalModelId = res[0].Id - res, err = api.ListBaremetalModels(1, 2, "name", "", "id,name") - - if err != nil { - t.Errorf("ListBaremetalModels with parameter options failed. Error: " + err.Error()) - return - } if len(res) == 0 { t.Errorf("No baremetal model found.") } - if len(res) > 2 { - t.Errorf("Wrong number of objects per page.") - } - if res[0].Hardware != nil { - t.Errorf("Filtering parameters failed.") - } - if res[0].Name == "" { - t.Errorf("Filtering parameters failed.") - } - - // Test for error response - res, err = api.ListBaremetalModels(0, 0, true, "name", "") - if res != nil || err == nil { - t.Errorf("ListBaremetalModels failed to handle incorrect argument type.") - } - - res, err = api.ListBaremetalModels(0, 0, "", "BMC", "") - - if err != nil { - t.Errorf("ListBaremetalModels with parameter options failed. Error: " + err.Error()) - return - } - - if !strings.Contains(res[0].Name, "BMC") { - t.Errorf("Search parameter failed.") - } } func TestListFixedInstanceSizes(t *testing.T) {