Skip to content

Commit d61df5a

Browse files
authored
feat(SMS): add SMS source server overview data source (#7137)
1 parent fc52ac9 commit d61df5a

File tree

4 files changed

+268
-3
lines changed

4 files changed

+268
-3
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
subcategory: "Server Migration Service (SMS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_sms_source_server_overview"
5+
description: |-
6+
Use this data source to obtain a summary of source servers.
7+
---
8+
9+
# huaweicloud_sms_source_server_overview
10+
11+
Use this data source to obtain a summary of source servers.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "huaweicloud_sms_source_server_overview" "test" {}
17+
```
18+
19+
## Attribute Reference
20+
21+
In addition to all arguments above, the following attributes are exported:
22+
23+
* `id` - The data source ID.
24+
25+
* `waiting` - Indicates the number of servers that are in a waiting migration status.
26+
27+
* `replicate` - Indicates the number of servers that are in a replicating migration status.
28+
29+
* `syncing` - Indicates the number of servers that are in a synchronizing migration status.
30+
31+
* `stopped` - Indicates the number of servers that are in a paused migration status.
32+
33+
* `deleting` - Indicates the number of servers that are in a deleting migration status.
34+
35+
* `cutovering` - Indicates the number of servers whose paired target servers are being launched.
36+
37+
* `unavailable` - Indicates the number of servers that fail the environment check.
38+
39+
* `stopping` - Indicates the number of servers that are in a stopping migration status.
40+
41+
* `skipping` - Indicates the number of servers that are in a skipping migration status.
42+
43+
* `finished` - Indicates the number of servers whose paired target servers have been launched.
44+
45+
* `initialize` - Indicates the number of servers that are in an initializing migration status.
46+
47+
* `error` - Indicates the number of servers that are in an error migration status.
48+
49+
* `cloning` - Indicates the number of servers whose paired target servers are being cloned.
50+
51+
* `unconfigured` - Indicates the number of servers that do not have target server configurations.

huaweicloud/provider.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,9 +1360,10 @@ func Provider() *schema.Provider {
13601360
"huaweicloud_smn_logtanks": smn.DataSourceSmnLogtanks(),
13611361
"huaweicloud_smn_topic_subscriptions": smn.DataSourceSmnTopicSubscriptions(),
13621362

1363-
"huaweicloud_sms_source_servers": sms.DataSourceServers(),
1364-
"huaweicloud_sms_agent_configs": sms.DataSourceSmsAgentConfigs(),
1365-
"huaweicloud_sms_migration_projects": sms.DataSourceSmsMigrationProjects(),
1363+
"huaweicloud_sms_source_servers": sms.DataSourceServers(),
1364+
"huaweicloud_sms_agent_configs": sms.DataSourceSmsAgentConfigs(),
1365+
"huaweicloud_sms_migration_projects": sms.DataSourceSmsMigrationProjects(),
1366+
"huaweicloud_sms_source_server_overview": sms.DataSourceSmsSourceServerOverview(),
13661367

13671368
"huaweicloud_sfs_turbos": sfsturbo.DataSourceTurbos(),
13681369
"huaweicloud_sfs_turbos_by_tags": sfsturbo.DataSourceSfsTurbosByTags(),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package sms
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
9+
)
10+
11+
func TestAccDataSourceSmsSourceServerOverview_basic(t *testing.T) {
12+
dataSource := "data.huaweicloud_sms_source_server_overview.test"
13+
dc := acceptance.InitDataSourceCheck(dataSource)
14+
15+
resource.ParallelTest(t, resource.TestCase{
16+
PreCheck: func() {
17+
acceptance.TestAccPreCheck(t)
18+
},
19+
ProviderFactories: acceptance.TestAccProviderFactories,
20+
Steps: []resource.TestStep{
21+
{
22+
Config: testDataSourceDataSourceSmsSourceServerOverview_basic(),
23+
Check: resource.ComposeTestCheckFunc(
24+
dc.CheckResourceExists(),
25+
resource.TestCheckResourceAttrSet(dataSource, "waiting"),
26+
resource.TestCheckResourceAttrSet(dataSource, "replicate"),
27+
resource.TestCheckResourceAttrSet(dataSource, "syncing"),
28+
resource.TestCheckResourceAttrSet(dataSource, "stopped"),
29+
resource.TestCheckResourceAttrSet(dataSource, "deleting"),
30+
resource.TestCheckResourceAttrSet(dataSource, "cutovering"),
31+
resource.TestCheckResourceAttrSet(dataSource, "unavailable"),
32+
resource.TestCheckResourceAttrSet(dataSource, "stopping"),
33+
resource.TestCheckResourceAttrSet(dataSource, "skipping"),
34+
resource.TestCheckResourceAttrSet(dataSource, "finished"),
35+
resource.TestCheckResourceAttrSet(dataSource, "initialize"),
36+
resource.TestCheckResourceAttrSet(dataSource, "error"),
37+
resource.TestCheckResourceAttrSet(dataSource, "cloning"),
38+
resource.TestCheckResourceAttrSet(dataSource, "unconfigured"),
39+
),
40+
},
41+
},
42+
})
43+
}
44+
45+
func testDataSourceDataSourceSmsSourceServerOverview_basic() string {
46+
return `
47+
data "huaweicloud_sms_source_server_overview" "test" {}
48+
`
49+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Generated by PMS #672
2+
package sms
3+
4+
import (
5+
"context"
6+
7+
"github.com/hashicorp/go-multierror"
8+
"github.com/hashicorp/go-uuid"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
11+
"github.com/tidwall/gjson"
12+
13+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
14+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/httphelper"
15+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/schemas"
16+
)
17+
18+
func DataSourceSmsSourceServerOverview() *schema.Resource {
19+
return &schema.Resource{
20+
ReadContext: dataSourceSmsSourceServerOverviewRead,
21+
22+
Schema: map[string]*schema.Schema{
23+
"waiting": {
24+
Type: schema.TypeInt,
25+
Computed: true,
26+
Description: `Indicates the number of servers that are in a waiting migration status.`,
27+
},
28+
"replicate": {
29+
Type: schema.TypeInt,
30+
Computed: true,
31+
Description: `Indicates the number of servers that are in a replicating migration status.`,
32+
},
33+
"syncing": {
34+
Type: schema.TypeInt,
35+
Computed: true,
36+
Description: `Indicates the number of servers that are in a synchronizing migration status.`,
37+
},
38+
"stopped": {
39+
Type: schema.TypeInt,
40+
Computed: true,
41+
Description: `Indicates the number of servers that are in a paused migration status.`,
42+
},
43+
"deleting": {
44+
Type: schema.TypeInt,
45+
Computed: true,
46+
Description: `Indicates the number of servers that are in a deleting migration status.`,
47+
},
48+
"cutovering": {
49+
Type: schema.TypeInt,
50+
Computed: true,
51+
Description: `Indicates the number of servers whose paired target servers are being launched.`,
52+
},
53+
"unavailable": {
54+
Type: schema.TypeInt,
55+
Computed: true,
56+
Description: `Indicates the number of servers that fail the environment check.`,
57+
},
58+
"stopping": {
59+
Type: schema.TypeInt,
60+
Computed: true,
61+
Description: `Indicates the number of servers that are in a stopping migration status.`,
62+
},
63+
"skipping": {
64+
Type: schema.TypeInt,
65+
Computed: true,
66+
Description: `Indicates the number of servers that are in a skipping migration status.`,
67+
},
68+
"finished": {
69+
Type: schema.TypeInt,
70+
Computed: true,
71+
Description: `Indicates the number of servers whose paired target servers have been launched.`,
72+
},
73+
"initialize": {
74+
Type: schema.TypeInt,
75+
Computed: true,
76+
Description: `Indicates the number of servers that are in an initializing migration status.`,
77+
},
78+
"error": {
79+
Type: schema.TypeInt,
80+
Computed: true,
81+
Description: `Indicates the number of servers that are in an error migration status.`,
82+
},
83+
"cloning": {
84+
Type: schema.TypeInt,
85+
Computed: true,
86+
Description: `Indicates the number of servers whose paired target servers are being cloned.`,
87+
},
88+
"unconfigured": {
89+
Type: schema.TypeInt,
90+
Computed: true,
91+
Description: `Indicates the number of servers that do not have target server configurations.`,
92+
},
93+
},
94+
}
95+
}
96+
97+
type SourceServerOverviewDSWrapper struct {
98+
*schemas.ResourceDataWrapper
99+
Config *config.Config
100+
}
101+
102+
func newSourceServerOverviewDSWrapper(d *schema.ResourceData, meta interface{}) *SourceServerOverviewDSWrapper {
103+
return &SourceServerOverviewDSWrapper{
104+
ResourceDataWrapper: schemas.NewSchemaWrapper(d),
105+
Config: meta.(*config.Config),
106+
}
107+
}
108+
109+
func dataSourceSmsSourceServerOverviewRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
110+
wrapper := newSourceServerOverviewDSWrapper(d, meta)
111+
showOverviewRst, err := wrapper.ShowOverview()
112+
if err != nil {
113+
return diag.FromErr(err)
114+
}
115+
116+
id, err := uuid.GenerateUUID()
117+
if err != nil {
118+
return diag.FromErr(err)
119+
}
120+
d.SetId(id)
121+
122+
err = wrapper.showOverviewToSchema(showOverviewRst)
123+
if err != nil {
124+
return diag.FromErr(err)
125+
}
126+
127+
return nil
128+
}
129+
130+
// @API SMS GET /v3/sources/overview
131+
func (w *SourceServerOverviewDSWrapper) ShowOverview() (*gjson.Result, error) {
132+
client, err := w.NewClient(w.Config, "sms")
133+
if err != nil {
134+
return nil, err
135+
}
136+
137+
uri := "/v3/sources/overview"
138+
return httphelper.New(client).
139+
Method("GET").
140+
URI(uri).
141+
Request().
142+
Result()
143+
}
144+
145+
func (w *SourceServerOverviewDSWrapper) showOverviewToSchema(body *gjson.Result) error {
146+
d := w.ResourceData
147+
mErr := multierror.Append(nil,
148+
d.Set("waiting", body.Get("waiting").Value()),
149+
d.Set("replicate", body.Get("replicate").Value()),
150+
d.Set("syncing", body.Get("syncing").Value()),
151+
d.Set("stopped", body.Get("stopped").Value()),
152+
d.Set("deleting", body.Get("deleting").Value()),
153+
d.Set("cutovering", body.Get("cutovering").Value()),
154+
d.Set("unavailable", body.Get("unavailable").Value()),
155+
d.Set("stopping", body.Get("stopping").Value()),
156+
d.Set("skipping", body.Get("skipping").Value()),
157+
d.Set("finished", body.Get("finished").Value()),
158+
d.Set("initialize", body.Get("initialize").Value()),
159+
d.Set("error", body.Get("error").Value()),
160+
d.Set("cloning", body.Get("cloning").Value()),
161+
d.Set("unconfigured", body.Get("unconfigured").Value()),
162+
)
163+
return mErr.ErrorOrNil()
164+
}

0 commit comments

Comments
 (0)