diff --git a/src/core/mcir/common.go b/src/core/mcir/common.go index 160fb8cfe..9805af8d3 100644 --- a/src/core/mcir/common.go +++ b/src/core/mcir/common.go @@ -40,6 +40,8 @@ import ( "reflect" validator "github.com/go-playground/validator/v10" + + "github.com/rs/zerolog/log" ) // CB-Store @@ -1718,10 +1720,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err resultInfo, err := CreateVNet(nsId, &reqTmp, "") if err != nil { - common.CBLog.Error(err) - // If already exist, error will occur - // Even if error, do not return here to update information - // return err + log.Error().Err(err).Msg("Failed to create vNet") + return err } fmt.Printf("[%d] Registered Default vNet\n", i) common.PrintJsonPretty(resultInfo) @@ -1755,10 +1755,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err resultInfo, err := CreateSecurityGroup(nsId, &reqTmp, "") if err != nil { - common.CBLog.Error(err) - // If already exist, error will occur - // Even if error, do not return here to update information - // return err + log.Error().Err(err).Msg("Failed to create SecurityGroup") + return err } fmt.Printf("[%d] Registered Default SecurityGroup\n", i) common.PrintJsonPretty(resultInfo) @@ -1776,10 +1774,8 @@ func LoadDefaultResource(nsId string, resType string, connectionName string) err resultInfo, err := CreateSshKey(nsId, &reqTmp, "") if err != nil { - common.CBLog.Error(err) - // If already exist, error will occur - // Even if error, do not return here to update information - // return err + log.Error().Err(err).Msg("Failed to create SshKey") + return err } fmt.Printf("[%d] Registered Default SSHKey\n", i) common.PrintJsonPretty(resultInfo) diff --git a/src/core/mcis/provisioning.go b/src/core/mcis/provisioning.go index de277b40c..d21e46000 100644 --- a/src/core/mcis/provisioning.go +++ b/src/core/mcis/provisioning.go @@ -1263,7 +1263,17 @@ func CreateMcisDynamic(nsId string, req *TbMcisDynamicReq) (*TbMcisInfo, error) for _, k := range vmRequest { vmReq, err := getVmReqFromDynamicReq(nsId, &k) if err != nil { - common.CBLog.Error(err) + log.Error().Err(err).Msg("Failed to prefare resources for dynamic MCIS creation") + // Rollback created default resources + time.Sleep(5 * time.Second) + log.Info().Msg("Try rollback created default resources") + rollbackResult, rollbackErr := mcir.DelAllDefaultResources(nsId) + if rollbackErr != nil { + err = fmt.Errorf("Failed in rollback operation: %w", rollbackErr) + } else { + ids := strings.Join(rollbackResult.IdList, ", ") + err = fmt.Errorf("Rollback results [%s]: %w", ids, err) + } return emptyMcis, err } mcisReq.Vm = append(mcisReq.Vm, *vmReq)