4.6.0
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
cb_account "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/account"
|
||||
cb_compute "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/compute"
|
||||
cb_disks "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/disks"
|
||||
cb_extnet "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/extnet"
|
||||
cb_gid "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/grid"
|
||||
cb_image "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/image"
|
||||
@@ -15,7 +16,9 @@ import (
|
||||
cb_lb "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/lb"
|
||||
cb_rg "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/rg"
|
||||
cb_stack "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/stack"
|
||||
cb_vfpool "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vfpool"
|
||||
cb_vins "repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/vins"
|
||||
|
||||
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
|
||||
)
|
||||
|
||||
@@ -37,6 +40,78 @@ func ExistRG(ctx context.Context, rgId uint64, c *controller.ControllerCfg) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistRGs(ctx context.Context, rgIDs []uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_rg.ListRequest{}
|
||||
|
||||
rgList, err := c.CloudBroker().RG().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(rgList.Data) == 0 {
|
||||
return fmt.Errorf("you have not been granted access to any resource group")
|
||||
}
|
||||
|
||||
notFound := make([]uint64, 0, len(rgIDs))
|
||||
|
||||
for _, rgID := range rgIDs {
|
||||
found := false
|
||||
|
||||
for _, rg := range rgList.Data {
|
||||
if rgID == rg.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
notFound = append(notFound, rgID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(notFound) > 0 {
|
||||
return fmt.Errorf("RGs with ids %v not found", notFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistAccouts(ctx context.Context, accountIDs []uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_account.ListRequest{}
|
||||
|
||||
accList, err := c.CloudBroker().Account().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(accList.Data) == 0 {
|
||||
return fmt.Errorf("you have not been granted access to any account")
|
||||
}
|
||||
|
||||
notFound := make([]uint64, 0, len(accountIDs))
|
||||
|
||||
for _, accID := range accountIDs {
|
||||
found := false
|
||||
|
||||
for _, acc := range accList.Data {
|
||||
if accID == acc.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
notFound = append(notFound, accID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(notFound) > 0 {
|
||||
return fmt.Errorf("Accounts with ids %v not found", notFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistImage(ctx context.Context, imageId uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_image.ListRequest{
|
||||
ByID: imageId,
|
||||
@@ -54,6 +129,42 @@ func ExistImage(ctx context.Context, imageId uint64, c *controller.ControllerCfg
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistImages(ctx context.Context, imageIDs []uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_image.ListRequest{}
|
||||
|
||||
listImages, err := c.CloudBroker().Image().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(listImages.Data) == 0 {
|
||||
return fmt.Errorf("you have not been granted access to any images")
|
||||
}
|
||||
|
||||
notFound := make([]uint64, 0, len(imageIDs))
|
||||
|
||||
for _, imageID := range imageIDs {
|
||||
found := false
|
||||
|
||||
for _, image := range listImages.Data {
|
||||
if imageID == image.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
notFound = append(notFound, imageID)
|
||||
}
|
||||
}
|
||||
|
||||
if len(notFound) > 0 {
|
||||
return fmt.Errorf("images with ids %v not found", notFound)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistVins(ctx context.Context, vinsId uint64, c *controller.ControllerCfg) error {
|
||||
req := cb_vins.ListRequest{
|
||||
ByID: vinsId,
|
||||
@@ -132,6 +243,35 @@ func ExistExtNets(ctx context.Context, extNetIds []uint64, c *controller.Control
|
||||
return errs
|
||||
}
|
||||
|
||||
func ExistVFPools(ctx context.Context, vfpoolIds []uint64, c *controller.ControllerCfg) []error {
|
||||
var errs []error
|
||||
|
||||
req := cb_vfpool.ListRequest{}
|
||||
|
||||
vfpoolList, err := c.CloudBroker().VFPool().List(ctx, req)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return errs
|
||||
}
|
||||
|
||||
for _, vfpoolId := range vfpoolIds {
|
||||
found := false
|
||||
|
||||
for _, vfpool := range vfpoolList.Data {
|
||||
if vfpoolId == vfpool.ID {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
errs = append(errs, fmt.Errorf("VFPool with ID %v not found", vfpoolId))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
|
||||
func ExistExtNetInLb(ctx context.Context, extNetId uint64, c *controller.ControllerCfg) error {
|
||||
if extNetId == 0 {
|
||||
return nil
|
||||
@@ -404,3 +544,88 @@ func ExistK8s(ctx context.Context, k8sId uint64, c *controller.ControllerCfg) er
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func IsMoreThanOneDisksTypeB(ctx context.Context, disks interface{}) error {
|
||||
count := 0
|
||||
|
||||
for _, elem := range disks.([]interface{}) {
|
||||
diskVal := elem.(map[string]interface{})
|
||||
if diskVal["disk_type"].(string) == "B" {
|
||||
count++
|
||||
}
|
||||
if count > 1 {
|
||||
return fmt.Errorf("block disks have more 1 disk type 'B'")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistDiskID(ctx context.Context, diskId uint64, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := cb_disks.ListRequest{
|
||||
ByID: diskId,
|
||||
}
|
||||
|
||||
diskList, err := c.CloudBroker().Disks().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(diskList.Data) == 0 {
|
||||
return fmt.Errorf("resourceDiskReplication: can't create or update Disk replication because DiskID %d is not allowed or does not exist", diskId)
|
||||
}
|
||||
|
||||
if diskList.Data[0].SEPType != "TATLIN" {
|
||||
return fmt.Errorf("resourceDiskReplication: can't create or update Disk replication because DiskID %d is not TATLIN SEP Type", diskId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistBlankCompute(ctx context.Context, computeId uint64, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
req := cb_compute.GetRequest{ComputeID: computeId}
|
||||
|
||||
// check for compute existence
|
||||
computeRecord, err := c.CloudBroker().Compute().Get(ctx, req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ComputeID %d is not allowed or does not exist", computeId)
|
||||
}
|
||||
|
||||
// check if compute was created as blank
|
||||
computeImageId := computeRecord.ImageID
|
||||
bootImageId := -1
|
||||
for _, d := range computeRecord.Disks {
|
||||
if d.Type == "B" {
|
||||
bootImageId = int(d.ImageID)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if computeImageId != 0 && bootImageId != 0 {
|
||||
return fmt.Errorf("ComputeID %d is not allowed because it is not blank compute (either compute imageId or boot imageId are not zero)", computeId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ExistPlatformDisk(ctx context.Context, diskId uint64, m interface{}) error {
|
||||
c := m.(*controller.ControllerCfg)
|
||||
|
||||
req := cb_disks.ListRequest{
|
||||
ByID: diskId,
|
||||
}
|
||||
|
||||
diskList, err := c.CloudBroker().Disks().List(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(diskList.Data) != 1 {
|
||||
return fmt.Errorf("DiskID %d is not allowed or does not exist", diskId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user