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

CSS: kibana #790

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open
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
99 changes: 99 additions & 0 deletions acceptance/openstack/css/v1/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/clusters"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/css/v1/kibana"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

Expand Down Expand Up @@ -185,3 +186,101 @@ func TestClusterPublicAccess(t *testing.T) {
err = clusters.WaitForCluster(client, managePublicOpts.ClusterId, timeout)
th.AssertNoErr(t, err)
}

func TestClusterKibanaPublicAccess(t *testing.T) {
client, err := clients.NewCssV1Client()
th.AssertNoErr(t, err)

vpcID := clients.EnvOS.GetEnv("VPC_ID")
subnetID := clients.EnvOS.GetEnv("NETWORK_ID")

if vpcID == "" || subnetID == "" {
t.Skip("Both `VPC_ID` and `NETWORK_ID` need to be defined")
}

sgID := openstack.DefaultSecurityGroup(t)

opts := clusters.CreateOpts{
Name: tools.RandomString("css-cluster-", 4),
Instance: &clusters.InstanceSpec{
Flavor: "css.medium.8",

Volume: &clusters.Volume{
Type: "COMMON",
Size: 40,
},
Nics: &clusters.Nics{
VpcID: vpcID,
SubnetID: subnetID,
SecurityGroupID: sgID,
},
AvailabilityZone: "eu-de-02",
},
InstanceNum: 1,
DiskEncryption: &clusters.DiskEncryption{
Encrypted: "0",
},
HttpsEnabled: "true",
AuthorityEnabled: true,
AdminPassword: "Test123!@#",
Datastore: &clusters.Datastore{
Version: "7.6.2",
Type: "elasticsearch",
},
}
created, err := clusters.Create(client, opts)
th.AssertNoErr(t, err)

defer func() {
err = clusters.Delete(client, created.ID)
th.AssertNoErr(t, err)
}()

got, err := clusters.Get(client, created.ID)
th.AssertNoErr(t, err)

log.Printf("Creating cluster, ID: %s", got.ID)
th.AssertEquals(t, created.ID, got.ID)
th.AssertEquals(t, created.Name, got.Name)

th.CheckNoErr(t, clusters.WaitForClusterOperationSucces(client, created.ID, timeout))

clusterId := got.ID

manageKibanaOpts := kibana.ManageOpts{
ClusterId: clusterId,
EipSize: 5,
EnableWhiteList: true,
Whitelist: "192.168.1.1",
}

err = kibana.Enable(client, manageKibanaOpts)
th.AssertNoErr(t, err)

err = clusters.WaitForCluster(client, manageKibanaOpts.ClusterId, timeout)
th.AssertNoErr(t, err)

err = kibana.Update(client, clusterId, 10)
th.AssertNoErr(t, err)

err = clusters.WaitForCluster(client, manageKibanaOpts.ClusterId, timeout)
th.AssertNoErr(t, err)

err = kibana.Disable(client, manageKibanaOpts)
th.AssertNoErr(t, err)

err = clusters.WaitForCluster(client, manageKibanaOpts.ClusterId, timeout)
th.AssertNoErr(t, err)

err = kibana.UpdateAccess(client, clusterId, manageKibanaOpts.Whitelist)
th.AssertNoErr(t, err)

err = clusters.WaitForCluster(client, manageKibanaOpts.ClusterId, timeout)
th.AssertNoErr(t, err)

err = kibana.DisableAccess(client, clusterId)
th.AssertNoErr(t, err)

err = clusters.WaitForCluster(client, manageKibanaOpts.ClusterId, timeout)
th.AssertNoErr(t, err)
}
30 changes: 30 additions & 0 deletions openstack/css/v1/kibana/Disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kibana

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

func Disable(client *golangsdk.ServiceClient, opts ManageOpts) error {
request := Whitelist{
EipSize: opts.EipSize,
ElbWhiteList: KibanaPublicWhitelist{
EnableWhitelist: opts.EnableWhiteList,
WhiteList: opts.Whitelist,
},
}

b, err := build.RequestBody(request, "")
if err != nil {
return err
}

_, err = client.Put(client.ServiceURL("clusters", opts.ClusterId, "publickibana", "close"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json",
},
})

return err
}
16 changes: 16 additions & 0 deletions openstack/css/v1/kibana/DisableAccess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kibana

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
)

func DisableAccess(client *golangsdk.ServiceClient, clusterId string) error {
_, err := client.Put(client.ServiceURL("clusters", clusterId, "publickibana", "whitelist", "close"), nil, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json",
},
})

return err
}
47 changes: 47 additions & 0 deletions openstack/css/v1/kibana/Enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package kibana

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type ManageOpts struct {
ClusterId string `json:"clusterId"`
EipSize int `json:"-"`
EnableWhiteList bool `json:"-"`
Whitelist string `json:"-"`
}

func Enable(client *golangsdk.ServiceClient, opts ManageOpts) error {
request := Whitelist{
EipSize: opts.EipSize,
ElbWhiteList: KibanaPublicWhitelist{
EnableWhitelist: opts.EnableWhiteList,
WhiteList: opts.Whitelist,
},
}

b, err := build.RequestBody(request, "")
if err != nil {
return err
}

_, err = client.Post(client.ServiceURL("clusters", opts.ClusterId, "publickibana", "open"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json",
},
})

return err
}

type Whitelist struct {
EipSize int `json:"eipSize"`
ElbWhiteList KibanaPublicWhitelist `json:"elbWhiteList"`
}

type KibanaPublicWhitelist struct {
EnableWhitelist bool `json:"enableWhiteList"`
WhiteList string `json:"whiteList"`
}
36 changes: 36 additions & 0 deletions openstack/css/v1/kibana/Update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package kibana

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

func Update(client *golangsdk.ServiceClient, clusterId string, size int) error {
request := UpdateOpts{
Bandwidth: Bandwidth{
Size: size,
},
}

b, err := build.RequestBody(request, "")
if err != nil {
return err
}

_, err = client.Post(client.ServiceURL("clusters", clusterId, "publickibana", "bandwidth"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json",
},
})

return err
}

type UpdateOpts struct {
Bandwidth Bandwidth `json:"bandWidth" required:"true"`
}

type Bandwidth struct {
Size int `json:"size" required:"true"`
}
29 changes: 29 additions & 0 deletions openstack/css/v1/kibana/UpdateAccess.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package kibana

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

func UpdateAccess(client *golangsdk.ServiceClient, clusterId, whitelist string) error {
config := Config{
WhiteList: whitelist,
}
b, err := build.RequestBody(config, "")
if err != nil {
return err
}

_, err = client.Post(client.ServiceURL("clusters", clusterId, "publickibana", "whitelist", "update"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{200},
MoreHeaders: map[string]string{
"Content-Type": "application/json",
},
})

return err
}

type Config struct {
WhiteList string `json:"whiteList"`
}