From 9b3cd5fd54d2ac3df13cf7839d0f59db2c203617 Mon Sep 17 00:00:00 2001 From: ioito Date: Wed, 8 Dec 2021 18:03:18 +0800 Subject: [PATCH] fix(region): add access info for es --- cmd/climc/shell/compute/elastic_search.go | 1 + pkg/apis/compute/elastic_search.go | 3 +++ pkg/cloudprovider/elasticsearch.go | 26 +++++++++++++++++++++++ pkg/cloudprovider/resources.go | 2 ++ pkg/compute/models/elastic_search.go | 8 +++++++ pkg/multicloud/aliyun/elastic_search.go | 10 +++++++++ pkg/multicloud/qcloud/elastic_search.go | 11 ++++++++++ 7 files changed, 61 insertions(+) create mode 100644 pkg/cloudprovider/elasticsearch.go diff --git a/cmd/climc/shell/compute/elastic_search.go b/cmd/climc/shell/compute/elastic_search.go index 6ed037cd5a..94aa12929c 100644 --- a/cmd/climc/shell/compute/elastic_search.go +++ b/cmd/climc/shell/compute/elastic_search.go @@ -27,4 +27,5 @@ func init() { cmd.Show(&compute.ElasticSearchIdOption{}) cmd.Delete(&compute.ElasticSearchIdOption{}) cmd.Perform("syncstatus", &compute.ElasticSearchIdOption{}) + cmd.Get("access-info", &compute.ElasticSearchIdOption{}) } diff --git a/pkg/apis/compute/elastic_search.go b/pkg/apis/compute/elastic_search.go index ba0aa42fbe..2e031c0910 100644 --- a/pkg/apis/compute/elastic_search.go +++ b/pkg/apis/compute/elastic_search.go @@ -49,3 +49,6 @@ type ElasticSearchListInput struct { ManagedResourceListInput VpcFilterListInput } + +type ElasticSearchAccessInfoInput struct { +} diff --git a/pkg/cloudprovider/elasticsearch.go b/pkg/cloudprovider/elasticsearch.go new file mode 100644 index 0000000000..ed0261e2dc --- /dev/null +++ b/pkg/cloudprovider/elasticsearch.go @@ -0,0 +1,26 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package cloudprovider + +// +onecloud:model-api-gen +type ElasticSearchAccessInfo struct { + Domain string + PrivateDomain string + Vip string + Port int + PrivatePort int + KibanaUrl string + KibanaPrivateUrl string +} diff --git a/pkg/cloudprovider/resources.go b/pkg/cloudprovider/resources.go index a19aaf885f..1ca0e90382 100644 --- a/pkg/cloudprovider/resources.go +++ b/pkg/cloudprovider/resources.go @@ -1441,6 +1441,8 @@ type ICloudElasticSearch interface { GetZoneId() string IsMultiAz() bool + GetAccessInfo() (*ElasticSearchAccessInfo, error) + Delete() error } diff --git a/pkg/compute/models/elastic_search.go b/pkg/compute/models/elastic_search.go index ddacefea19..ddc0a126f9 100644 --- a/pkg/compute/models/elastic_search.go +++ b/pkg/compute/models/elastic_search.go @@ -641,3 +641,11 @@ func (self *SElasticSearch) PerformSyncstatus(ctx context.Context, userCred mccl return nil, StartResourceSyncStatusTask(ctx, userCred, self, "ElasticSearchSyncstatusTask", "") } + +func (self *SElasticSearch) GetDetailsAccessInfo(ctx context.Context, userCred mcclient.TokenCredential, input api.ElasticSearchAccessInfoInput) (*cloudprovider.ElasticSearchAccessInfo, error) { + iEs, err := self.GetIElasticSearch() + if err != nil { + return nil, err + } + return iEs.GetAccessInfo() +} diff --git a/pkg/multicloud/aliyun/elastic_search.go b/pkg/multicloud/aliyun/elastic_search.go index e9d0cda202..47bcbe8993 100644 --- a/pkg/multicloud/aliyun/elastic_search.go +++ b/pkg/multicloud/aliyun/elastic_search.go @@ -276,6 +276,16 @@ func (self *SElasticSearch) GetStatus() string { } } +func (self *SElasticSearch) GetAccessInfo() (*cloudprovider.ElasticSearchAccessInfo, error) { + return &cloudprovider.ElasticSearchAccessInfo{ + Domain: self.PublicDomain, + PrivateDomain: self.Domain, + Port: self.PublicPort, + PrivatePort: self.Port, + KibanaUrl: self.KibanaDomain, + }, nil +} + func (self *SRegion) GetIElasticSearchs() ([]cloudprovider.ICloudElasticSearch, error) { ret := []SElasticSearch{} for { diff --git a/pkg/multicloud/qcloud/elastic_search.go b/pkg/multicloud/qcloud/elastic_search.go index 96ad853017..0db7dc09cb 100644 --- a/pkg/multicloud/qcloud/elastic_search.go +++ b/pkg/multicloud/qcloud/elastic_search.go @@ -264,6 +264,17 @@ func (self *SElasticSearch) Delete() error { return self.region.DeleteElasticSearch(self.InstanceId) } +func (self *SElasticSearch) GetAccessInfo() (*cloudprovider.ElasticSearchAccessInfo, error) { + return &cloudprovider.ElasticSearchAccessInfo{ + Port: self.EsPort, + Vip: self.EsVip, + Domain: self.EsPublicUrl, + PrivateDomain: self.EsDomain, + KibanaUrl: self.KibanaUrl, + KibanaPrivateUrl: self.KibanaPrivateUrl, + }, nil +} + func (self *SRegion) GetIElasticSearchs() ([]cloudprovider.ICloudElasticSearch, error) { ess := []SElasticSearch{} for {