-
Notifications
You must be signed in to change notification settings - Fork 23
Implementation EPS #953
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
Merged
Merged
Implementation EPS #953
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
65ec151
[Feat] Add EPS v1 client and project management functionality
bakhterets dfd4fb7
[Feat] Enhance EPS v1 client with domain-scoped authentication and pr…
bakhterets d054b49
[Feat] Implement full support for EPS v1 API, including resource mana…
bakhterets df17edc
Remove review documentation for EPS v1 API
bakhterets 44bbcb6
[Refactor] Update EPS V1 client initialization to use initClientOpts …
bakhterets 1deba2e
refactoring: EPS v1 project management functionality, including creat…
bakhterets d8a8776
skip tests
anton-sidelnikov 21f07e0
skip tests again
anton-sidelnikov daa4ff1
fix lts hg test (delete codes change)
anton-sidelnikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| package v1 | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/opentelekomcloud/gophertelekomcloud/acceptance/clients" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/openstack/eps/v1/projects" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/openstack/eps/v1/providers" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/openstack/eps/v1/resources" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/openstack/eps/v1/versions" | ||
| th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" | ||
| ) | ||
|
|
||
| func TestEnterpriseProjectsListAndGet(t *testing.T) { | ||
| t.Skip("enterprise project tests not for CI") | ||
| client, err := clients.NewEPSV1Client() | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| allProjects, err := projects.List(client, projects.ListOpts{}) | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| enterpriseProjectID := clients.EnvOS.GetEnv("ENTERPRISE_PROJECT_ID") | ||
| if enterpriseProjectID == "" { | ||
| if len(allProjects.EnterpriseProjects) == 0 { | ||
| t.Skip("no enterprise projects are available") | ||
| } | ||
| enterpriseProjectID = allProjects.EnterpriseProjects[0].ID | ||
| } | ||
|
|
||
| p, err := projects.Get(client, enterpriseProjectID) | ||
| th.AssertNoErr(t, err) | ||
| th.AssertEquals(t, enterpriseProjectID, p.ID) | ||
| } | ||
|
|
||
| func TestEnterpriseProjectsLifecycle(t *testing.T) { | ||
| t.Skip("enterprise project tests not for CI") | ||
| client, err := clients.NewEPSV1Client() | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| suffix := fmt.Sprintf("%d", time.Now().UnixNano()%100000) | ||
| createName := "eps-test-" + suffix | ||
| updateName := "eps-test-upd-" + suffix | ||
|
|
||
| // Create | ||
| created, err := projects.Create(client, projects.CreateOpts{ | ||
| Name: createName, | ||
| Description: "Created by gophertelekomcloud acceptance test", | ||
| }) | ||
| th.AssertNoErr(t, err) | ||
| th.AssertEquals(t, createName, created.Name) | ||
| t.Logf("Created enterprise project: %s (%s)", created.Name, created.ID) | ||
|
|
||
| // Ensure cleanup | ||
| defer func() { | ||
| _ = projects.Action(client, created.ID, projects.ActionOpts{Action: "disable"}) | ||
| }() | ||
|
|
||
| // Update | ||
| updated, err := projects.Update(client, created.ID, projects.UpdateOpts{ | ||
| Name: updateName, | ||
| Description: "Updated by acceptance test", | ||
| }) | ||
| th.AssertNoErr(t, err) | ||
| th.AssertEquals(t, updateName, updated.Name) | ||
|
|
||
| // List with name filter | ||
| filtered, err := projects.List(client, projects.ListOpts{ | ||
| Name: updateName, | ||
| }) | ||
| th.AssertNoErr(t, err) | ||
| if filtered.TotalCount < 1 { | ||
| t.Fatal("expected at least 1 project in filtered list") | ||
| } | ||
|
|
||
| // Disable (Action) | ||
| err = projects.Action(client, created.ID, projects.ActionOpts{Action: "disable"}) | ||
| th.AssertNoErr(t, err) | ||
| t.Log("Disabled enterprise project") | ||
|
|
||
| // Verify disabled | ||
| disabled, err := projects.Get(client, created.ID) | ||
| th.AssertNoErr(t, err) | ||
| th.AssertEquals(t, 2, disabled.Status) | ||
|
|
||
| // Enable (Action) | ||
| err = projects.Action(client, created.ID, projects.ActionOpts{Action: "enable"}) | ||
| th.AssertNoErr(t, err) | ||
| t.Log("Enabled enterprise project") | ||
|
|
||
| // Verify enabled | ||
| enabled, err := projects.Get(client, created.ID) | ||
| th.AssertNoErr(t, err) | ||
| th.AssertEquals(t, 1, enabled.Status) | ||
| } | ||
|
|
||
| func TestVersions(t *testing.T) { | ||
| t.Skip("enterprise project tests not for CI") | ||
| client, err := clients.NewEPSV1Client() | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| allVersions, err := versions.List(client) | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| if len(allVersions) == 0 { | ||
| t.Fatal("expected at least one API version") | ||
| } | ||
| t.Logf("Found %d API version(s)", len(allVersions)) | ||
| for _, v := range allVersions { | ||
| t.Logf(" %s (status: %s)", v.ID, v.Status) | ||
| } | ||
| } | ||
|
|
||
| func TestProviders(t *testing.T) { | ||
| t.Skip("enterprise project tests not for CI") | ||
| client, err := clients.NewEPSV1Client() | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| allProviders, err := providers.List(client, providers.ListOpts{}) | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| if len(allProviders) == 0 { | ||
| t.Fatal("expected at least one provider") | ||
| } | ||
| t.Logf("Found %d provider(s)", len(allProviders)) | ||
| for _, p := range allProviders[:3] { | ||
| t.Logf(" %s (%s)", p.Provider, p.ProviderI18nDisplay) | ||
| } | ||
| } | ||
|
|
||
| func TestResourcesFilter(t *testing.T) { | ||
| t.Skip("enterprise project tests not for CI") | ||
| client, err := clients.NewEPSV1Client() | ||
| th.AssertNoErr(t, err) | ||
|
|
||
| projectID := clients.EnvOS.GetEnv("PROJECT_ID") | ||
| if projectID == "" { | ||
| t.Skip("OS_PROJECT_ID is required for resource filtering") | ||
| } | ||
|
|
||
| result, err := resources.Filter(client, "0", resources.FilterOpts{ | ||
| Projects: []string{projectID}, | ||
| ResourceTypes: []string{"ecs"}, | ||
| Limit: 5, | ||
| }) | ||
| th.AssertNoErr(t, err) | ||
| t.Logf("Found %d resource(s) in default project (total: %d)", len(result.Resources), result.TotalCount) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
| ) | ||
|
|
||
| type ActionOpts struct { | ||
| Action string `json:"action" required:"true"` | ||
| } | ||
|
|
||
| func Action(client *golangsdk.ServiceClient, id string, opts ActionOpts) error { | ||
| b, err := build.RequestBody(opts, "") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = client.Post(client.ServiceURL("enterprise-projects", id, "action"), b, nil, &golangsdk.RequestOpts{ | ||
| OkCodes: []int{200, 204}, | ||
| }) | ||
| return err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
| ) | ||
|
|
||
| type CreateOpts struct { | ||
| Name string `json:"name" required:"true"` | ||
| Description string `json:"description,omitempty"` | ||
| } | ||
|
|
||
| func Create(client *golangsdk.ServiceClient, opts CreateOpts) (*EnterpriseProject, error) { | ||
| b, err := build.RequestBody(opts, "") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| raw, err := client.Post(client.ServiceURL("enterprise-projects"), b, nil, &golangsdk.RequestOpts{ | ||
| OkCodes: []int{200, 201}, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var res EnterpriseProject | ||
| err = extract.IntoStructPtr(raw.Body, &res, "enterprise_project") | ||
| return &res, err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package projects | ||
|
|
||
| // EnterpriseProject represents an EPS enterprise project. | ||
| type EnterpriseProject struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Description string `json:"description"` | ||
| Type string `json:"type"` | ||
| Status int `json:"status"` | ||
| DeleteFlag bool `json:"delete_flag"` | ||
| CreatedAt string `json:"created_at"` | ||
| UpdatedAt string `json:"updated_at"` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
| ) | ||
|
|
||
| func Get(client *golangsdk.ServiceClient, id string) (*EnterpriseProject, error) { | ||
| raw, err := client.Get(client.ServiceURL("enterprise-projects", id), nil, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var res EnterpriseProject | ||
| err = extract.IntoStructPtr(raw.Body, &res, "enterprise_project") | ||
| return &res, err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
| ) | ||
|
|
||
| type ListOpts struct { | ||
| ID string `q:"id"` | ||
| Limit int `q:"limit"` | ||
| Name string `q:"name"` | ||
| Offset int `q:"offset"` | ||
| SortDir string `q:"sort_dir"` | ||
| SortKey string `q:"sort_key"` | ||
| Status int `q:"status"` | ||
| } | ||
|
|
||
| type ListResult struct { | ||
| EnterpriseProjects []EnterpriseProject `json:"enterprise_projects"` | ||
| TotalCount int `json:"total_count"` | ||
| } | ||
|
|
||
| func List(client *golangsdk.ServiceClient, opts ListOpts) (*ListResult, error) { | ||
| q, err := golangsdk.BuildQueryString(&opts) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| raw, err := client.Get(client.ServiceURL("enterprise-projects")+q.String(), nil, nil) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var res ListResult | ||
| err = extract.Into(raw.Body, &res) | ||
| return &res, err | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package projects | ||
|
|
||
| import ( | ||
| golangsdk "github.com/opentelekomcloud/gophertelekomcloud" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/build" | ||
| "github.com/opentelekomcloud/gophertelekomcloud/internal/extract" | ||
| ) | ||
|
|
||
| type UpdateOpts struct { | ||
| Name string `json:"name" required:"true"` | ||
| Description string `json:"description,omitempty"` | ||
| Type string `json:"type,omitempty"` | ||
| } | ||
|
|
||
| func Update(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*EnterpriseProject, error) { | ||
| b, err := build.RequestBody(opts, "") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| raw, err := client.Put(client.ServiceURL("enterprise-projects", id), b, nil, &golangsdk.RequestOpts{ | ||
| OkCodes: []int{200}, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| var res EnterpriseProject | ||
| err = extract.IntoStructPtr(raw.Body, &res, "enterprise_project") | ||
| return &res, err | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.