-
Notifications
You must be signed in to change notification settings - Fork 55
service offering. sdk framework rewrite #138
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
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4a18d91
sdk framework rewrite
poddm 7e343ea
adding description to schema fields
poddm f4bbefd
fixing domainids value error
poddm 43f2e65
Adding better cpu_speed description for vmware, xen and kvm
poddm 9099f8e
cleaned up comments
poddm 0ef7e49
Adding service offering details
poddm 692cfca
Adding license header to files. Fixed an issue with setting zone ids…
poddm fa07258
add missing set blocks
poddm fdd4d0d
Update cloudstack/service_offering_schema.go
CodeBleu 5516db9
Merge branch 'main' into offerings
CodeBleu 9ebbb1d
add documentation
poddm 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,270 @@ | ||||||||||
| package cloudstack | ||||||||||
|
|
||||||||||
| import ( | ||||||||||
| "context" | ||||||||||
| "fmt" | ||||||||||
|
|
||||||||||
| "github.com/apache/cloudstack-go/v2/cloudstack" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/resource" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/int32planmodifier" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/types" | ||||||||||
| "github.com/hashicorp/terraform-plugin-framework/types/basetypes" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| var ( | ||||||||||
| _ resource.Resource = &serviceOfferingConstrainedResource{} | ||||||||||
| _ resource.ResourceWithConfigure = &serviceOfferingConstrainedResource{} | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| func NewserviceOfferingConstrainedResource() resource.Resource { | ||||||||||
| return &serviceOfferingConstrainedResource{} | ||||||||||
| } | ||||||||||
|
|
||||||||||
| type serviceOfferingConstrainedResource struct { | ||||||||||
| client *cloudstack.CloudStackClient | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (r *serviceOfferingConstrainedResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { | ||||||||||
| resp.Schema = schema.Schema{ | ||||||||||
| Attributes: serviceOfferingMergeCommonSchema(map[string]schema.Attribute{ | ||||||||||
| "cpu_speed": schema.Int32Attribute{ | ||||||||||
| Description: "Speed of CPU in Mhz. This does not apply to kvm.", | ||||||||||
| Required: true, | ||||||||||
| PlanModifiers: []planmodifier.Int32{ | ||||||||||
| int32planmodifier.RequiresReplace(), | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| "max_cpu_number": schema.Int32Attribute{ | ||||||||||
| Description: "The maximum number of CPUs to be set with Custom Computer Offering", | ||||||||||
poddm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| Required: true, | ||||||||||
| PlanModifiers: []planmodifier.Int32{ | ||||||||||
| int32planmodifier.RequiresReplace(), | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| "max_memory": schema.Int32Attribute{ | ||||||||||
| Description: "The maximum memory size of the custom service offering in MB", | ||||||||||
| Required: true, | ||||||||||
| PlanModifiers: []planmodifier.Int32{ | ||||||||||
| int32planmodifier.RequiresReplace(), | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| "min_cpu_number": schema.Int32Attribute{ | ||||||||||
| Description: "The minimum number of CPUs to be set with Custom Computer Offering", | ||||||||||
poddm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| Required: true, | ||||||||||
| PlanModifiers: []planmodifier.Int32{ | ||||||||||
| int32planmodifier.RequiresReplace(), | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| "min_memory": schema.Int32Attribute{ | ||||||||||
| Description: "The minimum memory size of the custom service offering in MB", | ||||||||||
| Required: true, | ||||||||||
| PlanModifiers: []planmodifier.Int32{ | ||||||||||
| int32planmodifier.RequiresReplace(), | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }), | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (r *serviceOfferingConstrainedResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { | ||||||||||
| // | ||||||||||
| var plan serviceOfferingConstrainedResourceModel | ||||||||||
| var planDiskQosHypervisor ServiceOfferingDiskQosHypervisor | ||||||||||
| var planDiskOffering ServiceOfferingDiskOffering | ||||||||||
| var planDiskQosStorage ServiceOfferingDiskQosStorage | ||||||||||
|
|
||||||||||
| // | ||||||||||
poddm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...) | ||||||||||
| if !plan.ServiceOfferingDiskQosHypervisor.IsNull() { | ||||||||||
| resp.Diagnostics.Append(plan.ServiceOfferingDiskQosHypervisor.As(ctx, &planDiskQosHypervisor, basetypes.ObjectAsOptions{})...) | ||||||||||
| } | ||||||||||
| if !plan.ServiceOfferingDiskOffering.IsNull() { | ||||||||||
| resp.Diagnostics.Append(plan.ServiceOfferingDiskOffering.As(ctx, &planDiskOffering, basetypes.ObjectAsOptions{})...) | ||||||||||
| } | ||||||||||
| if !plan.ServiceOfferingDiskQosStorage.IsNull() { | ||||||||||
| resp.Diagnostics.Append(plan.ServiceOfferingDiskQosStorage.As(ctx, &planDiskQosStorage, basetypes.ObjectAsOptions{})...) | ||||||||||
| } | ||||||||||
| if resp.Diagnostics.HasError() { | ||||||||||
| return | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // common params | ||||||||||
| params := r.client.ServiceOffering.NewCreateServiceOfferingParams(plan.DisplayText.ValueString(), plan.Name.ValueString()) | ||||||||||
| plan.commonCreateParams(ctx, params) | ||||||||||
| planDiskQosHypervisor.commonCreateParams(ctx, params) | ||||||||||
| planDiskOffering.commonCreateParams(ctx, params) | ||||||||||
| planDiskQosStorage.commonCreateParams(ctx, params) | ||||||||||
|
|
||||||||||
| // resource specific params | ||||||||||
| if !plan.CpuSpeed.IsNull() { | ||||||||||
| params.SetCpuspeed(int(plan.CpuSpeed.ValueInt32())) | ||||||||||
| } | ||||||||||
|
Comment on lines
+119
to
+121
|
||||||||||
| if !plan.CpuSpeed.IsNull() { | |
| params.SetCpuspeed(int(plan.CpuSpeed.ValueInt32())) | |
| } | |
| params.SetCpuspeed(int(plan.CpuSpeed.ValueInt32())) |
poddm marked this conversation as resolved.
Show resolved
Hide resolved
poddm marked this conversation as resolved.
Show resolved
Hide resolved
poddm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
poddm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
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.