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
8 changes: 8 additions & 0 deletions openstack/ces/v1/metrics/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metrics

import (
"bytes"
"strconv"

"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
Expand All @@ -11,6 +12,7 @@ type Metrics struct {
Metrics []Metric `json:"metrics"`
MetaData MetaData `json:"meta_data"`
}

type MetaData struct {
Count int `json:"count"`
Marker string `json:"marker"`
Expand Down Expand Up @@ -90,6 +92,12 @@ func (r MetricsPage) NextPageURL() (string, error) {
return "", nil
}

limit := r.URL.Query().Get("limit")
num, _ := strconv.Atoi(limit)
if num > len(metrics.Metrics) {
return "", nil
}

metricslen := len(metrics.Metrics) - 1

var buf bytes.Buffer
Expand Down
45 changes: 44 additions & 1 deletion openstack/dcs/v1/instances/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instances

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// CreateOpsBuilder is used for creating instance parameters.
Expand Down Expand Up @@ -118,6 +119,29 @@ type PeriodicalBackupPlan struct {
BackupAt []int `json:"backup_at" required:"true"`
}

type ListDcsInstanceOpts struct {
Id string `q:"id"`
Name string `q:"name"`
Type string `q:"type"`
DataStoreType string `q:"datastore_type"`
VpcId string `q:"vpc_id"`
SubnetId string `q:"subnet_id"`
Offset int `q:"offset"`
Limit int `q:"limit"`
}

type ListDcsBuilder interface {
ToDcsListDetailQuery() (string, error)
}

func (opts ListDcsInstanceOpts) ToDcsListDetailQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), err
}

// ToInstanceCreateMap is used for type convert
func (ops CreateOps) ToInstanceCreateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(ops, "")
Expand All @@ -134,7 +158,6 @@ func Create(client *golangsdk.ServiceClient, ops CreateOpsBuilder) (r CreateResu
_, r.Err = client.Post(createURL(client), b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{200},
})

return
}

Expand Down Expand Up @@ -281,3 +304,23 @@ func Extend(client *golangsdk.ServiceClient, id string, opts ExtendOptsBuilder)
})
return
}

func List(client *golangsdk.ServiceClient, opts ListDcsBuilder) pagination.Pager {
url := listURL(client)
if opts != nil {
query, err := opts.ToDcsListDetailQuery()

if err != nil {
return pagination.Pager{Err: err}
}
url += query
}

pageDcsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return DcsPage{pagination.SinglePageBase(r)}
})

dcsheader := map[string]string{"Content-Type": "application/json"}
pageDcsList.Headers = dcsheader
return pageDcsList
}
25 changes: 25 additions & 0 deletions openstack/dcs/v1/instances/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instances

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// InstanceCreate response
Expand All @@ -26,6 +27,11 @@ type DeleteResult struct {
golangsdk.ErrResult
}

type ListDcsResponse struct {
Instances []Instance `json:"instances"`
TotalCount int `json:"instance_num"`
}

// Instance response
type Instance struct {
Name string `json:"name"`
Expand Down Expand Up @@ -111,3 +117,22 @@ func (r UpdatePasswordResult) Extract() (*Password, error) {
type ExtendResult struct {
golangsdk.Result
}

type DcsPage struct {
pagination.SinglePageBase
}

func (r DcsPage) IsEmpty() (bool, error) {
data, err := ExtractDcsInstances(r)
if err != nil {
return false, err
}
return len(data.Instances) == 0, err
}

// ExtractCloudServers is a function that takes a ListResult and returns the services' information.
func ExtractDcsInstances(r pagination.Page) (ListDcsResponse, error) {
var s ListDcsResponse
err := (r.(DcsPage)).ExtractInto(&s)
return s, err
}
4 changes: 4 additions & 0 deletions openstack/dcs/v1/instances/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ func passwordURL(client *golangsdk.ServiceClient, id string) string {
func extendURL(client *golangsdk.ServiceClient, id string) string {
return client.ServiceURL(resourcePath, id, extendPath)
}

func listURL(client *golangsdk.ServiceClient) string {
return client.ServiceURL(resourcePath)
}
43 changes: 43 additions & 0 deletions openstack/dms/v1/instances/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instances

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// CreateOpsBuilder is used for creating instance parameters.
Expand Down Expand Up @@ -167,3 +168,45 @@ func Get(client *golangsdk.ServiceClient, id string) (r GetResult) {
_, r.Err = client.Get(getURL(client, id), &r.Body, nil)
return
}

type ListDmsInstanceOpts struct {
Id string `q:"id"`
Name string `q:"name"`
Engine string `q:"engine"`
Status string `q:"status"`
IncludeFailure string `q:"includeFailure"`
ExactMatchName string `q:"exactMatchName"`
EnterpriseProjectID int `q:"enterprise_project_id"`
}

type ListDmsBuilder interface {
ToDmsListDetailQuery() (string, error)
}

func (opts ListDmsInstanceOpts) ToDmsListDetailQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), err
}

func List(client *golangsdk.ServiceClient, opts ListDmsBuilder) pagination.Pager {
url := listURL(client)
if opts != nil {
query, err := opts.ToDmsListDetailQuery()

if err != nil {
return pagination.Pager{Err: err}
}
url += query
}

pageDmsList := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return DmsPage{pagination.SinglePageBase(r)}
})

