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

[NEW] RMS #468

Closed
wants to merge 6 commits into from
Closed
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 acceptance/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ func NewRdsV3() (*golangsdk.ServiceClient, error) {
})
}

func NewRmsV1Client() (*golangsdk.ServiceClient, error) {
cc, err := CloudAndClient()
if err != nil {
return nil, err
}
return openstack.NewRMSV1(cc.ProviderClient, golangsdk.EndpointOpts{Region: cc.RegionName})
}

// NewMrsV1 returns authenticated MRS v1 client
func NewMrsV1() (*golangsdk.ServiceClient, error) {
cc, err := CloudAndClient()
Expand Down
21 changes: 21 additions & 0 deletions acceptance/openstack/rms/v1/rms_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v1

import (
"testing"

"github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients"
"github.com/opentelekomcloud/gophertelekomcloud/acceptance/tools"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rms/v1/resources"
th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
)

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

all, err := resources.ListAllResources(client, resources.ListAllResourcesOpts{
Limit: 1,
})
th.AssertNoErr(t, err)
tools.PrintResource(t, all)
}
9 changes: 9 additions & 0 deletions openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,15 @@ func NewRDSV3(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*gol
return initClientOpts(client, eo, "rdsv3")
}

func NewRMSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
sc, err := initClientOpts(client, eo, "rms")
if err != nil {
return nil, err
}
sc.ResourceBase = sc.Endpoint + "v1/resource-manager/domains/" + client.DomainID + "/"
return sc, err
}

// NewSDRSV1 creates a ServiceClient that may be used with the v1 SDRS service.
func NewSDRSV1(client *golangsdk.ProviderClient, eo golangsdk.EndpointOpts) (*golangsdk.ServiceClient, error) {
return initClientOpts(client, eo, "sdrs")
Expand Down
64 changes: 64 additions & 0 deletions openstack/rms/v1/relations/ShowResourceRelations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package relations

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
"github.com/opentelekomcloud/gophertelekomcloud/openstack/rms/v1/resources"
)

type ShowResourceRelationsOpts struct {
// Specifies the resource ID.
// Maximum length: 256
ResourceId string
// Specifies the resource relationship direction.
// Possible values are as follows:
// - in
// - out
Direction string `q:"direction"`
// Specifies the maximum number of records to return.
// Minimum value: 1
// Maximum value: 1000
Limit int `q:"limit,omitempty"`
// Specifies the pagination parameter.
// You can use the marker value returned to the previous request as the number of the first page of records to return in this request.
// Minimum length: 4
// Maximum length: 400
Marker string `q:"marker,omitempty"`
}

