github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/autoscaling/v1/groups/create.go (about)

     1  package groups
     2  
     3  import (
     4  	"github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  type CreateOpts struct {
    10  	// Specifies the AS group name. The name contains only letters, digits, underscores (_), and hyphens (-), and cannot exceed 64 characters.
    11  	Name string `json:"scaling_group_name" required:"true"`
    12  	// Specifies the AS configuration ID, which can be obtained using the API for querying AS configurations.
    13  	ConfigurationID string `json:"scaling_configuration_id,omitempty"`
    14  	// Specifies the expected number of instances. The default value is the minimum number of instances.
    15  	// The value ranges from the minimum number of instances to the maximum number of instances.
    16  	DesireInstanceNumber int `json:"desire_instance_number,omitempty"`
    17  	// Specifies the minimum number of instances. The default value is 0.
    18  	MinInstanceNumber int `json:"min_instance_number,omitempty"`
    19  	// Specifies the maximum number of instances. The default value is 0.
    20  	MaxInstanceNumber int `json:"max_instance_number,omitempty"`
    21  	// Specifies the cooldown period (in seconds). The value ranges from 0 to 86400 and is 300 by default.
    22  	// After a scaling action is triggered, the system starts the cooldown period. During the cooldown period,
    23  	// scaling actions triggered by alarms will be denied. Scheduled, periodic, and manual scaling actions are not affected..
    24  	CoolDownTime int `json:"cool_down_time,omitempty"`
    25  	// Specifies the ID of a classic load balancer listener. The system supports the binding of up to six
    26  	// load balancer listeners, the IDs of which are separated using a comma (,).
    27  	// This parameter is alternative to lbaas_listeners.
    28  	LBListenerID string `json:"lb_listener_id,omitempty"`
    29  	// Specifies information about an enhanced load balancer. The system supports the binding of up to six load balancers.
    30  	// This parameter is in list data structure.This parameter is alternative to lb_listener_id.
    31  	LBaaSListeners []LBaaSListener `json:"lbaas_listeners,omitempty"`
    32  	// Specifies the AZ information. The instances added in a scaling action will be created in a specified AZ.
    33  	// If you do not specify an AZ, the system automatically specifies one.
    34  	AvailableZones []string `json:"available_zones,omitempty"`
    35  	// Specifies network information. The system supports up to five subnets. The first subnet transferred
    36  	// serves as the primary NIC of the ECS by default. This parameter is in data structure.
    37  	Networks []ID `json:"networks" required:"true"`
    38  	// Specifies the security group information. A maximum of one security group can be selected. This parameter is in data structure.
    39  	// If the security group is specified both in the AS configuration and AS group,
    40  	// scaled ECS instances will be added to the security group specified in the AS configuration.
    41  	// If the security group is not specified in either of them, scaled ECS instances will be added to the default security group.
    42  	// For your convenience, you are advised to specify the security group in the AS configuration.
    43  	SecurityGroup []ID `json:"security_groups,omitempty"`
    44  	// Specifies the VPC ID, which can be obtained using the API for querying VPCs. For details,
    45  	// see "Querying VPCs" in Virtual Private Network API Reference.
    46  	VpcID string `json:"vpc_id" required:"true"`
    47  	// Specifies the health check method for instances in the AS group. The health check methods include ELB_AUDIT and NOVA_AUDIT.
    48  	// When load balancing is configured for an AS group, the default value is ELB_AUDIT. Otherwise, the default value is NOVA_AUDIT.
    49  	// ELB_AUDIT: indicates the ELB health check, which takes effect in an AS group with a listener.
    50  	// NOVA_AUDIT: indicates the ECS instance health check, which is the health check method delivered with AS.
    51  	HealthPeriodicAuditMethod string `json:"health_periodic_audit_method,omitempty"`
    52  	// Specifies the instance health check period. The value can be 1, 5, 15, 60, or 180 in the unit of minutes.
    53  	// If this parameter is not specified, the default value is 5.
    54  	// If the value is set to 0, health check is performed every 10 seconds.
    55  	HealthPeriodicAuditTime int `json:"health_periodic_audit_time,omitempty"`
    56  	// Specifies the grace period for instance health check. The unit is second and value range is 0-86400. The default value is 600.
    57  	// The health check grace period starts after an instance is added to an AS group and is enabled.
    58  	// The AS group will start checking the instance status only after the grace period ends.
    59  	// This parameter is valid only when the instance health check method of the AS group is ELB_AUDIT.
    60  	HealthPeriodicAuditGrace int `json:"health_periodic_audit_grace_period,omitempty"`
    61  	// Specifies the instance removal policy.
    62  	// OLD_CONFIG_OLD_INSTANCE (default): The earlier-created instances based on the earlier-created AS configurations are removed first.
    63  	// OLD_CONFIG_NEW_INSTANCE: The later-created instances based on the earlier-created AS configurations are removed first.
    64  	// OLD_INSTANCE: The earlier-created instances are removed first.
    65  	// NEW_INSTANCE: The later-created instances are removed first.
    66  	InstanceTerminatePolicy string `json:"instance_terminate_policy,omitempty"`
    67  	// Specifies the notification mode.
    68  	// EMAIL refers to notification by email.
    69  	Notifications []string `json:"notifications,omitempty"`
    70  	// Specifies whether to delete the EIP bound to the ECS when deleting the ECS.
    71  	// The value can be true or false. The default value is false.
    72  	// true: deletes the EIP bound to the ECS when deleting the ECS.
    73  	// false: only unbinds the EIP bound to the ECS when deleting the ECS.
    74  	IsDeletePublicip *bool `json:"delete_publicip,omitempty"`
    75  	// Specifies whether to delete the data disks attached to the ECS when deleting the ECS.
    76  	// The value can be true or false. The default value is false.
    77  	// true: deletes the data disks attached to the ECS when deleting the ECS.
    78  	// false: only detaches the data disks attached to the ECS when deleting the ECS.
    79  	IsDeleteVolume *bool `json:"delete_volume,omitempty"`
    80  	// Specifies the enterprise project ID, which is used to specify the enterprise project to which the AS group belongs.
    81  	// If the value is 0 or left blank, the AS group belongs to the default enterprise project.
    82  	// If the value is a UUID, the AS group belongs to the enterprise project corresponding to the UUID.
    83  	// If an enterprise project is configured for an AS group, ECSs created in this AS group also belong to this enterprise project.
    84  	// Otherwise, the default enterprise project will be used.
    85  	EnterpriseProjectID string `json:"enterprise_project_id,omitempty"`
    86  	// Specifies the priority policy used to select target AZs when adjusting the number of instances in an AS group.
    87  	// EQUILIBRIUM_DISTRIBUTE (default): When adjusting the number of instances,
    88  	// ensure that instances in each AZ in the available_zones list is evenly distributed.
    89  	// If instances cannot be added in the target AZ, select another AZ based on the PICK_FIRST policy.
    90  	// PICK_FIRST: When adjusting the number of instances, target AZs are determined in the order in the available_zones list.
    91  	MultiAZPriorityPolicy string `json:"multi_az_priority_policy,omitempty"`
    92  	// Specifies the description of the AS group. The value can contain 1 to 256 characters.
    93  	Description string `json:"description,omitempty"`
    94  }
    95  
    96  type LBaaSListener struct {
    97  	ListenerID string `json:"listener_id"`
    98  	// Specifies the backend ECS group ID.
    99  	PoolID string `json:"pool_id" required:"true"`
   100  	// Specifies the backend protocol ID, which is the port on which a backend ECS listens for traffic. The port ID ranges from 1 to 65535.
   101  	ProtocolPort int `json:"protocol_port" required:"true"`
   102  	// Specifies the weight, which determines the portion of requests a backend ECS processes
   103  	// when being compared to other backend ECSs added to the same listener. The value of this parameter ranges from 0 to 100.
   104  	Weight int `json:"weight" required:"true"`
   105  }
   106  
   107  type ID struct {
   108  	ID string `json:"id" required:"true"`
   109  }
   110  
   111  func Create(client *golangsdk.ServiceClient, opts CreateOpts) (string, error) {
   112  	b, err := build.RequestBody(opts, "")
   113  	if err != nil {
   114  		return "", err
   115  	}
   116  
   117  	raw, err := client.Post(client.ServiceURL("scaling_group"), b, nil, &golangsdk.RequestOpts{
   118  		OkCodes: []int{200},
   119  	})
   120  	if err != nil {
   121  		return "", err
   122  	}
   123  
   124  	var res struct {
   125  		ID string `json:"scaling_group_id"`
   126  	}
   127  	err = extract.Into(raw.Body, &res)
   128  	return res.ID, err
   129  }