github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/acceptance/openstack/autoscaling/helpers.go (about)

     1  package autoscaling
     2  
     3  import (
     4  	"testing"
     5  
     6  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     7  	"github.com/opentelekomcloud/gophertelekomcloud/acceptance/openstack"
     8  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/autoscaling/v1/configurations"
     9  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/autoscaling/v1/groups"
    10  	"github.com/opentelekomcloud/gophertelekomcloud/openstack/common/pointerto"
    11  	th "github.com/opentelekomcloud/gophertelekomcloud/testhelper"
    12  )
    13  
    14  func CreateAutoScalingGroup(t *testing.T, client *golangsdk.ServiceClient, networkID, vpcID, asName string) string {
    15  	defaultSGID := openstack.DefaultSecurityGroup(t)
    16  
    17  	createOpts := groups.CreateOpts{
    18  		Name: asName,
    19  		Networks: []groups.ID{
    20  			{
    21  				ID: networkID,
    22  			},
    23  		},
    24  		SecurityGroup: []groups.ID{
    25  			{
    26  				ID: defaultSGID,
    27  			},
    28  		},
    29  		VpcID:                vpcID,
    30  		IsDeletePublicip:     pointerto.Bool(true),
    31  		DesireInstanceNumber: 1,
    32  		MinInstanceNumber:    1,
    33  		MaxInstanceNumber:    5,
    34  	}
    35  	t.Logf("Attempting to create AutoScaling Group")
    36  	groupID, err := groups.Create(client, createOpts)
    37  	th.AssertNoErr(t, err)
    38  	t.Logf("Created AutoScaling Group: %s", groupID)
    39  
    40  	return groupID
    41  }
    42  
    43  func DeleteAutoScalingGroup(t *testing.T, client *golangsdk.ServiceClient, groupID string) {
    44  	t.Logf("Attempting to delete AutoScaling Group")
    45  	err := groups.Delete(client, groups.DeleteOpts{
    46  		ScalingGroupId: groupID,
    47  	})
    48  	th.AssertNoErr(t, err)
    49  	t.Logf("Deleted AutoScaling Group: %s", groupID)
    50  }
    51  
    52  func CreateASConfig(t *testing.T, client *golangsdk.ServiceClient, asCreateName string, imageID string, keyPairName string) string {
    53  	defaultSGID := openstack.DefaultSecurityGroup(t)
    54  
    55  	t.Logf("Attempting to create AutoScaling Configuration")
    56  	configID, err := configurations.Create(client, configurations.CreateOpts{
    57  		Name: asCreateName,
    58  		InstanceConfig: configurations.InstanceConfigOpts{
    59  			FlavorRef: "s3.medium.1",
    60  			ImageRef:  imageID,
    61  			Disk: []configurations.Disk{
    62  				{
    63  					Size:       40,
    64  					VolumeType: "SSD",
    65  					DiskType:   "SYS",
    66  				},
    67  			},
    68  			SSHKey: keyPairName,
    69  			SecurityGroups: []configurations.SecurityGroup{
    70  				{
    71  					ID: defaultSGID,
    72  				},
    73  			},
    74  			Metadata: configurations.AdminPassMetadata{
    75  				AdminPass: "Test1234",
    76  			},
    77  		},
    78  	})
    79  	th.AssertNoErr(t, err)
    80  	t.Logf("Created AutoScaling Configuration: %s", configID)
    81  	return configID
    82  }
    83  
    84  func DeleteASConfig(t *testing.T, client *golangsdk.ServiceClient, configID string) {
    85  	t.Logf("Attempting to delete AutoScaling Configuration")
    86  	err := configurations.Delete(client, configID)
    87  	th.AssertNoErr(t, err)
    88  	t.Logf("Deleted AutoScaling Configuration: %s", configID)
    89  }