1.2.2
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
|
||||
@@ -131,7 +132,7 @@ func BServiceResourceCreate(ctx context.Context, plan *models.RecordBasicService
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(serviceId)))
|
||||
|
||||
enable := plan.Enable.ValueBool()
|
||||
if enable && (plan.Status.ValueString() == status.Disabled || plan.Status.ValueString() == status.Created) {
|
||||
if enable {
|
||||
tflog.Info(ctx, "resourceBasicServiceCreate: before calling CloudAPI().BService().Enable", map[string]any{"service_id": serviceId})
|
||||
res, err := c.CloudAPI().BService().Enable(ctx, bservice.EnableRequest{ServiceID: serviceId})
|
||||
if err != nil {
|
||||
@@ -142,7 +143,6 @@ func BServiceResourceCreate(ctx context.Context, plan *models.RecordBasicService
|
||||
return &serviceId, diags
|
||||
}
|
||||
tflog.Info(ctx, "resourceBasicServiceCreate: response from CloudAPI().BService().Enable", map[string]any{"service_id": serviceId, "response": res})
|
||||
return &serviceId, diags
|
||||
}
|
||||
|
||||
if plan.Start.ValueBool() {
|
||||
@@ -153,6 +153,7 @@ func BServiceResourceCreate(ctx context.Context, plan *models.RecordBasicService
|
||||
)
|
||||
return &serviceId, diags
|
||||
}
|
||||
tflog.Info(ctx, "resourceBasicServiceCreate: before calling CloudAPI().BService().Start", map[string]any{"service_id": serviceId})
|
||||
_, err := c.CloudAPI().BService().Start(ctx, bservice.StartRequest{
|
||||
ServiceID: serviceId,
|
||||
})
|
||||
@@ -250,115 +251,124 @@ func StartStopBService(ctx context.Context, plan *models.RecordBasicServiceResou
|
||||
return nil
|
||||
}
|
||||
|
||||
func SnapshotsBService(ctx context.Context, oldSnapshots basetypes.ListValue, newSnapshots basetypes.ListValue, serviceID uint64, c *client.Client) diag.Diagnostics {
|
||||
func SnapshotsBService(ctx context.Context, oldSnapshots basetypes.SetValue, newSnapshots basetypes.SetValue, serviceID uint64, c *client.Client) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
// Handle snapshot changes in the plan
|
||||
tflog.Info(ctx, "Start SnapshotsBService", map[string]any{"service_id": serviceID})
|
||||
|
||||
deletedSnapshots := make([]models.ItemSnapshotResourceModel, 0)
|
||||
addedSnapshots := make([]models.ItemSnapshotResourceModel, 0)
|
||||
updatedSnapshots := make([]models.ItemSnapshotResourceModel, 0)
|
||||
addMap, rollbackMap, deleteMap := differenceSnapshots(oldSnapshots, newSnapshots)
|
||||
|
||||
oldSnapshotsList := make([]models.ItemSnapshotResourceModel, 0, len(oldSnapshots.Elements()))
|
||||
newSnapshotsList := make([]models.ItemSnapshotResourceModel, 0, len(newSnapshots.Elements()))
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be deleted", map[string]any{"deleted_snapshots": deleteMap})
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be added", map[string]any{"added_snapshots": addMap})
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be updated", map[string]any{"updated_snapshots": rollbackMap})
|
||||
|
||||
diags.Append(oldSnapshots.ElementsAs(ctx, &oldSnapshotsList, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "SnapshotsBService: cannot populate SnapshotsBService with plan.Snapshots object element")
|
||||
return diags
|
||||
}
|
||||
|
||||
diags.Append(newSnapshots.ElementsAs(ctx, &newSnapshotsList, true)...)
|
||||
if diags.HasError() {
|
||||
tflog.Error(ctx, "SnapshotsBService: cannot populate SnapshotsBService with plan.Snapshots object element")
|
||||
return diags
|
||||
}
|
||||
|
||||
for _, el := range oldSnapshotsList {
|
||||
if !isContainsSnapshot(newSnapshotsList, el) {
|
||||
deletedSnapshots = append(deletedSnapshots, el)
|
||||
}
|
||||
}
|
||||
|
||||
for _, el := range newSnapshotsList {
|
||||
if !isContainsSnapshot(oldSnapshotsList, el) {
|
||||
addedSnapshots = append(addedSnapshots, el)
|
||||
} else if isRollback(oldSnapshotsList, el) {
|
||||
updatedSnapshots = append(updatedSnapshots, el)
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be deleted", map[string]any{"deleted_snapshots": deletedSnapshots})
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be added", map[string]any{"added_snapshots": addedSnapshots})
|
||||
tflog.Debug(ctx, "SnapshotsBService: Snapshots to be updated", map[string]any{"updated_snapshots": updatedSnapshots})
|
||||
|
||||
if len(deletedSnapshots) > 0 {
|
||||
for _, snapshot := range deletedSnapshots {
|
||||
if len(deleteMap) > 0 {
|
||||
for _, snapshot := range deleteMap {
|
||||
req := bservice.SnapshotDeleteRequest{
|
||||
ServiceID: serviceID,
|
||||
Label: snapshot.Label.ValueString(),
|
||||
Label: snapshot["label"].(types.String).ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "SnapshotsBService: before calling CloudAPI().BService().SnapshotDelete", map[string]any{"service_id": serviceID, "req": req})
|
||||
_, err := c.CloudAPI().BService().SnapshotDelete(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "SnapshotsBService: Failed to delete snapshot")
|
||||
diags.AddError(fmt.Sprintf("SnapshotsBService: failed to delete snapshot %d from service %d",
|
||||
snapshot["label"].(types.String).ValueString(), serviceID), err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "Deleted snapshot", map[string]any{"service_id": serviceID, "label": snapshot.Label})
|
||||
tflog.Info(ctx, "Deleted snapshot", map[string]any{"service_id": serviceID, "label": req.Label})
|
||||
}
|
||||
}
|
||||
|
||||
if len(addedSnapshots) > 0 {
|
||||
for _, snapshot := range addedSnapshots {
|
||||
if len(addMap) > 0 {
|
||||
for _, snapshot := range addMap {
|
||||
req := bservice.SnapshotCreateRequest{
|
||||
ServiceID: serviceID,
|
||||
Label: snapshot.Label.ValueString(),
|
||||
Label: snapshot["label"].(types.String).ValueString(),
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "SnapshotsBService: before calling CloudAPI().BService().SnapshotCreate", map[string]any{"service_id": serviceID, "req": req})
|
||||
_, err := c.CloudAPI().BService().SnapshotCreate(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "SnapshotsBService: Failed to create snapshot")
|
||||
diags.AddError(fmt.Sprintf("SnapshotsBService: failed to create snapshot %d for service %d",
|
||||
snapshot["label"].(types.String).ValueString(), serviceID), err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "Created snapshot", map[string]any{"service_id": serviceID, "label": snapshot.Label})
|
||||
tflog.Info(ctx, "Created snapshot", map[string]any{"service_id": serviceID, "label": req.Label})
|
||||
}
|
||||
}
|
||||
|
||||
if len(updatedSnapshots) > 0 {
|
||||
for _, snapshot := range updatedSnapshots {
|
||||
req := bservice.SnapshotRollbackRequest{
|
||||
ServiceID: serviceID,
|
||||
Label: snapshot.Label.ValueString(),
|
||||
if len(rollbackMap) > 0 {
|
||||
for _, snapshot := range rollbackMap {
|
||||
if snapshot["rollback"].(types.Bool).ValueBool() {
|
||||
req := bservice.SnapshotRollbackRequest{
|
||||
ServiceID: serviceID,
|
||||
Label: snapshot["label"].(types.String).ValueString(),
|
||||
}
|
||||
tflog.Info(ctx, "SnapshotsBService: before calling CloudAPI().BService().SnapshotRollback", map[string]any{"service_id": serviceID, "req": req})
|
||||
_, err := c.CloudAPI().BService().SnapshotRollback(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "SnapshotsBService: Failed to rollback snapshot")
|
||||
diags.AddError(fmt.Sprintf("SnapshotsBService: failed to rollback snapshot %d from service %d",
|
||||
snapshot["label"].(types.String).ValueString(), serviceID), err.Error())
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "Rolled back snapshot", map[string]any{"service_id": serviceID, "label": req.Label})
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().SnapshotRollback(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "SnapshotsBService: Failed to rollback snapshot")
|
||||
return diags
|
||||
}
|
||||
tflog.Info(ctx, "Rolled back snapshot", map[string]any{"service_id": serviceID, "label": snapshot.Label})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func isContainsSnapshot(els []models.ItemSnapshotResourceModel, el models.ItemSnapshotResourceModel) bool {
|
||||
for _, elOld := range els {
|
||||
if elOld.GUID == el.GUID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
func differenceSnapshots(oldSet, newSet types.Set) (added, rollback, removed []map[string]attr.Value) {
|
||||
oldSlice := oldSet.Elements()
|
||||
newSlice := newSet.Elements()
|
||||
|
||||
func isRollback(els []models.ItemSnapshotResourceModel, el models.ItemSnapshotResourceModel) bool {
|
||||
for _, elOld := range els {
|
||||
if elOld.GUID == el.GUID && elOld.Rollback != el.Rollback && el.Rollback.ValueBool() {
|
||||
return true
|
||||
added = make([]map[string]attr.Value, 0)
|
||||
rollback = make([]map[string]attr.Value, 0)
|
||||
removed = make([]map[string]attr.Value, 0)
|
||||
|
||||
for _, oldSnapshot := range oldSlice {
|
||||
oldMap := oldSnapshot.(types.Object).Attributes()
|
||||
found := false
|
||||
for _, newSnapshot := range newSlice {
|
||||
newMap := newSnapshot.(types.Object).Attributes()
|
||||
if newMap["label"] == oldMap["label"] {
|
||||
if newMap["rollback"] != oldMap["rollback"] {
|
||||
rollback = append(rollback, newMap)
|
||||
}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
removed = append(removed, oldMap)
|
||||
}
|
||||
return false
|
||||
|
||||
for _, newSnapshot := range newSlice {
|
||||
newMap := newSnapshot.(types.Object).Attributes()
|
||||
found := false
|
||||
for _, oldSnapshot := range oldSlice {
|
||||
oldMap := oldSnapshot.(types.Object).Attributes()
|
||||
if newMap["label"] == oldMap["label"] {
|
||||
if newMap["rollback"] != oldMap["rollback"] {
|
||||
rollback = append(rollback, newMap)
|
||||
}
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
added = append(added, newMap)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// restoreBservice performs BService Restore request.
|
||||
|
||||
@@ -91,7 +91,7 @@ func BServiceGroupResourceCreate(ctx context.Context, plan *models.ResourceRecor
|
||||
diags.AddError("Unable to add group", err.Error())
|
||||
return diags
|
||||
}
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(plan.CompgroupID.ValueInt64())))
|
||||
plan.ID = types.StringValue(strconv.Itoa(int(compgroupId)))
|
||||
plan.SID = types.StringValue(strconv.Itoa(int(plan.ServiceID.ValueInt64())))
|
||||
|
||||
if plan.Start.ValueBool() {
|
||||
@@ -114,35 +114,48 @@ func BServiceGroupResourceCreate(ctx context.Context, plan *models.ResourceRecor
|
||||
}
|
||||
|
||||
func BServiceGroupResize(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "BServiceGroupResize: start.", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupResize: start.", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupResize: cannot parsed ID compute from plan", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
req := bservice.GroupResizeRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompgroupID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
Count: plan.CompCount.ValueInt64(),
|
||||
Mode: plan.Mode.ValueString(),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().GroupResize(ctx, req)
|
||||
tflog.Info(ctx, "BServiceGroupResize: before calling CloudAPI().BService().GroupResize", map[string]any{"req": req})
|
||||
_, err = c.CloudAPI().BService().GroupResize(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot resize group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompCount.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot resize group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupResize: resize group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupResize: resize group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
return diags
|
||||
}
|
||||
|
||||
func BServiceGroupUpdate(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "BServiceGroupUpdate: start.", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupUpdate: start.", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupResize: cannot parsed ID compute from plan", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
req := bservice.GroupUpdateRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompgroupID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
Name: plan.Name.ValueString(),
|
||||
Role: plan.Role.ValueString(),
|
||||
CPU: uint64(plan.CPU.ValueInt64()),
|
||||
@@ -151,18 +164,19 @@ func BServiceGroupUpdate(ctx context.Context, plan *models.ResourceRecordGroupMo
|
||||
Force: plan.ForceUpdate.ValueBool(),
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().GroupUpdate(ctx, req)
|
||||
tflog.Info(ctx, "BServiceGroupResize: before calling CloudAPI().BService().GroupUpdate", map[string]any{"req": req})
|
||||
_, err = c.CloudAPI().BService().GroupUpdate(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompgroupID.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot update group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupUpdate: update group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupUpdate: update group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
return diags
|
||||
}
|
||||
|
||||
func BServiceGroupReadStatus(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Read status BServiceGroupReadStatus with ID", map[string]any{"service_id": plan.ServiceID.ValueInt64()})
|
||||
tflog.Info(ctx, "Read status BServiceGroupReadStatus with ID", map[string]any{"service_id": plan.SID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
@@ -201,43 +215,56 @@ func BServiceGroupReadStatus(ctx context.Context, plan *models.ResourceRecordGro
|
||||
}
|
||||
|
||||
func BServiceGroupStartStop(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "Start/Stop bservice group", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "Start/Stop bservice group", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupStartStop: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
if plan.Start.ValueBool() {
|
||||
req := bservice.GroupStartRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompgroupID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupStartStop: before calling CloudAPI().BService().GroupStart", map[string]any{"req": req})
|
||||
_, err := c.CloudAPI().BService().GroupStart(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot start bservice group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompCount.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot start bservice group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
} else {
|
||||
req := bservice.GroupStopRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompgroupID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
Force: plan.ForceStop.ValueBool(),
|
||||
}
|
||||
tflog.Info(ctx, "BServiceGroupStartStop: before calling CloudAPI().BService().GroupStop", map[string]any{"req": req})
|
||||
_, err := c.CloudAPI().BService().GroupStop(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot stop bservice group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompCount.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot stop bservice group with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "Start/Stop bservice group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "Start/Stop bservice group successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
return diags
|
||||
}
|
||||
|
||||
func BServiceGroupExtNet(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "update ExtNets", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "update ExtNets", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupStartStop: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
extnetList := make([]uint64, 0, len(plan.ExtNets.Elements()))
|
||||
|
||||
diags.Append(plan.ExtNets.ElementsAs(ctx, &extnetList, true)...)
|
||||
@@ -248,25 +275,32 @@ func BServiceGroupExtNet(ctx context.Context, plan *models.ResourceRecordGroupMo
|
||||
|
||||
req := bservice.GroupUpdateExtNetRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompgroupID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
ExtNets: extnetList,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().GroupUpdateExtNet(ctx, req)
|
||||
tflog.Info(ctx, "BServiceGroupExtNet: before calling CloudAPI().BService().GroupUpdateExtNet", map[string]any{"req": req})
|
||||
_, err = c.CloudAPI().BService().GroupUpdateExtNet(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update bservice group extnets with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompCount.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot update bservice group extnets with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupExtNet: update successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupExtNet: update successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
return diags
|
||||
}
|
||||
|
||||
func BServiceGroupVinses(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
tflog.Info(ctx, "update Vinses", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "update Vinses", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
diags := diag.Diagnostics{}
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupStartStop: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
vinsesList := make([]uint64, 0, len(plan.VINSes.Elements()))
|
||||
|
||||
diags.Append(plan.VINSes.ElementsAs(ctx, &vinsesList, true)...)
|
||||
@@ -277,23 +311,30 @@ func BServiceGroupVinses(ctx context.Context, plan *models.ResourceRecordGroupMo
|
||||
|
||||
req := bservice.GroupUpdateVINSRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
VINSes: vinsesList,
|
||||
}
|
||||
|
||||
_, err := c.CloudAPI().BService().GroupUpdateVINS(ctx, req)
|
||||
tflog.Info(ctx, "BServiceGroupVinses: before calling CloudAPI().BService().GroupUpdateVINS", map[string]any{"req": req})
|
||||
_, err = c.CloudAPI().BService().GroupUpdateVINS(ctx, req)
|
||||
if err != nil {
|
||||
diags.AddError(fmt.Sprintf("Cannot update bservice group vinses with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), plan.CompCount.ValueInt64()), err.Error())
|
||||
diags.AddError(fmt.Sprintf("Cannot update bservice group vinses with ServiceID - %d,CompgroupID - %d ", plan.ServiceID.ValueInt64(), compGroupID), err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupVinses: update successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "BServiceGroupVinses: update successfully", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
return diags
|
||||
}
|
||||
|
||||
func BServiceGroupParents(ctx context.Context, newParents basetypes.ListValue, oldParents basetypes.ListValue, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
tflog.Info(ctx, "Start BServiceGroupParents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "Start BServiceGroupParents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupStartStop: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
deletedParents := make([]uint64, 0)
|
||||
addedParents := make([]uint64, 0)
|
||||
@@ -330,7 +371,7 @@ func BServiceGroupParents(ctx context.Context, newParents basetypes.ListValue, o
|
||||
|
||||
req := bservice.GroupParentRemoveRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompCount.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
ParentID: parent,
|
||||
}
|
||||
|
||||
@@ -340,7 +381,7 @@ func BServiceGroupParents(ctx context.Context, newParents basetypes.ListValue, o
|
||||
return diags
|
||||
}
|
||||
}
|
||||
tflog.Info(ctx, "Deleted parents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "Deleted parents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
}
|
||||
|
||||
if len(addedParents) > 0 {
|
||||
@@ -348,17 +389,17 @@ func BServiceGroupParents(ctx context.Context, newParents basetypes.ListValue, o
|
||||
|
||||
req := bservice.GroupParentAddRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompCount.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
ParentID: parent,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupParents: before calling CloudAPI().BService().GroupParentAdd", map[string]any{"req": req})
|
||||
_, err := c.CloudAPI().BService().GroupParentAdd(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "BServiceGroupParents: Failed to add parent")
|
||||
return diags
|
||||
}
|
||||
}
|
||||
tflog.Info(ctx, "Added parents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.CompgroupID.ValueInt64()})
|
||||
tflog.Info(ctx, "Added parents", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": compGroupID})
|
||||
}
|
||||
|
||||
return diags
|
||||
@@ -366,6 +407,14 @@ func BServiceGroupParents(ctx context.Context, newParents basetypes.ListValue, o
|
||||
|
||||
func BServiceGroupRemoveComputes(ctx context.Context, plan *models.ResourceRecordGroupModel, c *client.Client) diag.Diagnostics {
|
||||
diags := diag.Diagnostics{}
|
||||
tflog.Info(ctx, "Start BServiceGroupRemoveComputes", map[string]any{"service_id": plan.ServiceID.ValueInt64(), "compgroup_id": plan.ID.ValueString()})
|
||||
|
||||
compGroupID, err := strconv.ParseUint(plan.ID.ValueString(), 10, 64)
|
||||
if err != nil {
|
||||
diags.AddError("BServiceGroupStartStop: Cannot parse resource ID from state", err.Error())
|
||||
return diags
|
||||
}
|
||||
|
||||
rcs := plan.RemoveComputes
|
||||
|
||||
rcsList := make([]uint64, 0, len(rcs.Elements()))
|
||||
@@ -379,10 +428,10 @@ func BServiceGroupRemoveComputes(ctx context.Context, plan *models.ResourceRecor
|
||||
for _, rc := range rcsList {
|
||||
req := bservice.GroupComputeRemoveRequest{
|
||||
ServiceID: uint64(plan.ServiceID.ValueInt64()),
|
||||
CompGroupID: uint64(plan.CompCount.ValueInt64()),
|
||||
CompGroupID: compGroupID,
|
||||
ComputeID: rc,
|
||||
}
|
||||
|
||||
tflog.Info(ctx, "BServiceGroupParents: before calling CloudAPI().BService().GroupComputeRemove", map[string]any{"req": req})
|
||||
_, err := c.CloudAPI().BService().GroupComputeRemove(ctx, req)
|
||||
if err != nil {
|
||||
tflog.Error(ctx, "BServiceGroupRemoveComputes: Failed to remove compute")
|
||||
|
||||
Reference in New Issue
Block a user