func ShowResourceRelations(client *golangsdk.ServiceClient, opts ShowResourceRelationsOpts) (*ShowResourceRelationsResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v1/resource-manager/domains/{domain_id}/resources/{resource_id}/relations
raw, err := client.Get(client.ServiceURL("resources", opts.ResourceId, "relations")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ShowResourceRelationsResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ShowResourceRelationsResponse struct {
// Specifies the list of the resource relationships.
Relations []ResourceRelation `json:"relations,omitempty"`
// Specifies the pagination object.
PageInfo resources.PageInfo `json:"page_info,omitempty"`
}

type ResourceRelation struct {
// Specifies the relationship type.
RelationType string `json:"relation_type,omitempty"`
// Specifies the type of the source resource.
FromResourceType string `json:"from_resource_type,omitempty"`
// Specifies the type of the associated resource.
ToResourceType string `json:"to_resource_type,omitempty"`
// Specifies the source resource ID.
FromResourceId string `json:"from_resource_id,omitempty"`
// Specifies the ID of the associated resource.
ToResourceId string `json:"to_resource_id,omitempty"`
}
48 changes: 48 additions & 0 deletions openstack/rms/v1/resources/ListAllResources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package resources

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

type ListAllResourcesOpts struct {
// Specifies the region ID.
// Maximum length: 36
RegionId string `q:"region_id,omitempty"`
// Specifies the resource type.
// Maximum length: 40
Type string `q:"type,omitempty"`
// Specifies the maximum number of records to return.
// Minimum value: 1
// Maximum value: 200
Limit int `q:"limit,omitempty"`
// Specifies the pagination parameter.
// You can use the marker value returned in the previous request as the number of the first page of records to return in this request.
// Minimum length: 4
// Maximum length: 400
Marker string `q:"marker,omitempty"`
}

func ListAllResources(client *golangsdk.ServiceClient, opts ListAllResourcesOpts) (*ListAllResourcesResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v1/resource-manager/domains/{domain_id}/all-resources
raw, err := client.Get(client.ServiceURL("all-resources")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListAllResourcesResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListAllResourcesResponse struct {
// Specifies the resource list
Resources []ResourceEntity `json:"resources,omitempty"`
// Specifies the pagination object.
PageInfo PageInfo `json:"page_info,omitempty"`
}
75 changes: 75 additions & 0 deletions openstack/rms/v1/resources/ListProviders.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package resources

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

type ListProvidersOpts struct {
// Specifies the pagination offset.
// Minimum value: 1
// Maximum value: 1000
Offset int `q:"offset,omitempty"`
// Specifies the maximum
// number of records to return.
// Minimum value: 1
// Maximum value: 200
Limit int `q:"limit,omitempty"`
}

func ListProviders(client *golangsdk.ServiceClient, opts ListProvidersOpts) (*ListProvidersResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v1/resource-manager/domains/{domain_id}/providers
raw, err := client.Get(client.ServiceURL("providers")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListProvidersResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListProvidersResponse struct {
// Specifies the list of cloud service details.
ResourceProviders []ResourceProvider `json:"resource_providers,omitempty"`
// Specifies the total number of cloud services supported by RMS.
TotalCount int `json:"total_count,omitempty"`
}

type ResourceProvider struct {
// Specifies the cloud service name. For details, see Supported Resource.
Provider string `json:"provider,omitempty"`
// Specifies the display name of the cloud service.
// You can set the language by configuring XLanguage in the request header
DisplayName string `json:"display_name,omitempty"`
// Specifies the display name of the cloud service category.
// You can set the language by configuring X-Language in the request header.
// Currently supported categories: Computing, Network, Storage, Database, Security, EI Enterprise.
CategoryDisplayName string `json:"category_display_name,omitempty"`
// Specifies the resource type list.
ResourceTypes []ResourceType `json:"resource_types,omitempty"`
}

type ResourceType struct {
// Specifies the resource type.
Name string `json:"name,omitempty"`
// Specifies the display name of the resource type.
// You can set the language by configuring X-Language in the request header.
DisplayName string `json:"display_name,omitempty"`
// Specifies whether the resource is a global resource.
Global *bool `json:"global,omitempty"`
// Specifies the list of supported regions.
// Array of Strings.
Regions []string `json:"regions,omitempty"`
// Specifies the endpoint ID of the console.
ConsoleEndpointId string `json:"console_endpoint_id,omitempty"`
// Specifies the URL of the resource list page.
ConsoleListUrl string `json:"console_list_url,omitempty"`
// Specifies the URL of the resource details page.
ConsoleDetailUrl string `json:"console_detail_url,omitempty"`
}
93 changes: 93 additions & 0 deletions openstack/rms/v1/resources/ListResources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package resources

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

type ListResourcesOpts struct {
// Specifies the cloud service name.
// Maximum length: 20
Provider string
// Specifies the resource type.
// Maximum length: 20
Type string
// Specifies the region ID.
// Maximum length: 36
RegionId string `q:"region_id,omitempty"`
// Specifies the resource tag.
Tag map[string]string `q:"tag,omitempty"`
// Specifies the maximum number of records to return.
// Minimum value: 1
// Maximum value: 200
Limit int `q:"limit,omitempty"`
// Specifies the pagination parameter.
// You can use the marker value returned in the previous request as the number of the first page of records to return in this request.
// Minimum length: 4
// Maximum length: 400
Marker string `q:"marker,omitempty"`
}

func ListResources(client *golangsdk.ServiceClient, opts ListResourcesOpts) (*ListResourcesResponse, error) {
q, err := golangsdk.BuildQueryString(opts)
if err != nil {
return nil, err
}

// GET /v1/resource-manager/domains/{domain_id}/provider/{provider}/type/{type}/resources
raw, err := client.Get(client.ServiceURL("provider", opts.Provider, "type", opts.Type, "resources")+q.String(), nil, nil)
if err != nil {
return nil, err
}

var res ListResourcesResponse
err = extract.Into(raw.Body, &res)
return &res, err
}

type ListResourcesResponse struct {
// Specifies the resource list
Resources []ResourceEntity `json:"resources,omitempty"`
// Specifies the pagination object.
PageInfo PageInfo `json:"page_info,omitempty"`
}

type ResourceEntity struct {
// Specifies the resource ID.
Id string `json:"id,omitempty"`
// Specifies the resource name.
Name string `json:"name,omitempty"`
// Specifies the cloud service name. For details, see Supported Resource.
Provider string `json:"provider,omitempty"`
// Specifies the resource type.
Type string `json:"type,omitempty"`
// Specifies the region ID.
RegionId string `json:"region_id,omitempty"`
// Specifies the project ID in OpenStack.
ProjectId string `json:"project_id,omitempty"`
// Specifies the project name in OpenStack.
ProjectName string `json:"project_name,omitempty"`
// Specifies the resource checksum.
Checksum string `json:"checksum,omitempty"`
// Specifies the time when the resource was created.
Created string `json:"created,omitempty"`
// Specifies the time when the resource was updated.
Updated string `json:"updated,omitempty"`
// Specifies the status of the operation that causes the resource change.
ProvisioningState string `json:"provisioning_state,omitempty"`
// Specifies the resource tags.
Tags map[string]string `json:"tags,omitempty"`
// Specifies the detailed properties of the resource.
Properties map[string]interface{} `json:"properties,omitempty"`
}

type PageInfo struct {
// Specifies the resource quantity on the current page.
// Minimum value: 0
// Maximum value: 200
CurrentCount int `json:"current_count,omitempty"`
// Specifies the marker value of the next page.
// Minimum length: 4
// Maximum length: 400
NextMarker string `json:"next_marker,omitempty"`
}
30 changes: 30 additions & 0 deletions openstack/rms/v1/resources/ShowResourceById.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package resources

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

type ShowResourceByIdOpts struct {
// Specifies the cloud service name.
// Maximum length: 20
Provider string
// Specifies the resource type.
// Maximum length: 20
Type string
// Specifies the resource ID.
// Maximum length: 256
ResourceId string
}

func ShowResourceById(client *golangsdk.ServiceClient, opts ShowResourceByIdOpts) (*ResourceEntity, error) {
// GET /v1/resource-manager/domains/{domain_id}/provider/{provider}/type/{type}/resources/{resource_id}
raw, err := client.Get(client.ServiceURL("provider", opts.Provider, "type", opts.Type, "resources", opts.ResourceId), nil, nil)
if err != nil {
return nil, err
}

var res ResourceEntity
err = extract.Into(raw.Body, &res)
return &res, err
}