dmsheader := map[string]string{"Content-Type": "application/json"}
pageDmsList.Headers = dmsheader
return pageDmsList
}
25 changes: 25 additions & 0 deletions openstack/dms/v1/instances/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instances

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// InstanceCreate response
Expand All @@ -26,6 +27,11 @@ type DeleteResult struct {
golangsdk.ErrResult
}

type ListDmsResponse struct {
Instances []Instance `json:"instances"`
TotalCount int `json:"instance_num"`
}

// Instance response
type Instance struct {
Name string `json:"name"`
Expand Down Expand Up @@ -76,3 +82,22 @@ func (r GetResult) Extract() (*Instance, error) {
err := r.Result.ExtractInto(&s)
return &s, err
}

type DmsPage struct {
pagination.SinglePageBase
}

func (r DmsPage) IsEmpty() (bool, error) {
data, err := ExtractDmsInstances(r)
if err != nil {
return false, err
}
return len(data.Instances) == 0, err
}

// ExtractCloudServers is a function that takes a ListResult and returns the services' information.
func ExtractDmsInstances(r pagination.Page) (ListDmsResponse, error) {
var s ListDmsResponse
err := (r.(DmsPage)).ExtractInto(&s)
return s, err
}
4 changes: 4 additions & 0 deletions openstack/dms/v1/instances/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ func updateURL(c *golangsdk.ServiceClient, id string) string {
func getURL(client *golangsdk.ServiceClient, id string) string {
return client.ServiceURL(resourcePath, id)
}

func listURL(client *golangsdk.ServiceClient) string {
return client.ServiceURL(resourcePath)
}
39 changes: 39 additions & 0 deletions openstack/networking/v2/extensions/natgateways/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package natgateways

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// CreateOptsBuilder is an interface must satisfy to be used as Create
Expand All @@ -21,6 +22,20 @@ type CreateOpts struct {
TenantID string `json:"tenant_id,omitempty"`
}

type ListOpts struct {
Limit int `q:"limit"`
ID string `q:"id"`
Name string `q:"name"`
TenantId string `q:"tenant_id"`
Description string `q:"description"`
Spec string `q:"spec"`
RouterID string `q:"router_id"`
InternalNetworkID string `q:"internal_network_id"`
Status string `q:"status"`
AdminStateUp *bool `q:"admin_state_up"`
CreatedAt string `q:"created_at"`
}

// ToNatGatewayCreateMap allows CreateOpts to satisfy the CreateOptsBuilder
// interface
func (opts CreateOpts) ToNatGatewayCreateMap() (map[string]interface{}, error) {
Expand Down Expand Up @@ -70,6 +85,15 @@ func (opts UpdateOpts) ToNatGatewayUpdateMap() (map[string]interface{}, error) {
return golangsdk.BuildRequestBody(opts, "nat_gateway")
}

func (opts ListOpts) ToNatGatewayListQuery() (string, error) {
q, err := golangsdk.BuildQueryString(opts)
return q.String(), err
}

type ListOptsBuilder interface {
ToNatGatewayListQuery() (string, error)
}

//Update allows nat gateway resources to be updated.
func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToNatGatewayUpdateMap()
Expand All @@ -82,3 +106,18 @@ func Update(c *golangsdk.ServiceClient, id string, opts UpdateOptsBuilder) (r Up
})
return
}

func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := rootURL(c)
if opts != nil {
query, err := opts.ToNatGatewayListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}

return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
return NatGatewayPage{pagination.LinkedPageBase{PageResult: r}}
})
}
29 changes: 29 additions & 0 deletions openstack/networking/v2/extensions/natgateways/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package natgateways

import (
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)

// NatGateway is a struct that represents a nat gateway
Expand Down Expand Up @@ -54,3 +55,31 @@ func (r UpdateResult) Extract() (NatGateway, error) {
type DeleteResult struct {
golangsdk.ErrResult
}

type NatGatewayPage struct {
pagination.LinkedPageBase
}

func (r NatGatewayPage) NextPageURL() (string, error) {
var s struct {
Links []golangsdk.Link `json:"nat_gateways_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return golangsdk.ExtractNextURL(s.Links)
}

func (r NatGatewayPage) IsEmpty() (bool, error) {
is, err := ExtractNatGateways(r)
return len(is) == 0, err
}

func ExtractNatGateways(r pagination.Page) ([]NatGateway, error) {
var s struct {
NatGateways []NatGateway `json:"nat_gateways"`
}
err := (r.(NatGatewayPage)).ExtractInto(&s)
return s.NatGateways, err
}
Loading