Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
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
21 changes: 21 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,21 @@ func initClientOpts(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts,
return sc, nil
}

// initcommonServiceClient create a ServiceClient which can not get from clientType directly.
// firstly, we initialize a service client by "volumev2" type, the endpoint likes https://evs.{region}.{xxx.com}/v2/{project_id}
// then we replace the endpoint with the specified srv and version.
func initcommonServiceClient(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts, srv string, version string) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "volumev2")
if err != nil {
return nil, err
}

e := strings.Replace(sc.Endpoint, "v2", version, 1)
sc.Endpoint = strings.Replace(e, "evs", srv, 1)
sc.ResourceBase = sc.Endpoint
return sc, err
}

// NewObjectStorageV1 creates a ServiceClient that may be used with the v1
// object storage package.
func NewObjectStorageV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
Expand Down Expand Up @@ -1039,3 +1054,9 @@ func NewDDSV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*gol
sc, err := initClientOpts(client, eo, "ddsv3")
return sc, err
}

// NewLTSV2 creates a ServiceClient that may be used to access the LTS service.
func NewLTSV2(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initcommonServiceClient(client, eo, "lts", "v2.0")
return sc, err
}
49 changes: 49 additions & 0 deletions openstack/lts/v2/loggroups/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package loggroups

import "github.com/huaweicloud/golangsdk"

// CreateOptsBuilder is used for creating log group parameters.
type CreateOptsBuilder interface {
ToLogGroupsCreateMap() (map[string]interface{}, error)
}

// CreateOpts is a struct that contains all the parameters.
type CreateOpts struct {
// Specifies the log group name.
LogGroupName string `json:"log_group_name" required:"true"`

// Specifies the log expiration time. The value is fixed to 7 days.
TTL int `json:"ttl_in_daysion,omitempty"`
}

// ToLogGroupsCreateMap is used for type convert
func (ops CreateOpts) ToLogGroupsCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}

// Create a log group with given parameters.
func Create(client *golangsdk.ServiceClient, ops CreateOptsBuilder) (r CreateResult) {
b, err := ops.ToLogGroupsCreateMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{201},
})

return
}

// Delete a log group by id
func Delete(client *golangsdk.ServiceClient, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, id), nil)
return
}

// Get a log group with detailed information by id
func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}
45 changes: 45 additions & 0 deletions openstack/lts/v2/loggroups/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package loggroups

import "github.com/huaweicloud/golangsdk"

// Log group Create response
type CreateResponse struct {
ID string `json:"log_group_id"`
}

// CreateResult is a struct that contains all the return parameters of creation
type CreateResult struct {
golangsdk.Result
}

// Extract from CreateResult
func (r CreateResult) Extract() (*CreateResponse, error) {
s := new(CreateResponse)
err := r.Result.ExtractInto(s)
return s, err
}

// DeleteResult is a struct which contains the result of deletion
type DeleteResult struct {
golangsdk.ErrResult
}

// Log group response
type LogGroup struct {
ID string `json:"log_group_id"`
Name string `json:"log_group_name"`
CreationTime int64 `json:"creation_time"`
TTLinDays int `json:"ttl_in_days"`
}

// GetResult contains the body of getting detailed
type GetResult struct {
golangsdk.Result
}

// Extract from GetResult
func (r GetResult) Extract() (*LogGroup, error) {
s := new(LogGroup)
err := r.Result.ExtractInto(s)
return s, err
}
20 changes: 20 additions & 0 deletions openstack/lts/v2/loggroups/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package loggroups

import "github.com/huaweicloud/golangsdk"

const rootPath = "log-groups"

// createURL will build the url of creation
func createURL(client *golangsdk.ServiceClient) string {
return client.ServiceURL(rootPath)
}

// deleteURL will build the url of deletion
func deleteURL(client *golangsdk.ServiceClient, id string) string {
return client.ServiceURL(rootPath, id)
}

// getURL will build the get url of get function
func getURL(client *golangsdk.ServiceClient, id string) string {
return client.ServiceURL(rootPath, id)
}
46 changes: 46 additions & 0 deletions openstack/lts/v2/logtopics/requests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package logtopics

import "github.com/huaweicloud/golangsdk"

// CreateOptsBuilder is used for creating log group parameters.
type CreateOptsBuilder interface {
ToLogTopicsCreateMap() (map[string]interface{}, error)
}

// CreateOpts is a struct that contains all the parameters.
type CreateOpts struct {
// Specifies the log group name.
LogTopicName string `json:"log_topic_name" required:"true"`
}

// ToLogTopicsCreateMap is used for type convert
func (ops CreateOpts) ToLogTopicsCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
}

// Create a log topic with given parameters.
func Create(client *golangsdk.ServiceClient, groupId string, ops CreateOptsBuilder) (r CreateResult) {
b, err := ops.ToLogTopicsCreateMap()
if err != nil {
r.Err = err
return
}

_, r.Err = client.Post(createURL(client, groupId), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{201},
})

return
}

// Delete a log topic by id
func Delete(client *golangsdk.ServiceClient, groupId string, id string) (r DeleteResult) {
_, r.Err = client.Delete(deleteURL(client, groupId, id), nil)
return
}

// Get a log topic with detailed information by id
func Get(client *golangsdk.ServiceClient, groupId string, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, groupId, id), &r.Body, nil)
return
}
45 changes: 45 additions & 0 deletions openstack/lts/v2/logtopics/results.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package logtopics

import "github.com/huaweicloud/golangsdk"

// Log topic Create response
type CreateResponse struct {
ID string `json:"log_topic_id"`
}

// CreateResult is a struct that contains all the return parameters of creation
type CreateResult struct {
golangsdk.Result
}

// Extract from CreateResult
func (r CreateResult) Extract() (*CreateResponse, error) {
s := new(CreateResponse)
err := r.Result.ExtractInto(s)
return s, err
}

// DeleteResult is a struct which contains the result of deletion
type DeleteResult struct {
golangsdk.ErrResult
}

// Log topic response
type LogTopic struct {
ID string `json:"log_topic_id,omitempty"`
Name string `json:"log_topic_name"`
CreationTime int64 `json:"creation_time"`
IndexEnabled bool `json:"index_enabled"`
}

// GetResult contains the body of getting detailed
type GetResult struct {
golangsdk.Result
}

// Extract from GetResult
func (r GetResult) Extract() (*LogTopic, error) {
s := new(LogTopic)
err := r.Result.ExtractInto(s)
return s, err
}
23 changes: 23 additions & 0 deletions openstack/lts/v2/logtopics/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package logtopics

import "github.com/huaweicloud/golangsdk"

const (
resourcePath = "log-topics"
rootPath = "log-groups"
)

// createURL will build the url of creation
func createURL(client *golangsdk.ServiceClient, groupId string) string {
return client.ServiceURL(rootPath, groupId, resourcePath)
}

// deleteURL will build the url of deletion
func deleteURL(client *golangsdk.ServiceClient, groupId string, id string) string {
return client.ServiceURL(rootPath, groupId, resourcePath, id)
}

// getURL will build the get url of get function
func getURL(client *golangsdk.ServiceClient, groupId string, id string) string {
return client.ServiceURL(rootPath, groupId, resourcePath, id)
}